block: push PrevStateRoot data into stack item, fix #2551
And add compiler/interop support for this.
This commit is contained in:
parent
6deb77a77a
commit
251c9bd89b
3 changed files with 33 additions and 3 deletions
|
@ -371,7 +371,8 @@ func canConvert(s string) bool {
|
|||
s = s[len(interopPrefix):]
|
||||
return s != "/iterator.Iterator" && s != "/storage.Context" &&
|
||||
s != "/native/ledger.Block" && s != "/native/ledger.Transaction" &&
|
||||
s != "/native/management.Contract" && s != "/native/neo.AccountState"
|
||||
s != "/native/management.Contract" && s != "/native/neo.AccountState" &&
|
||||
s != "/native/ledger.BlockSR"
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ func (b *Block) GetExpectedBlockSizeWithoutTransactions(txCount int) int {
|
|||
|
||||
// ToStackItem converts Block to stackitem.Item.
|
||||
func (b *Block) ToStackItem() stackitem.Item {
|
||||
return stackitem.NewArray([]stackitem.Item{
|
||||
items := []stackitem.Item{
|
||||
stackitem.NewByteArray(b.Hash().BytesBE()),
|
||||
stackitem.NewBigInteger(big.NewInt(int64(b.Version))),
|
||||
stackitem.NewByteArray(b.PrevHash.BytesBE()),
|
||||
|
@ -226,5 +226,10 @@ func (b *Block) ToStackItem() stackitem.Item {
|
|||
stackitem.NewBigInteger(big.NewInt(int64(b.Index))),
|
||||
stackitem.NewByteArray(b.NextConsensus.BytesBE()),
|
||||
stackitem.NewBigInteger(big.NewInt(int64(len(b.Transactions)))),
|
||||
})
|
||||
}
|
||||
if b.StateRootEnabled {
|
||||
items = append(items, stackitem.NewByteArray(b.PrevStateRoot.BytesBE()))
|
||||
}
|
||||
|
||||
return stackitem.NewArray(items)
|
||||
}
|
||||
|
|
|
@ -29,3 +29,27 @@ type Block struct {
|
|||
// 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
|
||||
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 interface{}(b).(*BlockSR)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue