github.com/BlockABC/godash@v0.0.0-20191112120524-f4aa3a32c566/btcjson/walletsvrwsntfns.go (about) 1 // Copyright (c) 2014 The btcsuite developers 2 // Copyright (c) 2016 The Dash developers 3 // Use of this source code is governed by an ISC 4 // license that can be found in the LICENSE file. 5 6 // NOTE: This file is intended to house the RPC websocket notifications that are 7 // supported by a wallet server. 8 9 package btcjson 10 11 const ( 12 // AccountBalanceNtfnMethod is the method used for account balance 13 // notifications. 14 AccountBalanceNtfnMethod = "accountbalance" 15 16 // BtcdConnectedNtfnMethod is the method used for notifications when 17 // a wallet server is connected to a chain server. 18 BtcdConnectedNtfnMethod = "btcdconnected" 19 20 // WalletLockStateNtfnMethod is the method used to notify the lock state 21 // of a wallet has changed. 22 WalletLockStateNtfnMethod = "walletlockstate" 23 24 // NewTxNtfnMethod is the method used to notify that a wallet server has 25 // added a new transaction to the transaciton store. 26 NewTxNtfnMethod = "newtx" 27 ) 28 29 // AccountBalanceNtfn defines the accountbalance JSON-RPC notification. 30 type AccountBalanceNtfn struct { 31 Account string 32 Balance float64 // In BTC 33 Confirmed bool // Whether Balance is confirmed or unconfirmed. 34 } 35 36 // NewAccountBalanceNtfn returns a new instance which can be used to issue an 37 // accountbalance JSON-RPC notification. 38 func NewAccountBalanceNtfn(account string, balance float64, confirmed bool) *AccountBalanceNtfn { 39 return &AccountBalanceNtfn{ 40 Account: account, 41 Balance: balance, 42 Confirmed: confirmed, 43 } 44 } 45 46 // BtcdConnectedNtfn defines the btcdconnected JSON-RPC notification. 47 type BtcdConnectedNtfn struct { 48 Connected bool 49 } 50 51 // NewBtcdConnectedNtfn returns a new instance which can be used to issue a 52 // btcdconnected JSON-RPC notification. 53 func NewBtcdConnectedNtfn(connected bool) *BtcdConnectedNtfn { 54 return &BtcdConnectedNtfn{ 55 Connected: connected, 56 } 57 } 58 59 // WalletLockStateNtfn defines the walletlockstate JSON-RPC notification. 60 type WalletLockStateNtfn struct { 61 Locked bool 62 } 63 64 // NewWalletLockStateNtfn returns a new instance which can be used to issue a 65 // walletlockstate JSON-RPC notification. 66 func NewWalletLockStateNtfn(locked bool) *WalletLockStateNtfn { 67 return &WalletLockStateNtfn{ 68 Locked: locked, 69 } 70 } 71 72 // NewTxNtfn defines the newtx JSON-RPC notification. 73 type NewTxNtfn struct { 74 Account string 75 Details ListTransactionsResult 76 } 77 78 // NewNewTxNtfn returns a new instance which can be used to issue a newtx 79 // JSON-RPC notification. 80 func NewNewTxNtfn(account string, details ListTransactionsResult) *NewTxNtfn { 81 return &NewTxNtfn{ 82 Account: account, 83 Details: details, 84 } 85 } 86 87 func init() { 88 // The commands in this file are only usable with a wallet server via 89 // websockets and are notifications. 90 flags := UFWalletOnly | UFWebsocketOnly | UFNotification 91 92 MustRegisterCmd(AccountBalanceNtfnMethod, (*AccountBalanceNtfn)(nil), flags) 93 MustRegisterCmd(BtcdConnectedNtfnMethod, (*BtcdConnectedNtfn)(nil), flags) 94 MustRegisterCmd(WalletLockStateNtfnMethod, (*WalletLockStateNtfn)(nil), flags) 95 MustRegisterCmd(NewTxNtfnMethod, (*NewTxNtfn)(nil), flags) 96 }