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

* [NOD-270] Added notifyChainChanges and related commands. * [NOD-270] Added NTChainChanged to blockdag. * [NOD-270] Implemented collection and sending of ChainChanged notifications. * [NOD-270] Fixed an improperly named test. * [NOD-270] Added a test: TestChainChangedNotification. * [NOD-270] Fixed a couple copy+paste errors. * [NOD-270] Added a couple of comments for TestChainChangedNotification. * [NOD-270] Fixed formatting error. * [NOD-270] Fixed a comment. * [NOD-270] Uncoupled chain updates inside blockdag from the concept of a notification. * [NOD-270] Removed intermediary ChainUpdates object from ChainChangedNotificationData.
165 lines
5.6 KiB
Go
165 lines
5.6 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 commands that are supported by
|
|
// a dag server, but are only available via websockets.
|
|
|
|
package btcjson
|
|
|
|
// AuthenticateCmd defines the authenticate JSON-RPC command.
|
|
type AuthenticateCmd struct {
|
|
Username string
|
|
Passphrase string
|
|
}
|
|
|
|
// NewAuthenticateCmd returns a new instance which can be used to issue an
|
|
// authenticate JSON-RPC command.
|
|
func NewAuthenticateCmd(username, passphrase string) *AuthenticateCmd {
|
|
return &AuthenticateCmd{
|
|
Username: username,
|
|
Passphrase: passphrase,
|
|
}
|
|
}
|
|
|
|
// NotifyBlocksCmd defines the notifyBlocks JSON-RPC command.
|
|
type NotifyBlocksCmd struct{}
|
|
|
|
// NewNotifyBlocksCmd returns a new instance which can be used to issue a
|
|
// notifyBlocks JSON-RPC command.
|
|
func NewNotifyBlocksCmd() *NotifyBlocksCmd {
|
|
return &NotifyBlocksCmd{}
|
|
}
|
|
|
|
// StopNotifyBlocksCmd defines the stopNotifyBlocks JSON-RPC command.
|
|
type StopNotifyBlocksCmd struct{}
|
|
|
|
// NewStopNotifyBlocksCmd returns a new instance which can be used to issue a
|
|
// stopNotifyBlocks JSON-RPC command.
|
|
func NewStopNotifyBlocksCmd() *StopNotifyBlocksCmd {
|
|
return &StopNotifyBlocksCmd{}
|
|
}
|
|
|
|
// NotifyChainChangesCmd defines the notifyChainChanges JSON-RPC command.
|
|
type NotifyChainChangesCmd struct{}
|
|
|
|
// NewNotifyChainChangesCmd returns a new instance which can be used to issue a
|
|
// notifyChainChanges JSON-RPC command.
|
|
func NewNotifyChainChangesCmd() *NotifyChainChangesCmd {
|
|
return &NotifyChainChangesCmd{}
|
|
}
|
|
|
|
// StopNotifyChainChangesCmd defines the stopNotifyChainChanges JSON-RPC command.
|
|
type StopNotifyChainChangesCmd struct{}
|
|
|
|
// NewStopNotifyChainChangesCmd returns a new instance which can be used to issue a
|
|
// stopNotifyChainChanges JSON-RPC command.
|
|
func NewStopNotifyChainChangesCmd() *StopNotifyChainChangesCmd {
|
|
return &StopNotifyChainChangesCmd{}
|
|
}
|
|
|
|
// NotifyNewTransactionsCmd defines the notifyNewTransactions JSON-RPC command.
|
|
type NotifyNewTransactionsCmd struct {
|
|
Verbose *bool `jsonrpcdefault:"false"`
|
|
Subnetwork *string
|
|
}
|
|
|
|
// NewNotifyNewTransactionsCmd returns a new instance which can be used to issue
|
|
// a notifyNewTransactions JSON-RPC command.
|
|
//
|
|
// The parameters which are pointers indicate they are optional. Passing nil
|
|
// for optional parameters will use the default value.
|
|
func NewNotifyNewTransactionsCmd(verbose *bool, subnetworkID *string) *NotifyNewTransactionsCmd {
|
|
return &NotifyNewTransactionsCmd{
|
|
Verbose: verbose,
|
|
Subnetwork: subnetworkID,
|
|
}
|
|
}
|
|
|
|
// SessionCmd defines the session JSON-RPC command.
|
|
type SessionCmd struct{}
|
|
|
|
// NewSessionCmd returns a new instance which can be used to issue a session
|
|
// JSON-RPC command.
|
|
func NewSessionCmd() *SessionCmd {
|
|
return &SessionCmd{}
|
|
}
|
|
|
|
// StopNotifyNewTransactionsCmd defines the stopNotifyNewTransactions JSON-RPC command.
|
|
type StopNotifyNewTransactionsCmd struct{}
|
|
|
|
// NewStopNotifyNewTransactionsCmd returns a new instance which can be used to issue
|
|
// a stopNotifyNewTransactions JSON-RPC command.
|
|
//
|
|
// The parameters which are pointers indicate they are optional. Passing nil
|
|
// for optional parameters will use the default value.
|
|
func NewStopNotifyNewTransactionsCmd() *StopNotifyNewTransactionsCmd {
|
|
return &StopNotifyNewTransactionsCmd{}
|
|
}
|
|
|
|
// Outpoint describes a transaction outpoint that will be marshalled to and
|
|
// from JSON.
|
|
type Outpoint struct {
|
|
TxID string `json:"txid"`
|
|
Index uint32 `json:"index"`
|
|
}
|
|
|
|
// LoadTxFilterCmd defines the loadTxFilter request parameters to load or
|
|
// reload a transaction filter.
|
|
//
|
|
// NOTE: This is a btcd extension ported from github.com/decred/dcrd/dcrjson
|
|
// and requires a websocket connection.
|
|
type LoadTxFilterCmd struct {
|
|
Reload bool
|
|
Addresses []string
|
|
Outpoints []Outpoint
|
|
}
|
|
|
|
// NewLoadTxFilterCmd returns a new instance which can be used to issue a
|
|
// loadTxFilter JSON-RPC command.
|
|
//
|
|
// NOTE: This is a btcd extension ported from github.com/decred/dcrd/dcrjson
|
|
// and requires a websocket connection.
|
|
func NewLoadTxFilterCmd(reload bool, addresses []string, outpoints []Outpoint) *LoadTxFilterCmd {
|
|
return &LoadTxFilterCmd{
|
|
Reload: reload,
|
|
Addresses: addresses,
|
|
Outpoints: outpoints,
|
|
}
|
|
}
|
|
|
|
// RescanBlocksCmd defines the rescan JSON-RPC command.
|
|
//
|
|
// NOTE: This is a btcd extension ported from github.com/decred/dcrd/dcrjson
|
|
// and requires a websocket connection.
|
|
type RescanBlocksCmd struct {
|
|
// Block hashes as a string array.
|
|
BlockHashes []string
|
|
}
|
|
|
|
// NewRescanBlocksCmd returns a new instance which can be used to issue a rescan
|
|
// JSON-RPC command.
|
|
//
|
|
// NOTE: This is a btcd extension ported from github.com/decred/dcrd/dcrjson
|
|
// and requires a websocket connection.
|
|
func NewRescanBlocksCmd(blockHashes []string) *RescanBlocksCmd {
|
|
return &RescanBlocksCmd{BlockHashes: blockHashes}
|
|
}
|
|
|
|
func init() {
|
|
// The commands in this file are only usable by websockets.
|
|
flags := UFWebsocketOnly
|
|
|
|
MustRegisterCmd("authenticate", (*AuthenticateCmd)(nil), flags)
|
|
MustRegisterCmd("loadTxFilter", (*LoadTxFilterCmd)(nil), flags)
|
|
MustRegisterCmd("notifyBlocks", (*NotifyBlocksCmd)(nil), flags)
|
|
MustRegisterCmd("notifyChainChanges", (*NotifyChainChangesCmd)(nil), flags)
|
|
MustRegisterCmd("notifyNewTransactions", (*NotifyNewTransactionsCmd)(nil), flags)
|
|
MustRegisterCmd("session", (*SessionCmd)(nil), flags)
|
|
MustRegisterCmd("stopNotifyBlocks", (*StopNotifyBlocksCmd)(nil), flags)
|
|
MustRegisterCmd("stopNotifyChainChanges", (*StopNotifyChainChangesCmd)(nil), flags)
|
|
MustRegisterCmd("stopNotifyNewTransactions", (*StopNotifyNewTransactionsCmd)(nil), flags)
|
|
MustRegisterCmd("rescanBlocks", (*RescanBlocksCmd)(nil), flags)
|
|
}
|