Convert {Dump,Import}PrivKey to use new WIF type.
The btcutil package recently exposed a WIF type to provide more functionality and simplify working with WIF strings. This commit changes the DumpPrivKey and ImportPrivKey RPCs to use the new WIF type.
This commit is contained in:
parent
9d9c343247
commit
6af13826ae
1 changed files with 13 additions and 8 deletions
21
wallet.go
21
wallet.go
|
@ -1899,20 +1899,20 @@ type FutureDumpPrivKeyResult chan *futureResult
|
||||||
// Receive waits for the response promised by the future and returns the private
|
// Receive waits for the response promised by the future and returns the private
|
||||||
// key corresponding to the passed address encoded in the wallet import format
|
// key corresponding to the passed address encoded in the wallet import format
|
||||||
// (WIF)
|
// (WIF)
|
||||||
func (r FutureDumpPrivKeyResult) Receive() (string, error) {
|
func (r FutureDumpPrivKeyResult) Receive() (*btcutil.WIF, error) {
|
||||||
reply, err := receiveFuture(r)
|
reply, err := receiveFuture(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the returned data is the expected type.
|
// Ensure the returned data is the expected type.
|
||||||
privKeyWIF, ok := reply.(string)
|
privKeyWIF, ok := reply.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("unexpected response type for "+
|
return nil, fmt.Errorf("unexpected response type for "+
|
||||||
"dumpprivkey: %T\n", reply)
|
"dumpprivkey: %T\n", reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
return privKeyWIF, nil
|
return btcutil.DecodeWIF(privKeyWIF)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DumpPrivKeyAsync returns an instance of a type that can be used to get the
|
// DumpPrivKeyAsync returns an instance of a type that can be used to get the
|
||||||
|
@ -1936,7 +1936,7 @@ func (c *Client) DumpPrivKeyAsync(address btcutil.Address) FutureDumpPrivKeyResu
|
||||||
//
|
//
|
||||||
// NOTE: This function requires to the wallet to be unlocked. See the
|
// NOTE: This function requires to the wallet to be unlocked. See the
|
||||||
// WalletPassphrase function for more details.
|
// WalletPassphrase function for more details.
|
||||||
func (c *Client) DumpPrivKey(address btcutil.Address) (string, error) {
|
func (c *Client) DumpPrivKey(address btcutil.Address) (*btcutil.WIF, error) {
|
||||||
return c.DumpPrivKeyAsync(address).Receive()
|
return c.DumpPrivKeyAsync(address).Receive()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1961,9 +1961,14 @@ func (r FutureImportPrivKeyResult) Receive() error {
|
||||||
// returned instance.
|
// returned instance.
|
||||||
//
|
//
|
||||||
// See ImportPrivKey for the blocking version and more details.
|
// See ImportPrivKey for the blocking version and more details.
|
||||||
func (c *Client) ImportPrivKeyAsync(privKeyWIF string) FutureImportPrivKeyResult {
|
func (c *Client) ImportPrivKeyAsync(privKeyWIF *btcutil.WIF) FutureImportPrivKeyResult {
|
||||||
|
wif := ""
|
||||||
|
if privKeyWIF != nil {
|
||||||
|
wif = privKeyWIF.String()
|
||||||
|
}
|
||||||
|
|
||||||
id := c.NextID()
|
id := c.NextID()
|
||||||
cmd, err := btcjson.NewImportPrivKeyCmd(id, privKeyWIF)
|
cmd, err := btcjson.NewImportPrivKeyCmd(id, wif)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newFutureError(err)
|
return newFutureError(err)
|
||||||
}
|
}
|
||||||
|
@ -1973,7 +1978,7 @@ func (c *Client) ImportPrivKeyAsync(privKeyWIF string) FutureImportPrivKeyResult
|
||||||
|
|
||||||
// ImportPrivKey imports the passed private key which must be the wallet import
|
// ImportPrivKey imports the passed private key which must be the wallet import
|
||||||
// format (WIF).
|
// format (WIF).
|
||||||
func (c *Client) ImportPrivKey(privKeyWIF string) error {
|
func (c *Client) ImportPrivKey(privKeyWIF *btcutil.WIF) error {
|
||||||
return c.ImportPrivKeyAsync(privKeyWIF).Receive()
|
return c.ImportPrivKeyAsync(privKeyWIF).Receive()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue