From 63fc4e7991b8a85c60fd30d3c24ea2adfaf17b4c Mon Sep 17 00:00:00 2001 From: C Jepson Date: Fri, 3 Jun 2016 16:05:09 -0400 Subject: [PATCH] Add rescan and scanfrom options to importprivkey and importscript (#267) --- dcrjson/dcrwalletextcmds.go | 8 +++++--- dcrjson/walletsvrcmds.go | 16 +++++++++------- dcrjson/walletsvrcmds_test.go | 22 +++++++++++++++++++--- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/dcrjson/dcrwalletextcmds.go b/dcrjson/dcrwalletextcmds.go index d934dd19..ce55debc 100644 --- a/dcrjson/dcrwalletextcmds.go +++ b/dcrjson/dcrwalletextcmds.go @@ -281,12 +281,14 @@ func NewGetWalletFeeCmd() *GetWalletFeeCmd { // ImportScriptCmd is a type for handling custom marshaling and // unmarshaling of importscript JSON wallet extension commands. type ImportScriptCmd struct { - Hex string + Hex string + Rescan *bool `jsonrpcdefault:"true"` + ScanFrom *int } // NewImportScriptCmd creates a new GetImportScriptCmd. -func NewImportScriptCmd(hex string) *ImportScriptCmd { - return &ImportScriptCmd{hex} +func NewImportScriptCmd(hex string, rescan *bool, scanFrom *int) *ImportScriptCmd { + return &ImportScriptCmd{hex, rescan, scanFrom} } // ListScriptsCmd is a type for handling custom marshaling and diff --git a/dcrjson/walletsvrcmds.go b/dcrjson/walletsvrcmds.go index e3879660..eda38cbe 100644 --- a/dcrjson/walletsvrcmds.go +++ b/dcrjson/walletsvrcmds.go @@ -235,9 +235,10 @@ func NewGetTransactionCmd(txHash string, includeWatchOnly *bool) *GetTransaction // ImportPrivKeyCmd defines the importprivkey JSON-RPC command. type ImportPrivKeyCmd struct { - PrivKey string - Label *string - Rescan *bool `jsonrpcdefault:"true"` + PrivKey string + Label *string + Rescan *bool `jsonrpcdefault:"true"` + ScanFrom *int } // NewImportPrivKeyCmd returns a new instance which can be used to issue a @@ -245,11 +246,12 @@ type ImportPrivKeyCmd struct { // // The parameters which are pointers indicate they are optional. Passing nil // for optional parameters will use the default value. -func NewImportPrivKeyCmd(privKey string, label *string, rescan *bool) *ImportPrivKeyCmd { +func NewImportPrivKeyCmd(privKey string, label *string, rescan *bool, scanFrom *int) *ImportPrivKeyCmd { return &ImportPrivKeyCmd{ - PrivKey: privKey, - Label: label, - Rescan: rescan, + PrivKey: privKey, + Label: label, + Rescan: rescan, + ScanFrom: scanFrom, } } diff --git a/dcrjson/walletsvrcmds_test.go b/dcrjson/walletsvrcmds_test.go index f3446e23..e5ac0212 100644 --- a/dcrjson/walletsvrcmds_test.go +++ b/dcrjson/walletsvrcmds_test.go @@ -356,7 +356,7 @@ func TestWalletSvrCmds(t *testing.T) { return dcrjson.NewCmd("importprivkey", "abc") }, staticCmd: func() interface{} { - return dcrjson.NewImportPrivKeyCmd("abc", nil, nil) + return dcrjson.NewImportPrivKeyCmd("abc", nil, nil, nil) }, marshalled: `{"jsonrpc":"1.0","method":"importprivkey","params":["abc"],"id":1}`, unmarshalled: &dcrjson.ImportPrivKeyCmd{ @@ -371,7 +371,7 @@ func TestWalletSvrCmds(t *testing.T) { return dcrjson.NewCmd("importprivkey", "abc", "label") }, staticCmd: func() interface{} { - return dcrjson.NewImportPrivKeyCmd("abc", dcrjson.String("label"), nil) + return dcrjson.NewImportPrivKeyCmd("abc", dcrjson.String("label"), nil, nil) }, marshalled: `{"jsonrpc":"1.0","method":"importprivkey","params":["abc","label"],"id":1}`, unmarshalled: &dcrjson.ImportPrivKeyCmd{ @@ -386,7 +386,7 @@ func TestWalletSvrCmds(t *testing.T) { return dcrjson.NewCmd("importprivkey", "abc", "label", false) }, staticCmd: func() interface{} { - return dcrjson.NewImportPrivKeyCmd("abc", dcrjson.String("label"), dcrjson.Bool(false)) + return dcrjson.NewImportPrivKeyCmd("abc", dcrjson.String("label"), dcrjson.Bool(false), nil) }, marshalled: `{"jsonrpc":"1.0","method":"importprivkey","params":["abc","label",false],"id":1}`, unmarshalled: &dcrjson.ImportPrivKeyCmd{ @@ -395,6 +395,22 @@ func TestWalletSvrCmds(t *testing.T) { Rescan: dcrjson.Bool(false), }, }, + { + name: "importprivkey optional3", + newCmd: func() (interface{}, error) { + return dcrjson.NewCmd("importprivkey", "abc", "label", false, 12345) + }, + staticCmd: func() interface{} { + return dcrjson.NewImportPrivKeyCmd("abc", dcrjson.String("label"), dcrjson.Bool(false), dcrjson.Int(12345)) + }, + marshalled: `{"jsonrpc":"1.0","method":"importprivkey","params":["abc","label",false,12345],"id":1}`, + unmarshalled: &dcrjson.ImportPrivKeyCmd{ + PrivKey: "abc", + Label: dcrjson.String("label"), + Rescan: dcrjson.Bool(false), + ScanFrom: dcrjson.Int(12345), + }, + }, { name: "keypoolrefill", newCmd: func() (interface{}, error) {