OSDN Git Service

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