github.com/dashpay/godash@v0.0.0-20160726055534-e038a21e0e3d/btcjson/chainsvrwsntfns.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 chain server.
     8  
     9  package btcjson
    10  
    11  const (
    12  	// BlockConnectedNtfnMethod is the method used for notifications from
    13  	// the chain server that a block has been connected.
    14  	BlockConnectedNtfnMethod = "blockconnected"
    15  
    16  	// BlockDisconnectedNtfnMethod is the method used for notifications from
    17  	// the chain server that a block has been disconnected.
    18  	BlockDisconnectedNtfnMethod = "blockdisconnected"
    19  
    20  	// RecvTxNtfnMethod is the method used for notifications from the chain
    21  	// server that a transaction which pays to a registered address has been
    22  	// processed.
    23  	RecvTxNtfnMethod = "recvtx"
    24  
    25  	// RedeemingTxNtfnMethod is the method used for notifications from the
    26  	// chain server that a transaction which spends a registered outpoint
    27  	// has been processed.
    28  	RedeemingTxNtfnMethod = "redeemingtx"
    29  
    30  	// RescanFinishedNtfnMethod is the method used for notifications from
    31  	// the chain server that a rescan operation has finished.
    32  	RescanFinishedNtfnMethod = "rescanfinished"
    33  
    34  	// RescanProgressNtfnMethod is the method used for notifications from
    35  	// the chain server that a rescan operation this is underway has made
    36  	// progress.
    37  	RescanProgressNtfnMethod = "rescanprogress"
    38  
    39  	// TxAcceptedNtfnMethod is the method used for notifications from the
    40  	// chain server that a transaction has been accepted into the mempool.
    41  	TxAcceptedNtfnMethod = "txaccepted"
    42  
    43  	// TxAcceptedVerboseNtfnMethod is the method used for notifications from
    44  	// the chain server that a transaction has been accepted into the
    45  	// mempool.  This differs from TxAcceptedNtfnMethod in that it provides
    46  	// more details in the notification.
    47  	TxAcceptedVerboseNtfnMethod = "txacceptedverbose"
    48  )
    49  
    50  // BlockConnectedNtfn defines the blockconnected JSON-RPC notification.
    51  type BlockConnectedNtfn struct {
    52  	Hash   string
    53  	Height int32
    54  	Time   int64
    55  }
    56  
    57  // NewBlockConnectedNtfn returns a new instance which can be used to issue a
    58  // blockconnected JSON-RPC notification.
    59  func NewBlockConnectedNtfn(hash string, height int32, time int64) *BlockConnectedNtfn {
    60  	return &BlockConnectedNtfn{
    61  		Hash:   hash,
    62  		Height: height,
    63  		Time:   time,
    64  	}
    65  }
    66  
    67  // BlockDisconnectedNtfn defines the blockdisconnected JSON-RPC notification.
    68  type BlockDisconnectedNtfn struct {
    69  	Hash   string
    70  	Height int32
    71  	Time   int64
    72  }
    73  
    74  // NewBlockDisconnectedNtfn returns a new instance which can be used to issue a
    75  // blockdisconnected JSON-RPC notification.
    76  func NewBlockDisconnectedNtfn(hash string, height int32, time int64) *BlockDisconnectedNtfn {
    77  	return &BlockDisconnectedNtfn{
    78  		Hash:   hash,
    79  		Height: height,
    80  		Time:   time,
    81  	}
    82  }
    83  
    84  // BlockDetails describes details of a tx in a block.
    85  type BlockDetails struct {
    86  	Height int32  `json:"height"`
    87  	Hash   string `json:"hash"`
    88  	Index  int    `json:"index"`
    89  	Time   int64  `json:"time"`
    90  }
    91  
    92  // RecvTxNtfn defines the recvtx JSON-RPC notification.
    93  type RecvTxNtfn struct {
    94  	HexTx string
    95  	Block *BlockDetails
    96  }
    97  
    98  // NewRecvTxNtfn returns a new instance which can be used to issue a recvtx
    99  // JSON-RPC notification.
   100  func NewRecvTxNtfn(hexTx string, block *BlockDetails) *RecvTxNtfn {
   101  	return &RecvTxNtfn{
   102  		HexTx: hexTx,
   103  		Block: block,
   104  	}
   105  }
   106  
   107  // RedeemingTxNtfn defines the redeemingtx JSON-RPC notification.
   108  type RedeemingTxNtfn struct {
   109  	HexTx string
   110  	Block *BlockDetails
   111  }
   112  
   113  // NewRedeemingTxNtfn returns a new instance which can be used to issue a
   114  // redeemingtx JSON-RPC notification.
   115  func NewRedeemingTxNtfn(hexTx string, block *BlockDetails) *RedeemingTxNtfn {
   116  	return &RedeemingTxNtfn{
   117  		HexTx: hexTx,
   118  		Block: block,
   119  	}
   120  }
   121  
   122  // RescanFinishedNtfn defines the rescanfinished JSON-RPC notification.
   123  type RescanFinishedNtfn struct {
   124  	Hash   string
   125  	Height int32
   126  	Time   int64
   127  }
   128  
   129  // NewRescanFinishedNtfn returns a new instance which can be used to issue a
   130  // rescanfinished JSON-RPC notification.
   131  func NewRescanFinishedNtfn(hash string, height int32, time int64) *RescanFinishedNtfn {
   132  	return &RescanFinishedNtfn{
   133  		Hash:   hash,
   134  		Height: height,
   135  		Time:   time,
   136  	}
   137  }
   138  
   139  // RescanProgressNtfn defines the rescanprogress JSON-RPC notification.
   140  type RescanProgressNtfn struct {
   141  	Hash   string
   142  	Height int32
   143  	Time   int64
   144  }
   145  
   146  // NewRescanProgressNtfn returns a new instance which can be used to issue a
   147  // rescanprogress JSON-RPC notification.
   148  func NewRescanProgressNtfn(hash string, height int32, time int64) *RescanProgressNtfn {
   149  	return &RescanProgressNtfn{
   150  		Hash:   hash,
   151  		Height: height,
   152  		Time:   time,
   153  	}
   154  }
   155  
   156  // TxAcceptedNtfn defines the txaccepted JSON-RPC notification.
   157  type TxAcceptedNtfn struct {
   158  	TxID   string
   159  	Amount float64
   160  }
   161  
   162  // NewTxAcceptedNtfn returns a new instance which can be used to issue a
   163  // txaccepted JSON-RPC notification.
   164  func NewTxAcceptedNtfn(txHash string, amount float64) *TxAcceptedNtfn {
   165  	return &TxAcceptedNtfn{
   166  		TxID:   txHash,
   167  		Amount: amount,
   168  	}
   169  }
   170  
   171  // TxAcceptedVerboseNtfn defines the txacceptedverbose JSON-RPC notification.
   172  type TxAcceptedVerboseNtfn struct {
   173  	RawTx TxRawResult
   174  }
   175  
   176  // NewTxAcceptedVerboseNtfn returns a new instance which can be used to issue a
   177  // txacceptedverbose JSON-RPC notification.
   178  func NewTxAcceptedVerboseNtfn(rawTx TxRawResult) *TxAcceptedVerboseNtfn {
   179  	return &TxAcceptedVerboseNtfn{
   180  		RawTx: rawTx,
   181  	}
   182  }
   183  
   184  func init() {
   185  	// The commands in this file are only usable by websockets and are
   186  	// notifications.
   187  	flags := UFWebsocketOnly | UFNotification
   188  
   189  	MustRegisterCmd(BlockConnectedNtfnMethod, (*BlockConnectedNtfn)(nil), flags)
   190  	MustRegisterCmd(BlockDisconnectedNtfnMethod, (*BlockDisconnectedNtfn)(nil), flags)
   191  	MustRegisterCmd(RecvTxNtfnMethod, (*RecvTxNtfn)(nil), flags)
   192  	MustRegisterCmd(RedeemingTxNtfnMethod, (*RedeemingTxNtfn)(nil), flags)
   193  	MustRegisterCmd(RescanFinishedNtfnMethod, (*RescanFinishedNtfn)(nil), flags)
   194  	MustRegisterCmd(RescanProgressNtfnMethod, (*RescanProgressNtfn)(nil), flags)
   195  	MustRegisterCmd(TxAcceptedNtfnMethod, (*TxAcceptedNtfn)(nil), flags)
   196  	MustRegisterCmd(TxAcceptedVerboseNtfnMethod, (*TxAcceptedVerboseNtfn)(nil), flags)
   197  }