types

package
v0.0.2-unstable Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2019 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package types contains data types related to Fractal.

/ Copyright 2018 The Fractal Team Authors This file is part of the fractal project.

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

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. 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 action if execution failed.
	ReceiptStatusFailed = uint64(0)

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

Variables

View Source
var (
	//ErrInvalidchainID invalid chain id for signer
	ErrInvalidchainID = errors.New("invalid chain id for signer")
	//ErrSigUnprotected signature is considered unprotected
	ErrSigUnprotected = errors.New("signature is considered unprotected")
)
View Source
var Bloom9 = bloom9
View Source
var ErrInvalidSig = errors.New("invalid action v, r, s values")

ErrInvalidSig invalid signature.

Functions

func BloomLookup

func BloomLookup(bin Bloom, topic bytesBacked) bool

func DeriveReceiPtMerkleRoot

func DeriveReceiPtMerkleRoot(receipts []*Receipt) common.Hash

func DeriveTxMerkleRoot

func DeriveTxMerkleRoot(txs []*Transaction) common.Hash

func LogsBloom

func LogsBloom(logs []*Log) *big.Int

func Number

func Number(b1, b2 *Block) bool

func Recover

func Recover(signer Signer, a *Action, tx *Transaction) (common.PubKey, error)

Recover returns the pubkey derived from the signature (V, R, S) using secp256k1 elliptic curve and an error if it failed deriving or upon an incorrect signature.

func SignAction

func SignAction(a *Action, tx *Transaction, s Signer, prv *ecdsa.PrivateKey) error

SignAction signs the action using the given signer and private key

Types

type Action

type Action struct {
	// contains filtered or unexported fields
}

Action represents an entire action in the transaction.

func NewAction

func NewAction(actionType ActionType, from, to common.Name, nonce, assetID, gasLimit uint64, amount *big.Int, payload []byte) *Action

NewAction initialize transaction's action.

func (*Action) AssetID

func (a *Action) AssetID() uint64

func (*Action) ChainID

func (a *Action) ChainID() *big.Int

ChainID returns which chain id this action was signed for (if at all)

func (*Action) Data

func (a *Action) Data() []byte

func (*Action) DecodeRLP

func (a *Action) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder

func (*Action) EncodeRLP

func (a *Action) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder

func (*Action) Gas

func (a *Action) Gas() uint64

func (*Action) Hash

func (a *Action) Hash() common.Hash

Hash hashes the RLP encoding of action.

func (*Action) NewRPCAction

func (a *Action) NewRPCAction(index uint64) *RPCAction

NewRPCAction returns a action that will serialize to the RPC.

func (*Action) Nonce

func (a *Action) Nonce() uint64

func (*Action) RawSignatureValues

func (a *Action) RawSignatureValues() (*big.Int, *big.Int, *big.Int)

RawSignatureValues return raw signature values.

func (*Action) Recipient

func (a *Action) Recipient() common.Name

func (*Action) Sender

func (a *Action) Sender() common.Name

func (*Action) Type

func (a *Action) Type() ActionType

func (*Action) Value

func (a *Action) Value() *big.Int

func (*Action) WithSignature

func (a *Action) WithSignature(signer Signer, sig []byte) error

WithSignature returns a new transaction with the given signature.

type ActionResult

type ActionResult struct {
	Status  uint64
	Index   uint64
	GasUsed uint64
	Error   string
}

ActionResult represents the results the transaction action.

func (*ActionResult) DecodeRLP

func (a *ActionResult) DecodeRLP(data []byte) error

DecodeRLP implements rlp.Decoder

func (*ActionResult) EncodeRLP

func (a *ActionResult) EncodeRLP() ([]byte, error)

EncodeRLP implements rlp.Encoder

func (*ActionResult) NewRPCActionResult

func (a *ActionResult) NewRPCActionResult(aType ActionType) *RPCActionResult

NewRPCActionResult returns a ActionResult that will serialize to the RPC.

type ActionType

type ActionType uint64

ActionType type of Action.

const (
	// Transfer represents the ordinary and contract transfer action.
	Transfer ActionType = iota
	// CreateContract repesents the create contract action.
	CreateContract
	// CreateAccount repesents the create account.
	CreateAccount
	UpdateAccount
	DeleteAccount
	// Asset operation
	IncreaseAsset
	IssueAsset
	SetAssetOwner
	// dpos
	Miner
	RegProducer
	UpdateProducer
	UnregProducer
	RemoveVoter
	VoteProducer
	ChangeProducer
	UnvoteProducer
)

type Block

type Block struct {
	Head *Header
	Txs  []*Transaction
	// contains filtered or unexported fields
}

Block represents an entire block in the blockchain.

func NewBlock

func NewBlock(header *Header, txs []*Transaction, receipts []*Receipt) *Block

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

func NewBlockWithHeader

func NewBlockWithHeader(header *Header) *Block

NewBlockWithHeader creates a block with the given header data. The header data is copied, changes to header and to the field values will not affect the block.

func (*Block) Body

func (b *Block) Body() *Body

func (*Block) Coinbase

func (b *Block) Coinbase() common.Name

func (*Block) DecodeRLP

func (b *Block) DecodeRLP(input []byte) error

DecodeRLP decodes the block

func (*Block) Difficulty

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

func (*Block) EncodeRLP

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

EncodeRLP serializes b into the RLP block format.

func (*Block) Extra

func (b *Block) Extra() []byte

func (*Block) GasLimit

func (b *Block) GasLimit() uint64

func (*Block) GasUsed

func (b *Block) GasUsed() uint64

func (*Block) Hash

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

Hash returns the keccak256 hash of b's header. The hash is computed on the first call and cached thereafter.

func (*Block) HashNoNonce

func (b *Block) HashNoNonce() common.Hash

func (*Block) Header

func (b *Block) Header() *Header

func (*Block) Marshal

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

Marshal encodes the web3 RPC block format.

func (*Block) Number

func (b *Block) Number() *big.Int

func (*Block) NumberU64

func (b *Block) NumberU64() uint64

func (*Block) ParentHash

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

func (*Block) ReceiptHash

func (b *Block) ReceiptHash() common.Hash

func (*Block) Root

func (b *Block) Root() common.Hash

func (*Block) Size

func (b *Block) Size() common.StorageSize

Size returns the true RLP encoded storage size of the block, either by encoding and returning it, or returning a previsouly cached value.

func (*Block) Time

func (b *Block) Time() *big.Int

func (*Block) Transactions

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

func (*Block) TxHash

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

func (*Block) WithBody

func (b *Block) WithBody(transactions []*Transaction) *Block

WithBody returns a new block with the given transaction and uncle contents.

func (*Block) WithSeal

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

WithSeal returns a new block with the data from b but the header replaced with the sealed one.

type BlockBy

type BlockBy func(b1, b2 *Block) bool

func (BlockBy) Sort

func (self BlockBy) Sort(blocks Blocks)

type Blocks

type Blocks []*Block

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 []*Receipt) Bloom

func (*Bloom) Add

func (b *Bloom) Add(d *big.Int)

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.

func (Bloom) Bytes

func (b Bloom) Bytes() []byte

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(test *big.Int) bool

func (Bloom) TestBytes

func (b Bloom) TestBytes(test []byte) bool

func (*Bloom) UnmarshalText

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

UnmarshalText b as a hex string with 0x prefix.

type Body

type Body struct {
	Transactions []*Transaction
}
type Header struct {
	ParentHash   common.Hash `json:"parentHash"`
	Coinbase     common.Name `json:"miner"`
	Root         common.Hash `json:"stateRoot"`
	TxsRoot      common.Hash `json:"transactionsRoot"`
	ReceiptsRoot common.Hash `json:"receiptsRoot"`
	Bloom        Bloom       `json:"logsBloom"`
	Difficulty   *big.Int    `json:"difficulty"`
	Number       *big.Int    `json:"number"`
	GasLimit     uint64      `json:"gasLimit"`
	GasUsed      uint64      `json:"gasUsed"`
	Time         *big.Int    `json:"timestamp"`
	Extra        []byte      `json:"extraData"`
}

Header represents a block header in the blockchain.

func CopyHeader

func CopyHeader(h *Header) *Header

CopyHeader creates a deep copy of a block header to prevent side effects from modifying a header variable.

func (*Header) DecodeRLP

func (h *Header) DecodeRLP(input []byte) error

DecodeRLP decodes the header

func (*Header) EncodeRLP

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

EncodeRLP serializes b into the RLP block header format.

func (*Header) Hash

func (h *Header) Hash() common.Hash

Hash returns the block hash of the header, which is simply the keccak256 hash of its RLP encoding.

func (*Header) HashNoNonce

func (h *Header) HashNoNonce() common.Hash

HashNoNonce returns the hash which is used as input for the proof-of-work search.

func (*Header) Marshal

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

Marshal encodes the web3 RPC block header format.

func (*Header) Unmarshal

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

Unmarshal decodes the web3 RPC block header format.

type KvNode

type KvNode struct {
	Key   string
	Value []byte
}

type Log

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

	// Derived fields. These fields are filled in by the node
	// but not secured by consensus.
	// block in which the transaction was included
	BlockNumber uint64 `json:"blockNumber"`
	// hash of the transaction
	TxHash common.Hash `json:"transactionHash"`
	// index of the transaction in the block
	TxIndex uint `json:"transactionIndex"`
	// index of the input and output in the transaction
	ActionIndex uint `json:"actionIndex"`
	// hash of the block in which the transaction was included
	BlockHash common.Hash `json:"blockHash"`
	// index of the log in the receipt
	Index uint `json:"logIndex"`

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

Log represents a contract log event. These events are generated by the LOG opcode and stored/indexed by the node.

func (*Log) DecodeRLP

func (l *Log) DecodeRLP(data []byte) error

DecodeRLP implements rlp.Decoder

func (*Log) EncodeRLP

func (l *Log) EncodeRLP() ([]byte, error)

EncodeRLP implements rlp.Encoder

type OptInfo

type OptInfo struct {
	Key   string
	Value []byte
	Opt   uint // record modification status : add/delete/update
}

type RPCAction

type RPCAction struct {
	Type       uint64        `json:"type"`
	Nonce      uint64        `json:"nonce"`
	From       common.Name   `json:"from"`
	To         common.Name   `json:"to"`
	AssetID    uint64        `json:"assetID"`
	GasLimit   uint64        `json:"gas"`
	Amount     *big.Int      `json:"value"`
	Payload    hexutil.Bytes `json:"payload"`
	V          *hexutil.Big  `json:"v"`
	R          *hexutil.Big  `json:"r"`
	S          *hexutil.Big  `json:"s"`
	Hash       common.Hash   `json:"actionHash"`
	ActionIdex uint64        `json:"actionIndex"`
}

RPCAction represents a action that will serialize to the RPC representation of a action.

type RPCActionResult

type RPCActionResult struct {
	ActionType uint64 `json:"actionType"`
	Status     uint64 `json:"status"`
	Index      uint64 `json:"index"`
	GasUsed    uint64 `json:"gasUsed"`
	Error      string `json:"error"`
}

RPCActionResult that will serialize to the RPC representation of a ActionResult.

type RPCReceipt

type RPCReceipt struct {
	BlockHash         common.Hash        `json:"blockHash"`
	BlockNumber       uint64             `json:"blockNumber"`
	Hash              common.Hash        `json:"txHash"`
	TransactionIndex  uint64             `json:"transactionIndex"`
	PostState         hexutil.Bytes      `json:"postState"`
	ActionResults     []*RPCActionResult `json:"actionResults"`
	CumulativeGasUsed uint64             `json:"cumulativeGasUsed"`
	TotalGasUsed      uint64             `json:"totalGasUsed"`
	Bloom             Bloom              `json:"logsBloom"`
	Logs              []*Log             `json:"logs"`
}

RPCReceipt that will serialize to the RPC representation of a Receipt.

type RPCTransaction

type RPCTransaction struct {
	BlockHash        common.Hash  `json:"blockHash"`
	BlockNumber      uint64       `json:"blockNumber"`
	Hash             common.Hash  `json:"txHash"`
	TransactionIndex uint64       `json:"transactionIndex"`
	RPCActions       []*RPCAction `json:"actions"`
	GasAssetID       uint64       `json:"gasAssetID"`
	GasPrice         *big.Int     `json:"gasPrice"`
	GasCost          *big.Int     `json:"gasCost"`
}

RPCTransaction that will serialize to the RPC representation of a transaction.

type Receipt

type Receipt struct {
	PostState         []byte
	ActionResults     []*ActionResult
	CumulativeGasUsed uint64
	Bloom             Bloom
	Logs              []*Log
	TxHash            common.Hash
	TotalGasUsed      uint64
}

Receipt represents the results of a transaction.

func NewReceipt

func NewReceipt(root []byte, cumulativeGasUsed, totalGasUsed uint64) *Receipt

NewReceipt creates a barebone transaction receipt, copying the init fields.

func (*Receipt) DecodeRLP

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

DecodeRLP implements rlp.Decoder

func (*Receipt) EncodeRLP

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

EncodeRLP implements rlp.Encoder

func (*Receipt) Hash

func (r *Receipt) Hash() common.Hash

Hash hashes the RLP encoding of Receipt.

func (*Receipt) NewRPCReceipt

func (r *Receipt) NewRPCReceipt(blockHash common.Hash, blockNumber uint64, index uint64, tx *Transaction) *RPCReceipt

NewRPCReceipt returns a Receipt that will serialize to the RPC.

func (*Receipt) Size

func (r *Receipt) Size() common.StorageSize

Size returns the approximate memory used by all internal contents

type Signer

type Signer struct {
	// contains filtered or unexported fields
}

Signer implements Signer .

func MakeSigner

func MakeSigner(chainID *big.Int) Signer

MakeSigner returns a Signer based on the given chainID .

func NewSigner

func NewSigner(chainID *big.Int) Signer

NewSigner initialize signer

func (Signer) Equal

func (s Signer) Equal(s2 Signer) bool

Equal judging the same chainID

func (Signer) Hash

func (s Signer) Hash(tx *Transaction) common.Hash

Hash returns the hash to be signed by the sender.

func (Signer) PubKey

func (s Signer) PubKey(a *Action, tx *Transaction) ([]byte, error)

PubKey return Action sender

func (Signer) SignatureValues

func (s Signer) SignatureValues(sig []byte) (R, S, V *big.Int, err error)

SignatureValues returns a new transaction with the given signature. This signature needs to be in the [R || S || V] format where V is 0 or 1.

type StateOut

type StateOut struct {
	ReadSet    []*KvNode   // replay
	Reverts    []*OptInfo  // rollback previous block
	Changes    []*OptInfo  // forward next block
	ParentHash common.Hash // block parent hash
	Number     uint64      // block num
	Hash       common.Hash // current block hash
}

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

Transaction represents an entire transaction in the block.

func NewTransaction

func NewTransaction(assetID uint64, price *big.Int, actions ...*Action) *Transaction

NewTransaction initialize a transaction.

func TxDifference

func TxDifference(a, b []*Transaction) []*Transaction

TxDifference returns a new set which is the difference between a and b.

func (*Transaction) Cost

func (tx *Transaction) Cost() *big.Int

Cost returns all actions gasprice * gaslimit.

func (*Transaction) DecodeRLP

func (tx *Transaction) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder

func (*Transaction) EncodeRLP

func (tx *Transaction) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder

func (*Transaction) GasAssetID

func (tx *Transaction) GasAssetID() uint64

GasAssetID returns transaction gas asset id.

func (*Transaction) GasPrice

func (tx *Transaction) GasPrice() *big.Int

GasPrice returns transaction gas price.

func (*Transaction) GetActions

func (tx *Transaction) GetActions() []*Action

GetActions return transaction actons.

func (*Transaction) Hash

func (tx *Transaction) Hash() common.Hash

Hash hashes the RLP encoding of tx.

func (*Transaction) NewRPCTransaction

func (tx *Transaction) NewRPCTransaction(blockHash common.Hash, blockNumber uint64, index uint64) *RPCTransaction

NewRPCTransaction returns a transaction that will serialize to the RPC.

func (*Transaction) Size

func (tx *Transaction) Size() common.StorageSize

Size returns the true RLP encoded storage size of the transaction,

type TransactionsByPriceAndNonce

type TransactionsByPriceAndNonce struct {
	// contains filtered or unexported fields
}

TransactionsByPriceAndNonce represents a set of transactions that can return transactions in a profit-maximizing sorted order, while supporting removing entire batches of transactions for non-executable accounts.

func NewTransactionsByPriceAndNonce

func NewTransactionsByPriceAndNonce(txs map[common.Name][]*Transaction) *TransactionsByPriceAndNonce

NewTransactionsByPriceAndNonce creates a transaction set that can retrieve price sorted transactions in a nonce-honouring way.

Note, the input map is reowned so the caller should not interact any more with if after providing it to the constructor.

func (*TransactionsByPriceAndNonce) Peek

Peek returns the next transaction by price.

func (*TransactionsByPriceAndNonce) Pop

func (t *TransactionsByPriceAndNonce) Pop()

Pop removes the best transaction, *not* replacing it with the next one from the same account. This should be used when a transaction cannot be executed and hence all subsequent ones should be discarded from the same account.

func (*TransactionsByPriceAndNonce) Shift

func (t *TransactionsByPriceAndNonce) Shift()

Shift replaces the current best head with the next one from the same account.

type TxByNonce

type TxByNonce []*Transaction

TxByNonce sort by transaction first action nonce

func (TxByNonce) Len

func (s TxByNonce) Len() int

func (TxByNonce) Less

func (s TxByNonce) Less(i, j int) bool

func (TxByNonce) Swap

func (s TxByNonce) Swap(i, j int)

type TxByPrice

type TxByPrice []*Transaction

TxByPrice implements both the sort and the heap interface,

func (TxByPrice) Len

func (s TxByPrice) Len() int

func (TxByPrice) Less

func (s TxByPrice) Less(i, j int) bool

func (*TxByPrice) Pop

func (s *TxByPrice) Pop() interface{}

func (*TxByPrice) Push

func (s *TxByPrice) Push(x interface{})

func (TxByPrice) Swap

func (s TxByPrice) Swap(i, j int)

Jump to

Keyboard shortcuts

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