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,17 +211,38 @@ func TestNEP17MultiTransfer(t *testing.T) {
|
|||
"GAS:" + privs[1].Address() + ":7",
|
||||
neoContractHash.StringLE() + ":" + privs[2].Address() + ":13",
|
||||
}
|
||||
hVerify := deployVerifyContract(t, e)
|
||||
|
||||
e.In.WriteString("one\r")
|
||||
e.Run(t, args...)
|
||||
e.checkTxPersisted(t)
|
||||
t.Run("no cosigners", func(t *testing.T) {
|
||||
e.In.WriteString("one\r")
|
||||
e.Run(t, args...)
|
||||
e.checkTxPersisted(t)
|
||||
|
||||
b, _ := e.Chain.GetGoverningTokenBalance(privs[0].GetScriptHash())
|
||||
require.Equal(t, big.NewInt(42), b)
|
||||
b = e.Chain.GetUtilityTokenBalance(privs[1].GetScriptHash())
|
||||
require.Equal(t, big.NewInt(int64(fixedn.Fixed8FromInt64(7))), b)
|
||||
b, _ = e.Chain.GetGoverningTokenBalance(privs[2].GetScriptHash())
|
||||
require.Equal(t, big.NewInt(13), b)
|
||||
b, _ := e.Chain.GetGoverningTokenBalance(privs[0].GetScriptHash())
|
||||
require.Equal(t, big.NewInt(42), b)
|
||||
b = e.Chain.GetUtilityTokenBalance(privs[1].GetScriptHash())
|
||||
require.Equal(t, big.NewInt(int64(fixedn.Fixed8FromInt64(7))), b)
|
||||
b, _ = e.Chain.GetGoverningTokenBalance(privs[2].GetScriptHash())
|
||||
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) {
|
||||
|
|
|
@ -126,7 +126,7 @@ func newNEP17Commands() []cli.Command {
|
|||
Name: "multitransfer",
|
||||
Usage: "transfer NEP17 tokens to multiple recipients",
|
||||
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,
|
||||
Flags: multiTransferFlags,
|
||||
},
|
||||
|
@ -384,10 +384,17 @@ func multiTransferNEP17(ctx *cli.Context) error {
|
|||
if ctx.NArg() == 0 {
|
||||
return cli.NewExitError("empty recipients list", 1)
|
||||
}
|
||||
var recipients []client.TransferTarget
|
||||
var (
|
||||
recipients []client.TransferTarget
|
||||
cosignersOffset = ctx.NArg()
|
||||
)
|
||||
cache := make(map[string]*wallet.Token)
|
||||
for i := 0; i < ctx.NArg(); i++ {
|
||||
arg := ctx.Args().Get(i)
|
||||
if arg == cmdargs.CosignersSeparator {
|
||||
cosignersOffset = i + 1
|
||||
break
|
||||
}
|
||||
ss := strings.SplitN(arg, ":", 3)
|
||||
if len(ss) != 3 {
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue