ethutil

package
v0.0.0-...-83323f8 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//bytes of "\x19Ethereum Signed Message:\n32"
	SIGN_PREFIX_STANDARD []byte = []byte("\u0019Ethereum Signed Message:\n32")

	//bytes of "\x19\x01"
	SIGN_PREFIX_HEX1901 []byte = []byte("\u0019\u0001")
)

Functions

func Add0xPrefix

func Add0xPrefix(hexStr string) string

func AddressToHex

func AddressToHex(addr common.Address) string

func Bytes2HexWith0x

func Bytes2HexWith0x(buffer []byte) string

func Bytes2HexWithout0x

func Bytes2HexWithout0x(buffer []byte) string

func BytesToHex

func BytesToHex(buf []byte) string

func CalcSignVByChainId

func CalcSignVByChainId(chainID *big.Int, v uint8) int64

func DecryptKeystore

func DecryptKeystore(keystoreJson []byte, pwd string) *ecdsa.PrivateKey

decrypt json keystore to private key plantext hex string

func DeriveChainId

func DeriveChainId(v *big.Int) *big.Int

deriveChainId derives the chain id from the given v parameter

func ECDSAPrivateKeyToHex

func ECDSAPrivateKeyToHex(prv *ecdsa.PrivateKey) string

ecdsa私钥指针转私钥字符串

func EcRecover

func EcRecover(digestHash []byte, sig []byte) (common.Address, error)

获取签名地址

func EncryptPrivLight

func EncryptPrivLight(priv *ecdsa.PrivateKey, pwd string) []byte

encrypt private key to json keystore,use light scryptN,scryptP

func EncryptPrivStandard

func EncryptPrivStandard(priv *ecdsa.PrivateKey, pwd string) []byte

encrypt private key to json keystore,use standard scryptN,scryptP

func FillTo32Bytes

func FillTo32Bytes(data []byte) []byte

填充到32位长度

func FromWei

func FromWei(amount *big.Int) decimal.Decimal

func FromWeiWithDecimals

func FromWeiWithDecimals(amount *big.Int, decimals int32) decimal.Decimal

func GenNewPrivateKey

func GenNewPrivateKey() string

func GetAddress

func GetAddress(privateKey string) string

根据私钥获取地址

func GetBalance

func GetBalance(client *ethclient.Client, account string) *big.Int

func GetChainID

func GetChainID(client *ethclient.Client) *big.Int

func GetContractAbi

func GetContractAbi(abiJson string) *abi.ABI

获取合约abi对象

func GetEthClientWithHeader

func GetEthClientWithHeader(endpoint string, key string, val string) (*ethclient.Client, error)

func GetEthStandardHex

func GetEthStandardHex(hex string) string

将16进制字符串转换为eth标准的16进制形式字符串(统一小写)

func GetInfuraEthClientUseJWT

func GetInfuraEthClientUseJWT(endpoint string, token string) (*ethclient.Client, error)

func GetInfuraEthClientUseSecret

func GetInfuraEthClientUseSecret(endpoint string, secret string) (*ethclient.Client, error)

func GetNextNonce

func GetNextNonce(client *ethclient.Client, account string) uint64

func GetRawTxHash

func GetRawTxHash(tx *types.Transaction) string

获取已签名交易的txhash

func GetTxFrom

func GetTxFrom(tx *types.Transaction, chainID *big.Int) string

获取交易from地址

func Hex2Bytes

func Hex2Bytes(s string) []byte

func HexToAddress

func HexToAddress(addr string) common.Address

func HexToBytes

func HexToBytes(hexStr string) []byte

func HexToECDSAPrivateKey

func HexToECDSAPrivateKey(privateKey string) *ecdsa.PrivateKey

私钥字符串转ecdsa私钥指针

func Int32ToBytes

func Int32ToBytes(i int64) []byte

func Int64ToBytes

func Int64ToBytes(i int64) []byte

func IntToBytes

func IntToBytes(i int) []byte

func IsContract

func IsContract(client *ethclient.Client, account string) bool

func IsValidAddressHex

func IsValidAddressHex(hex string) bool

判断是否是有效的地址16进制字符串

func IsValidPrivateKeyHex

func IsValidPrivateKeyHex(hex string) bool

是否是有效的私钥16进制字符串

func JoinSignature

func JoinSignature(sign *Signature) string

将签名转换为16进制字符串

func Keccak256

func Keccak256(data []byte) []byte

计算数据的Keccak256值

func LogWithTime

func LogWithTime(msg string)

func NewContractCreation

func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *types.Transaction

生成部署合约的交易

func NewTx

func NewTx(nonce uint64, to string, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *types.Transaction

生成新交易

func PackFuncArgs

func PackFuncArgs(datas *[]AbiParam) *[]byte

打包调用合约方法用的参数

func PackSignArgs

func PackSignArgs(datas *[]AbiParam) *[]byte

打包签名用的参数

func PaddingLeft0

func PaddingLeft0(data []byte, targetLen int) []byte

func PaddingRight0

func PaddingRight0(data []byte, targetLen int) []byte

func PubkeyToAddress

func PubkeyToAddress(pubkey *ecdsa.PublicKey) string

func ReadPrivateKeys

func ReadPrivateKeys(filePath string) []string

func RestoreSignV

func RestoreSignV(chainID *big.Int, v int64) uint8

还原签名中的V,总是返回0||1

func SendRawTx

func SendRawTx(client *ethclient.Client, tx *types.Transaction) error

发送已签名的tx

func SignTx

func SignTx(prv *ecdsa.PrivateKey, tx *types.Transaction, chainID *big.Int) *types.Transaction

签名交易

func ToWei

func ToWei(amount decimal.Decimal) *big.Int

func ToWeiWithDecimals

func ToWeiWithDecimals(amount decimal.Decimal, decimals int32) *big.Int

func VerifySignature

func VerifySignature(address common.Address, digestHash []byte, signature []byte) bool

验证签名

func WaitTxReceipt

func WaitTxReceipt(client *ethclient.Client, txId string, txDesc string, timeoutSeconds int64) bool

func WaitTxReceiptSuccess

func WaitTxReceiptSuccess(client *ethclient.Client, txId string, txDesc string, timeoutSeconds int64)

Types

type AbiParam

type AbiParam struct {
	Type string
	Data []byte
}

type Signature

type Signature struct {
	R []byte
	S []byte
	V uint8
}

签名

func ExtractEcdsaSignature

func ExtractEcdsaSignature(signHex string) *Signature

16进制字符串转换为签名

func SignMessage

func SignMessage(digestHash []byte, prv *ecdsa.PrivateKey) *Signature

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

func SignOriginDatas

func SignOriginDatas(prv *ecdsa.PrivateKey, prefix []byte, params *[]AbiParam) *Signature

签名原始参数

type TxBaseParams

type TxBaseParams struct {
	ChainID  *big.Int
	Nonce    uint64
	Gas      uint64
	GasPrice *big.Int
}

Jump to

Keyboard shortcuts

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