MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / runTransfer

Function runTransfer

cmd/cql/internal/transfer.go:68–131  ·  view source on GitHub ↗
(cmd *Command, args []string)

Source from the content-addressed store, hash-verified

66}
67
68func 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)

Callers

nothing calls this directly

Calls 14

FromStringFunction · 0.92
NewHashFromStrFunction · 0.92
AccountAddressTypeAlias · 0.92
TransferTokenFunction · 0.92
commonFlagsInitFunction · 0.85
SetExitStatusFunction · 0.85
printCommandHelpFunction · 0.85
ExitFunction · 0.85
configInitFunction · 0.85
waitFunction · 0.85
ErrorMethod · 0.80
ListedMethod · 0.80

Tested by

no test coverage detected