types

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: 24 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// candidate profile
	CandidateKeyIsCandidate   string = "isCandidate"
	CandidateKeyNodeID        string = "nodeID"
	CandidateKeyHost          string = "host"
	CandidateKeyPort          string = "port"
	CandidateKeyIncomeAddress string = "incomeAddress"
	CandidateKeyDepositAmount string = "depositBalance" // 质押金额
	CandidateKeyIntroduction  string = "introduction"   // 候选节点自我介绍
	IsCandidateNode                  = "true"
	NotCandidateNode                 = "false"
	// asset profile
	AssetName              string = "name"
	AssetSymbol            string = "symbol"
	AssetDescription       string = "description"
	AssetFreeze            string = "freeze"
	AssetSuggestedGasLimit string = "suggestedGasLimit"
)
View Source
const (
	TokenAsset            = uint32(1)  // erc20
	NonFungibleAsset      = uint32(2)  // erc721
	CommonAsset           = uint32(3)  // erc20+721
	MaxAssetDecimal       = uint32(18) // 资产小数位最大值
	MaxMarshalAssetLength = 680        // asset序列化之后的最大长度线坠
	MaxMetaDataLength     = 256
)
View Source
const (
	TxSigLength        = 65
	MaxTxToNameLength  = 100
	MaxTxMessageLength = 1024
)

Variables

View Source
var (
	ErrAssetKind                     = errors.New("this type of asset does not exist")
	ErrTokenAssetDivisible           = errors.New("an asset of type 1 must be divisible")
	ErrNonFungibleAssetDivisible     = errors.New("an asset of type 2 must be indivisible")
	ErrNonFungibleAssetReplenishable = errors.New("an asset of type 2 must be non-replenishable")
	ErrCommonAssetDivisible          = errors.New("an asset of type 3 must be divisible")
	ErrAssetDecimal                  = errors.New("asset decimal must be less than 18")
)
View Source
var (
	ErrUnknownChangeLogType = errors.New("unknown change log type")
	// ErrWrongChangeLogVersion is returned by the ChangeLog Undo/Redo if account has an unexpected version
	ErrWrongChangeLogVersion = errors.New("the version of change log and account is not match")
	ErrAlreadyRedo           = errors.New("the change log's version is lower than account's. maybe it has redid")
	ErrWrongChangeLogData    = errors.New("change log data is incorrect")
)
View Source
var (
	ErrMinerAddressInvalid = errors.New("incorrect field: 'MinerAddress'")
	ErrNodeIDInvalid       = errors.New("incorrect field: 'NodeID'")
	ErrIntroductionInvalid = errors.New("incorrect field: 'Introduction'")
	ErrRankInvalid         = errors.New("max deputy node's rank is 65535")
	ErrVotesInvalid        = errors.New("min deputy node's votes are 0")
)
View Source
var (
	ErrNegativeBalance = errors.New("balance can't be negative")
	ErrLoadCodeFail    = errors.New("can't load contract code")
	ErrAssetNotExist   = errors.New("asset dose not exist")
	ErrAssetIdNotExist = errors.New("assetId dose not exist")
	ErrEquityNotExist  = errors.New("equity dose not exist")
	ErrTrieFail        = errors.New("can't load contract storage trie")
	ErrTrieChanged     = errors.New("the trie has changed after Finalise")

	// ErrGasLimitReached is returned by the gas pool if the amount of gas required
	// by a transaction is higher than what's left in the block.
	ErrGasLimitReached = errors.New("block gas limit reached")

	// ErrBlacklistedHash is returned if a block to import is on the blacklist.
	ErrBlacklistedHash = errors.New("blacklisted hash")
	ErrInvalidSig      = errors.New("invalid transaction sig")
	ErrInvalidVersion  = errors.New("invalid transaction version")
	ErrToNameLength    = errors.New("the length of 'toName' field in transaction is out of limit")
	ErrToNameCharacter = errors.New("the 'toName' field in transaction contains illegal characters")
	ErrTxMessage       = errors.New("the length of 'message' field in transaction is out of limit")
	ErrCreateContract  = errors.New("the 'data' field of create contract transaction can't be null")
	ErrSpecialTx       = errors.New("the 'data' field of special transaction can't be null")
	ErrTxType          = errors.New("the 'type' field of transaction does not exist")
	ErrGasPrice        = errors.New("the 'gasPrice' filed of transaction is too low")
	ErrTxExpired       = errors.New("the 'expirationTime' field of transaction must be later than current time")
	ErrTxExpiration    = errors.New("the 'expirationTime' field of transaction must not be later than 30 minutes")
	ErrNegativeValue   = errors.New("the 'amount' field of transaction can't be negative")
	ErrTxChainID       = errors.New("the 'chainID' field of transaction is incorrect")
	ErrBoxTx           = errors.New("the 'expirationTime' field of box transaction must be later than all sub transactions")
	ErrVerifyBoxTx     = errors.New("box transaction cannot be in another box transaction")
	ErrToExist         = errors.New("the 'to' field of transaction is incorrect")
)
View Source
var (
	TopicContractCreation = rlpHash("Contract creation")
	TopicRunFail          = rlpHash("Contract run fail")
)
View Source
var (
	DefaultTTTL uint64 = 2 * 60 * 60 // Transaction Time To Live, 2hours
	TxVersion   uint8  = 1           // current transaction version. should between 0 and 128
)
View Source
var (
	ErrPublicKey   = errors.New("invalid public key")
	ErrNoSignsData = errors.New("no signature data")
)

Functions

func IsToExist added in v1.3.0

func IsToExist(txType uint16, to *common.Address) bool

IsToExist

func MarshalBoxData added in v1.4.0

func MarshalBoxData(txs Transactions) ([]byte, error)

MarshalBoxData 通过传入的子交易序列化出箱子data

func RegisterChangeLog

func RegisterChangeLog(logType ChangeLogType, TypeName string, newValDecoder, extraDecoder changeLogDecoder, redo, undo changeLogDoFunc)

Types

type AccountAccessor

type AccountAccessor interface {
	GetAddress() common.Address
	GetVersion(logType ChangeLogType) uint32
	GetNextVersion(logType ChangeLogType) uint32

	GetVoteFor() common.Address
	SetVoteFor(addr common.Address)

	GetVotes() *big.Int
	SetVotes(votes *big.Int)

	GetCandidate() Profile
	SetCandidate(profile Profile)
	GetCandidateState(key string) string
	SetCandidateState(key string, val string)

	GetBalance() *big.Int
	SetBalance(balance *big.Int)

	GetCodeHash() common.Hash
	SetCodeHash(codeHash common.Hash)

	GetCode() (Code, error)
	SetCode(code Code)

	GetStorageRoot() common.Hash
	SetStorageRoot(root common.Hash)
	GetAssetCodeRoot() common.Hash
	SetAssetCodeRoot(root common.Hash)
	GetAssetIdRoot() common.Hash
	SetAssetIdRoot(root common.Hash)
	GetEquityRoot() common.Hash
	SetEquityRoot(root common.Hash)

	GetStorageState(key common.Hash) ([]byte, error)
	SetStorageState(key common.Hash, value []byte) error

	GetAssetCode(code common.Hash) (*Asset, error)
	SetAssetCode(code common.Hash, asset *Asset) error
	GetAssetCodeTotalSupply(code common.Hash) (*big.Int, error)
	SetAssetCodeTotalSupply(code common.Hash, val *big.Int) error
	GetAssetCodeState(code common.Hash, key string) (string, error)
	SetAssetCodeState(code common.Hash, key string, val string) error

	GetAssetIdState(id common.Hash) (string, error)
	SetAssetIdState(id common.Hash, data string) error

	GetEquityState(id common.Hash) (*AssetEquity, error)
	SetEquityState(id common.Hash, equity *AssetEquity) error

	SetSingers(signers Signers) error
	GetSigners() Signers

	PushEvent(event *Event)
	PopEvent() error
	GetEvents() []*Event

	GetSuicide() bool
	SetSuicide(suicided bool)

	IsEmpty() bool
	MarshalJSON() ([]byte, error)
}

type AccountData

type AccountData struct {
	Address  common.Address `json:"address" gencodec:"required"`
	Balance  *big.Int       `json:"balance" gencodec:"required"`
	CodeHash common.Hash    `json:"codeHash" gencodec:"required"`

	StorageRoot   common.Hash `json:"root" gencodec:"required"`
	AssetCodeRoot common.Hash `json:"assetCodeRoot" gencodec:"required"`
	AssetIdRoot   common.Hash `json:"assetIdRoot" gencodec:"required"`
	EquityRoot    common.Hash `json:"equityRoot" gencodec:"required"`

	VoteFor   common.Address `json:"voteFor"`
	Candidate Candidate      `json:"candidate"`

	// It records the block height which contains any type of newest change log. It is updated in finalize step
	NewestRecords map[ChangeLogType]VersionRecord `json:"records" gencodec:"required"`
	Signers       Signers                         `json:"signers"`
}

func (*AccountData) Clone added in v1.1.1

func (a *AccountData) Clone() NodeData

func (*AccountData) Copy

func (a *AccountData) Copy() *AccountData

func (*AccountData) DecodeRLP

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

DecodeRLP implements rlp.Decoder.

func (*AccountData) EncodeRLP

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

EncodeRLP implements rlp.Encoder.

func (AccountData) MarshalJSON

func (a AccountData) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*AccountData) String

func (a *AccountData) String() string

func (*AccountData) UnmarshalJSON

func (a *AccountData) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type Asset added in v1.2.0

type Asset struct {
	Category        uint32         `json:"category" gencodec:"required"`
	IsDivisible     bool           `json:"isDivisible" gencodec:"required"`
	AssetCode       common.Hash    `json:"assetCode"`
	Decimal         uint32         `json:"decimal" gencodec:"required"`
	TotalSupply     *big.Int       `json:"totalSupply"`
	IsReplenishable bool           `json:"isReplenishable" gencodec:"required"`
	Issuer          common.Address `json:"issuer"`
	Profile         Profile        `json:"profile"`
}

func GetAsset added in v1.4.0

func GetAsset(txData []byte) (*Asset, error)

GetAsset

func (*Asset) Clone added in v1.2.0

func (asset *Asset) Clone() *Asset

func (Asset) MarshalJSON added in v1.3.0

func (a Asset) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Asset) String added in v1.2.0

func (asset *Asset) String() string

func (*Asset) UnmarshalJSON added in v1.3.0

func (a *Asset) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

func (*Asset) VerifyAsset added in v1.3.0

func (asset *Asset) VerifyAsset() error

VerifyAsset 验证资产设置

type AssetEquity added in v1.2.0

type AssetEquity struct {
	AssetCode common.Hash `json:"assetCode" gencodec:"required"`
	AssetId   common.Hash `json:"assetId" gencodec:"required"`
	Equity    *big.Int    `json:"equity" gencodec:"required"`
}

func (*AssetEquity) Clone added in v1.2.0

func (equity *AssetEquity) Clone() *AssetEquity

func (AssetEquity) MarshalJSON added in v1.2.0

func (a AssetEquity) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*AssetEquity) String added in v1.2.0

func (equity *AssetEquity) String() string

func (*AssetEquity) UnmarshalJSON added in v1.2.0

func (a *AssetEquity) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type Block

type Block struct {
	Header      *Header        `json:"header"        gencodec:"required"`
	Txs         Transactions   `json:"transactions"  gencodec:"required"`
	ChangeLogs  ChangeLogSlice `json:"changeLogs"    gencodec:"required"`
	Confirms    []SignData     `json:"confirms"` // no miner's signature inside
	DeputyNodes DeputyNodes    `json:"deputyNodes"`
}

Block

func NewBlock

func NewBlock(header *Header, txs []*Transaction, changeLog []*ChangeLog) *Block

func (*Block) DeputyRoot added in v1.3.0

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

func (*Block) Extra

func (b *Block) Extra() string

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

func (*Block) Height

func (b *Block) Height() uint32

func (*Block) IsConfirmExist added in v1.2.0

func (b *Block) IsConfirmExist(sig SignData) bool

IsConfirmExist test if the signature is exist in Header.SignData or Confirms

func (*Block) Json added in v1.1.0

func (b *Block) Json() string

func (*Block) LogRoot added in v1.3.0

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

func (Block) MarshalJSON

func (b Block) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Block) MinerAddress

func (b *Block) MinerAddress() common.Address

func (*Block) ParentHash

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

func (*Block) SetChangeLogs

func (b *Block) SetChangeLogs(logs []*ChangeLog)

func (*Block) SetConfirms

func (b *Block) SetConfirms(confirms []SignData)

func (*Block) SetDeputyNodes

func (b *Block) SetDeputyNodes(deputyNodes DeputyNodes)

func (*Block) SetHeader

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

func (*Block) SetTxs

func (b *Block) SetTxs(txs []*Transaction)

func (*Block) ShallowCopy added in v1.4.0

func (b *Block) ShallowCopy() *Block

func (*Block) ShortString added in v1.3.0

func (b *Block) ShortString() string

func (*Block) SignData

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

func (*Block) SignerNodeID added in v1.3.0

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

func (*Block) Size added in v1.0.2

func (b *Block) Size() int

func (*Block) String

func (b *Block) String() string

func (*Block) Time

func (b *Block) Time() uint32

func (*Block) TxRoot added in v1.3.0

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

func (*Block) UnmarshalJSON

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

UnmarshalJSON unmarshals from JSON.

func (*Block) VersionRoot

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

type Blocks

type Blocks []*Block

type Box added in v1.3.0

type Box struct {
	SubTxList Transactions `json:"subTxList"  gencodec:"required"`
}

箱子交易

func GetBox added in v1.3.0

func GetBox(txData []byte) (*Box, error)

GetBox

func (Box) MarshalJSON added in v1.4.0

func (b Box) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Box) UnmarshalJSON added in v1.4.0

func (b *Box) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type Candidate added in v1.1.0

type Candidate struct {
	Votes   *big.Int `json:"votes"`
	Profile Profile  `json:"profile"`
}

func (Candidate) MarshalJSON added in v1.1.0

func (c Candidate) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Candidate) UnmarshalJSON added in v1.1.0

func (c *Candidate) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type ChangeLog

type ChangeLog struct {
	LogType ChangeLogType  `json:"type"       gencodec:"required"`
	Address common.Address `json:"address"    gencodec:"required"`
	// The No. of ChangeLog in an account
	Version uint32 `json:"version"    gencodec:"required"`

	// data pointer. Their content type depend on specific NewXXXLog function
	OldVal interface{} `json:"-"` // It's used for undo. So no need to save or send to others
	NewVal interface{} `json:"newValue"`
	Extra  interface{} `json:"extra"`
}

func (*ChangeLog) Copy

func (c *ChangeLog) Copy() *ChangeLog

func (*ChangeLog) DecodeRLP

func (c *ChangeLog) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder.

func (*ChangeLog) EncodeRLP

func (c *ChangeLog) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

func (*ChangeLog) Hash

func (c *ChangeLog) Hash() (h common.Hash)

Hash returns the keccak256 hash of its RLP encoding.

func (ChangeLog) MarshalJSON

func (c ChangeLog) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*ChangeLog) Redo

func (c *ChangeLog) Redo(processor ChangeLogProcessor) error

Redo reply the change for light client. Its behavior depends on ChangeLog.ChangeLogType

func (*ChangeLog) String

func (c *ChangeLog) String() string

func (*ChangeLog) Undo

func (c *ChangeLog) Undo(processor ChangeLogProcessor) error

Undo reverts the change. Its behavior depends on ChangeLog.ChangeLogType

func (*ChangeLog) UnmarshalJSON

func (c *ChangeLog) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type ChangeLogProcessor

type ChangeLogProcessor interface {
	GetAccount(addr common.Address) AccountAccessor
}

ChangeLogProcessor is used to access account, and the intermediate data generated by transactions. It is implemented by account.Manager

type ChangeLogSlice

type ChangeLogSlice []*ChangeLog

func (ChangeLogSlice) FindByType

func (c ChangeLogSlice) FindByType(target *ChangeLog) *ChangeLog

FindByType find the first same type change log.

func (ChangeLogSlice) Len

func (c ChangeLogSlice) Len() int

func (ChangeLogSlice) Less

func (c ChangeLogSlice) Less(i, j int) bool

func (ChangeLogSlice) MerkleRootSha added in v1.2.0

func (c ChangeLogSlice) MerkleRootSha() common.Hash

MerkleRootSha compute the root hash of ChangeLog merkle trie

func (ChangeLogSlice) Search

func (c ChangeLogSlice) Search(version uint32) int

func (ChangeLogSlice) Swap

func (c ChangeLogSlice) Swap(i, j int)

type ChangeLogType

type ChangeLogType uint32

func (ChangeLogType) String

func (t ChangeLogType) String() string

type Code

type Code []byte

func (Code) String

func (c Code) String() string

type DefaultSigner

type DefaultSigner struct {
}

DefaultSigner implements Signer.

func (DefaultSigner) GetSigners added in v1.3.0

func (s DefaultSigner) GetSigners(tx *Transaction) ([]common.Address, error)

func (DefaultSigner) Hash

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

Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.

func (DefaultSigner) SignTx added in v1.1.1

func (s DefaultSigner) SignTx(tx *Transaction, prv *ecdsa.PrivateKey) (*Transaction, error)

type DeputyNode added in v1.4.0

type DeputyNode struct {
	MinerAddress common.Address `json:"minerAddress"   gencodec:"required"` // candidate account address
	NodeID       []byte         `json:"nodeID"         gencodec:"required"`
	Rank         uint32         `json:"rank"           gencodec:"required"` // start from 0
	Votes        *big.Int       `json:"votes"          gencodec:"required"`
}

DeputyNode

func NewDeputyNode added in v1.4.0

func NewDeputyNode(votes *big.Int, rank uint32, minerAddr common.Address, nodeIDStr string) *DeputyNode

func (*DeputyNode) Check added in v1.4.0

func (d *DeputyNode) Check() error

func (*DeputyNode) Copy added in v1.4.0

func (d *DeputyNode) Copy() *DeputyNode

func (*DeputyNode) Hash added in v1.4.0

func (d *DeputyNode) Hash() (h common.Hash)

func (DeputyNode) MarshalJSON added in v1.4.0

func (d DeputyNode) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*DeputyNode) UnmarshalJSON added in v1.4.0

func (d *DeputyNode) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type DeputyNodes added in v1.4.0

type DeputyNodes []*DeputyNode

func (DeputyNodes) MerkleRootSha added in v1.4.0

func (nodes DeputyNodes) MerkleRootSha() common.Hash

MerkleRootSha compute the root hash of deputy nodes merkle trie

func (DeputyNodes) String added in v1.4.0

func (nodes DeputyNodes) String() string

type Event

type Event struct {
	// Consensus fields:
	// address of the contract that generated the event
	Address common.Address `json:"address" gencodec:"required"`
	// list of topics provided by the contract.
	Topics []common.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
	// hash of the transaction
	TxHash common.Hash `json:"transactionHash" gencodec:"required"`
	// index of the transaction in the block
	TxIndex uint `json:"transactionIndex" gencodec:"required"`
	// index of the event in the receipt
	Index uint `json:"eventIndex" gencodec:"required"`

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

Event represents a contract event event. These Events are generated by the LOG opcode and stored/indexed by the node.

func (*Event) DecodeRLP

func (l *Event) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*Event) EncodeRLP

func (l *Event) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

func (*Event) Hash

func (l *Event) Hash() (h common.Hash)

Hash returns the keccak256 hash of its RLP encoding.

func (Event) MarshalJSON

func (e Event) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Event) String

func (l *Event) String() string

func (*Event) UnmarshalJSON

func (e *Event) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type EventForStorage

type EventForStorage Event

EventForStorage is a wrapper around a Event that flattens and parses the entire content of a event including non-consensus fields.

func (*EventForStorage) DecodeRLP

func (l *EventForStorage) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*EventForStorage) EncodeRLP

func (l *EventForStorage) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

type GasPayerSigner added in v1.1.1

type GasPayerSigner struct {
}

func (GasPayerSigner) GetSigners added in v1.3.0

func (g GasPayerSigner) GetSigners(tx *Transaction) ([]common.Address, error)

GetGasPayer returns gas payer address

func (GasPayerSigner) Hash added in v1.1.1

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

Hash returns sign hash

func (GasPayerSigner) SignTx added in v1.1.1

func (g GasPayerSigner) SignTx(tx *Transaction, prv *ecdsa.PrivateKey) (*Transaction, error)

SignTx returns last signature to reimbursement gas transaction

type GasPool

type GasPool uint64

func (*GasPool) AddGas

func (gp *GasPool) AddGas(amount uint64) *GasPool

func (*GasPool) Gas

func (gp *GasPool) Gas() uint64

func (*GasPool) String

func (gp *GasPool) String() string

func (*GasPool) SubGas

func (gp *GasPool) SubGas(amount uint64) error
type Header struct {
	ParentHash   common.Hash    `json:"parentHash"       gencodec:"required"`
	MinerAddress common.Address `json:"miner"            gencodec:"required"`
	VersionRoot  common.Hash    `json:"versionRoot"      gencodec:"required"`
	TxRoot       common.Hash    `json:"transactionRoot"  gencodec:"required"`
	LogRoot      common.Hash    `json:"changeLogRoot"    gencodec:"required"`
	Height       uint32         `json:"height"           gencodec:"required"`
	GasLimit     uint64         `json:"gasLimit"         gencodec:"required"`
	GasUsed      uint64         `json:"gasUsed"          gencodec:"required"`
	Time         uint32         `json:"timestamp"        gencodec:"required"` // seconds
	SignData     []byte         `json:"signData"         gencodec:"required"`
	DeputyRoot   []byte         `json:"deputyRoot"`
	Extra        string         `json:"extraData"` // max length is 256 bytes
	// contains filtered or unexported fields
}

func (*Header) Copy

func (h *Header) Copy() *Header

Copy 拷贝一份头

func (*Header) DecodeRLP added in v1.2.0

func (h *Header) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*Header) EncodeRLP added in v1.2.0

func (h *Header) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

func (*Header) Hash

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

Hash 块hash 排除 SignData字段

func (Header) MarshalJSON

func (h Header) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Header) SignerNodeID added in v1.3.0

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

func (*Header) String

func (h *Header) String() string

func (*Header) UnmarshalJSON

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

UnmarshalJSON unmarshals from JSON.

type IssueAsset added in v1.2.0

type IssueAsset struct {
	AssetCode common.Hash `json:"assetCode" gencodec:"required"`
	MetaData  string      `json:"metaData"` // 用户传进来的数据
	Amount    *big.Int    `json:"supplyAmount" gencodec:"required"`
}

tx data marshal unmarshal struct 发行资产

func GetIssueAsset added in v1.3.0

func GetIssueAsset(txData []byte) (*IssueAsset, error)

GetIssueAsset

func (IssueAsset) MarshalJSON added in v1.3.0

func (i IssueAsset) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*IssueAsset) UnmarshalJSON added in v1.3.0

func (i *IssueAsset) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type ModifyAssetInfo added in v1.2.0

type ModifyAssetInfo struct {
	AssetCode     common.Hash `json:"assetCode" gencodec:"required"`
	UpdateProfile Profile     `json:"updateProfile" gencodec:"required"`
}

修改资产profile

func GetModifyAssetInfo added in v1.3.0

func GetModifyAssetInfo(txData []byte) (*ModifyAssetInfo, error)

GetModifyAssetInfo

func (ModifyAssetInfo) MarshalJSON added in v1.3.0

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

MarshalJSON marshals as JSON.

func (*ModifyAssetInfo) UnmarshalJSON added in v1.3.0

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

UnmarshalJSON unmarshals from JSON.

type NodeData added in v1.1.1

type NodeData interface {
	Clone() NodeData
}

type Pair added in v1.1.0

type Pair struct {
	Key string
	Val string
}

type Profile added in v1.2.0

type Profile map[string]string

func (*Profile) Clone added in v1.2.0

func (a *Profile) Clone() *Profile

func (*Profile) DecodeRLP added in v1.2.0

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

func (*Profile) EncodeRLP added in v1.2.0

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

type ReimbursementTxSigner added in v1.1.1

type ReimbursementTxSigner struct {
}

func (ReimbursementTxSigner) GetSigners added in v1.3.0

func (s ReimbursementTxSigner) GetSigners(tx *Transaction) ([]common.Address, error)

GetSigners

func (ReimbursementTxSigner) Hash added in v1.1.1

Hash excluding gasLimit and gasPrice

func (ReimbursementTxSigner) SignTx added in v1.1.1

SignTx returns first signature to reimbursement gas transaction

type ReplenishAsset added in v1.2.0

type ReplenishAsset struct {
	AssetCode common.Hash `json:"assetCode" gencodec:"required"`
	AssetId   common.Hash `json:"assetId" gencodec:"required"`
	Amount    *big.Int    `json:"replenishAmount" gencodec:"required"`
}

增发资产

func GetReplenishAsset added in v1.3.0

func GetReplenishAsset(txData []byte) (*ReplenishAsset, error)

GetReplenishAsset

func (ReplenishAsset) MarshalJSON added in v1.3.0

func (r ReplenishAsset) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*ReplenishAsset) UnmarshalJSON added in v1.3.0

func (r *ReplenishAsset) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type SignAccount added in v1.3.0

type SignAccount struct {
	Address common.Address `json:"address" gencodec:"required"`
	Weight  uint8          `json:"weight" gencodec:"required"`
}

func (SignAccount) MarshalJSON added in v1.3.0

func (s SignAccount) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*SignAccount) UnmarshalJSON added in v1.3.0

func (s *SignAccount) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type SignData

type SignData [65]byte

签名信息

func BytesToSignData added in v1.4.0

func BytesToSignData(bytes []byte) SignData

func (SignData) MarshalText

func (sd SignData) MarshalText() ([]byte, error)

func (SignData) RecoverNodeID added in v1.3.0

func (sd SignData) RecoverNodeID(hash common.Hash) ([]byte, error)

func (SignData) String

func (sd SignData) String() string

type Signer

type Signer interface {
	// SignTx returns transaction after signature
	SignTx(tx *Transaction, prv *ecdsa.PrivateKey) (*Transaction, error)

	// GetSigners returns the sender address of the transaction.
	GetSigners(tx *Transaction) ([]common.Address, error)

	// Hash returns the hash to be signed.
	Hash(tx *Transaction) common.Hash
}

Signer encapsulates transaction signature handling.

func MakeGasPayerSigner added in v1.1.1

func MakeGasPayerSigner() Signer

MakeGasPayerSigner returns gas payer signer

func MakeReimbursementTxSigner added in v1.1.1

func MakeReimbursementTxSigner() Signer

MakeReimbursementTxSigner returns instead of pay gas transaction signer

func MakeSigner

func MakeSigner() Signer

MakeSigner returns a Signer based on the given version and chainID.

type SignerMap added in v1.3.0

type SignerMap map[common.Address]uint8

type Signers added in v1.3.0

type Signers []SignAccount

func (Signers) Len added in v1.3.0

func (signers Signers) Len() int

func (Signers) Less added in v1.3.0

func (signers Signers) Less(i, j int) bool

func (Signers) Set added in v1.3.0

func (signers Signers) Set(address common.Address, weight uint8)

func (Signers) String added in v1.3.0

func (signers Signers) String() string

func (Signers) Swap added in v1.3.0

func (signers Signers) Swap(i, j int)

func (Signers) ToSignerMap added in v1.3.0

func (signers Signers) ToSignerMap() SignerMap

type Transaction

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

func GasPayerSignatureTx added in v1.1.1

func GasPayerSignatureTx(tx *Transaction, gasPrice *big.Int, gasLimit uint64) *Transaction

GasPayerSignatureTx

func NewContractCreation

func NewContractCreation(from common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, TxType uint16, chainID uint16, expiration uint64, toName string, message string) *Transaction

创建智能合约交易

func NewReimbursementContractCreation added in v1.1.1

func NewReimbursementContractCreation(from common.Address, gasPayer common.Address, amount *big.Int, data []byte, TxType uint16, chainID uint16, expiration uint64, toName string, message string) *Transaction

NewReimbursementContractCreation

func NewReimbursementTransaction added in v1.1.1

func NewReimbursementTransaction(from common.Address, to, gasPayer common.Address, amount *big.Int, data []byte, TxType uint16, chainID uint16, expiration uint64, toName string, message string) *Transaction

NewReimbursementTransaction new instead of paying gas transaction

func NewTransaction

func NewTransaction(from common.Address, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, TxType uint16, chainID uint16, expiration uint64, toName string, message string) *Transaction

NewTransaction TxType取值为OrdinaryTx等

func NoReceiverTransaction added in v1.2.0

func NoReceiverTransaction(from common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, TxType uint16, chainID uint16, expiration uint64, toName string, message string) *Transaction

实例化一个to == nil的交易

func (*Transaction) Amount

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

func (*Transaction) ChainID added in v1.0.2

func (tx *Transaction) ChainID() uint16

func (*Transaction) Clone added in v1.2.0

func (tx *Transaction) Clone() *Transaction

Clone deep copy transaction

func (*Transaction) Cost

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

Cost returns amount + gasprice * gaslimit.

func (*Transaction) Data

func (tx *Transaction) Data() []byte

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) Expiration

func (tx *Transaction) Expiration() uint64

func (*Transaction) From

func (tx *Transaction) From() common.Address

func (*Transaction) GasLimit

func (tx *Transaction) GasLimit() uint64

func (*Transaction) GasPayer added in v1.1.1

func (tx *Transaction) GasPayer() common.Address

GetSigners returns address of instead of pay transaction gas.

func (*Transaction) GasPayerSigs added in v1.3.0

func (tx *Transaction) GasPayerSigs() [][]byte

func (*Transaction) GasPrice

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

func (*Transaction) GasUsed added in v1.4.0

func (tx *Transaction) GasUsed() uint64

func (*Transaction) Hash

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

Hash

func (*Transaction) MarshalJSON

func (tx *Transaction) MarshalJSON() ([]byte, error)

MarshalJSON encodes the client RPC transaction format.

func (*Transaction) Message

func (tx *Transaction) Message() string

func (*Transaction) SetData added in v1.4.0

func (tx *Transaction) SetData(newData []byte)

func (*Transaction) SetGasUsed added in v1.4.0

func (tx *Transaction) SetGasUsed(gasUsed uint64)

func (*Transaction) Sigs added in v1.3.0

func (tx *Transaction) Sigs() [][]byte

func (*Transaction) String

func (tx *Transaction) String() string

func (*Transaction) To

func (tx *Transaction) To() *common.Address

func (*Transaction) ToName

func (tx *Transaction) ToName() string

func (*Transaction) Type

func (tx *Transaction) Type() uint16

func (*Transaction) UnmarshalJSON

func (tx *Transaction) UnmarshalJSON(input []byte) error

UnmarshalJSON decodes the client RPC transaction format.

func (*Transaction) VerifyTxBody added in v1.4.0

func (tx *Transaction) VerifyTxBody(chainID uint16, timeStamp uint64, isBlockTx bool) (err error)

VerifyTxBody isBlockTx 为true表示验证block中的tx, 为false表示验证收到的交易

func (*Transaction) Version

func (tx *Transaction) Version() uint8

type Transactions

type Transactions []*Transaction

func (Transactions) MerkleRootSha added in v1.2.0

func (ts Transactions) MerkleRootSha() common.Hash

MerkleRootSha compute the root hash of transaction merkle trie

type TransferAsset added in v1.4.0

type TransferAsset struct {
	AssetId common.Hash `json:"assetId" gencodec:"required"`
	Amount  *big.Int    `json:"transferAmount" gencodec:"required"`
	Input   []byte      `json:"input"`
}

交易资产

func GetTransferAsset added in v1.4.0

func GetTransferAsset(txData []byte) (*TransferAsset, error)

GetTransferAsset

func (TransferAsset) MarshalJSON added in v1.4.0

func (t TransferAsset) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*TransferAsset) UnmarshalJSON added in v1.4.0

func (t *TransferAsset) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type VersionRecord

type VersionRecord struct {
	Version uint32 `json:"version" gencodec:"required"`
	Height  uint32 `json:"height" gencodec:"required"`
}

func (VersionRecord) MarshalJSON

func (v VersionRecord) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*VersionRecord) UnmarshalJSON

func (v *VersionRecord) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

Jump to

Keyboard shortcuts

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