mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-24 15:56:42 +00:00

* '' * '' * '' * Changes genesis block version to 0. * a * a * All tests are done. * All tests passed for changed block version from int32 to uint16 * Adds validation of rejecting blocks with unknown versions. * Changes txn version from int32 to uint16. * . * Adds comments to exported functions. * Change functions name from ConvertFromRpcScriptPubKeyToRPCScriptPubKey to ConvertFromAppMsgRPCScriptPubKeyToRPCScriptPubKey and from ConvertFromRPCScriptPubKeyToRpcScriptPubKey to ConvertFromRPCScriptPubKeyToAppMsgRPCScriptPubKey * change comment to "ScriptPublicKey represents a Kaspad ScriptPublicKey" * delete part (tx.Version < 0) that cannot be exist on the if statement. * Revert protobuf version. * Fix a comment. * Fix a comment. * Rename a variable. * Rename a variable. * Remove a const. * Rename a type. * Rename a field. * Rename a field. * Remove commented-out code. * Remove dangerous nil case in DomainTransactionOutput.Clone(). * Remove a constant. * Fix a string. * Fix wrong totalScriptPubKeySize in transactionMassStandalonePart. * Remove a constant. * Remove an unused error. * Fix a serialization error. * Specify version types to be uint16 explicitly. * Use constants.ScriptPublicKeyVersion. * Fix a bad test. * Remove some whitespace. * Add a case to utxoEntry.Equal(). * Rename scriptPubKey to scriptPublicKey. * Remove a TODO. * Rename constants. * Rename a variable. * Add version to parseShortForm. Co-authored-by: tal <tal@daglabs.com> Co-authored-by: stasatdaglabs <stas@daglabs.com>
76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
package externalapi
|
|
|
|
// DomainBlock represents a Kaspa block
|
|
type DomainBlock struct {
|
|
Header BlockHeader
|
|
Transactions []*DomainTransaction
|
|
}
|
|
|
|
// Clone returns a clone of DomainBlock
|
|
func (block *DomainBlock) Clone() *DomainBlock {
|
|
transactionClone := make([]*DomainTransaction, len(block.Transactions))
|
|
for i, tx := range block.Transactions {
|
|
transactionClone[i] = tx.Clone()
|
|
}
|
|
|
|
return &DomainBlock{
|
|
Header: block.Header,
|
|
Transactions: transactionClone,
|
|
}
|
|
}
|
|
|
|
// If this doesn't compile, it means the type definition has been changed, so it's
|
|
// an indication to update Equal and Clone accordingly.
|
|
var _ = DomainBlock{nil, []*DomainTransaction{}}
|
|
|
|
// Equal returns whether block equals to other
|
|
func (block *DomainBlock) Equal(other *DomainBlock) bool {
|
|
if block == nil || other == nil {
|
|
return block == other
|
|
}
|
|
|
|
if len(block.Transactions) != len(other.Transactions) {
|
|
return false
|
|
}
|
|
|
|
if !block.Header.Equal(other.Header) {
|
|
return false
|
|
}
|
|
|
|
for i, tx := range block.Transactions {
|
|
if !tx.Equal(other.Transactions[i]) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// BlockHeader represents an immutable block header.
|
|
type BlockHeader interface {
|
|
BaseBlockHeader
|
|
ToMutable() MutableBlockHeader
|
|
}
|
|
|
|
// BaseBlockHeader represents the header part of a Kaspa block
|
|
type BaseBlockHeader interface {
|
|
Version() uint16
|
|
ParentHashes() []*DomainHash
|
|
HashMerkleRoot() *DomainHash
|
|
AcceptedIDMerkleRoot() *DomainHash
|
|
UTXOCommitment() *DomainHash
|
|
TimeInMilliseconds() int64
|
|
Bits() uint32
|
|
Nonce() uint64
|
|
Equal(other BaseBlockHeader) bool
|
|
}
|
|
|
|
// MutableBlockHeader represents a block header that can be mutated, but only
|
|
// the fields that are relevant to mining (Nonce and TimeInMilliseconds).
|
|
type MutableBlockHeader interface {
|
|
BaseBlockHeader
|
|
ToImmutable() BlockHeader
|
|
SetNonce(nonce uint64)
|
|
SetTimeInMilliseconds(timeInMilliseconds int64)
|
|
}
|