Add getunconfirmedbalance websocket RPC extension.
This commit is contained in:
parent
8be51e37cf
commit
920ff10155
1 changed files with 36 additions and 0 deletions
36
cmdmgr.go
36
cmdmgr.go
|
@ -97,6 +97,7 @@ var rpcHandlers = map[string]cmdHandler{
|
|||
var wsHandlers = map[string]cmdHandler{
|
||||
"getaddressbalance": GetAddressBalance,
|
||||
"getbalances": GetBalances,
|
||||
"getunconfirmedbalance": GetUnconfirmedBalance,
|
||||
"listaddresstransactions": ListAddressTransactions,
|
||||
"listalltransactions": ListAllTransactions,
|
||||
"walletislocked": WalletIsLocked,
|
||||
|
@ -379,6 +380,41 @@ func GetAddressBalance(frontend chan []byte, icmd btcjson.Cmd) {
|
|||
ReplySuccess(frontend, cmd.Id(), bal)
|
||||
}
|
||||
|
||||
// GetUnconfirmedBalance replies to a getunconfirmedbalance extension request
|
||||
// by replying with the current unconfirmed balance of an account.
|
||||
func GetUnconfirmedBalance(frontend chan []byte, icmd btcjson.Cmd) {
|
||||
// Type assert icmd to access parameters.
|
||||
cmd, ok := icmd.(*btcws.GetUnconfirmedBalanceCmd)
|
||||
if !ok {
|
||||
ReplyError(frontend, icmd.Id(), &btcjson.ErrInternal)
|
||||
return
|
||||
}
|
||||
|
||||
// Get the account included in the request.
|
||||
a, err := accountstore.Account(cmd.Account)
|
||||
switch err {
|
||||
case nil:
|
||||
break
|
||||
|
||||
case ErrAcctNotExist:
|
||||
ReplyError(frontend, cmd.Id(),
|
||||
&btcjson.ErrWalletInvalidAccountName)
|
||||
return
|
||||
|
||||
default:
|
||||
e := &btcjson.Error{
|
||||
Code: btcjson.ErrWallet.Code,
|
||||
Message: err.Error(),
|
||||
}
|
||||
ReplyError(frontend, cmd.Id(), e)
|
||||
return
|
||||
}
|
||||
|
||||
confirmed := a.CalculateBalance(1)
|
||||
unconfirmed := a.CalculateBalance(0) - confirmed
|
||||
ReplySuccess(frontend, cmd.Id(), unconfirmed)
|
||||
}
|
||||
|
||||
// ImportPrivKey replies to an importprivkey request by parsing
|
||||
// a WIF-encoded private key and adding it to an account.
|
||||
func ImportPrivKey(frontend chan []byte, icmd btcjson.Cmd) {
|
||||
|
|
Loading…
Reference in a new issue