cli: support contract import in wallets

Sometimes we need to use custom verification script, e.g.
for contracts where funds needs to become accessible only
after a certain amount of time.
This commit is contained in:
Evgenii Stratonikov 2020-03-13 17:03:38 +03:00
parent ffc0729adb
commit cc5ec8e6d6

View file

@ -3,6 +3,7 @@ package wallet
import (
"bufio"
"context"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
@ -143,6 +144,10 @@ func NewCommands() []cli.Command {
Name: "name, n",
Usage: "Optional account name",
},
cli.StringFlag{
Name: "contract",
Usage: "Verification script for custom contracts",
},
},
},
{
@ -403,6 +408,14 @@ func importWallet(ctx *cli.Context) error {
return cli.NewExitError(err, 1)
}
if ctrFlag := ctx.String("contract"); ctrFlag != "" {
ctr, err := hex.DecodeString(ctrFlag)
if err != nil {
return cli.NewExitError("invalid contract", 1)
}
acc.Contract.Script = ctr
}
acc.Label = ctx.String("name")
if err := addAccountAndSave(wall, acc); err != nil {
return cli.NewExitError(err, 1)