From fd99f572cfd52ca722ad501ccb34acdcb22b4a67 Mon Sep 17 00:00:00 2001 From: githubsands Date: Fri, 30 Mar 2018 13:00:41 -0600 Subject: [PATCH] dcrjson: Add VerifySeedCmd. --- Gopkg.lock | 6 +++--- dcrjson/walletsvrcmds.go | 21 ++++++++++++++++++++- dcrjson/walletsvrcmds_test.go | 31 ++++++++++++++++++++++++++++++- dcrjson/walletsvrresults.go | 9 ++++++++- rpcserver.go | 1 + 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 332ef64f..10828d4a 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -87,7 +87,7 @@ branch = "master" name = "github.com/decred/base58" packages = ["."] - revision = "229e657bc9be5d592855a910428907f851950ed5" + revision = "56c501706f00d9e1cfacee19a27117e12da24734" [[projects]] name = "github.com/jessevdk/go-flags" @@ -114,7 +114,7 @@ "ripemd160", "ssh/terminal" ] - revision = "beaf6a35706e5032ae4c3fcf342c663c069f44d2" + revision = "88942b9c40a4c9d203b82b3731787b672d6e809b" [[projects]] branch = "master" @@ -123,7 +123,7 @@ "unix", "windows" ] - revision = "f6cff0780e542efa0c8e864dc8fa522808f6a598" + revision = "13d03a9a82fba647c21a0ef8fba44a795d0f0835" [solve-meta] analyzer-name = "dep" diff --git a/dcrjson/walletsvrcmds.go b/dcrjson/walletsvrcmds.go index 1920555c..16ea837e 100644 --- a/dcrjson/walletsvrcmds.go +++ b/dcrjson/walletsvrcmds.go @@ -1,5 +1,5 @@ // Copyright (c) 2014 The btcsuite developers -// Copyright (c) 2015-2016 The Decred developers +// Copyright (c) 2015-2018 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -524,6 +524,24 @@ func NewSignRawTransactionCmd(hexEncodedTx string, inputs *[]RawTxInput, privKey } } +// VerifySeedCmd defines the verifyseed JSON-RPC command. +type VerifySeedCmd struct { + Seed string + Account *uint32 +} + +// NewVerifySeedCmd returns a new instance which can be used to issue a +// walletlock JSON-RPC command. +// +// The parameters which are pointers indicate that they are optional. Passing +// nil for the optional parameters will use the default value. +func NewVerifySeedCmd(seed string, account *uint32) *VerifySeedCmd { + return &VerifySeedCmd{ + Seed: seed, + Account: account, + } +} + // WalletLockCmd defines the walletlock JSON-RPC command. type WalletLockCmd struct{} @@ -597,6 +615,7 @@ func init() { MustRegisterCmd("settxfee", (*SetTxFeeCmd)(nil), flags) MustRegisterCmd("signmessage", (*SignMessageCmd)(nil), flags) MustRegisterCmd("signrawtransaction", (*SignRawTransactionCmd)(nil), flags) + MustRegisterCmd("verifyseed", (*VerifySeedCmd)(nil), flags) MustRegisterCmd("walletlock", (*WalletLockCmd)(nil), flags) MustRegisterCmd("walletpassphrase", (*WalletPassphraseCmd)(nil), flags) MustRegisterCmd("walletpassphrasechange", (*WalletPassphraseChangeCmd)(nil), flags) diff --git a/dcrjson/walletsvrcmds_test.go b/dcrjson/walletsvrcmds_test.go index 5f0a4a70..098424af 100644 --- a/dcrjson/walletsvrcmds_test.go +++ b/dcrjson/walletsvrcmds_test.go @@ -1,5 +1,5 @@ // Copyright (c) 2014 The btcsuite developers -// Copyright (c) 2015-2016 The Decred developers +// Copyright (c) 2015-2018 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -1071,6 +1071,35 @@ func TestWalletSvrCmds(t *testing.T) { Flags: dcrjson.String("ALL"), }, }, + { + name: "verifyseed", + newCmd: func() (interface{}, error) { + return dcrjson.NewCmd("verifyseed", "abc") + }, + staticCmd: func() interface{} { + return dcrjson.NewVerifySeedCmd("abc", nil) + }, + marshalled: `{"jsonrpc":"1.0","method":"verifyseed","params":["abc"],"id":1}`, + unmarshalled: &dcrjson.VerifySeedCmd{ + Seed: "abc", + Account: nil, + }, + }, + { + name: "verifyseed optional", + newCmd: func() (interface{}, error) { + return dcrjson.NewCmd("verifyseed", "abc", 5) + }, + staticCmd: func() interface{} { + account := dcrjson.Uint32(5) + return dcrjson.NewVerifySeedCmd("abc", account) + }, + marshalled: `{"jsonrpc":"1.0","method":"verifyseed","params":["abc",5],"id":1}`, + unmarshalled: &dcrjson.VerifySeedCmd{ + Seed: "abc", + Account: dcrjson.Uint32(5), + }, + }, { name: "walletlock", newCmd: func() (interface{}, error) { diff --git a/dcrjson/walletsvrresults.go b/dcrjson/walletsvrresults.go index e440f528..5cf3cb10 100644 --- a/dcrjson/walletsvrresults.go +++ b/dcrjson/walletsvrresults.go @@ -1,5 +1,5 @@ // Copyright (c) 2014 The btcsuite developers -// Copyright (c) 2015-2016 The Decred developers +// Copyright (c) 2015-2018 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -187,6 +187,13 @@ type SignRawTransactionResult struct { Errors []SignRawTransactionError `json:"errors,omitempty"` } +// VerifySeedResult models the data returned by the wallet server verify +// seed command. +type VerifySeedResult struct { + Result bool `json:"keyresult"` + CoinType uint32 `json:"cointype"` +} + // ValidateAddressWalletResult models the data returned by the wallet server // validateaddress command. type ValidateAddressWalletResult struct { diff --git a/rpcserver.go b/rpcserver.go index 107ba929..134f3f31 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -287,6 +287,7 @@ var rpcAskWallet = map[string]struct{}{ "signrawtransaction": {}, "sweepaccount": {}, "stakepooluserinfo": {}, + "verifyseed": {}, "walletinfo": {}, "walletlock": {}, "walletpassphrase": {},