forked from TrueCloudLab/neoneo-go
cli: allow to provide cosigners for 'wallet nep17 multitransfer'
This commit is contained in:
parent
f848783d5d
commit
14c2d7d25a
2 changed files with 49 additions and 12 deletions
|
@ -211,7 +211,9 @@ func TestNEP17MultiTransfer(t *testing.T) {
|
||||||
"GAS:" + privs[1].Address() + ":7",
|
"GAS:" + privs[1].Address() + ":7",
|
||||||
neoContractHash.StringLE() + ":" + privs[2].Address() + ":13",
|
neoContractHash.StringLE() + ":" + privs[2].Address() + ":13",
|
||||||
}
|
}
|
||||||
|
hVerify := deployVerifyContract(t, e)
|
||||||
|
|
||||||
|
t.Run("no cosigners", func(t *testing.T) {
|
||||||
e.In.WriteString("one\r")
|
e.In.WriteString("one\r")
|
||||||
e.Run(t, args...)
|
e.Run(t, args...)
|
||||||
e.checkTxPersisted(t)
|
e.checkTxPersisted(t)
|
||||||
|
@ -222,6 +224,25 @@ func TestNEP17MultiTransfer(t *testing.T) {
|
||||||
require.Equal(t, big.NewInt(int64(fixedn.Fixed8FromInt64(7))), b)
|
require.Equal(t, big.NewInt(int64(fixedn.Fixed8FromInt64(7))), b)
|
||||||
b, _ = e.Chain.GetGoverningTokenBalance(privs[2].GetScriptHash())
|
b, _ = e.Chain.GetGoverningTokenBalance(privs[2].GetScriptHash())
|
||||||
require.Equal(t, big.NewInt(13), b)
|
require.Equal(t, big.NewInt(13), b)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("invalid sender scope", func(t *testing.T) {
|
||||||
|
e.In.WriteString("one\r")
|
||||||
|
e.RunWithError(t, append(args,
|
||||||
|
"--", validatorAddr+":None")...) // invalid sender scope
|
||||||
|
})
|
||||||
|
t.Run("Global sender scope", func(t *testing.T) {
|
||||||
|
e.In.WriteString("one\r")
|
||||||
|
e.Run(t, append(args,
|
||||||
|
"--", validatorAddr+":Global")...)
|
||||||
|
e.checkTxPersisted(t)
|
||||||
|
})
|
||||||
|
t.Run("Several cosigners", func(t *testing.T) {
|
||||||
|
e.In.WriteString("one\r")
|
||||||
|
e.Run(t, append(args,
|
||||||
|
"--", validatorAddr, hVerify.StringLE())...)
|
||||||
|
e.checkTxPersisted(t)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNEP17ImportToken(t *testing.T) {
|
func TestNEP17ImportToken(t *testing.T) {
|
||||||
|
|
|
@ -126,7 +126,7 @@ func newNEP17Commands() []cli.Command {
|
||||||
Name: "multitransfer",
|
Name: "multitransfer",
|
||||||
Usage: "transfer NEP17 tokens to multiple recipients",
|
Usage: "transfer NEP17 tokens to multiple recipients",
|
||||||
UsageText: `multitransfer --wallet <path> --rpc-endpoint <node> --timeout <time> --from <addr>` +
|
UsageText: `multitransfer --wallet <path> --rpc-endpoint <node> --timeout <time> --from <addr>` +
|
||||||
` <token1>:<addr1>:<amount1> [<token2>:<addr2>:<amount2> [...]]`,
|
` <token1>:<addr1>:<amount1> [<token2>:<addr2>:<amount2> [...]] [-- <cosigner1:Scope> [<cosigner2> [...]]]`,
|
||||||
Action: multiTransferNEP17,
|
Action: multiTransferNEP17,
|
||||||
Flags: multiTransferFlags,
|
Flags: multiTransferFlags,
|
||||||
},
|
},
|
||||||
|
@ -384,10 +384,17 @@ func multiTransferNEP17(ctx *cli.Context) error {
|
||||||
if ctx.NArg() == 0 {
|
if ctx.NArg() == 0 {
|
||||||
return cli.NewExitError("empty recipients list", 1)
|
return cli.NewExitError("empty recipients list", 1)
|
||||||
}
|
}
|
||||||
var recipients []client.TransferTarget
|
var (
|
||||||
|
recipients []client.TransferTarget
|
||||||
|
cosignersOffset = ctx.NArg()
|
||||||
|
)
|
||||||
cache := make(map[string]*wallet.Token)
|
cache := make(map[string]*wallet.Token)
|
||||||
for i := 0; i < ctx.NArg(); i++ {
|
for i := 0; i < ctx.NArg(); i++ {
|
||||||
arg := ctx.Args().Get(i)
|
arg := ctx.Args().Get(i)
|
||||||
|
if arg == cmdargs.CosignersSeparator {
|
||||||
|
cosignersOffset = i + 1
|
||||||
|
break
|
||||||
|
}
|
||||||
ss := strings.SplitN(arg, ":", 3)
|
ss := strings.SplitN(arg, ":", 3)
|
||||||
if len(ss) != 3 {
|
if len(ss) != 3 {
|
||||||
return cli.NewExitError("send format must be '<token>:<addr>:<amount>", 1)
|
return cli.NewExitError("send format must be '<token>:<addr>:<amount>", 1)
|
||||||
|
@ -420,7 +427,16 @@ func multiTransferNEP17(ctx *cli.Context) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return signAndSendTransfer(ctx, c, acc, recipients, nil)
|
cosigners, extErr := cmdargs.GetSignersFromContext(ctx, cosignersOffset)
|
||||||
|
if extErr != nil {
|
||||||
|
return extErr
|
||||||
|
}
|
||||||
|
cosignersAccounts, err := cmdargs.GetSignersAccounts(wall, cosigners)
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(fmt.Errorf("failed to create NEP17 multitransfer transaction: %w", err), 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return signAndSendTransfer(ctx, c, acc, recipients, cosignersAccounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func transferNEP17(ctx *cli.Context) error {
|
func transferNEP17(ctx *cli.Context) error {
|
||||||
|
|
Loading…
Reference in a new issue