mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-29 02:06:43 +00:00

* Replace BlockMessage with RpcBlock in rpc.proto. * Convert everything in kaspad to use RPCBlocks and fix tests. * Fix compilation errors in stability tests and the miner. * Update TransactionVerboseData in rpc.proto. * Update TransactionVerboseData in the rest of kaspad. * Make golint happy. * Include RpcTransactionVerboseData in RpcTransaction instead of the other way around. * Regenerate rpc.pb.go after merge. * Update appmessage types. * Update appmessage request and response types. * Reimplement conversion functions between appmessage.RPCTransaction and protowire.RpcTransaction. * Extract RpcBlockHeader toAppMessage/fromAppMessage out of RpcBlock. * Fix compilation errors in getBlock, getBlocks, and submitBlock. * Fix compilation errors in getMempoolEntry. * Fix compilation errors in notifyBlockAdded. * Update verbosedata.go. * Fix compilation errors in getBlock and getBlocks. * Fix compilation errors in getBlocks tests. * Fix conversions between getBlocks message types. * Fix integration tests. * Fix a comment. * Add selectedParent to the verbose block response.
92 lines
2.5 KiB
Go
92 lines
2.5 KiB
Go
package appmessage
|
|
|
|
// SubmitBlockRequestMessage is an appmessage corresponding to
|
|
// its respective RPC message
|
|
type SubmitBlockRequestMessage struct {
|
|
baseMessage
|
|
Block *RPCBlock
|
|
}
|
|
|
|
// Command returns the protocol command string for the message
|
|
func (msg *SubmitBlockRequestMessage) Command() MessageCommand {
|
|
return CmdSubmitBlockRequestMessage
|
|
}
|
|
|
|
// NewSubmitBlockRequestMessage returns a instance of the message
|
|
func NewSubmitBlockRequestMessage(block *RPCBlock) *SubmitBlockRequestMessage {
|
|
return &SubmitBlockRequestMessage{
|
|
Block: block,
|
|
}
|
|
}
|
|
|
|
// RejectReason describes the reason why a block sent by SubmitBlock was rejected
|
|
type RejectReason byte
|
|
|
|
// RejectReason constants
|
|
// Not using iota, since in the .proto file those are hardcoded
|
|
const (
|
|
RejectReasonNone RejectReason = 0
|
|
RejectReasonBlockInvalid RejectReason = 1
|
|
RejectReasonIsInIBD RejectReason = 2
|
|
)
|
|
|
|
var rejectReasonToString = map[RejectReason]string{
|
|
RejectReasonNone: "None",
|
|
RejectReasonBlockInvalid: "Block is invalid",
|
|
RejectReasonIsInIBD: "Node is in IBD",
|
|
}
|
|
|
|
func (rr RejectReason) String() string {
|
|
return rejectReasonToString[rr]
|
|
}
|
|
|
|
// SubmitBlockResponseMessage is an appmessage corresponding to
|
|
// its respective RPC message
|
|
type SubmitBlockResponseMessage struct {
|
|
baseMessage
|
|
RejectReason RejectReason
|
|
Error *RPCError
|
|
}
|
|
|
|
// Command returns the protocol command string for the message
|
|
func (msg *SubmitBlockResponseMessage) Command() MessageCommand {
|
|
return CmdSubmitBlockResponseMessage
|
|
}
|
|
|
|
// NewSubmitBlockResponseMessage returns a instance of the message
|
|
func NewSubmitBlockResponseMessage() *SubmitBlockResponseMessage {
|
|
return &SubmitBlockResponseMessage{}
|
|
}
|
|
|
|
// RPCBlock is a kaspad block representation meant to be
|
|
// used over RPC
|
|
type RPCBlock struct {
|
|
Header *RPCBlockHeader
|
|
Transactions []*RPCTransaction
|
|
VerboseData *RPCBlockVerboseData
|
|
}
|
|
|
|
// RPCBlockHeader is a kaspad block header representation meant to be
|
|
// used over RPC
|
|
type RPCBlockHeader struct {
|
|
Version uint32
|
|
ParentHashes []string
|
|
HashMerkleRoot string
|
|
AcceptedIDMerkleRoot string
|
|
UTXOCommitment string
|
|
Timestamp int64
|
|
Bits uint32
|
|
Nonce uint64
|
|
}
|
|
|
|
// RPCBlockVerboseData holds verbose data about a block
|
|
type RPCBlockVerboseData struct {
|
|
Hash string
|
|
Difficulty float64
|
|
SelectedParentHash string
|
|
TransactionIDs []string
|
|
IsHeaderOnly bool
|
|
BlueScore uint64
|
|
ChildrenHashes []string
|
|
}
|