(cmd *Command, args []string)
| 66 | } |
| 67 | |
| 68 | func runTransfer(cmd *Command, args []string) { |
| 69 | commonFlagsInit(cmd) |
| 70 | |
| 71 | if len(args) > 0 || (toUser == "" && toDSN == "") || tokenType == "" { |
| 72 | ConsoleLog.Error("transfer command need to-user(or to-dsn) address and token type as param") |
| 73 | SetExitStatus(1) |
| 74 | printCommandHelp(cmd) |
| 75 | Exit() |
| 76 | } |
| 77 | if toUser != "" && toDSN != "" { |
| 78 | ConsoleLog.Error("transfer command accepts either to-user or to-dsn as param") |
| 79 | SetExitStatus(1) |
| 80 | printCommandHelp(cmd) |
| 81 | Exit() |
| 82 | } |
| 83 | |
| 84 | unit := types.FromString(tokenType) |
| 85 | if !unit.Listed() { |
| 86 | ConsoleLog.Error("transfer token failed: invalid token type") |
| 87 | SetExitStatus(1) |
| 88 | return |
| 89 | } |
| 90 | |
| 91 | var addr string |
| 92 | if toUser != "" { |
| 93 | addr = toUser |
| 94 | } else { |
| 95 | if !strings.HasPrefix(toDSN, client.DBScheme) && !strings.HasPrefix(toDSN, client.DBSchemeAlias) { |
| 96 | ConsoleLog.Error("transfer token failed: invalid dsn provided, use address start with 'covenantsql://'") |
| 97 | SetExitStatus(1) |
| 98 | return |
| 99 | } |
| 100 | toDSN = strings.TrimLeft(toDSN, client.DBScheme+"://") |
| 101 | addr = strings.TrimLeft(toDSN, client.DBSchemeAlias+"://") |
| 102 | } |
| 103 | |
| 104 | targetAccountHash, err := hash.NewHashFromStr(addr) |
| 105 | if err != nil { |
| 106 | ConsoleLog.WithError(err).Error("target account address is not valid") |
| 107 | SetExitStatus(1) |
| 108 | return |
| 109 | } |
| 110 | targetAccount := proto.AccountAddress(*targetAccountHash) |
| 111 | |
| 112 | configInit() |
| 113 | |
| 114 | txHash, err := client.TransferToken(targetAccount, amount, unit) |
| 115 | if err != nil { |
| 116 | ConsoleLog.WithError(err).Error("transfer token failed") |
| 117 | SetExitStatus(1) |
| 118 | return |
| 119 | } |
| 120 | |
| 121 | if waitTxConfirmation { |
| 122 | err = wait(txHash) |
| 123 | if err != nil { |
| 124 | ConsoleLog.WithError(err).Error("transfer token failed") |
| 125 | SetExitStatus(1) |
nothing calls this directly
no test coverage detected