2021-03-19 09:11:48 +00:00
|
|
|
/*
|
2022-04-20 18:30:09 +00:00
|
|
|
Package ledger provides an interface to LedgerContract native contract.
|
2021-03-19 09:11:48 +00:00
|
|
|
It allows to access ledger contents like transactions and blocks.
|
|
|
|
*/
|
2021-02-08 08:10:25 +00:00
|
|
|
package ledger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
2021-12-08 19:33:03 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/neogointernal"
|
2021-02-08 08:10:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Hash represents Ledger contract hash.
|
2021-02-15 13:40:44 +00:00
|
|
|
const Hash = "\xbe\xf2\x04\x31\x40\x36\x2a\x77\xc1\x50\x99\xc7\xe6\x4c\x12\xf7\x00\xb6\x65\xda"
|
2021-02-08 08:10:25 +00:00
|
|
|
|
2022-04-04 10:22:20 +00:00
|
|
|
// VMState represents VM execution state.
|
|
|
|
type VMState uint8
|
|
|
|
|
|
|
|
// Various VM execution states.
|
|
|
|
const (
|
|
|
|
// NoneState represents NONE VM state.
|
|
|
|
NoneState VMState = 0
|
|
|
|
// HaltState represents HALT VM state.
|
|
|
|
HaltState VMState = 1
|
|
|
|
// FaultState represents FAULT VM state.
|
|
|
|
FaultState VMState = 2
|
|
|
|
// BreakState represents BREAK VM state.
|
|
|
|
BreakState VMState = 4
|
|
|
|
)
|
|
|
|
|
2021-02-08 08:10:25 +00:00
|
|
|
// CurrentHash represents `currentHash` method of Ledger native contract.
|
|
|
|
func CurrentHash() interop.Hash256 {
|
2021-12-08 19:33:03 +00:00
|
|
|
return neogointernal.CallWithToken(Hash, "currentHash", int(contract.ReadStates)).(interop.Hash256)
|
2021-02-08 08:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CurrentIndex represents `currentIndex` method of Ledger native contract.
|
|
|
|
func CurrentIndex() int {
|
2021-12-08 19:33:03 +00:00
|
|
|
return neogointernal.CallWithToken(Hash, "currentIndex", int(contract.ReadStates)).(int)
|
2021-02-08 08:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetBlock represents `getBlock` method of Ledger native contract.
|
|
|
|
func GetBlock(indexOrHash interface{}) *Block {
|
2021-12-08 19:33:03 +00:00
|
|
|
return neogointernal.CallWithToken(Hash, "getBlock", int(contract.ReadStates), indexOrHash).(*Block)
|
2021-02-08 08:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTransaction represents `getTransaction` method of Ledger native contract.
|
|
|
|
func GetTransaction(hash interop.Hash256) *Transaction {
|
2021-12-08 19:33:03 +00:00
|
|
|
return neogointernal.CallWithToken(Hash, "getTransaction", int(contract.ReadStates), hash).(*Transaction)
|
2021-02-08 08:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTransactionHeight represents `getTransactionHeight` method of Ledger native contract.
|
|
|
|
func GetTransactionHeight(hash interop.Hash256) int {
|
2021-12-08 19:33:03 +00:00
|
|
|
return neogointernal.CallWithToken(Hash, "getTransactionHeight", int(contract.ReadStates), hash).(int)
|
2021-02-08 08:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTransactionFromBlock represents `getTransactionFromBlock` method of Ledger native contract.
|
|
|
|
func GetTransactionFromBlock(indexOrHash interface{}, txIndex int) *Transaction {
|
2021-12-08 19:33:03 +00:00
|
|
|
return neogointernal.CallWithToken(Hash, "getTransactionFromBlock", int(contract.ReadStates),
|
2021-02-08 08:10:25 +00:00
|
|
|
indexOrHash, txIndex).(*Transaction)
|
|
|
|
}
|
2022-04-04 10:22:20 +00:00
|
|
|
|
2022-04-25 11:27:34 +00:00
|
|
|
// GetTransactionSigners represents `getTransactionSigners` method of Ledger native contract.
|
|
|
|
func GetTransactionSigners(hash interop.Hash256) []TransactionSigner {
|
|
|
|
return neogointernal.CallWithToken(Hash, "getTransactionSigners", int(contract.ReadStates),
|
|
|
|
hash).([]TransactionSigner)
|
|
|
|
}
|
|
|
|
|
2022-04-04 10:22:20 +00:00
|
|
|
// GetTransactionVMState represents `getTransactionVMState` method of Ledger native contract.
|
|
|
|
func GetTransactionVMState(hash interop.Hash256) VMState {
|
|
|
|
return neogointernal.CallWithToken(Hash, "getTransactionVMState", int(contract.ReadStates), hash).(VMState)
|
|
|
|
}
|