mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 23:42:23 +00:00
1a48f1ce43
This is a bad one. $ ./bin/neo-go contract testinvokefunction -r https://rpc10.n3.nspcc.ru:10331 0xda65b600f7124ce6c79950c1772a36403104f2be getBlock 5762000 { "state": "HALT", "gasconsumed": "202812", "script": "AtDrVwARwB8MCGdldEJsb2NrDBS+8gQxQDYqd8FQmcfmTBL3ALZl2kFifVtS", "stack": [ { "type": "Array", "value": [ { "type": "ByteString", "value": "vq5IPTPEDRhz0JA4cQKIa6/o97pnJt/HfVkDRknd1rg=" }, { "type": "Integer", "value": "0" }, { "type": "ByteString", "value": "zFYF3LGaTKdbqVX99shaBUzTq9YjXb0jaPMjk2jdSP4=" }, { "type": "ByteString", "value": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" }, { "type": "Integer", "value": "1722060076994" }, { "type": "Integer", "value": "5293295626238767595" }, { "type": "Integer", "value": "5762000" }, { "type": "ByteString", "value": "LIt05Fpxhl/kXMX3EAGIASyOSQs=" }, { "type": "Integer", "value": "0" } ] } ], "exception": null, "notifications": [] } $ ./bin/neo-go contract testinvokefunction -r http://seed3.neo.org:10332 0xda65b600f7124ce6c79950c1772a36403104f2be getBlock 5762000 { "state": "HALT", "gasconsumed": "202812", "script": "AtDrVwARwB8MCGdldEJsb2NrDBS+8gQxQDYqd8FQmcfmTBL3ALZl2kFifVtS", "stack": [ { "type": "Array", "value": [ { "type": "ByteString", "value": "vq5IPTPEDRhz0JA4cQKIa6/o97pnJt/HfVkDRknd1rg=" }, { "type": "Integer", "value": "0" }, { "type": "ByteString", "value": "zFYF3LGaTKdbqVX99shaBUzTq9YjXb0jaPMjk2jdSP4=" }, { "type": "ByteString", "value": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" }, { "type": "Integer", "value": "1722060076994" }, { "type": "Integer", "value": "5293295626238767595" }, { "type": "Integer", "value": "5762000" }, { "type": "Integer", "value": "6" }, { "type": "ByteString", "value": "LIt05Fpxhl/kXMX3EAGIASyOSQs=" }, { "type": "Integer", "value": "0" } ] } ], "exception": null, "notifications": [] } 9 fields vs 10, notice the primary index right after the block number. Back whenac527650eb
initially added Ledger I've used https://github.com/neo-project/neo/pull/2215 as a reference and it was correct (no primary index). But then https://github.com/neo-project/neo/pull/2296 came into the C# codebase and while it looked like a pure refactoring it actually did add the primary index as well and this wasn't noticed. It wasn't noticed even when3a4e0caeb8
had touched some nearby code. In short, we had a completely wrong implementation of this call for more than three years. But looks like it's not a very popular one. Signed-off-by: Roman Khimov <roman@nspcc.ru>
58 lines
2.2 KiB
Go
58 lines
2.2 KiB
Go
package ledger
|
|
|
|
import "github.com/nspcc-dev/neo-go/pkg/interop"
|
|
|
|
// Block represents a NEO block, it's a data structure where you can get
|
|
// block-related data from. It's similar to the Block class in the Neo .net
|
|
// framework. To use it, you need to get it via GetBlock function call.
|
|
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
|
|
// Nonce represents block nonce.
|
|
Nonce int
|
|
// Index represents the height of the block.
|
|
Index int
|
|
// PrimaryIndex represents the index of the primary node that created this block.
|
|
PrimaryIndex int
|
|
// NextConsensus represents the contract address of the next miner (160 bit BE
|
|
// value in a 20 byte slice).
|
|
NextConsensus interop.Hash160
|
|
// TransactionsLength represents the length of block's transactions array.
|
|
TransactionsLength int
|
|
}
|
|
|
|
// 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
|
|
PrimaryIndex 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 {
|
|
return any(b).(*BlockSR)
|
|
}
|