ledger

package
v0.0.0-...-886a677 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 3 Imported by: 5

Documentation

Overview

Package ledger provides an interface to LedgerContract native contract. It allows to access ledger contents like transactions and blocks.

Index

Constants

View Source
const Hash = "\xbe\xf2\x04\x31\x40\x36\x2a\x77\xc1\x50\x99\xc7\xe6\x4c\x12\xf7\x00\xb6\x65\xda"

Hash represents Ledger contract hash.

Variables

This section is empty.

Functions

func CurrentHash

func CurrentHash() interop.Hash256

CurrentHash represents `currentHash` method of Ledger native contract.

func CurrentIndex

func CurrentIndex() int

CurrentIndex represents `currentIndex` method of Ledger native contract.

func GetTransactionHeight

func GetTransactionHeight(hash interop.Hash256) int

GetTransactionHeight represents `getTransactionHeight` method of Ledger native contract.

Types

type Block

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
	// 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
}

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.

func GetBlock

func GetBlock(indexOrHash any) *Block

GetBlock represents `getBlock` method of Ledger native contract.

func (*Block) ToBlockSR

func (b *Block) ToBlockSR() *BlockSR

ToBlockSR converts Block into BlockSR for chains with StateRootInHeader option.

type BlockSR

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
}

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 SignerScope

type SignerScope byte

SignerScope represents a signer's witness scope.

const (
	// None specifies that no contract was witnessed. Only signs the transaction
	// and pays GAS fee if a sender.
	None SignerScope = 0
	// CalledByEntry means that the witness is valid only when the witness
	// checking contract is called from the entry script.
	CalledByEntry SignerScope = 0x01
	// CustomContracts define custom hash for contract-specific witness.
	CustomContracts SignerScope = 0x10
	// CustomGroups define custom public key for group members.
	CustomGroups SignerScope = 0x20
	// Rules is a set of conditions with boolean operators.
	Rules SignerScope = 0x40
	// Global allows this witness in all contexts. This cannot be combined with
	// other flags.
	Global SignerScope = 0x80
)

Various witness scopes.

type Transaction

type Transaction struct {
	// Hash represents the hash (256 bit BE value in a 32 byte slice) of the
	// given transaction (which also is its ID).
	Hash interop.Hash256
	// Version represents the transaction version.
	Version int
	// Nonce is a random number to avoid hash collision.
	Nonce int
	// Sender represents the sender (160 bit BE value in a 20 byte slice) of the
	// given Transaction.
	Sender interop.Hash160
	// SysFee represents the fee to be burned.
	SysFee int
	// NetFee represents the fee to be distributed to consensus nodes.
	NetFee int
	// ValidUntilBlock is the maximum blockchain height exceeding which
	// a transaction should fail verification.
	ValidUntilBlock int
	// Script represents a code to run in NeoVM for this transaction.
	Script []byte
}

Transaction represents a NEO transaction. It's similar to Transaction class in Neo .net framework.

func GetTransaction

func GetTransaction(hash interop.Hash256) *Transaction

GetTransaction represents `getTransaction` method of Ledger native contract.

func GetTransactionFromBlock

func GetTransactionFromBlock(indexOrHash any, txIndex int) *Transaction

GetTransactionFromBlock represents `getTransactionFromBlock` method of Ledger native contract.

type TransactionSigner

type TransactionSigner struct {
	// Account represents the account (160 bit BE value in a 20 byte slice) of
	// the given signer.
	Account interop.Hash160
	// Scopes represents a set of witness flags for the given signer.
	Scopes SignerScope
	// Contracts represents the set of contract hashes (160 bit BE value in a 20
	// byte slice) allowed to be called by the signer. It is only non-empty if
	// CustomContracts scope flag is set.
	AllowedContracts []interop.Hash160
	// AllowedGroups represents the set of contract groups (ecdsa public key
	// bytes in a 33 byte slice) allowed to be called by the signer. It is only
	// non-empty if CustomGroups scope flag is set.
	AllowedGroups []interop.PublicKey
	// Rules represents a rule-based witness scope of the given signer. It is
	// only non-empty if Rules scope flag is set.
	Rules []WitnessRule
}

TransactionSigner represent the signer of a NEO transaction. It's similar to Signer class in Neo .net framework.

func GetTransactionSigners

func GetTransactionSigners(hash interop.Hash256) []TransactionSigner

GetTransactionSigners represents `getTransactionSigners` method of Ledger native contract.

type VMState

type VMState uint8

VMState represents VM execution state.

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
)

Various VM execution states.

func GetTransactionVMState

func GetTransactionVMState(hash interop.Hash256) VMState

GetTransactionVMState represents `getTransactionVMState` method of Ledger native contract.

type WitnessAction

type WitnessAction byte

WitnessAction represents an action to perform in WitnessRule if witness condition matches.

const (
	// WitnessDeny rejects current witness if condition is met.
	WitnessDeny WitnessAction = 0
	// WitnessAllow approves current witness if condition is met.
	WitnessAllow WitnessAction = 1
)

Various rule-based witness actions.

type WitnessCondition

type WitnessCondition struct {
	Type WitnessConditionType
	// Depends on the witness condition Type, its value can be asserted to the
	// certain structure according to the following rule:
	// WitnessBoolean -> bool
	// WitnessNot ->  []WitnessCondition with one element
	// WitnessAnd -> []WitnessCondition
	// WitnessOr -> []WitnessCondition
	// WitnessScriptHash -> interop.Hash160
	// WitnessGroup -> interop.PublicKey
	// WitnessCalledByContract -> interop.Hash160
	// WitnessCalledByGroup -> interop.PublicKey
	// WitnessCalledByEntry -> doesn't have value, thus, an attempt to access the Value leads to runtime exception.
	Value any
}

WitnessCondition represents a single witness condition for a rule-based witness. Its type can always be safely accessed, but trying to access its value causes runtime exception for those types that don't have value (currently, it's only CalledByEntry witness condition).

type WitnessConditionType

type WitnessConditionType byte

WitnessConditionType represents the type of rule-based witness condition.

const (
	// WitnessBoolean is a generic boolean condition.
	WitnessBoolean WitnessConditionType = 0x00
	// WitnessNot reverses another condition.
	WitnessNot WitnessConditionType = 0x01
	// WitnessAnd means that all conditions must be met.
	WitnessAnd WitnessConditionType = 0x02
	// WitnessOr means that any of conditions must be met.
	WitnessOr WitnessConditionType = 0x03
	// WitnessScriptHash matches executing contract's script hash.
	WitnessScriptHash WitnessConditionType = 0x18
	// WitnessGroup matches executing contract's group key.
	WitnessGroup WitnessConditionType = 0x19
	// WitnessCalledByEntry matches when current script is an entry script or is
	// called by an entry script.
	WitnessCalledByEntry WitnessConditionType = 0x20
	// WitnessCalledByContract matches when current script is called by the
	// specified contract.
	WitnessCalledByContract WitnessConditionType = 0x28
	// WitnessCalledByGroup matches when current script is called by contract
	// belonging to the specified group.
	WitnessCalledByGroup WitnessConditionType = 0x29
)

Various witness condition types

type WitnessRule

type WitnessRule struct {
	// Action denotes whether the witness condition should be accepted or denied.
	Action WitnessAction
	// Condition holds a set of nested witness rules. Max nested depth is 2.
	Condition WitnessCondition
}

WitnessRule represents a single rule for Rules witness scope.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL