forked from iost-official/go-iost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcall.go
41 lines (37 loc) · 1.25 KB
/
call.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package iwallet
import (
"github.com/spf13/cobra"
"github.com/iost-official/go-iost/rpc/pb"
)
// callCmd represents the call command that call a contract with given actions.
var callCmd = &cobra.Command{
Use: "call [ACTION]...",
Short: "Call the method in contracts",
Long: `Call the method in contracts
Would accept arguments as call actions or load transaction request directly from given file (which could be generated by "save" command).
An ACTION is a group of 3 arguments: contract name, function name, method parameters.
The method parameters should be a string with format '["arg0","arg1",...]'.`,
Example: ` iwallet call "token.iost" "transfer" '["iost","user0001","user0002","123.45",""]' --account test0
iwallet call "token.iost" "transfer" '["iost","user0001","user0002","123.45",""]' --output tx.json`,
Args: func(cmd *cobra.Command, args []string) error {
if outputTxFile == "" {
return checkAccount(cmd)
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
var actions []*rpcpb.Action
actions, err := actionsFromFlags(args)
if err != nil {
return err
}
tx, err := initTxFromActions(actions)
if err != nil {
return err
}
return saveOrSendTx(tx)
},
}
func init() {
rootCmd.AddCommand(callCmd)
}