kaspad/infrastructure/network/rpc/model/rpc_websocket_notifications.go
stasatdaglabs d14809694f
[NOD-1223] Reorganize directory structure (#874)
* [NOD-1223] Delete unused files/packages.

* [NOD-1223] Move signal and limits to the os package.

* [NOD-1223] Put database and dbaccess into the db package.

* [NOD-1223] Fold the logs package into the logger package.

* [NOD-1223] Rename domainmessage to appmessage.

* [NOD-1223] Rename to/from DomainMessage to AppMessage.

* [NOD-1223] Move appmessage to the app packge.

* [NOD-1223] Move protocol to the app packge.

* [NOD-1223] Move the network package to the infrastructure packge.

* [NOD-1223] Rename cmd to executables.

* [NOD-1223] Fix go.doc in the logger package.
2020-08-18 10:26:39 +03:00

139 lines
4.8 KiB
Go

// Copyright (c) 2014-2017 The btcsuite developers
// Copyright (c) 2015-2017 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
// NOTE: This file is intended to house the RPC websocket notifications that are
// supported by a kaspa rpc server.
package model
const (
// FilteredBlockAddedNtfnMethod is the new method used for
// notifications from the kaspa rpc server that a block has been connected.
FilteredBlockAddedNtfnMethod = "filteredBlockAdded"
// TxAcceptedNtfnMethod is the method used for notifications from the
// kaspa rpc server that a transaction has been accepted into the mempool.
TxAcceptedNtfnMethod = "txAccepted"
// TxAcceptedVerboseNtfnMethod is the method used for notifications from
// the kaspa rpc server that a transaction has been accepted into the
// mempool. This differs from TxAcceptedNtfnMethod in that it provides
// more details in the notification.
TxAcceptedVerboseNtfnMethod = "txAcceptedVerbose"
// RelevantTxAcceptedNtfnMethod is the new method used for notifications
// from the kaspa rpc server that inform a client that a transaction that
// matches the loaded filter was accepted by the mempool.
RelevantTxAcceptedNtfnMethod = "relevantTxAccepted"
// ChainChangedNtfnMethod is the new method used for notifications
// from the kaspa rpc server that inform a client that the selected chain
// has changed.
ChainChangedNtfnMethod = "chainChanged"
)
// FilteredBlockAddedNtfn defines the filteredBlockAdded JSON-RPC
// notification.
type FilteredBlockAddedNtfn struct {
BlueScore uint64
Header string
SubscribedTxs []string
}
// NewFilteredBlockAddedNtfn returns a new instance which can be used to
// issue a filteredBlockAdded JSON-RPC notification.
func NewFilteredBlockAddedNtfn(blueScore uint64, header string, subscribedTxs []string) *FilteredBlockAddedNtfn {
return &FilteredBlockAddedNtfn{
BlueScore: blueScore,
Header: header,
SubscribedTxs: subscribedTxs,
}
}
// ChainChangedNtfn defines the chainChanged JSON-RPC
// notification.
type ChainChangedNtfn struct {
ChainChangedRawParam ChainChangedRawParam
}
// ChainChangedRawParam is the first parameter
// of ChainChangedNtfn which contains all the
// remove chain block hashes and the added
// chain blocks.
type ChainChangedRawParam struct {
RemovedChainBlockHashes []string `json:"removedChainBlockHashes"`
AddedChainBlocks []ChainBlock `json:"addedChainBlocks"`
}
// NewChainChangedNtfn returns a new instance which can be used to
// issue a chainChanged JSON-RPC notification.
func NewChainChangedNtfn(removedChainBlockHashes []string,
addedChainBlocks []ChainBlock) *ChainChangedNtfn {
return &ChainChangedNtfn{ChainChangedRawParam: ChainChangedRawParam{
RemovedChainBlockHashes: removedChainBlockHashes,
AddedChainBlocks: addedChainBlocks,
}}
}
// BlockDetails describes details of a tx in a block.
type BlockDetails struct {
Height uint64 `json:"height"`
Hash string `json:"hash"`
Index int `json:"index"`
Time int64 `json:"time"`
}
// TxAcceptedNtfn defines the txAccepted JSON-RPC notification.
type TxAcceptedNtfn struct {
TxID string
Amount float64
}
// NewTxAcceptedNtfn returns a new instance which can be used to issue a
// txAccepted JSON-RPC notification.
func NewTxAcceptedNtfn(txHash string, amount float64) *TxAcceptedNtfn {
return &TxAcceptedNtfn{
TxID: txHash,
Amount: amount,
}
}
// TxAcceptedVerboseNtfn defines the txAcceptedVerbose JSON-RPC notification.
type TxAcceptedVerboseNtfn struct {
RawTx TxRawResult
}
// NewTxAcceptedVerboseNtfn returns a new instance which can be used to issue a
// txAcceptedVerbose JSON-RPC notification.
func NewTxAcceptedVerboseNtfn(rawTx TxRawResult) *TxAcceptedVerboseNtfn {
return &TxAcceptedVerboseNtfn{
RawTx: rawTx,
}
}
// RelevantTxAcceptedNtfn defines the parameters to the relevantTxAccepted
// JSON-RPC notification.
type RelevantTxAcceptedNtfn struct {
Transaction string `json:"transaction"`
}
// NewRelevantTxAcceptedNtfn returns a new instance which can be used to issue a
// relevantxaccepted JSON-RPC notification.
func NewRelevantTxAcceptedNtfn(txHex string) *RelevantTxAcceptedNtfn {
return &RelevantTxAcceptedNtfn{Transaction: txHex}
}
func init() {
// The commands in this file are only usable by websockets and are
// notifications.
flags := UFWebsocketOnly | UFNotification
MustRegisterCommand(FilteredBlockAddedNtfnMethod, (*FilteredBlockAddedNtfn)(nil), flags)
MustRegisterCommand(TxAcceptedNtfnMethod, (*TxAcceptedNtfn)(nil), flags)
MustRegisterCommand(TxAcceptedVerboseNtfnMethod, (*TxAcceptedVerboseNtfn)(nil), flags)
MustRegisterCommand(RelevantTxAcceptedNtfnMethod, (*RelevantTxAcceptedNtfn)(nil), flags)
MustRegisterCommand(ChainChangedNtfnMethod, (*ChainChangedNtfn)(nil), flags)
}