github.com/lbryio/lbcd@v0.22.119/btcjson/chainsvrwsntfns.go (about)

     1  // Copyright (c) 2014-2017 The btcsuite developers
     2  // Copyright (c) 2015-2017 The Decred 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 legacy, deprecated method used for
    13  	// notifications from the chain server that a block has been connected.
    14  	//
    15  	// Deprecated: Use FilteredBlockConnectedNtfnMethod instead.
    16  	BlockConnectedNtfnMethod = "blockconnected"
    17  
    18  	// BlockDisconnectedNtfnMethod is the legacy, deprecated method used for
    19  	// notifications from the chain server that a block has been
    20  	// disconnected.
    21  	//
    22  	// Deprecated: Use FilteredBlockDisconnectedNtfnMethod instead.
    23  	BlockDisconnectedNtfnMethod = "blockdisconnected"
    24  
    25  	// FilteredBlockConnectedNtfnMethod is the new method used for
    26  	// notifications from the chain server that a block has been connected.
    27  	FilteredBlockConnectedNtfnMethod = "filteredblockconnected"
    28  
    29  	// FilteredBlockDisconnectedNtfnMethod is the new method used for
    30  	// notifications from the chain server that a block has been
    31  	// disconnected.
    32  	FilteredBlockDisconnectedNtfnMethod = "filteredblockdisconnected"
    33  
    34  	// RecvTxNtfnMethod is the legacy, deprecated method used for
    35  	// notifications from the chain server that a transaction which pays to
    36  	// a registered address has been processed.
    37  	//
    38  	// Deprecated: Use RelevantTxAcceptedNtfnMethod and
    39  	// FilteredBlockConnectedNtfnMethod instead.
    40  	RecvTxNtfnMethod = "recvtx"
    41  
    42  	// RedeemingTxNtfnMethod is the legacy, deprecated method used for
    43  	// notifications from the chain server that a transaction which spends a
    44  	// registered outpoint has been processed.
    45  	//
    46  	// Deprecated: Use RelevantTxAcceptedNtfnMethod and
    47  	// FilteredBlockConnectedNtfnMethod instead.
    48  	RedeemingTxNtfnMethod = "redeemingtx"
    49  
    50  	// RescanFinishedNtfnMethod is the legacy, deprecated method used for
    51  	// notifications from the chain server that a legacy, deprecated rescan
    52  	// operation has finished.
    53  	//
    54  	// Deprecated: Not used with rescanblocks command.
    55  	RescanFinishedNtfnMethod = "rescanfinished"
    56  
    57  	// RescanProgressNtfnMethod is the legacy, deprecated method used for
    58  	// notifications from the chain server that a legacy, deprecated rescan
    59  	// operation this is underway has made progress.
    60  	//
    61  	// Deprecated: Not used with rescanblocks command.
    62  	RescanProgressNtfnMethod = "rescanprogress"
    63  
    64  	// TxAcceptedNtfnMethod is the method used for notifications from the
    65  	// chain server that a transaction has been accepted into the mempool.
    66  	TxAcceptedNtfnMethod = "txaccepted"
    67  
    68  	// TxAcceptedVerboseNtfnMethod is the method used for notifications from
    69  	// the chain server that a transaction has been accepted into the
    70  	// mempool.  This differs from TxAcceptedNtfnMethod in that it provides
    71  	// more details in the notification.
    72  	TxAcceptedVerboseNtfnMethod = "txacceptedverbose"
    73  
    74  	// RelevantTxAcceptedNtfnMethod is the new method used for notifications
    75  	// from the chain server that inform a client that a transaction that
    76  	// matches the loaded filter was accepted by the mempool.
    77  	RelevantTxAcceptedNtfnMethod = "relevanttxaccepted"
    78  )
    79  
    80  // BlockConnectedNtfn defines the blockconnected JSON-RPC notification.
    81  //
    82  // Deprecated: Use FilteredBlockConnectedNtfn instead.
    83  type BlockConnectedNtfn struct {
    84  	Hash   string
    85  	Height int32
    86  	Time   int64
    87  }
    88  
    89  // NewBlockConnectedNtfn returns a new instance which can be used to issue a
    90  // blockconnected JSON-RPC notification.
    91  //
    92  // Deprecated: Use NewFilteredBlockConnectedNtfn instead.
    93  func NewBlockConnectedNtfn(hash string, height int32, time int64) *BlockConnectedNtfn {
    94  	return &BlockConnectedNtfn{
    95  		Hash:   hash,
    96  		Height: height,
    97  		Time:   time,
    98  	}
    99  }
   100  
   101  // BlockDisconnectedNtfn defines the blockdisconnected JSON-RPC notification.
   102  //
   103  // Deprecated: Use FilteredBlockDisconnectedNtfn instead.
   104  type BlockDisconnectedNtfn struct {
   105  	Hash   string
   106  	Height int32
   107  	Time   int64
   108  }
   109  
   110  // NewBlockDisconnectedNtfn returns a new instance which can be used to issue a
   111  // blockdisconnected JSON-RPC notification.
   112  //
   113  // Deprecated: Use NewFilteredBlockDisconnectedNtfn instead.
   114  func NewBlockDisconnectedNtfn(hash string, height int32, time int64) *BlockDisconnectedNtfn {
   115  	return &BlockDisconnectedNtfn{
   116  		Hash:   hash,
   117  		Height: height,
   118  		Time:   time,
   119  	}
   120  }
   121  
   122  // FilteredBlockConnectedNtfn defines the filteredblockconnected JSON-RPC
   123  // notification.
   124  type FilteredBlockConnectedNtfn struct {
   125  	Height        int32
   126  	Header        string
   127  	SubscribedTxs []string
   128  }
   129  
   130  // NewFilteredBlockConnectedNtfn returns a new instance which can be used to
   131  // issue a filteredblockconnected JSON-RPC notification.
   132  func NewFilteredBlockConnectedNtfn(height int32, header string, subscribedTxs []string) *FilteredBlockConnectedNtfn {
   133  	return &FilteredBlockConnectedNtfn{
   134  		Height:        height,
   135  		Header:        header,
   136  		SubscribedTxs: subscribedTxs,
   137  	}
   138  }
   139  
   140  // FilteredBlockDisconnectedNtfn defines the filteredblockdisconnected JSON-RPC
   141  // notification.
   142  type FilteredBlockDisconnectedNtfn struct {
   143  	Height int32
   144  	Header string
   145  }
   146  
   147  // NewFilteredBlockDisconnectedNtfn returns a new instance which can be used to
   148  // issue a filteredblockdisconnected JSON-RPC notification.
   149  func NewFilteredBlockDisconnectedNtfn(height int32, header string) *FilteredBlockDisconnectedNtfn {
   150  	return &FilteredBlockDisconnectedNtfn{
   151  		Height: height,
   152  		Header: header,
   153  	}
   154  }
   155  
   156  // BlockDetails describes details of a tx in a block.
   157  type BlockDetails struct {
   158  	Height int32  `json:"height"`
   159  	Hash   string `json:"hash"`
   160  	Index  int    `json:"index"`
   161  	Time   int64  `json:"time"`
   162  }
   163  
   164  // RecvTxNtfn defines the recvtx JSON-RPC notification.
   165  //
   166  // Deprecated: Use RelevantTxAcceptedNtfn and FilteredBlockConnectedNtfn
   167  // instead.
   168  type RecvTxNtfn struct {
   169  	HexTx string
   170  	Block *BlockDetails
   171  }
   172  
   173  // NewRecvTxNtfn returns a new instance which can be used to issue a recvtx
   174  // JSON-RPC notification.
   175  //
   176  // Deprecated: Use NewRelevantTxAcceptedNtfn and
   177  // NewFilteredBlockConnectedNtfn instead.
   178  func NewRecvTxNtfn(hexTx string, block *BlockDetails) *RecvTxNtfn {
   179  	return &RecvTxNtfn{
   180  		HexTx: hexTx,
   181  		Block: block,
   182  	}
   183  }
   184  
   185  // RedeemingTxNtfn defines the redeemingtx JSON-RPC notification.
   186  //
   187  // Deprecated: Use RelevantTxAcceptedNtfn and FilteredBlockConnectedNtfn
   188  // instead.
   189  type RedeemingTxNtfn struct {
   190  	HexTx string
   191  	Block *BlockDetails
   192  }
   193  
   194  // NewRedeemingTxNtfn returns a new instance which can be used to issue a
   195  // redeemingtx JSON-RPC notification.
   196  //
   197  // Deprecated: Use NewRelevantTxAcceptedNtfn and
   198  // NewFilteredBlockConnectedNtfn instead.
   199  func NewRedeemingTxNtfn(hexTx string, block *BlockDetails) *RedeemingTxNtfn {
   200  	return &RedeemingTxNtfn{
   201  		HexTx: hexTx,
   202  		Block: block,
   203  	}
   204  }
   205  
   206  // RescanFinishedNtfn defines the rescanfinished JSON-RPC notification.
   207  //
   208  // Deprecated: Not used with rescanblocks command.
   209  type RescanFinishedNtfn struct {
   210  	Hash   string
   211  	Height int32
   212  	Time   int64
   213  }
   214  
   215  // NewRescanFinishedNtfn returns a new instance which can be used to issue a
   216  // rescanfinished JSON-RPC notification.
   217  //
   218  // Deprecated: Not used with rescanblocks command.
   219  func NewRescanFinishedNtfn(hash string, height int32, time int64) *RescanFinishedNtfn {
   220  	return &RescanFinishedNtfn{
   221  		Hash:   hash,
   222  		Height: height,
   223  		Time:   time,
   224  	}
   225  }
   226  
   227  // RescanProgressNtfn defines the rescanprogress JSON-RPC notification.
   228  //
   229  // Deprecated: Not used with rescanblocks command.
   230  type RescanProgressNtfn struct {
   231  	Hash   string
   232  	Height int32
   233  	Time   int64
   234  }
   235  
   236  // NewRescanProgressNtfn returns a new instance which can be used to issue a
   237  // rescanprogress JSON-RPC notification.
   238  //
   239  // Deprecated: Not used with rescanblocks command.
   240  func NewRescanProgressNtfn(hash string, height int32, time int64) *RescanProgressNtfn {
   241  	return &RescanProgressNtfn{
   242  		Hash:   hash,
   243  		Height: height,
   244  		Time:   time,
   245  	}
   246  }
   247  
   248  // TxAcceptedNtfn defines the txaccepted JSON-RPC notification.
   249  type TxAcceptedNtfn struct {
   250  	TxID   string
   251  	Amount float64
   252  }
   253  
   254  // NewTxAcceptedNtfn returns a new instance which can be used to issue a
   255  // txaccepted JSON-RPC notification.
   256  func NewTxAcceptedNtfn(txHash string, amount float64) *TxAcceptedNtfn {
   257  	return &TxAcceptedNtfn{
   258  		TxID:   txHash,
   259  		Amount: amount,
   260  	}
   261  }
   262  
   263  // TxAcceptedVerboseNtfn defines the txacceptedverbose JSON-RPC notification.
   264  type TxAcceptedVerboseNtfn struct {
   265  	RawTx TxRawResult
   266  }
   267  
   268  // NewTxAcceptedVerboseNtfn returns a new instance which can be used to issue a
   269  // txacceptedverbose JSON-RPC notification.
   270  func NewTxAcceptedVerboseNtfn(rawTx TxRawResult) *TxAcceptedVerboseNtfn {
   271  	return &TxAcceptedVerboseNtfn{
   272  		RawTx: rawTx,
   273  	}
   274  }
   275  
   276  // RelevantTxAcceptedNtfn defines the parameters to the relevanttxaccepted
   277  // JSON-RPC notification.
   278  type RelevantTxAcceptedNtfn struct {
   279  	Transaction string `json:"transaction"`
   280  }
   281  
   282  // NewRelevantTxAcceptedNtfn returns a new instance which can be used to issue a
   283  // relevantxaccepted JSON-RPC notification.
   284  func NewRelevantTxAcceptedNtfn(txHex string) *RelevantTxAcceptedNtfn {
   285  	return &RelevantTxAcceptedNtfn{Transaction: txHex}
   286  }
   287  
   288  func init() {
   289  	// The commands in this file are only usable by websockets and are
   290  	// notifications.
   291  	flags := UFWebsocketOnly | UFNotification
   292  
   293  	MustRegisterCmd(BlockConnectedNtfnMethod, (*BlockConnectedNtfn)(nil), flags)
   294  	MustRegisterCmd(BlockDisconnectedNtfnMethod, (*BlockDisconnectedNtfn)(nil), flags)
   295  	MustRegisterCmd(FilteredBlockConnectedNtfnMethod, (*FilteredBlockConnectedNtfn)(nil), flags)
   296  	MustRegisterCmd(FilteredBlockDisconnectedNtfnMethod, (*FilteredBlockDisconnectedNtfn)(nil), flags)
   297  	MustRegisterCmd(RecvTxNtfnMethod, (*RecvTxNtfn)(nil), flags)
   298  	MustRegisterCmd(RedeemingTxNtfnMethod, (*RedeemingTxNtfn)(nil), flags)
   299  	MustRegisterCmd(RescanFinishedNtfnMethod, (*RescanFinishedNtfn)(nil), flags)
   300  	MustRegisterCmd(RescanProgressNtfnMethod, (*RescanProgressNtfn)(nil), flags)
   301  	MustRegisterCmd(TxAcceptedNtfnMethod, (*TxAcceptedNtfn)(nil), flags)
   302  	MustRegisterCmd(TxAcceptedVerboseNtfnMethod, (*TxAcceptedVerboseNtfn)(nil), flags)
   303  	MustRegisterCmd(RelevantTxAcceptedNtfnMethod, (*RelevantTxAcceptedNtfn)(nil), flags)
   304  }