forked from TrueCloudLab/neoneo-go
core: add System.Blockchain.GetTransactionFromBlock interop
This commit is contained in:
parent
1e63ae4b3f
commit
d692de5ea4
6 changed files with 103 additions and 9 deletions
|
@ -148,6 +148,27 @@ func bcGetTransaction(ic *interop.Context, v *vm.VM) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// bcGetTransactionFromBlock returns transaction with the given index from the
|
||||
// block with height or hash specified.
|
||||
func bcGetTransactionFromBlock(ic *interop.Context, v *vm.VM) error {
|
||||
hash, err := getBlockHashFromElement(ic.Chain, v.Estack().Pop())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
block, err := ic.DAO.GetBlock(hash)
|
||||
if err != nil || !isTraceableBlock(ic, block.Index) {
|
||||
v.Estack().PushVal(stackitem.Null{})
|
||||
return nil
|
||||
}
|
||||
index := v.Estack().Pop().BigInt().Int64()
|
||||
if index < 0 || index >= int64(len(block.Transactions)) {
|
||||
return errors.New("wrong transaction index")
|
||||
}
|
||||
tx := block.Transactions[index]
|
||||
v.Estack().PushVal(tx.Hash().BytesBE())
|
||||
return nil
|
||||
}
|
||||
|
||||
// bcGetTransactionHeight returns transaction height.
|
||||
func bcGetTransactionHeight(ic *interop.Context, v *vm.VM) error {
|
||||
_, h, err := getTransactionAndHeight(ic.DAO, v)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue