types

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeType_OK uint32 = 0
	// General response codes, 0 ~ 99
	CodeType_InternalError uint32 = 1 // 内部错误
	CodeType_EncodingError uint32 = 2 // 编解码错误
	CodeType_UnsupportedTx uint32 = 3 // 不支持的tx类型
	CodeType_BadSignature  uint32 = 4 // 签名错误
	CodeType_BadArgument   uint32 = 5 // 参数错误
	CodeType_ExecuteTx     uint32 = 6 // tx执行错误
	CodeType_Deadline      uint32 = 7 // 交易过期
	CodeType_Gas           uint32 = 8 // gas太低

	CodeType_SenderNotExist    uint32 = 11 // 帐户不存在
	CodeType_BadNonce          uint32 = 12 // nonce错误
	CodeType_InsufficientFunds uint32 = 13 // 资金不足
	CodeType_ReceiverNotExist  uint32 = 14 // 帐户不存在

	// evm tx
	CodeType_ContractExecuteErr    uint32 = 30 // 合约执行错误
	CodeType_ContractExecuteFailed uint32 = 31 // 合约执行失败
)
View Source
const (
	API_V2_QUERY_ACCOUNT          = "/v2/account"
	API_V2_CONTRACT_QUERY_ACCOUNT = "/v2/contract/account"
	API_V2_CONTRACT_QUERY_LOGS    = "/v2/contract/logs"
	API_V2_CONTRACT_CALL          = "/v2/contract/call"
)
View Source
const PubKeyLength = 33
View Source
const (
	TxGas = int64(21000) // tx gas
)
View Source
const TxTagLength = 2

Variables

View Source
var (
	ZERO_ADDRESS   = ethcmn.Address{}
	ZERO_HASH      = ethcmn.Hash{}
	ZERO_PUBLICKEY = PublicKey{}
)
View Source
var (
	ErrUnsupportedTx           = errors.New("unsupported tx")
	ErrInvalidSignature        = errors.New("signature verify failed")
	ErrInvalidOperations       = errors.New("too little/much operations")
	ErrInvalidGasLimit         = errors.New("invalid gasLimit")
	ErrInvalidGasPrice         = errors.New("invalid gasPrice")
	ErrNotFoundSender          = errors.New("sender not exist")
	ErrNotFoundReceiver        = errors.New("receiver not exist")
	ErrInsufficientBalance     = errors.New("insufficient balance")
	ErrInsufficientPermissions = errors.New("insufficient permissions")
	ErrDeadline                = errors.New("tx deadline")
	ErrGas                     = errors.New("gas too low")
)
View Source
var (
	//TxTagAppInit        = TxTag{0, 0}     // 账户迁移,采用与batch相同的交易结构,但是不收取手续费 v4废弃
	//TxTagTinInit        = TxTag{0, 1}     // v3初始化TIN用户 v4废弃
	//TxTagAppOLO         = TxTag{1, 1}     // 原生交易 v1 - v3废弃
	TxTagAppEvm = TxTag{1, 2} // 合约交易
	//TxTagAppFee         = TxTag{1, 3}     // 收取手续费 - v3废弃
	TxTagAppBatch   = TxTag{1, 4} // 批量交易
	TxTagEthereumTx = TxTag{1, 5} // 以太坊兼容交易
	//TxTagNodeDelegate   = TxTag{2, 1}     // 节点抵押赎回提现
	//TxTagUserDelegate   = TxTag{2, 2}     // 用户抵押赎回提现
	TxTagAppEvmMultisig = TxTag{3, 2} // EVM多签交易

)
View Source
var (
	ErrUnknownTxType = errors.New("unknown tx type")
)

Functions

func DecodeTx

func DecodeTx(raw []byte) (TxTag, HashTx, error)

DecodeTx 当是不支持的解析类型, interface == nil

func PubkeyToAddress

func PubkeyToAddress(pub PublicKey) ethcmn.Address

func RLPHash

func RLPHash(x interface{}) (h ethcmn.Hash)

func SaveLastBlock

func SaveLastBlock(db ethdb.Database, appHash ethcmn.Hash, header *AppHeader)

func ValidAddress

func ValidAddress(s string) bool

func ValidPublicKey

func ValidPublicKey(s string) bool

Types

type Address

type Address struct {
	ethcmn.Address
}

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

type AppBlock

type AppBlock struct {
	Height    int64
	StateRoot ethcmn.Hash
}

func NewAppBlock

func NewAppBlock(height int64, root ethcmn.Hash) *AppBlock

func (*AppBlock) FromBytes

func (b *AppBlock) FromBytes(bz []byte)

func (*AppBlock) FromDB

func (b *AppBlock) FromDB(db ethdb.Database, height int64) (*AppBlock, error)

func (*AppBlock) ToBytes

func (b *AppBlock) ToBytes() []byte

func (*AppBlock) ToDB

func (b *AppBlock) ToDB(db ethdb.Database) error

type AppHeader

type AppHeader struct {
	Height    *big.Int       // refresh by new block
	ClosedAt  time.Time      // ON abci beginBlock
	BlockHash ethcmn.Hash    // fill on new block
	Validator ethcmn.Address // refresh by new block
	MinerFee  *big.Int       // miner fee, added on deliverTx
	StateRoot ethcmn.Hash    // fill after statedb commit
	TxCount   uint64         // fill when ready to save
	PrevHash  ethcmn.Hash    // global, just used to calculate header-hash
}

AppHeader ledger header for app

func (*AppHeader) Copy

func (h *AppHeader) Copy() *AppHeader

func (*AppHeader) Hash

func (h *AppHeader) Hash() []byte

Hash hash

func (*AppHeader) String

func (h *AppHeader) String() string

type BeanAccount

type BeanAccount struct {
	Address string `json:"address"` // 地址
	Balance string `json:"balance"` // 余额
	Nonce   uint64 `json:"nonce"`   // nonce
}

type BeanContract

type BeanContract struct {
	Address  string `json:"address"`  // 地址
	Balance  string `json:"balance"`  // 余额
	Nonce    uint64 `json:"nonce"`    // nonce
	Code     string `json:"code"`     // 合约代码
	Suicided bool   `json:"suicided"` // 合约是否已自杀
}

type BeanEvmCallResult

type BeanEvmCallResult = struct {
	Code    uint32 `json:"code"`    // 错误码
	Msg     string `json:"msg"`     // msg
	Ret     string `json:"ret"`     // 返回数据的hex编码
	GasUsed uint64 `json:"gasUsed"` // 消耗的gas
}

type DPosQuery

type DPosQuery struct {
	QueryBase
	Height  uint64
	Address ethcmn.Address
}

func (*DPosQuery) FromBytes

func (q *DPosQuery) FromBytes(bz []byte) error

func (*DPosQuery) GetQuery

func (q *DPosQuery) GetQuery(bz []byte) error

func (*DPosQuery) ToBytes

func (q *DPosQuery) ToBytes() []byte

type HashTx

type HashTx interface {
	Hash() ethcmn.Hash
}

type LastBlockInfo

type LastBlockInfo struct {
	Height    int64
	StateRoot ethcmn.Hash
	AppHash   ethcmn.Hash
	PrevHash  ethcmn.Hash
}

func LoadLastBlock

func LoadLastBlock(db ethdb.Database) (lastBlock LastBlockInfo)

func (*LastBlockInfo) FromBytes

func (block *LastBlockInfo) FromBytes(bz []byte)

func (*LastBlockInfo) ToBytes

func (block *LastBlockInfo) ToBytes() []byte

type MultisigEvmTx

type MultisigEvmTx struct {
	Deadline  uint64         // 有效期 截止时间 秒
	GasLimit  uint64         // gas限额
	GasPrice  *big.Int       // gas价格
	From      ethcmn.Address // 多签账户地址
	Nonce     uint64         // 多签账户nonce
	To        ethcmn.Address // 交易接收方地址
	Value     *big.Int       // 交易金额
	Load      []byte         // 合约交易负荷
	Memo      []byte         // 备注信息
	Signature Signature      // 签名信息
	// contains filtered or unexported fields
}

func NewMultisigEvmTx

func NewMultisigEvmTx(k int, pks []PublicKey) *MultisigEvmTx

func (*MultisigEvmTx) AddSign

func (tx *MultisigEvmTx) AddSign(signature string) error

func (*MultisigEvmTx) Cost

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

func (*MultisigEvmTx) FromBytes

func (tx *MultisigEvmTx) FromBytes(bs []byte) error

func (*MultisigEvmTx) Hash

func (tx *MultisigEvmTx) Hash() ethcmn.Hash

func (*MultisigEvmTx) SigHash

func (tx *MultisigEvmTx) SigHash() ethcmn.Hash

func (*MultisigEvmTx) Sign

func (tx *MultisigEvmTx) Sign(privkey string) error

func (MultisigEvmTx) Signer

func (tx MultisigEvmTx) Signer() []ethcmn.Address

func (*MultisigEvmTx) ToBytes

func (tx *MultisigEvmTx) ToBytes() []byte

func (*MultisigEvmTx) Verify

func (tx *MultisigEvmTx) Verify() bool

type Multisignature

type Multisignature struct {
	BitArray *bitarray.CompactBitArray
	Sigs     [][]byte
}

Multisignature is used to represent the signature object used in the multisigs. Sigs is a list of signatures, sorted by corresponding index.

func NewMultisig

func NewMultisig(n int) *Multisignature

NewMultisig returns a new Multisignature of size n.

func (*Multisignature) AddSignature

func (mSig *Multisignature) AddSignature(sig []byte, index int)

AddSignature adds a signature to the multisig, at the corresponding index. If the signature already exists, replace it.

func (*Multisignature) AddSignatureFromPubKey

func (mSig *Multisignature) AddSignatureFromPubKey(sig []byte, pubkey PublicKey, keys []PublicKey) error

AddSignatureFromPubKey adds a signature to the multisig, at the index in keys corresponding to the provided pubkey.

func (*Multisignature) Marshal

func (mSig *Multisignature) Marshal() []byte

Marshal the multisignature with RLP

func (*Multisignature) UnMarshal

func (mSig *Multisignature) UnMarshal(bz []byte) error

type PubKeyMultisigThreshold

type PubKeyMultisigThreshold struct {
	K       uint        `json:"threshold"`
	PubKeys []PublicKey `json:"pubkeys"`
}

func NewPubKeyMultisigThreshold

func NewPubKeyMultisigThreshold(k int, pubkeys []PublicKey) PubKeyMultisigThreshold

func (PubKeyMultisigThreshold) Address

func (pk PubKeyMultisigThreshold) Address() ethcmn.Address

func (PubKeyMultisigThreshold) Bytes

func (pk PubKeyMultisigThreshold) Bytes() []byte

func (PubKeyMultisigThreshold) Hash

func (pk PubKeyMultisigThreshold) Hash() (sum ethcmn.Hash)

func (PubKeyMultisigThreshold) VerifyBytes

func (pk PubKeyMultisigThreshold) VerifyBytes(msg []byte, marshalledSig []byte) bool

type PublicKey

type PublicKey [PubKeyLength]byte

func BytesToPubkey

func BytesToPubkey(b []byte) (PublicKey, error)

func HexToPubkey

func HexToPubkey(s string) (PublicKey, error)

func (PublicKey) Big

func (pk PublicKey) Big() *big.Int

func (PublicKey) Bytes

func (pk PublicKey) Bytes() []byte

func (PublicKey) Copy

func (pk PublicKey) Copy() PublicKey

func (PublicKey) Equals

func (pk PublicKey) Equals(pk1 PublicKey) bool

func (PublicKey) Format

func (pk PublicKey) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (PublicKey) Hex

func (pk PublicKey) Hex() string

func (PublicKey) IsAddress

func (pk PublicKey) IsAddress() bool

unsafe 前13个字节都是0

func (PublicKey) MarshalText

func (pk PublicKey) MarshalText() ([]byte, error)

MarshalText returns the hex representation of pk.

func (*PublicKey) SetBytes

func (pk *PublicKey) SetBytes(b []byte)

SetBytes sets the address to the value of b. If b is larger than len(pk) it will panic.

func (PublicKey) String

func (pk PublicKey) String() string

String implements fmt.Stringer.

func (PublicKey) ToAddress

func (pk PublicKey) ToAddress() Address

unsafe 兼容老版本

func (*PublicKey) UnmarshalJSON

func (pk *PublicKey) UnmarshalJSON(input []byte) error

UnmarshalJSON parses pk hash in hex syntax.

func (*PublicKey) UnmarshalText

func (pk *PublicKey) UnmarshalText(input []byte) error

UnmarshalText parses pk hash in hex syntax.

func (PublicKey) VerifyBytes

func (pk PublicKey) VerifyBytes(msg, signature []byte) bool

type QueryBase

type QueryBase struct {
	Order  string
	Limit  uint64
	Cursor uint64

	Begin uint64
	End   uint64
}

type Result

type Result struct {
	Code uint32 `json:"Code"`
	Data []byte `json:"Data"`
	Log  string `json:"Log"` // Can be non-deterministic
}

CONTRACT: a zero Result is OK.

func NewError

func NewError(code uint32, log string) Result

func NewResultOK

func NewResultOK(data []byte, log string) Result

NOTE: if data == nil and log == "", same as zero Result.

func (Result) AppendLog

func (res Result) AppendLog(log string) Result

func (Result) Error

func (res Result) Error() string

func (*Result) FromJSON

func (res *Result) FromJSON(j string) *Result

func (Result) IsErr

func (res Result) IsErr() bool

func (Result) IsOK

func (res Result) IsOK() bool

func (Result) PrependLog

func (res Result) PrependLog(log string) Result

func (Result) SetData

func (res Result) SetData(data []byte) Result

func (Result) SetLog

func (res Result) SetLog(log string) Result

func (Result) String

func (res Result) String() string

func (Result) ToJSON

func (res Result) ToJSON() string

type Signature

type Signature struct {
	PubKey   PubKeyMultisigThreshold
	MultiSig *Multisignature
}

type TxBatch

type TxBatch struct {
	CreatedAt uint64    // 交易发起时间
	GasLimit  uint64    // gas限额
	GasPrice  *big.Int  // gas价格
	Nonce     uint64    // 交易发起者nonce
	Sender    PublicKey // 交易发起者公钥
	Ops       []TxOp    // 交易列表
	Memo      []byte    // 备注
	Signature []byte    // 交易签名
	// contains filtered or unexported fields
}

1对多批量交易

func NewTxBatch

func NewTxBatch() *TxBatch

func (*TxBatch) Cost

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

func (*TxBatch) FromBytes

func (tx *TxBatch) FromBytes(bs []byte) error

func (*TxBatch) GasWanted

func (tx *TxBatch) GasWanted() int64

func (*TxBatch) Hash

func (tx *TxBatch) Hash() ethcmn.Hash

func (*TxBatch) SigHash

func (tx *TxBatch) SigHash() ethcmn.Hash

func (*TxBatch) Sign

func (tx *TxBatch) Sign(privkey string) ([]byte, error)

func (*TxBatch) ToBytes

func (tx *TxBatch) ToBytes() []byte

func (*TxBatch) Verify

func (tx *TxBatch) Verify() bool

type TxEvm

type TxEvm struct {
	CreatedAt uint64      // 交易发起时间
	GasLimit  uint64      // gas限额
	GasPrice  *big.Int    // gas价格
	Nonce     uint64      // 交易发起者nonce
	Sender    PublicKey   // 交易发起者公钥
	Body      TxEvmCommon // 交易结构
	Signature []byte      // 交易签名
	// contains filtered or unexported fields
}

evm交易时sender和receiver都传public key,如果是合约帐户,receiver填写最后20个字节,前12字节填0

func NewTxEvm

func NewTxEvm() *TxEvm

func (*TxEvm) Cost

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

func (*TxEvm) FromBytes

func (tx *TxEvm) FromBytes(bs []byte) error

func (*TxEvm) Hash

func (tx *TxEvm) Hash() ethcmn.Hash

func (*TxEvm) SigHash

func (tx *TxEvm) SigHash() ethcmn.Hash

func (*TxEvm) Sign

func (tx *TxEvm) Sign(privkey string) ([]byte, error)

func (*TxEvm) ToBytes

func (tx *TxEvm) ToBytes() []byte

func (*TxEvm) Verify

func (tx *TxEvm) Verify() bool

type TxEvmCommon

type TxEvmCommon struct {
	To    PublicKey // 交易接收方公钥或地址,地址时填后20字节,创建合约是为全0
	Value *big.Int  // 交易金额
	Load  []byte    // 合约交易负荷
	Memo  []byte    // 备注信息
}

type TxOp

type TxOp struct {
	To    PublicKey // 转账接收方公钥或地址,地址时填后20字节
	Value *big.Int  // 交易金额
}

type TxResult

type TxResult struct {
	Ret      []byte      `json:"ret"`      // 返回数据
	Hash     common.Hash `json:"hash"`     // tx hash
	Reversed []byte      `json:"reversed"` // 保留
}

注意amino的兼容类型

func NewTxResult

func NewTxResult(ret []byte, hash common.Hash) *TxResult

func (TxResult) Copy

func (tx TxResult) Copy() *TxResult

func (*TxResult) FromBytes

func (tx *TxResult) FromBytes(bs []byte) error

func (TxResult) ToBytes

func (tx TxResult) ToBytes() []byte

type TxTag

type TxTag [TxTagLength]byte

func NewTxTag

func NewTxTag(tag []byte) TxTag

func (TxTag) Bytes

func (t TxTag) Bytes() []byte

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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