set-up app messages for notifications

This commit is contained in:
D-Stacks 2022-10-16 13:03:06 +02:00
parent d6f0a16ebd
commit f6d149352d
9 changed files with 234 additions and 226 deletions

View File

@ -171,12 +171,14 @@ const (
CmdGetTxsConfirmationsResponseMessage CmdGetTxsConfirmationsResponseMessage
CmdNotifyTxsConfirmationChangedRequestMessage CmdNotifyTxsConfirmationChangedRequestMessage
CmdNotifyTxsConfirmationChangedResponseMessage CmdNotifyTxsConfirmationChangedResponseMessage
CmdStartNotifyingTxsConfirmationChangedRequestMessage CmdModifyNotifyingTxsConfirmationChangedRequestMessage
CmdStartNotifyingTxsConfirmationChangedResponseMessage CmdModifyNotifyingTxsConfirmationChangedResponseMessage
CmdStopNotifyingTxsConfirmationChangedRequestMessage CmdTxsConfirmationChangedNotificationMessage
CmdStopNotifyingTxsConfirmationChangedResponseMessage CmdNotifyAddressesTxsRequestMessage
CmdModifyNotifyTxsConfirmationChangedParamsRequestMessage CmdNotifyAddressesTxsResponseMessage
CmdModifyNotifyTxsConfirmationChangedParamsResponseMessage CmdModifyNotifyingAddressesTxsRequestMessage
CmdModifyNotifyingAddressesTxsResponseMessage
CmdAddressesTxsNotificationMessage
) )
// ProtocolMessageCommandToString maps all MessageCommands to their string representation // ProtocolMessageCommandToString maps all MessageCommands to their string representation
@ -320,6 +322,16 @@ var RPCMessageCommandToString = map[MessageCommand]string{
CmdGetTxsResponseMessage: "GetTxsResponse", CmdGetTxsResponseMessage: "GetTxsResponse",
CmdGetTxsConfirmationsRequestMessage: "GetTxsConfirmationsRequest", CmdGetTxsConfirmationsRequestMessage: "GetTxsConfirmationsRequest",
CmdGetTxsConfirmationsResponseMessage: "GetTxsConfirmationsResponse", CmdGetTxsConfirmationsResponseMessage: "GetTxsConfirmationsResponse",
CmdNotifyTxsConfirmationChangedRequestMessage: "NotifyTxsConfirmationChangedRequest",
CmdNotifyTxsConfirmationChangedResponseMessage: "ModifyNotifyingTxsConfirmationChangedRequest",
CmdModifyNotifyingTxsConfirmationChangedRequestMessage: "ModifyNotifyingTxsConfirmationChangedResponse",
CmdModifyNotifyingTxsConfirmationChangedResponseMessage: "TxsConfirmationChangedNotification",
CmdTxsConfirmationChangedNotificationMessage: "TxsConfirmationChangedNotification",
CmdNotifyAddressesTxsRequestMessage: "NotifyAddressesTxsRequest",
CmdNotifyAddressesTxsResponseMessage: "NotifyAddressesTxsResponse",
CmdModifyNotifyingAddressesTxsRequestMessage: "ModifyNotifyingAddressesTxsRequest",
CmdModifyNotifyingAddressesTxsResponseMessage: "ModifyNotifyingAddressesTxsResponse",
CmdAddressesTxsNotificationMessage: "AddressesTxsNotification",
} }
// Message is an interface that describes a kaspa message. A type that // Message is an interface that describes a kaspa message. A type that

View File

@ -0,0 +1,47 @@
package appmessage
type ModifyNotifyingAddressesTxsRequestMessage struct {
baseMessage
AddAddresses []string
RemoveAddresses []string
RequiredConfirmations uint32
IncludePending bool
IncludeSending bool
IncludeReceiving bool
}
// Command returns the protocol command string for the message
func (msg *ModifyNotifyingAddressesTxsRequestMessage) Command() MessageCommand {
return CmdModifyNotifyingAddressesTxsRequestMessage
}
// NewModifyNotifyingAddressesTxsRequestMessage returns a instance of the message
func NewModifyNotifyingAddressesTxsRequestMessage(addAddresses []string, removeAddresses []string,
requiredConfirmations uint32, includePending bool, includeSending bool,
includeReceiving bool) *ModifyNotifyingAddressesTxsRequestMessage {
return &ModifyNotifyingAddressesTxsRequestMessage{
AddAddresses: addAddresses,
RemoveAddresses: removeAddresses,
RequiredConfirmations: requiredConfirmations,
IncludePending: includePending,
IncludeSending: includeSending,
IncludeReceiving: includeReceiving,
}
}
// ModifyNotifyingAddressesTxsResponseMessage is an appmessage corresponding to
// its respective RPC message
type ModifyNotifyingAddressesTxsResponseMessage struct {
baseMessage
Error *RPCError
}
// Command returns the protocol command string for the message
func (msg *ModifyNotifyingAddressesTxsResponseMessage) Command() MessageCommand {
return CmdModifyNotifyingAddressesTxsResponseMessage
}
// NewModifyNotifyingAddressesTxsesponseMessage returns a instance of the message
func NewModifyNotifyingAddressesTxsResponseMessage() *NotifyAddressesTxsResponseMessage {
return &NotifyAddressesTxsResponseMessage{}
}

View File

@ -0,0 +1,42 @@
package appmessage
type ModifyNotifyingTxsConfirmationChangedRequestMessage struct {
baseMessage
AddTxIDs []string
RemoveTxIDs []string
RequiredConfirmations uint32
IncludePending bool
}
// Command returns the protocol command string for the message
func (msg *ModifyNotifyingTxsConfirmationChangedRequestMessage) Command() MessageCommand {
return CmdModifyNotifyingTxsConfirmationChangedRequestMessage
}
// NewModifyNotifyingTxsConfirmationChangedRequestMessage returns a instance of the message
func NewModifyNotifyingTxsConfirmationChangedRequestMessage(addTxIDs []string, removeTxIDs []string,
requiredConfirmations uint32, includePending bool) *ModifyNotifyingTxsConfirmationChangedRequestMessage {
return &ModifyNotifyingTxsConfirmationChangedRequestMessage{
AddTxIDs: addTxIDs,
RemoveTxIDs: removeTxIDs,
RequiredConfirmations: requiredConfirmations,
IncludePending: includePending,
}
}
// ModifyNotifyingTxsConfirmationChangedResponseMessage is an appmessage corresponding to
// its respective RPC message
type ModifyNotifyingTxsConfirmationChangedResponseMessage struct {
baseMessage
Error *RPCError
}
// Command returns the protocol command string for the message
func (msg *ModifyNotifyingTxsConfirmationChangedResponseMessage) Command() MessageCommand {
return CmdModifyNotifyingTxsConfirmationChangedResponseMessage
}
// NewModifyNotifyingTXChangedResponseMessage returns a instance of the message
func NewModifyNotifyingTxsChangedResponseMessage() *NotifyTxsConfirmationChangedResponseMessage {
return &NotifyTxsConfirmationChangedResponseMessage{}
}

View File

@ -1 +1,89 @@
package appmessage
// NotifyAddressesTxsRequestMessage is an appmessage corresponding to
// its respective RPC message
type NotifyAddressesTxsRequestMessage struct {
baseMessage
Addresses []string
RequiredConfirmations uint32
IncludePending bool
IncludeSending bool
IncludeReceiving bool
}
// Command returns the protocol command string for the message
func (msg *NotifyAddressesTxsRequestMessage) Command() MessageCommand {
return CmdNotifyAddressesTxsRequestMessage
}
// NewNotifyAddressesTxsRequestMessage returns a instance of the message
func NewNotifyAddressesTxsRequestMessage(addresses []string, requiredConfirmations uint32,
includePending bool, includeSending bool, includeReceiving bool) *NotifyAddressesTxsRequestMessage {
return &NotifyAddressesTxsRequestMessage{
Addresses: addresses,
RequiredConfirmations: requiredConfirmations,
IncludePending: includePending,
IncludeSending: includeSending,
IncludeReceiving: includeReceiving,
}
}
// NotifyAddressesTxsResponseMessage is an appmessage corresponding to
// its respective RPC message
type NotifyAddressesTxsResponseMessage struct {
baseMessage
Error *RPCError
}
// Command returns the protocol command string for the message
func (msg *NotifyAddressesTxsResponseMessage) Command() MessageCommand {
return CmdNotifyAddressesTxsResponseMessage
}
// NewNotifyTXChangedResponseMessage returns a instance of the message
func NewNotifyAddressesTxsResponseMessage() *NotifyAddressesTxsResponseMessage {
return &NotifyAddressesTxsResponseMessage{}
}
// AddressesTxsNotificationMessage is an appmessage corresponding to
// its respective RPC message
type AddressesTxsNotificationMessage struct {
baseMessage
RequiredConfirmations uint32
Pending []*TxEntriesByAddresses
Confirmed []*TxEntriesByAddresses
Unconfirmed []string
}
// Command returns the protocol command string for the message
func (msg *AddressesTxsNotificationMessage) Command() MessageCommand {
return CmdAddressesTxsNotificationMessage
}
// NewAddressesTxsNotificationMessage returns a instance of the message
func NewAddressesTxsNotificationMessage(requiredConfirmations uint32, pending []*TxEntriesByAddresses,
confirmed []*TxEntriesByAddresses, unconfirmed []string) *AddressesTxsNotificationMessage {
return &AddressesTxsNotificationMessage{
RequiredConfirmations: requiredConfirmations,
Pending: pending,
Confirmed: confirmed,
Unconfirmed: unconfirmed,
}
}
// TxEntriesByAddresses is an appmessage corresponding to
// its respective RPC message
type TxEntriesByAddresses struct {
Sending []*TxEntryByAddress
Reciving []*TxEntryByAddress
}
// TxEntryByAddress is an appmessage corresponding to
// its respective RPC message
type TxEntryByAddress struct {
Address string
TxID string
Confirmations uint32
}

View File

@ -1,62 +1,69 @@
package appmessage package appmessage
// NotifyUTXOsChangedRequestMessage is an appmessage corresponding to // NotifyTxsConfirmationChangedRequestMessage is an appmessage corresponding to
// its respective RPC message // its respective RPC message
type NotifyTxsConfirmationChangedRequstMessage struct { type NotifyTxsConfirmationChangedRequestMessage struct {
baseMessage baseMessage
Addresses []string TxIDs []string
RequiredConfirmations uint32
IncludePending bool
} }
// Command returns the protocol command string for the message // Command returns the protocol command string for the message
func (msg *NotifyUTXOsChangedRequestMessage) Command() MessageCommand { func (msg *NotifyTxsConfirmationChangedRequestMessage) Command() MessageCommand {
return CmdNotifyUTXOsChangedRequestMessage return CmdNotifyTxsConfirmationChangedRequestMessage
} }
// NewNotifyUTXOsChangedRequestMessage returns a instance of the message // NewNotifyTxsConfirmationChangedRequestMessage returns a instance of the message
func NewNotifyUTXOsChangedRequestMessage(addresses []string) *NotifyUTXOsChangedRequestMessage { func NewNotifyTxsConfirmationChangedRequestMessage(TxIDs []string, requiredConfirmations uint32,
return &NotifyUTXOsChangedRequestMessage{ includePending bool) *NotifyTxsConfirmationChangedRequestMessage {
Addresses: addresses, return &NotifyTxsConfirmationChangedRequestMessage{
TxIDs: TxIDs,
RequiredConfirmations: requiredConfirmations,
IncludePending: includePending,
} }
} }
// NotifyUTXOsChangedResponseMessage is an appmessage corresponding to // NotifyTxsConfirmationChangedResponseMessage is an appmessage corresponding to
// its respective RPC message // its respective RPC message
type NotifyUTXOsChangedResponseMessage struct { type NotifyTxsConfirmationChangedResponseMessage struct {
baseMessage baseMessage
Error *RPCError Error *RPCError
} }
// Command returns the protocol command string for the message // Command returns the protocol command string for the message
func (msg *NotifyUTXOsChangedResponseMessage) Command() MessageCommand { func (msg *NotifyTxsConfirmationChangedResponseMessage) Command() MessageCommand {
return CmdNotifyUTXOsChangedResponseMessage return CmdNotifyTxsConfirmationChangedResponseMessage
} }
// NewNotifyUTXOsChangedResponseMessage returns a instance of the message // NewNotifyTXChangedResponseMessage returns a instance of the message
func NewNotifyTXChangedResponseMessage() *NotifyUTXOsChangedResponseMessage { func NewNotifyTxsChangedResponseMessage() *NotifyTxsConfirmationChangedResponseMessage {
return &NotifyUTXOsChangedResponseMessage{} return &NotifyTxsConfirmationChangedResponseMessage{}
} }
// UTXOsChangedNotificationMessage is an appmessage corresponding to // TxsConfirmationChangedNotificationMessage is an appmessage corresponding to
// its respective RPC message // its respective RPC message
type UTXOsChangedNotificationMessage struct { type TxsConfirmationChangedNotificationMessage struct {
baseMessage baseMessage
Added []*UTXOsByAddressesEntry RequiredConfirmations uint32
Removed []*UTXOsByAddressesEntry Pending []*TxIDConfirmationsPair
} Confirmed []TxIDConfirmationsPair
Unconfirmed []string
// UTXOsByAddressesEntry represents a UTXO of some address
type UTXOsByAddressesEntry struct {
Address string
Outpoint *RPCOutpoint
UTXOEntry *RPCUTXOEntry
} }
// Command returns the protocol command string for the message // Command returns the protocol command string for the message
func (msg *UTXOsChangedNotificationMessage) Command() MessageCommand { func (msg *TxsConfirmationChangedNotificationMessage) Command() MessageCommand {
return CmdUTXOsChangedNotificationMessage return CmdTxsConfirmationChangedNotificationMessage
} }
// NewUTXOsChangedNotificationMessage returns a instance of the message // NewTxsChangedNotificationMessage returns a instance of the message
func NewUTXOsChangedNotificationMessage() *UTXOsChangedNotificationMessage { func NewTxsChangedNotificationMessage(requiredConfirmations uint32, pending []*TxIDConfirmationsPair,
return &UTXOsChangedNotificationMessage{} confirmed []TxIDConfirmationsPair, unconfirmed []string) *TxsConfirmationChangedNotificationMessage {
return &TxsConfirmationChangedNotificationMessage{
RequiredConfirmations: requiredConfirmations,
Pending: pending,
Confirmed: confirmed,
Unconfirmed: unconfirmed,
}
} }

View File

@ -1,47 +0,0 @@
package protowire
import (
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/pkg/errors"
)
func (x *KaspadMessage_StartNotifyAddressesTxsRequest) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "KaspadMessage_StartNotifyAddressesTxsRequest is nil")
}
return x.StartNotifyAddressesTxsRequest.toAppMessage()
}
func (x *KaspadMessage_StartNotifyAddressesTxsRequest) fromAppMessage(message *appmessage.StartNotifyAddressesTxsRequestMessage) error {
x.StartNotifyAddressesTxsRequest = &StartNotifyAddressesTxsRequestMessage{
Addresses: message.Addresses,
}
return nil
}
func (x *StartNotifyAddressesTxsRequestMessage) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "StartNotifyAddressesTxsRequestMessage is nil")
}
return &appmessage.StartNotifyAddressesTxsRequestMessage{
Addresses: x.Addresses,
}, nil
}
func (x *KaspadMessage_StartNotifyAddressesTxsResponse) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "StartNotifyAddressesTxsResponseMessage is nil")
}
return x.StartNotifyAddressesTxsResponse.toAppMessage()
}
func (x *KaspadMessage_StartNotifyAddressesTxsResponse) fromAppMessage(message *appmessage.StartNotifyAddressesTxsResponseMessage) error {
var err *RPCError
if message.Error != nil {
err = &RPCError{Message: message.Error.Message}
}
x.StartNotifyAddressesTxsResponse = &StartNotifytTxsConfirmationChangedResponseMessage{
Error: err,
}
return nil
}

View File

@ -1,47 +0,0 @@
package protowire
import (
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/pkg/errors"
)
func (x *KaspadMessage_StartNotifyTxsConfirmationChangedRequest) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "KaspadMessage_StartNotifyTxsConfirmationChangedRequest is nil")
}
return x.StartNotifyTxsConfirmationChangedRequest.toAppMessage()
}
func (x *KaspadMessage_StartNotifyTxsConfirmationChangedRequest) fromAppMessage(message *appmessage.StartNotifyTxsConfirmationChangedRequestMessage) error {
x.StartNotifyTxsConfirmationChangedRequest = &StartNotifyTxsConfirmationChangedRequestMessage{
TxIDs: message.TxIDs,
}
return nil
}
func (x *StartNotifyTxsConfirmationChangedRequestMessage) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "StartNotifyTxsConfirmationChangedRequestMessage is nil")
}
return &appmessage.StartNotifyTxsConfirmationChangedRequestMessage{
TxIDs: x.TxIDs,
}, nil
}
func (x *KaspadMessage_StartNotifyTxsConfirmationChangedResponse) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "StartNotifyTxsConfirmationChangedResponseMessage is nil")
}
return x.StartNotifyTxsConfirmationChangedResponse.toAppMessage()
}
func (x *KaspadMessage_StartNotifyTxsConfirmationChangedResponse) fromAppMessage(message *appmessage.StartNotifyTxsConfirmationChangedResponseMessage) error {
var err *RPCError
if message.Error != nil {
err = &RPCError{Message: message.Error.Message}
}
x.StartNotifyTxsConfirmationChangedResponse = &StartNotifytTxsConfirmationChangedResponseMessage{
Error: err,
}
return nil
}

View File

@ -1,47 +0,0 @@
package protowire
import (
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/pkg/errors"
)
func (x *KaspadMessage_StopNotifyAddressesTxsRequest) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "KaspadMessage_StopNotifyAddressesTxsRequest is nil")
}
return x.StopNotifyAddressesTxsRequest.toAppMessage()
}
func (x *KaspadMessage_StopNotifyAddressesTxsRequest) fromAppMessage(message *appmessage.StopNotifyAddressesTxsRequestMessage) error {
x.StopNotifyAddressesTxsRequest = &StopNotifyAddressesTxsRequestMessage{
Addresses: message.Addresses,
}
return nil
}
func (x *StopNotifyAddressesTxsRequestMessage) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "StopNotifyAddressesTxsRequestMessage is nil")
}
return &appmessage.StopNotifyAddressesTxsRequestMessage{
Addresses: x.Addresses,
}, nil
}
func (x *KaspadMessage_StopNotifyAddressesTxsResponse) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "StopNotifyAddressesTxsResponseMessage is nil")
}
return x.StopNotifyAddressesTxsResponse.toAppMessage()
}
func (x *KaspadMessage_StopNotifyAddressesTxsResponse) fromAppMessage(message *appmessage.StopNotifyAddressesTxsResponseMessage) error {
var err *RPCError
if message.Error != nil {
err = &RPCError{Message: message.Error.Message}
}
x.StopNotifyAddressesTxsResponse = &StopNotifytTxsConfirmationChangedResponseMessage{
Error: err,
}
return nil
}

View File

@ -1,47 +0,0 @@
package protowire
import (
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/pkg/errors"
)
func (x *KaspadMessage_StopNotifyTxsConfirmationChangedRequest) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "KaspadMessage_StopNotifyTxsConfirmationChangedRequest is nil")
}
return x.StopNotifyTxsConfirmationChangedRequest.toAppMessage()
}
func (x *KaspadMessage_StopNotifyTxsConfirmationChangedRequest) fromAppMessage(message *appmessage.StopNotifyTxsConfirmationChangedRequestMessage) error {
x.StopNotifyTxsConfirmationChangedRequest = &StopNotifyTxsConfirmationChangedRequestMessage{
TxIDs: message.TxIDs,
}
return nil
}
func (x *StopNotifyTxsConfirmationChangedRequestMessage) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "StopNotifyTxsConfirmationChangedRequestMessage is nil")
}
return &appmessage.StopNotifyTxsConfirmationChangedRequestMessage{
TxIDs: x.TxIDs,
}, nil
}
func (x *KaspadMessage_StopNotifyTxsConfirmationChangedResponse) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "StopNotifyTxsConfirmationChangedResponseMessage is nil")
}
return x.StopNotifyTxsConfirmationChangedResponse.toAppMessage()
}
func (x *KaspadMessage_StopNotifyTxsConfirmationChangedResponse) fromAppMessage(message *appmessage.StopNotifyTxsConfirmationChangedResponseMessage) error {
var err *RPCError
if message.Error != nil {
err = &RPCError{Message: message.Error.Message}
}
x.StopNotifyTxsConfirmationChangedResponse = &StopNotifytTxsConfirmationChangedResponseMessage{
Error: err,
}
return nil
}