Add arguments to transactions send
package send
import (
+ "github.com/onflow/cadence"
"io/ioutil"
"log"
"os"
@@ -31,9 +32,10 @@ import (
)
type Config struct {
- Signer string `default:"service" flag:"signer,s"`
+ Args string `default:"" flag:"args" info:"arguments to pass to transaction"`
Code string `flag:"code,c" info:"path to Cadence file"`
Host string `flag:"host" info:"Flow Access API host address"`
+ Signer string `default:"service" flag:"signer,s"`
Results bool `default:"false" flag:"results" info:"Display the results of the transaction"`
}
@@ -42,6 +44,7 @@ var conf Config
var Cmd = &cobra.Command{
Use: "send",
Short: "Send a transaction",
+ Example: `flow transactions send --code=./tx.cdc --args="[{\"type\": \"String\", \"value\": \"Hello, Cadence\"}]"`,
Run: func(cmd *cobra.Command, args []string) {
projectConf := cli.LoadConfig()
@@ -59,10 +62,28 @@ var Cmd = &cobra.Command{
}
}
- tx := flow.NewTransaction().
+ tx := flow.
+ NewTransaction().
SetScript(code).
AddAuthorizer(signerAccount.Address)
+ // Arguments
+ transactionArguments := make([]cadence.Value, 0)
+ if conf.Args != "" {
+ transactionArguments, err = cli.ParseArguments(conf.Args)
+ if err != nil {
+ cli.Exitf(1, "Invalid arguments passed: %s", conf.Args)
+ }
+
+ for _, arg := range transactionArguments {
+ err := tx.AddArgument(arg)
+
+ if err != nil {
+ cli.Exitf(1, "Failed to add %s argument to a transaction ", conf.Code)
+ }
+ }
+ }
+
cli.SendTransaction(projectConf.HostWithOverride(conf.Host), signerAccount, tx, conf.Results)
},
}
