mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* [NOD-297] Fix onChainChanged on rpcclient * [NOD-285] create gorm models for db (#378) * [NOD-285] Map API-Server database using GORM * [NOD-285] Add accepting block to transactions and blocks models, and remove accepting block model * [NOD-285] Define model relations * [NOD-285] Fix many to many for Transaction and Block models * [NOD-285] Remove redundant main file * [NOD-296] Send SyncMgr.SubmitBlock errors as rpc errors (#381) * [NOD-296] Send SyncMgr.SubmitBlock errors as rpc errors * [NOD-296] Add error message prefix * [NOD-298] Add comments to gorm models (#382) * [NOD-294] Fix golint in deploy.sh and fix all lint warnings (#380) * [NOD-294] Fix golint in deploy.sh and fixed all lint errors * [NOD-294] Fix typos in comments * [NOD-294] Convert VirtualForTest into alias of *virtualBlock * [NOD-294] Fixed some more typos in comments * [NOD-295] Limit the length of GetData to 50 (#383) * [NOD-295] Fixed bad break condition in addInvsToGetDataMessageFromQueue. * [NOD-295] Fixed the fix for bad break condition in addInvsToGetDataMessageFromQueue. * [NOD-295] Made the check for max invs refer to invsNum instead of MaxInvPerGetDataMsg. * [NOD-297] Fix onChainChanged on rpcclient * [NOD-286] Implement API-Server base structure (#379) * [NOD-286] Implement API-Server base structure * [NOD-286] Add rpc user and password as command line arguments * [NOD-286] Make log directory a CLI argument * [NOD-286] Add db login details as CLI arguments * [NOD-297] Fix onChainChanged on rpcclient and server * [NOD-297] Fix variables and functions names * [NOD-297] Fix AcceptedTxIds -> AcceptedTxIDs
139 lines
4.7 KiB
Go
139 lines
4.7 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 dag server.
|
|
|
|
package btcjson
|
|
|
|
const (
|
|
// FilteredBlockAddedNtfnMethod is the new method used for
|
|
// notifications from the dag server that a block has been connected.
|
|
FilteredBlockAddedNtfnMethod = "filteredBlockAdded"
|
|
|
|
// TxAcceptedNtfnMethod is the method used for notifications from the
|
|
// dag server that a transaction has been accepted into the mempool.
|
|
TxAcceptedNtfnMethod = "txAccepted"
|
|
|
|
// TxAcceptedVerboseNtfnMethod is the method used for notifications from
|
|
// the dag 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 dag 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 dag server that inform a client that the selected chain
|
|
// has changed.
|
|
ChainChangedNtfnMethod = "chainChanged"
|
|
)
|
|
|
|
// FilteredBlockAddedNtfn defines the filteredBlockAdded JSON-RPC
|
|
// notification.
|
|
type FilteredBlockAddedNtfn struct {
|
|
ChainHeight uint64
|
|
Header string
|
|
SubscribedTxs []string
|
|
}
|
|
|
|
// NewFilteredBlockAddedNtfn returns a new instance which can be used to
|
|
// issue a filteredBlockAdded JSON-RPC notification.
|
|
func NewFilteredBlockAddedNtfn(chainHeight uint64, header string, subscribedTxs []string) *FilteredBlockAddedNtfn {
|
|
return &FilteredBlockAddedNtfn{
|
|
ChainHeight: chainHeight,
|
|
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
|
|
|
|
MustRegisterCmd(FilteredBlockAddedNtfnMethod, (*FilteredBlockAddedNtfn)(nil), flags)
|
|
MustRegisterCmd(TxAcceptedNtfnMethod, (*TxAcceptedNtfn)(nil), flags)
|
|
MustRegisterCmd(TxAcceptedVerboseNtfnMethod, (*TxAcceptedVerboseNtfn)(nil), flags)
|
|
MustRegisterCmd(RelevantTxAcceptedNtfnMethod, (*RelevantTxAcceptedNtfn)(nil), flags)
|
|
MustRegisterCmd(ChainChangedNtfnMethod, (*ChainChangedNtfn)(nil), flags)
|
|
}
|