chain

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

description: sync_eth

@author: xwc1125 @date: 2020/10/05

Package chain description: sync_eth

@author: xwc1125 @date: 2020/10/05

description: sync_eth

@author: xwc1125 @date: 2020/10/05

description: sync_eth

@author: xwc1125 @date: 2020/10/05

description: sync_eth

@author: xwc1125 @date: 2020/10/05

description: sync_eth

@author: xwc1125 @date: 2020/10/05

description: sync_eth

@author: xwc1125 @date: 2020/10/05

description: sync_eth

@author: xwc1125 @date: 2020/10/05

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressPubkey

func CompressPubkey(pubkey *ecdsa.PublicKey) []byte

CompressPubkey encodes a public key to the 33-byte compressed format.

func DecompressPubkey

func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error)

DecompressPubkey parses a public key in the 33-byte compressed format.

func Ecrecover

func Ecrecover(hash, sig []byte) ([]byte, error)

Ecrecover returns the uncompressed public key that created the given signature.

func S256

func S256() elliptic.Curve

S256 returns an instance of the secp256k1 curve.

func SigToPub

func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error)

SigToPub returns the public key that created the given signature.

func Sign

func Sign(hash []byte, prv *ecdsa.PrivateKey) ([]byte, error)

Sign calculates an ECDSA signature.

This function is susceptible to chosen plaintext attacks that can leak information about the private key that is used for signing. Callers must be aware that the given hash cannot be chosen by an adversery. Common solution is to hash any input before calculating the signature.

The produced signature is in the [R || S || V] format where V is 0 or 1.

func ToECDSA

func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)

func TxStatus

func TxStatus(txReceipt *TransactionReceipt, isToken bool) bool

TxStatus get transaction status

func VerifySignature

func VerifySignature(pubkey, hash, signature []byte) bool

VerifySignature checks that the given public key created signature over hash. The public key should be in compressed (33 bytes) or uncompressed (65 bytes) format. The signature should have the 64 byte [R || S] format.

Types

type Block

type Block struct {
	BlockHeader
	Transactions []*Transaction `json:"transactions"`
}

Block block with transactions

type BlockHeader

type BlockHeader struct {
	Number     hexutil.Uint64 `json:"number"`
	Hash       string         `json:"hash"`
	ParentHash string         `json:"parentHash"`
	Coinbase   string         `json:"coinbase"`
	Size       hexutil.Uint64 `json:"size"`
	Timestamp  hexutil.Uint64 `json:"timestamp"`
	GasLimit   hexutil.Uint64 `json:"gasLimit"`
	GasUsed    hexutil.Uint64 `json:"gasUsed"`
}

BlockHeader block header

type BlockTxHashes

type BlockTxHashes struct {
	BlockHeader
	Transactions []string `json:"transactions"`
}

BlockTxHashes block with txHashes

func Block2BlockTxHashes

func Block2BlockTxHashes(b *Block) *BlockTxHashes

Block2BlockTxHashes block to blockTxHashes

func (*BlockTxHashes) Bytes

func (b *BlockTxHashes) Bytes() ([]byte, error)

Bytes blockTxHashes json bytes

type Eth

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

Eth eth

func NewETH

func NewETH(host string, clientIdentifier string, chainId int64, isEip155 bool) (*Eth, error)

NewETH new eth struct

func (*Eth) GetBalance

func (eth *Eth) GetBalance(address string, result interface{}) error

GetBalance get balance

func (*Eth) GetBlockByHash

func (eth *Eth) GetBlockByHash(height uint64, isFullTx bool, result interface{}) error

GetBlockByHash get block by hash

func (*Eth) GetBlockByNumber

func (eth *Eth) GetBlockByNumber(height uint64, isFullTx bool, result interface{}) error

GetBlockByNumber get block by height isFullTx whether return the full transaction

func (*Eth) GetCode

func (eth *Eth) GetCode(contract string) (hexutil.Bytes, error)

GetCode get code

func (*Eth) GetLatestBlock

func (eth *Eth) GetLatestBlock(isFullTx bool, result interface{}) error

GetLatestBlock get latest block

func (*Eth) GetNonce

func (eth *Eth) GetNonce(address string) (hexutil.Uint64, error)

GetNonce get nonce

func (*Eth) GetTokenBalance

func (eth *Eth) GetTokenBalance(contract, address string, blockNumber *big.Int, result interface{}) error

GetTokenBalance get token balance

func (*Eth) GetTokenDecimals

func (eth *Eth) GetTokenDecimals(contract string) (decimals big.Int, err error)

GetTokenDecimals get token decimals

func (*Eth) GetTokenName

func (eth *Eth) GetTokenName(contract string) (name string, err error)

GetTokenName get token name

func (*Eth) GetTokenSymbol

func (eth *Eth) GetTokenSymbol(contract string) (symbol string, err error)

GetTokenSymbol get token symbol

func (*Eth) GetTokenTotalSupply

func (eth *Eth) GetTokenTotalSupply(contract string) (totalSupply big.Int, err error)

GetTokenTotalSupply get token total supply

func (*Eth) GetTransactionByHash

func (eth *Eth) GetTransactionByHash(hash string, result interface{}) error

GetTransactionByHash get transaction by hash

func (*Eth) GetTransactionReceipt

func (eth *Eth) GetTransactionReceipt(hash string, result interface{}) error

GetTransactionReceipt get tx receipt by hash

func (*Eth) IsContract

func (eth *Eth) IsContract(address string) (bool, error)

IsContract whether address is contract

func (*Eth) SendRawTransactionMethod

func (eth *Eth) SendRawTransactionMethod(tx *RawTransaction) (string, error)

SendRawTransactionMethod send rawTx

func (*Eth) SignTx

func (eth *Eth) SignTx(privateKey string, to *types.Address, value *big.Int, nonce uint64, gasPrice *big.Int, gasLimit uint64, input []byte) (*RawTransaction, error)

SignTx sign rawTx

type RawTransaction

type RawTransaction struct {
	Nonce   uint64         `json:"nonce"    gencodec:"required"`
	GaPrice *big.Int       `json:"gasPrice" gencodec:"required"`
	Gas     uint64         `json:"gas"      gencodec:"required"`
	To      *types.Address `json:"to"       rlp:"nil"` // nil means contract creation
	Value   *big.Int       `json:"value"    gencodec:"required"`
	Input   []byte         `json:"input"    gencodec:"required"`

	// Signature values
	V *big.Int `json:"v" gencodec:"required"`
	R *big.Int `json:"r" gencodec:"required"`
	S *big.Int `json:"s" gencodec:"required"`
}

func (*RawTransaction) GetRawTx

func (t *RawTransaction) GetRawTx() []byte

func (*RawTransaction) GetTxHash

func (t *RawTransaction) GetTxHash() string

type TokenTransferInput

type TokenTransferInput struct {
	Method     string `json:"method"`
	MethodName string `json:"methodName"`
	From       string `json:"from,omitempty"`
	To         string `json:"to"`
	Value      string `json:"value"`
}

func ParseInput

func ParseInput(input string) *TokenTransferInput

func ParseInputBytes

func ParseInputBytes(inputBytes hexutil.Bytes) *TokenTransferInput

type TokenTransferParams

type TokenTransferParams struct {
	MethodName string          `json:"methodName"`
	From       string          `json:"from,omitempty"`
	To         string          `json:"to"`
	Value      decimal.Decimal `json:"value"`
}

func ParseTransferInput

func ParseTransferInput(input *TokenTransferInput) *TokenTransferParams

type Transaction

type Transaction struct {
	Hash             string         `json:"hash"`
	Nonce            hexutil.Uint64 `json:"nonce"`
	BlockHash        string         `json:"blockHash"`
	BlockNumber      hexutil.Uint64 `json:"blockNumber"`
	TransactionIndex hexutil.Uint64 `json:"transactionIndex"`
	From             types.Address  `json:"from"`
	To               *types.Address `json:"to"`
	Value            *hexutil.Big   `json:"value"`
	GasPrice         *hexutil.Big   `json:"gasPrice"`
	GasLimit         hexutil.Uint64 `json:"gas"`
	Input            hexutil.Bytes  `json:"input"`
}

func (*Transaction) Bytes

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

type TransactionDetail

type TransactionDetail struct {
	*Transaction

	CumulativeGasUsed hexutil.Uint64  `json:"cumulativeGasUsed"`
	GasUsed           hexutil.Uint64  `json:"gasUsed"`
	ContractAddress   *types.Address  `json:"contractAddress"`
	Logs              json.RawMessage `json:"logs"`
	//LogsBloom         hexutil.Bytes  `json:"logsBloom"`
	Status      bool                `json:"status"`
	InputFormat *TokenTransferInput `json:"inputFormat"`
}

type TransactionReceipt

type TransactionReceipt struct {
	TransactionHash   string          `json:"transactionHash"`
	TransactionIndex  hexutil.Uint64  `json:"transactionIndex"`
	BlockHash         string          `json:"blockHash"`
	BlockNumber       hexutil.Uint64  `json:"blockNumber"`
	From              types.Address   `json:"from"`
	To                *types.Address  `json:"to"`
	CumulativeGasUsed hexutil.Uint64  `json:"cumulativeGasUsed"`
	GasUsed           hexutil.Uint64  `json:"gasUsed"`
	ContractAddress   *types.Address  `json:"contractAddress"`
	Logs              json.RawMessage `json:"logs"`
	Status            hexutil.Uint64  `json:"status"`
}

func (*TransactionReceipt) Bytes

func (t *TransactionReceipt) Bytes() ([]byte, error)

Jump to

Keyboard shortcuts

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