Add rescan and scanfrom options to importprivkey and importscript (#267)

This commit is contained in:
C Jepson 2016-06-03 16:05:09 -04:00 committed by Alex Yocom-Piatt
parent 164f67787b
commit 63fc4e7991
3 changed files with 33 additions and 13 deletions

View File

@ -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

View File

@ -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,
}
}

View File

@ -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) {