forked from TrueCloudLab/neoneo-go
cli: move combining signers and accounts to a separate package
This code will be reused in other packages.
This commit is contained in:
parent
94316fa36d
commit
16fa191ccb
2 changed files with 23 additions and 9 deletions
|
@ -7,7 +7,10 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/cli/flags"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
|
@ -128,3 +131,20 @@ func ParseParams(args []string, calledFromMain bool) (int, []smartcontract.Param
|
|||
}
|
||||
return 0, []smartcontract.Parameter{}, errors.New("invalid array syntax: missing closing bracket")
|
||||
}
|
||||
|
||||
// GetSignersAccounts returns the list of signers combined with the corresponding
|
||||
// accounts from the provided wallet.
|
||||
func GetSignersAccounts(wall *wallet.Wallet, signers []transaction.Signer) ([]client.SignerAccount, error) {
|
||||
signersAccounts := make([]client.SignerAccount, len(signers))
|
||||
for i := range signers {
|
||||
signerAcc := wall.GetAccount(signers[i].Account)
|
||||
if signerAcc == nil {
|
||||
return nil, fmt.Errorf("no account was found in the wallet for signer #%d (%s)", i, address.Uint160ToString(signers[i].Account))
|
||||
}
|
||||
signersAccounts[i] = client.SignerAccount{
|
||||
Signer: signers[i],
|
||||
Account: signerAcc,
|
||||
}
|
||||
}
|
||||
return signersAccounts, nil
|
||||
}
|
||||
|
|
|
@ -555,15 +555,9 @@ func invokeInternal(ctx *cli.Context, signAndPush bool) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := range cosigners {
|
||||
cosignerAcc := wall.GetAccount(cosigners[i].Account)
|
||||
if cosignerAcc == nil {
|
||||
return cli.NewExitError(fmt.Errorf("can't calculate network fee: no account was found in the wallet for cosigner #%d", i), 1)
|
||||
}
|
||||
cosignersAccounts = append(cosignersAccounts, client.SignerAccount{
|
||||
Signer: cosigners[i],
|
||||
Account: cosignerAcc,
|
||||
})
|
||||
cosignersAccounts, err = cmdargs.GetSignersAccounts(wall, cosigners)
|
||||
if err != nil {
|
||||
return cli.NewExitError(fmt.Errorf("failed to calculate network fee: %w", err), 1)
|
||||
}
|
||||
}
|
||||
gctx, cancel := options.GetTimeoutContext(ctx)
|
||||
|
|
Loading…
Reference in a new issue