Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeTx(raw []byte) (TxTag, HashTx, error)
- func PubkeyToAddress(pub PublicKey) ethcmn.Address
- func RLPHash(x interface{}) (h ethcmn.Hash)
- func SaveLastBlock(db ethdb.Database, appHash ethcmn.Hash, header *AppHeader)
- func ValidAddress(s string) bool
- func ValidPublicKey(s string) bool
- type Address
- type AppBlock
- type AppHeader
- type BeanAccount
- type BeanContract
- type BeanEvmCallResult
- type DPosQuery
- type HashTx
- type LastBlockInfo
- type MultisigEvmTx
- func (tx *MultisigEvmTx) AddSign(signature string) error
- func (tx *MultisigEvmTx) Cost() *big.Int
- func (tx *MultisigEvmTx) FromBytes(bs []byte) error
- func (tx *MultisigEvmTx) Hash() ethcmn.Hash
- func (tx *MultisigEvmTx) SigHash() ethcmn.Hash
- func (tx *MultisigEvmTx) Sign(privkey string) error
- func (tx MultisigEvmTx) Signer() []ethcmn.Address
- func (tx *MultisigEvmTx) ToBytes() []byte
- func (tx *MultisigEvmTx) Verify() bool
- type Multisignature
- type PubKeyMultisigThreshold
- type PublicKey
- func (pk PublicKey) Big() *big.Int
- func (pk PublicKey) Bytes() []byte
- func (pk PublicKey) Copy() PublicKey
- func (pk PublicKey) Equals(pk1 PublicKey) bool
- func (pk PublicKey) Format(s fmt.State, c rune)
- func (pk PublicKey) Hex() string
- func (pk PublicKey) IsAddress() bool
- func (pk PublicKey) MarshalText() ([]byte, error)
- func (pk *PublicKey) SetBytes(b []byte)
- func (pk PublicKey) String() string
- func (pk PublicKey) ToAddress() Address
- func (pk *PublicKey) UnmarshalJSON(input []byte) error
- func (pk *PublicKey) UnmarshalText(input []byte) error
- func (pk PublicKey) VerifyBytes(msg, signature []byte) bool
- type QueryBase
- type Result
- func (res Result) AppendLog(log string) Result
- func (res Result) Error() string
- func (res *Result) FromJSON(j string) *Result
- func (res Result) IsErr() bool
- func (res Result) IsOK() bool
- func (res Result) PrependLog(log string) Result
- func (res Result) SetData(data []byte) Result
- func (res Result) SetLog(log string) Result
- func (res Result) String() string
- func (res Result) ToJSON() string
- type Signature
- type TxBatch
- func (tx *TxBatch) Cost() *big.Int
- func (tx *TxBatch) FromBytes(bs []byte) error
- func (tx *TxBatch) GasWanted() int64
- func (tx *TxBatch) Hash() ethcmn.Hash
- func (tx *TxBatch) SigHash() ethcmn.Hash
- func (tx *TxBatch) Sign(privkey string) ([]byte, error)
- func (tx *TxBatch) ToBytes() []byte
- func (tx *TxBatch) Verify() bool
- type TxEvm
- type TxEvmCommon
- type TxOp
- type TxResult
- type TxTag
Constants ¶
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 // 合约执行失败 )
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" )
const PubKeyLength = 33
const (
TxGas = int64(21000) // tx gas
)
const TxTagLength = 2
Variables ¶
var ( ZERO_ADDRESS = ethcmn.Address{} ZERO_HASH = ethcmn.Hash{} ZERO_PUBLICKEY = PublicKey{} )
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") )
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多签交易 )
var (
ErrUnknownTxType = errors.New("unknown tx type")
)
Functions ¶
func PubkeyToAddress ¶
func ValidAddress ¶
func ValidPublicKey ¶
Types ¶
type Address ¶
func (Address) MarshalText ¶
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
type BeanAccount ¶
type BeanContract ¶
type BeanEvmCallResult ¶
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 HexToPubkey ¶
func (PublicKey) Format ¶
Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.
func (PublicKey) MarshalText ¶
MarshalText returns the hex representation of pk.
func (*PublicKey) SetBytes ¶
SetBytes sets the address to the value of b. If b is larger than len(pk) it will panic.
func (*PublicKey) UnmarshalJSON ¶
UnmarshalJSON parses pk hash in hex syntax.
func (*PublicKey) UnmarshalText ¶
UnmarshalText parses pk hash in hex syntax.
func (PublicKey) VerifyBytes ¶
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 NewResultOK ¶
NOTE: if data == nil and log == "", same as zero Result.
func (Result) PrependLog ¶
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
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