2021-02-08 08:10:25 +00:00
|
|
|
package ledger
|
|
|
|
|
|
|
|
import "github.com/nspcc-dev/neo-go/pkg/interop"
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// Block represents a NEO block, it's a data structure where you can get
|
2021-02-08 08:10:25 +00:00
|
|
|
// block-related data from. It's similar to the Block class in the Neo .net
|
2022-04-20 18:30:09 +00:00
|
|
|
// framework. To use it, you need to get it via GetBlock function call.
|
2021-02-08 08:10:25 +00:00
|
|
|
type Block struct {
|
|
|
|
// Hash represents the hash (256 bit BE value in a 32 byte slice) of the
|
|
|
|
// given block.
|
|
|
|
Hash interop.Hash256
|
|
|
|
// Version of the block.
|
|
|
|
Version int
|
|
|
|
// PrevHash represents the hash (256 bit BE value in a 32 byte slice) of the
|
|
|
|
// previous block.
|
|
|
|
PrevHash interop.Hash256
|
|
|
|
// MerkleRoot represents the root hash (256 bit BE value in a 32 byte slice)
|
|
|
|
// of a transaction list.
|
|
|
|
MerkleRoot interop.Hash256
|
|
|
|
// Timestamp represents millisecond-precision block timestamp.
|
|
|
|
Timestamp int
|
2021-07-14 08:32:54 +00:00
|
|
|
// Nonce represents block nonce.
|
|
|
|
Nonce int
|
2021-02-08 08:10:25 +00:00
|
|
|
// Index represents the height of the block.
|
|
|
|
Index int
|
2022-04-20 18:30:09 +00:00
|
|
|
// NextConsensus represents the contract address of the next miner (160 bit BE
|
2021-02-08 08:10:25 +00:00
|
|
|
// value in a 20 byte slice).
|
|
|
|
NextConsensus interop.Hash160
|
|
|
|
// TransactionsLength represents the length of block's transactions array.
|
|
|
|
TransactionsLength int
|
|
|
|
}
|
2022-07-06 08:52:06 +00:00
|
|
|
|
|
|
|
// BlockSR is a stateroot-enabled Neo block. It's returned from the Ledger contract's
|
|
|
|
// GetBlock method when StateRootInHeader NeoGo extension is used. Use it only when
|
|
|
|
// you have it enabled when you need to access PrevStateRoot field, Block is sufficient
|
|
|
|
// otherwise. To get this data type ToBlockSR method of Block should be used. All of
|
|
|
|
// the fields are same as in Block except PrevStateRoot.
|
|
|
|
type BlockSR struct {
|
|
|
|
Hash interop.Hash256
|
|
|
|
Version int
|
|
|
|
PrevHash interop.Hash256
|
|
|
|
MerkleRoot interop.Hash256
|
|
|
|
Timestamp int
|
|
|
|
Nonce int
|
|
|
|
Index int
|
|
|
|
NextConsensus interop.Hash160
|
|
|
|
TransactionsLength int
|
|
|
|
// PrevStateRoot is a hash of the previous block's state root.
|
|
|
|
PrevStateRoot interop.Hash256
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToBlockSR converts Block into BlockSR for chains with StateRootInHeader option.
|
|
|
|
func (b *Block) ToBlockSR() *BlockSR {
|
2023-04-03 10:34:24 +00:00
|
|
|
return any(b).(*BlockSR)
|
2022-07-06 08:52:06 +00:00
|
|
|
}
|