block

package
v0.0.0-...-8430543 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const AddressLen = sha256.Size
View Source
const CREATE_INIT = 2
View Source
const CREATE_TRIMELF = 1
View Source
const CREATE_USENONCE = 4
View Source
const CallExternal = 1
View Source
const CallInit = 4
View Source
const CallRegular = 3
View Source
const CallStart = 2
View Source
const CallView = 5
View Source
const DefaultSp = 0x30000000 + vm.PageSize*vm.MaxPagesPerBlock - 16
View Source
const GasCall = 2800
View Source
const GasLoadContractCode = 20000
View Source
const GasLoadContractCodeCached = 400
View Source
const GasLoadContractCodePerBlock = 2000
View Source
const GasSyscallCreatePerByte = 1
View Source
const GasSyscallCreateStorePerBlock = 10000
View Source
const GasSyscallEd25519PerBlock = 100
View Source
const GasSyscallRevertPerByte = 1
View Source
const GasSyscallSha256PerBlock = 60
View Source
const GasSyscallTransferMessagePerByte = 1
View Source
const GasVmTxRawCode = 5000
View Source
const HashLen = sha256.Size
View Source
const MaxByteArrayLen = 1 << 20
View Source
const MaxRevertMsgLen = 1024
View Source
const PrivkeyLen = ed25519.PrivateKeySize
View Source
const PubkeyLen = ed25519.PublicKeySize
View Source
const SYSCALL_BALANCE = 8
View Source
const SYSCALL_BLOCK_NUMBER = 14
View Source
const SYSCALL_CALLER = 3
View Source
const SYSCALL_CALLVALUE = 4
View Source
const SYSCALL_CHAINID = 16
View Source
const SYSCALL_CREATE = 20
View Source
const SYSCALL_DIFFICULTY = 15
View Source
const SYSCALL_ED25519_VERIFY = 21
View Source
const SYSCALL_GAS = 17
View Source
const SYSCALL_JUMPDEST = 18
View Source
const SYSCALL_LOAD_CONTRACT = 9
View Source
const SYSCALL_LOAD_ELF = 22
View Source
const SYSCALL_MINER = 13
View Source
const SYSCALL_ORIGIN = 2
View Source
const SYSCALL_PROTECTED_CALL = 10
View Source
const SYSCALL_REVERT = 11
View Source
const SYSCALL_SELF = 1
View Source
const SYSCALL_SHA256 = 7
View Source
const SYSCALL_STORAGE_LOAD = 6
View Source
const SYSCALL_STORAGE_STORE = 5
View Source
const SYSCALL_TIME = 12
View Source
const SYSCALL_TRANSFER = 19
View Source
const SyscallProg = 0x7fffffff

Variables

View Source
var ErrContractExists = errors.New("contract exists")
View Source
var ErrContractNotExist = errors.New("contract not exist")
View Source
var ErrIllegalEntry = errors.New("illegal entry")
View Source
var ErrIllegalSyscallParameters = errors.New("illegal syscall parameters")
View Source
var ErrInsufficientBalance = errors.New("insufficient balance")
View Source
var ErrInvalidJumpDest = errors.New("invalid jump dest")
View Source
var ErrInvalidSyscall = errors.New("invalid syscall")

Functions

func EncodeBlock

func EncodeBlock(w utils.Writer, b *Block) error

func EncodeBlockHeader

func EncodeBlockHeader(w utils.Writer, bh BlockHeader) error

func EncodeBlockSelf

func EncodeBlockSelf(w utils.Writer, b *Block) error

func EncodeTx

func EncodeTx(w utils.Writer, tx *Transaction) error

func ExecVmTxRawCode

func ExecVmTxRawCode(origin AddressType, gasLimit uint64, data []byte, s *storage.Slice, ctx *ExecutionContext, tx *Transaction) (uint64, error)

func ExecVmViewRawCode

func ExecVmViewRawCode(origin AddressType, gasLimit uint64, data []byte, s *storage.Slice, ctx *ExecutionContext) ([]byte, error)

func ExecuteBlock

func ExecuteBlock(b *Block, reward uint64, s *storage.Slice, ctx *ExecutionContext) error

func ExecuteTx

func ExecuteTx(tx *Transaction, s *storage.Slice, ctx *ExecutionContext) error

func GenKeyPair

func GenKeyPair(r io.Reader) (a PubkeyType, b PrivkeyType)

func LoadContractCode

func LoadContractCode(s *storage.Slice, addr AddressType) ([]byte, error)

func SetAccountInfo

func SetAccountInfo(s *storage.Slice, address AddressType, info AccountInfo)

Types

type AccountInfo

type AccountInfo struct {
	Balance uint64 `json:"balance"`
	Nonce   uint64 `json:"nonce"`
}

func GetAccountInfo

func GetAccountInfo(s *storage.Slice, address AddressType) AccountInfo

type AddressType

type AddressType [AddressLen]byte

func PubkeyToAddress

func PubkeyToAddress(pk PubkeyType) AddressType

type Block

type Block struct {
	Header BlockHeader    `json:"header"`
	Miner  AddressType    `json:"miner"`
	Time   uint64         `json:"time"`
	Txs    []*Transaction `json:"txs"`
}

func DecodeBlock

func DecodeBlock(r utils.Reader) (*Block, error)

func (*Block) ComputeHash

func (b *Block) ComputeHash() HashType

func (*Block) FillHash

func (b *Block) FillHash()

type BlockHeader

type BlockHeader struct {
	Hash       HashType `json:"hash"`
	ParentHash HashType `json:"parent_hash"`
	BodyHash   HashType `json:"body_hash"`
	ExtraData  HashType `json:"extra_data"`
}

func DecodeBlockHeader

func DecodeBlockHeader(r utils.Reader) (BlockHeader, error)

func (*BlockHeader) ComputeHash

func (bh *BlockHeader) ComputeHash() HashType

type ExecutionCallback

type ExecutionCallback struct {
	Transfer func(s *storage.Slice, from AddressType, to AddressType, value uint64, msg []byte, tx *Transaction, ctx *ExecutionContext)
	Block    func(s *storage.Slice, b *Block, ctx *ExecutionContext)
}

type ExecutionContext

type ExecutionContext struct {
	Height      int
	Time        uint64
	Miner       AddressType
	Difficulty  HashType
	ChainId     uint16
	Tip1Enabled bool
	Callback    *ExecutionCallback
}

type HashType

type HashType [HashLen]byte

type PrivkeyType

type PrivkeyType [PrivkeyLen]byte

type PubkeyType

type PubkeyType [PubkeyLen]byte

type SigType

type SigType [SigLen]byte

type Transaction

type Transaction struct {
	TxType       byte        `json:"tx_type"`
	SenderPubkey PubkeyType  `json:"sender_pubkey"`
	SenderSig    SigType     `json:"sender_sig"`
	Receiver     AddressType `json:"receiver"`
	Value        uint64      `json:"value"`
	GasLimit     uint64      `json:"gas_limit"`
	Fee          uint64      `json:"fee"`
	Nonce        uint64      `json:"nonce"`
	Data         []byte      `json:"data"`
}

func DecodeTx

func DecodeTx(r utils.Reader) (*Transaction, error)

func (*Transaction) Hash

func (tx *Transaction) Hash() HashType

func (*Transaction) Sign

func (tx *Transaction) Sign(privKey PrivkeyType)

Jump to

Keyboard shortcuts

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