transaction

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2020 License: LGPL-3.0 Imports: 21 Imported by: 2

Documentation

Index

Constants

View Source
const (
	NodeIDFieldLength                = 130
	MaxProfileFieldLength            = 128
	MaxIntroductionLength            = 1024
	MaxMarshalCandidateProfileLength = 1200 // candidate 中profile marshal之后得到的byte数组的最大长度
	StandardNodeIdLength             = 64
	SignerWeightThreshold            = 100
	MaxSignersNumber                 = 100
)

Variables

View Source
var (
	ErrIssueAssetAmount     = errors.New("issue asset amount can't be 0 or nil")
	ErrIssueAssetMetaData   = errors.New("the length of metaData more than limit")
	ErrReplenishAssetAmount = errors.New("replenish asset amount can't be 0 or nil")
	ErrAssetIssuer          = errors.New("issue asset transaction's sender must the asset issuer")
	ErrFrozenAsset          = errors.New("can't replenish the frozen assets")
	ErrIsReplenishable      = errors.New("asset's \"IsReplenishable\" is false")
	ErrIsDivisible          = errors.New("this \"isDivisible == false\" kind of asset can't be replenished")
	ErrNotEqualAssetCode    = errors.New("assetCode not equal")
	ErrModifyAssetInfo      = errors.New("missing required field 'info' for ModifyAssetInfo")
	ErrMarshalAssetLength   = errors.New("the length of data by marshal asset more than max length")
	ErrAssetCategory        = errors.New("assert's Category not exist")
	ErrModifyAssetTxSender  = errors.New("the sender does not have permission to modify this asset")
)
View Source
var (
	ErrAlreadyVoted              = errors.New("already voted the same as candidate node")
	ErrOfNotCandidateNode        = errors.New("node address is not candidate account")
	ErrOfRegisterNodeID          = errors.New("can't get nodeId of RegisterInfo")
	ErrOfRegisterHost            = errors.New("can't get host of RegisterInfo")
	ErrOfRegisterPort            = errors.New("can't get port of RegisterInfo")
	ErrRegisterAgain             = errors.New("cannot register again after unregistering")
	ErrIsCandidate               = errors.New("get an unexpected character")
	ErrInsufficientBalance       = errors.New("the balance is insufficient to deduct the deposit for candidate register")
	ErrMarshalProfileLength      = errors.New("the data of candidate profile exceed the length limit 1200 Bytes")
	ErrInsufficientDepositAmount = errors.New("the deposit amount is not enough for candidate register")
	ErrParseDepositAmount        = errors.New("parse deposit amount failed")
	ErrDepositPoolInsufficient   = errors.New("insufficient deposit pool balance")
	ErrFailedGetDepositBalacne   = errors.New("failed to get deposit balance")
)
View Source
var (
	ErrAddressRepeat        = errors.New("cannot set two identical addresses")
	ErrWeight               = errors.New("signer weight error")
	ErrTempAccount          = errors.New("temp account format error")
	ErrSignersNumber        = errors.New("cannot exceed the maximum number of signers")
	ErrRepeatSetTempAddress = errors.New("the temp address's multisig has been set up")
)
View Source
var (
	ErrInsufficientBalanceForGas = errors.New("insufficient balance to pay for gas")
	ErrInvalidTxInBlock          = errors.New("block contains invalid transaction")
	ErrTxGasUsedNotEqual         = errors.New("tx gas used not equal")
	ErrInvalidGenesis            = errors.New("can't process genesis block")
	ErrInvalidProfile            = errors.New("the length of candidate profile field in transaction is out of max length limit")
	ErrInvalidPort               = errors.New("invalid port")
	ErrInvalidIntroduction       = errors.New("the length of introduction field in transaction is out of max length limit")
	ErrInvalidAddress            = errors.New("invalid address")
	ErrInvalidNodeId             = errors.New("invalid nodeId")
	ErrTxNotSign                 = errors.New("the transaction is not signed")
	ErrTotalWeight               = errors.New("insufficient total weight of signatories")
	ErrSignerAndFromUnequally    = errors.New("the signer and from of transaction are not equal")
	ErrGasPayer                  = errors.New("the gasPayer error")
	ErrAddressType               = errors.New("address type wrong")
	ErrTempAddress               = errors.New("the issuer part in temp address is incorrect")
)
View Source
var (
	ErrApplyBoxTxsTimeout = errors.New("apply box txs timeout")
)

Functions

func CanTransfer

func CanTransfer(am vm.AccountManager, addr common.Address, amount *big.Int) bool

CanTransfer checks whether there are enough funds in the address' account to make a transfer. This does not take the necessary gas in to account to make the transfer valid.

func ChangeVotesByBalance added in v1.4.0

func ChangeVotesByBalance(am *account.Manager)

ChangeVotesByBalance 设置余额变化导致的候选节点票数的变化

func CheckRegisterTxProfile added in v1.4.0

func CheckRegisterTxProfile(profile types.Profile) error

检查: 1. nodeID必须存在并检验是否可用。 2. 如果有introduction长度必须小于10245,其他字段长度必须小于130. 3. incomeAddress host port 限制性判断

CheckRegisterTxProfile

func GetHashFn

func GetHashFn(ref *types.Header, chain ParentBlockLoader) vm.GetHashFunc

GetHashFn returns a GetHashFunc which retrieves header hashes by number

func InitCandidateProfile added in v1.4.0

func InitCandidateProfile(registerAcc types.AccountAccessor, newProfile types.Profile)

InitCandidateProfile

func IntrinsicGas

func IntrinsicGas(txType uint16, data []byte, txMessage string) (uint64, error)

IntrinsicGas computes the 'intrinsic gas' for a message with the given data.

func NewEVMContext

func NewEVMContext(tx *types.Transaction, header *types.Header, txIndex uint, blockHash common.Hash, chain ParentBlockLoader) vm.Context

NewEVMContext creates a new context for use in the EVM.

func Refund added in v1.4.0

func Refund(candidateAddress common.Address, am *account.Manager)

Refund 进行退款操作

func Transfer

func Transfer(am vm.AccountManager, sender, recipient common.Address, amount *big.Int)

Transfer subtracts amount from sender and adds amount to recipient using the given Db

Types

type BlockLoader

type BlockLoader interface {
	// GetBlockByHash returns the hash corresponding to their hash.
	GetBlockByHash(hash common.Hash) *types.Block
	// GetBlockByHash returns the hash corresponding to their hash.
	GetParentByHeight(height uint32, sonBlockHash common.Hash) *types.Block
}

BlockLoader supports retrieving headers and consensus parameters from the current blockchain to be used during transaction processing.

type BoxTxEnv

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

func NewBoxTxEnv

func NewBoxTxEnv(p *TxProcessor) *BoxTxEnv

func (*BoxTxEnv) RunBoxTxs

func (b *BoxTxEnv) RunBoxTxs(gp *types.GasPool, boxTx *types.Transaction, header *types.Header, txIndex uint, restApplyTime int64) (uint64, error)

RunBoxTx 执行箱子中的子交易

type CandidateVoteEnv

type CandidateVoteEnv struct {
	CanTransfer func(vm.AccountManager, common.Address, *big.Int) bool
	Transfer    func(vm.AccountManager, common.Address, common.Address, *big.Int)
	// contains filtered or unexported fields
}

func NewCandidateVoteEnv

func NewCandidateVoteEnv(am *account.Manager, dm *deputynode.Manager) *CandidateVoteEnv

func (*CandidateVoteEnv) CallVoteTx

func (c *CandidateVoteEnv) CallVoteTx(voter, newCandidateAddr common.Address, initialBalance *big.Int) error

CallVoteTx voting transaction call

func (*CandidateVoteEnv) RegisterOrUpdateToCandidate

func (c *CandidateVoteEnv) RegisterOrUpdateToCandidate(tx *types.Transaction) error

RegisterOrUpdateToCandidate candidate node account transaction call

type ModifySigners

type ModifySigners struct {
	Signers types.Signers `json:"signers"  gencodec:"required"`
}

func (ModifySigners) MarshalJSON added in v1.4.0

func (m ModifySigners) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*ModifySigners) UnmarshalJSON added in v1.4.0

func (m *ModifySigners) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type ParentBlockLoader added in v1.4.0

type ParentBlockLoader interface {
	// GetParentByHeight returns the parent block corresponding to their hash.
	GetParentByHeight(height uint32, sonBlockHash common.Hash) *types.Block
}

ParentBlockLoader is the interface of BlockChain

type RunAssetEnv

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

func NewRunAssetEnv

func NewRunAssetEnv(am *account.Manager) *RunAssetEnv

func (*RunAssetEnv) CreateAssetTx

func (r *RunAssetEnv) CreateAssetTx(sender common.Address, data []byte, txHash common.Hash) error

CreateAssetTx

func (*RunAssetEnv) IssueAssetTx

func (r *RunAssetEnv) IssueAssetTx(sender, receiver common.Address, txHash common.Hash, data []byte) error

IssueAssetTx

func (*RunAssetEnv) ModifyAssetProfileTx

func (r *RunAssetEnv) ModifyAssetProfileTx(sender common.Address, data []byte) error

ModifyAssetProfileTx

func (*RunAssetEnv) ReplenishAssetTx

func (r *RunAssetEnv) ReplenishAssetTx(sender, receiver common.Address, data []byte) error

ReplenishAssetTx

type SetMultisigAccountEnv

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

func NewSetMultisigAccountEnv

func NewSetMultisigAccountEnv(am *account.Manager) *SetMultisigAccountEnv

func (*SetMultisigAccountEnv) ModifyMultisigTx

func (s *SetMultisigAccountEnv) ModifyMultisigTx(from, to common.Address, data []byte) error

ModifyMultisigTx

type TxProcessor

type TxProcessor struct {
	ChainID uint16
	// contains filtered or unexported fields
}

func NewTxProcessor

func NewTxProcessor(issueRewardAddress common.Address, chainID uint16, blockLoader ParentBlockLoader, am *account.Manager, db protocol.ChainDB, dm *deputynode.Manager) *TxProcessor

func (*TxProcessor) ApplyTxs

func (p *TxProcessor) ApplyTxs(header *types.Header, txs types.Transactions, timeLimitSecond int64) (types.Transactions, types.Transactions, uint64)

ApplyTxs picks and processes transactions from miner's tx pool.

func (*TxProcessor) Process

func (p *TxProcessor) Process(header *types.Header, txs types.Transactions) (uint64, error)

Process processes all transactions in a block. Change accounts' data and execute contract codes.

func (*TxProcessor) ReadContract added in v1.4.0

func (p *TxProcessor) ReadContract(accM *account.ReadOnlyManager, header *types.Header, to common.Address, data hexutil.Bytes, timeout time.Duration) ([]byte, error)

ReadContract pre-execute transactions and contracts.

func (*TxProcessor) VerifyAssetTx added in v1.4.0

func (p *TxProcessor) VerifyAssetTx(tx *types.Transaction) error

VerifyAssetTx

func (*TxProcessor) VerifyTxBeforeApply added in v1.4.0

func (p *TxProcessor) VerifyTxBeforeApply(tx *types.Transaction) error

VerifyTxBeforeApply 执行交易之前的交易校验

Jump to

Keyboard shortcuts

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