From cc5ec8e6d6b3fc949980492f38ce971de1769504 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 13 Mar 2020 17:03:38 +0300 Subject: [PATCH] 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. --- cli/wallet/wallet.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index 71f4fbe9a..b6cfb7f9a 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -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)