Implement JSON extension walletislocked
This commit is contained in:
parent
b0f6a70d40
commit
cc13f2eed5
2 changed files with 36 additions and 0 deletions
29
cmdmgr.go
29
cmdmgr.go
|
@ -151,6 +151,7 @@ func ProcessFrontendMsg(reply chan []byte, msg []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch cmd {
|
switch cmd {
|
||||||
|
// Standard bitcoind methods
|
||||||
case "getaddressesbyaccount":
|
case "getaddressesbyaccount":
|
||||||
GetAddressesByAccount(reply, msg)
|
GetAddressesByAccount(reply, msg)
|
||||||
case "getnewaddress":
|
case "getnewaddress":
|
||||||
|
@ -159,6 +160,11 @@ func ProcessFrontendMsg(reply chan []byte, msg []byte) {
|
||||||
WalletLock(reply, msg)
|
WalletLock(reply, msg)
|
||||||
case "walletpassphrase":
|
case "walletpassphrase":
|
||||||
WalletPassphrase(reply, msg)
|
WalletPassphrase(reply, msg)
|
||||||
|
|
||||||
|
// btcwallet extensions
|
||||||
|
case "walletislocked":
|
||||||
|
WalletIsLocked(reply, msg)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// btcwallet does not understand method. Pass to btcd.
|
// btcwallet does not understand method. Pass to btcd.
|
||||||
log.Info("Unknown btcwallet method", cmd)
|
log.Info("Unknown btcwallet method", cmd)
|
||||||
|
@ -236,6 +242,29 @@ func GetNewAddress(reply chan []byte, msg []byte) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WalletIsLocked returns whether the wallet used by the specified
|
||||||
|
// account, or default account, is locked.
|
||||||
|
func WalletIsLocked(reply chan []byte, msg []byte) {
|
||||||
|
var v map[string]interface{}
|
||||||
|
json.Unmarshal(msg, &v)
|
||||||
|
params := v["params"].([]interface{})
|
||||||
|
account := ""
|
||||||
|
if len(params) > 0 {
|
||||||
|
if acct, ok := params[0].(string); ok {
|
||||||
|
account = acct
|
||||||
|
} else {
|
||||||
|
ReplyError(reply, v["id"], &InvalidParams)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if w := wallets[account]; w != nil {
|
||||||
|
result := w.IsLocked()
|
||||||
|
ReplySuccess(reply, v["id"], result)
|
||||||
|
} else {
|
||||||
|
ReplyError(reply, v["id"], &WalletInvalidAccountName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WalletLock locks the wallet.
|
// WalletLock locks the wallet.
|
||||||
//
|
//
|
||||||
// TODO(jrick): figure out how multiple wallets/accounts will work
|
// TODO(jrick): figure out how multiple wallets/accounts will work
|
||||||
|
|
|
@ -383,6 +383,13 @@ func (wallet *Wallet) Lock() (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (wallet *Wallet) IsLocked() (locked bool) {
|
||||||
|
wallet.key.Lock()
|
||||||
|
locked = wallet.key.secret == nil
|
||||||
|
wallet.key.Unlock()
|
||||||
|
return locked
|
||||||
|
}
|
||||||
|
|
||||||
// Returns wallet version as string and int.
|
// Returns wallet version as string and int.
|
||||||
// TODO(jrick)
|
// TODO(jrick)
|
||||||
func (wallet *Wallet) Version() (string, int) {
|
func (wallet *Wallet) Version() (string, int) {
|
||||||
|
|
Loading…
Reference in a new issue