block

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: GPL-3.0 Imports: 20 Imported by: 1

Documentation

Overview

Copyright 2023 The AmazeChain Authors This file is part of the AmazeChain library.

The AmazeChain library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The AmazeChain library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with the AmazeChain library. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	// BloomByteLength represents the number of bytes used in a header log bloom.
	BloomByteLength = 256

	// BloomBitLength represents the number of bits used in a header log bloom.
	BloomBitLength = 8 * BloomByteLength
)
View Source
const (
	// ReceiptStatusFailed is the status code of a transaction if execution failed.
	ReceiptStatusFailed = uint64(0)

	// ReceiptStatusSuccessful is the status code of a transaction if execution succeeded.
	ReceiptStatusSuccessful = uint64(1)
)

Variables

This section is empty.

Functions

func Bloom9

func Bloom9(data []byte) []byte

Bloom9 returns the bloom filter for the given data

func BloomLookup

func BloomLookup(bin Bloom, topic bytesBacked) bool

BloomLookup is a convenience-method to check presence int he bloom filter

func LogsBloom

func LogsBloom(logs []*Log) []byte

LogsBloom returns the bloom bytes for the given logs

Types

type Block

type Block struct {
	ReceiveAt    time.Time
	ReceivedFrom interface{}
	// contains filtered or unexported fields
}

func NewBlockFromStorage

func NewBlockFromStorage(hash types.Hash, header *Header, body *Body) *Block

func (*Block) BaseFee64

func (b *Block) BaseFee64() *uint256.Int

func (*Block) Body

func (b *Block) Body() IBody

func (*Block) Coinbase

func (b *Block) Coinbase() types.Address

func (*Block) Difficulty

func (b *Block) Difficulty() *uint256.Int

func (*Block) FromProtoMessage

func (b *Block) FromProtoMessage(message proto.Message) error

func (*Block) GasLimit

func (b *Block) GasLimit() uint64

func (*Block) GasUsed

func (b *Block) GasUsed() uint64

func (*Block) Hash

func (b *Block) Hash() types.Hash

func (*Block) Header

func (b *Block) Header() IHeader

func (*Block) Marshal

func (b *Block) Marshal() ([]byte, error)

func (*Block) Nonce

func (b *Block) Nonce() uint64

func (*Block) Number64

func (b *Block) Number64() *uint256.Int

func (*Block) ParentHash

func (b *Block) ParentHash() types.Hash

func (*Block) SendersToTxs

func (b *Block) SendersToTxs(senders []types.Address)

func (*Block) StateRoot

func (b *Block) StateRoot() types.Hash

func (*Block) Time

func (b *Block) Time() uint64

func (*Block) ToProtoMessage

func (b *Block) ToProtoMessage() proto.Message

func (*Block) Transaction

func (b *Block) Transaction(hash types.Hash) *transaction.Transaction

func (*Block) Transactions

func (b *Block) Transactions() []*transaction.Transaction

func (*Block) TxHash

func (b *Block) TxHash() types.Hash

func (*Block) Uncles

func (b *Block) Uncles() []*Header

func (*Block) Unmarshal

func (b *Block) Unmarshal(data []byte) error

func (*Block) WithSeal

func (b *Block) WithSeal(header IHeader) *Block

type BlockNonce

type BlockNonce [8]byte

func EncodeNonce

func EncodeNonce(i uint64) BlockNonce

EncodeNonce converts the given integer to a block nonce.

func (BlockNonce) MarshalText

func (n BlockNonce) MarshalText() ([]byte, error)

MarshalText todo copy eth

func (BlockNonce) Uint64

func (n BlockNonce) Uint64() uint64

Uint64 returns the integer value of a block nonce.

func (*BlockNonce) UnmarshalText

func (n *BlockNonce) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Blocks

type Blocks []IBlock

type Bloom

type Bloom [BloomByteLength]byte

Bloom represents a 2048 bit bloom filter.

func BytesToBloom

func BytesToBloom(b []byte) Bloom

BytesToBloom converts a byte slice to a bloom filter. It panics if b is not of suitable size.

func CreateBloom

func CreateBloom(receipts Receipts) Bloom

func (*Bloom) Add

func (b *Bloom) Add(d []byte)

Add adds d to the filter. Future calls of Test(d) will return true.

func (Bloom) Big

func (b Bloom) Big() *big.Int

Big converts b to a big integer. Note: Converting a bloom filter to a big.Int and then calling GetBytes does not return the same bytes, since big.Int will trim leading zeroes

func (Bloom) Bytes

func (b Bloom) Bytes() []byte

Bytes returns the backing byte slice of the bloom

func (Bloom) MarshalText

func (b Bloom) MarshalText() ([]byte, error)

MarshalText encodes b as a hex string with 0x prefix.

func (*Bloom) SetBytes

func (b *Bloom) SetBytes(d []byte)

SetBytes sets the content of b to the given bytes. It panics if d is not of suitable size.

func (Bloom) Test

func (b Bloom) Test(topic []byte) bool

Test checks if the given topic is present in the bloom filter

func (*Bloom) UnmarshalText

func (b *Bloom) UnmarshalText(input []byte) error

UnmarshalText b as a hex string with 0x prefix.

type Body

type Body struct {
	Txs       []*transaction.Transaction
	Verifiers []*Verify
	Rewards   []*Reward
}

func (*Body) FromProtoMessage

func (b *Body) FromProtoMessage(message proto.Message) error

func (*Body) Reward

func (b *Body) Reward() []*Reward

func (*Body) SendersFromTxs

func (b *Body) SendersFromTxs() []types.Address

func (*Body) SendersToTxs

func (b *Body) SendersToTxs(senders []types.Address)

func (*Body) ToProtoMessage

func (b *Body) ToProtoMessage() proto.Message

func (*Body) Transactions

func (b *Body) Transactions() []*transaction.Transaction

func (*Body) Verifier

func (b *Body) Verifier() []*Verify

type BodyForStorage

type BodyForStorage struct {
	BaseTxId uint64
	TxAmount uint32
}
type Header struct {
	ParentHash  types.Hash    `json:"parentHash"       gencodec:"required"`
	Coinbase    types.Address `json:"miner"`
	Root        types.Hash    `json:"stateRoot"        gencodec:"required"`
	TxHash      types.Hash    `json:"transactionsRoot" gencodec:"required"`
	ReceiptHash types.Hash    `json:"receiptsRoot"     gencodec:"required"`
	Bloom       Bloom         `json:"logsBloom"        gencodec:"required"`
	Difficulty  *uint256.Int  `json:"difficulty"       gencodec:"required"`
	Number      *uint256.Int  `json:"number"           gencodec:"required"`
	GasLimit    uint64        `json:"gasLimit"         gencodec:"required"`
	GasUsed     uint64        `json:"gasUsed"          gencodec:"required"`
	Time        uint64        `json:"timestamp"        gencodec:"required"`
	MixDigest   types.Hash    `json:"mixHash"`
	Nonce       BlockNonce    `json:"nonce"`
	Extra       []byte        `json:"extraData"        gencodec:"required"`

	// BaseFee was added by EIP-1559 and is ignored in legacy headers.
	BaseFee *uint256.Int `json:"baseFeePerGas" rlp:"optional"`

	Signature types.Signature `json:"signature"`
	// contains filtered or unexported fields
}

func CopyHeader

func CopyHeader(h *Header) *Header

func (*Header) BaseFee64

func (h *Header) BaseFee64() *uint256.Int

func (*Header) FromProtoMessage

func (h *Header) FromProtoMessage(message proto.Message) error

func (Header) Hash

func (h Header) Hash() types.Hash

func (*Header) Marshal

func (h *Header) Marshal() ([]byte, error)

func (*Header) Number64

func (h *Header) Number64() *uint256.Int

func (*Header) StateRoot

func (h *Header) StateRoot() types.Hash

func (*Header) ToProtoMessage

func (h *Header) ToProtoMessage() proto.Message

func (*Header) Unmarshal

func (h *Header) Unmarshal(data []byte) error

type IBlock

type IBlock interface {
	IHeader
	Header() IHeader
	Body() IBody
	Transaction(hash types.Hash) *transaction.Transaction
	Transactions() []*transaction.Transaction
	Number64() *uint256.Int
	Difficulty() *uint256.Int
	Time() uint64
	GasLimit() uint64
	GasUsed() uint64
	Nonce() uint64
	Coinbase() types.Address
	ParentHash() types.Hash
	TxHash() types.Hash
	WithSeal(header IHeader) *Block
}

func NewBlock

func NewBlock(h IHeader, txs []*transaction.Transaction) IBlock

NewBlock creates a new block. The input data is copied, changes to header and to the field values will not affect the block.

The values of TxHash, UncleHash, ReceiptHash and Bloom in header are ignored and set to values derived from the given txs, uncles and receipts.

func NewBlockFromReceipt

func NewBlockFromReceipt(h IHeader, txs []*transaction.Transaction, uncles []IHeader, receipts []*Receipt, reward []*Reward) IBlock

type IBody

type IBody interface {
	Verifier() []*Verify
	Reward() []*Reward
	Transactions() []*transaction.Transaction
	ToProtoMessage() proto.Message
	FromProtoMessage(message proto.Message) error
}

type IHeader

type IHeader interface {
	Number64() *uint256.Int
	BaseFee64() *uint256.Int
	Hash() types.Hash
	ToProtoMessage() proto.Message
	FromProtoMessage(message proto.Message) error
	Marshal() ([]byte, error)
	Unmarshal(data []byte) error
	StateRoot() types.Hash
}

type Log

type Log struct {
	// Consensus fields:
	// address of the contract that generated the event
	Address types.Address `json:"address" gencodec:"required"`
	// list of topics provided by the contract.
	Topics []types.Hash `json:"topics" gencodec:"required"`
	// supplied by the contract, usually ABI-encoded
	Data []byte `json:"data" gencodec:"required"`

	// Derived fields. These fields are filled in by the node
	// but not secured by consensus.
	// block in which the transaction was included
	BlockNumber *uint256.Int `json:"blockNumber"`
	// hash of the transaction
	TxHash types.Hash `json:"transactionHash" gencodec:"required"`
	// index of the transaction in the block
	TxIndex uint `json:"transactionIndex" gencodec:"required"`
	// hash of the block in which the transaction was included
	BlockHash types.Hash `json:"blockHash"`
	// index of the log in the receipt
	Index uint `json:"logIndex" gencodec:"required"`

	// The Removed field is true if this log was reverted due to a chain reorganisation.
	// You must pay attention to this field if you receive logs through a filter query.
	Removed bool `json:"removed"`
}

func (*Log) FromProtoMessage

func (l *Log) FromProtoMessage(message proto.Message) error

func (*Log) ToProtoMessage

func (l *Log) ToProtoMessage() proto.Message

type Logs

type Logs []*Log

func (*Logs) Marshal

func (l *Logs) Marshal() ([]byte, error)

func (*Logs) Unmarshal

func (l *Logs) Unmarshal(data []byte) error

type RawBody

type RawBody struct {
	Transactions [][]byte
}

type Receipt

type Receipt struct {
	// Consensus fields: These fields are defined by the Yellow Paper
	Type              uint8  `json:"type,omitempty"`
	PostState         []byte `json:"root"`
	Status            uint64 `json:"status"`
	CumulativeGasUsed uint64 `json:"cumulativeGasUsed" gencodec:"required"`
	Bloom             Bloom  `json:"logsBloom"         gencodec:"required"`
	Logs              []*Log `json:"logs"              gencodec:"required"`

	// Implementation fields: These fields are added by geth when processing a transaction.
	// They are stored in the chain database.
	TxHash          types.Hash    `json:"transactionHash" gencodec:"required"`
	ContractAddress types.Address `json:"contractAddress"`
	GasUsed         uint64        `json:"gasUsed" gencodec:"required"`

	// Inclusion information: These fields provide information about the inclusion of the
	// transaction corresponding to this receipt.
	BlockHash        types.Hash   `json:"blockHash,omitempty"`
	BlockNumber      *uint256.Int `json:"blockNumber,omitempty"`
	TransactionIndex uint         `json:"transactionIndex"`
}

func (*Receipt) Marshal

func (r *Receipt) Marshal() ([]byte, error)

func (*Receipt) Unmarshal

func (r *Receipt) Unmarshal(data []byte) error

type Receipts

type Receipts []*Receipt

func (Receipts) EncodeIndex

func (rs Receipts) EncodeIndex(i int, w *bytes.Buffer)

EncodeIndex encodes the i'th receipt to w.

func (*Receipts) FromProtoMessage

func (rs *Receipts) FromProtoMessage(receipts *types_pb.Receipts) error

func (Receipts) Len

func (rs Receipts) Len() int

Len returns the number of receipts in this list.

func (*Receipts) Marshal

func (rs *Receipts) Marshal() ([]byte, error)

func (*Receipts) ToProtoMessage

func (rs *Receipts) ToProtoMessage() proto.Message

func (*Receipts) Unmarshal

func (rs *Receipts) Unmarshal(data []byte) error

type Reward

type Reward struct {
	Address types.Address
	Amount  *uint256.Int
}

func CopyReward

func CopyReward(rewards []*Reward) []*Reward

func (*Reward) FromProtoMessage

func (r *Reward) FromProtoMessage(pbReward *types_pb.Reward) *Reward

func (*Reward) ToProtoMessage

func (r *Reward) ToProtoMessage() proto.Message

type Rewards

type Rewards []*Reward

func (Rewards) Len

func (r Rewards) Len() int

func (Rewards) Less

func (r Rewards) Less(i, j int) bool

func (Rewards) Swap

func (r Rewards) Swap(i, j int)

type Verify

type Verify struct {
	Address   types.Address
	PublicKey types.PublicKey
}

func (*Verify) FromProtoMessage

func (v *Verify) FromProtoMessage(pbVerifier *types_pb.Verifier) *Verify

func (*Verify) ToProtoMessage

func (v *Verify) ToProtoMessage() proto.Message

Jump to

Keyboard shortcuts

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