mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 03:47:18 +00:00
cli: export GetAccFromContext and GetUnlockedAccount methods
Exported to avoid code duplication. Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
parent
7a1bf77585
commit
20a57d8337
2 changed files with 9 additions and 6 deletions
|
@ -37,7 +37,7 @@ func manifestAddGroup(ctx *cli.Context) error {
|
||||||
|
|
||||||
h := state.CreateContractHash(sender, nf.Checksum, m.Name)
|
h := state.CreateContractHash(sender, nf.Checksum, m.Name)
|
||||||
|
|
||||||
gAcc, w, err := getAccFromContext(ctx)
|
gAcc, w, err := GetAccFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(fmt.Errorf("can't get account to sign group with: %w", err), 1)
|
return cli.NewExitError(fmt.Errorf("can't get account to sign group with: %w", err), 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -581,7 +581,7 @@ func invokeInternal(ctx *cli.Context, signAndPush bool) error {
|
||||||
w *wallet.Wallet
|
w *wallet.Wallet
|
||||||
)
|
)
|
||||||
if signAndPush {
|
if signAndPush {
|
||||||
acc, w, err = getAccFromContext(ctx)
|
acc, w, err = GetAccFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
@ -757,7 +757,8 @@ func inspect(ctx *cli.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAccFromContext(ctx *cli.Context) (*wallet.Account, *wallet.Wallet, error) {
|
// GetAccFromContext returns account and wallet from context. If address is not set, default address is used.
|
||||||
|
func GetAccFromContext(ctx *cli.Context) (*wallet.Account, *wallet.Wallet, error) {
|
||||||
var addr util.Uint160
|
var addr util.Uint160
|
||||||
|
|
||||||
wPath := ctx.String("wallet")
|
wPath := ctx.String("wallet")
|
||||||
|
@ -789,11 +790,13 @@ func getAccFromContext(ctx *cli.Context) (*wallet.Account, *wallet.Wallet, error
|
||||||
addr = wall.GetChangeAddress()
|
addr = wall.GetChangeAddress()
|
||||||
}
|
}
|
||||||
|
|
||||||
acc, err := getUnlockedAccount(wall, addr, pass)
|
acc, err := GetUnlockedAccount(wall, addr, pass)
|
||||||
return acc, wall, err
|
return acc, wall, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUnlockedAccount(wall *wallet.Wallet, addr util.Uint160, pass *string) (*wallet.Account, error) {
|
// GetUnlockedAccount returns account from wallet, address and uses pass to unlock specified account if given.
|
||||||
|
// If the password is not given, then it is requested from user.
|
||||||
|
func GetUnlockedAccount(wall *wallet.Wallet, addr util.Uint160, pass *string) (*wallet.Account, error) {
|
||||||
acc := wall.GetAccount(addr)
|
acc := wall.GetAccount(addr)
|
||||||
if acc == nil {
|
if acc == nil {
|
||||||
return nil, fmt.Errorf("wallet contains no account for '%s'", address.Uint160ToString(addr))
|
return nil, fmt.Errorf("wallet contains no account for '%s'", address.Uint160ToString(addr))
|
||||||
|
@ -844,7 +847,7 @@ func contractDeploy(ctx *cli.Context) error {
|
||||||
appCallParams = append(appCallParams, data[0])
|
appCallParams = append(appCallParams, data[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
acc, w, err := getAccFromContext(ctx)
|
acc, w, err := GetAccFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(fmt.Errorf("can't get sender address: %w", err), 1)
|
return cli.NewExitError(fmt.Errorf("can't get sender address: %w", err), 1)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue