tools

package
v0.0.0-...-500bc43 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHexPrefix

func AddHexPrefix(hex string) string

func ConvertPrivateKey

func ConvertPrivateKey(key string) (privateKey *ecdsa.PrivateKey, err error)

ConvertPrivateKey() converts a private key (hex) string to an ecdsa.PrivateKey

func ConvertToBigEndian

func ConvertToBigEndian(hex string) (string, error)

Converts a hex string (without 0x prefix) to a hex string in Big Endian format

func CreateHTTPRPCRequest

func CreateHTTPRPCRequest(url string, method string, args ...string) (*http.Request, error)

CreateHTTPRPCRequest is a helper function to create a new JSON RPC http request with the given method and arguments.

func CreateJSONRequest

func CreateJSONRequest(method string, paramsStr ...string) ([]byte, error)

CreateJSONRequest creates a JSON RPC request with the given method and params and returns the JSON encoded request as a byte array.

func DecodeBig

func DecodeBig(input string) (*big.Int, error)

Decodes a hex string (with or w/o 0x prefix) into an int .

func DecodeRawTx

func DecodeRawTx(rawtx string) (*types.Transaction, error)

DecodeRawTX decodes a raw ethereum RLP encoded transaction and returns a go-ethereum types.Transaction

func EncodeBig

func EncodeBig(input *big.Int) string

Converts an int to a hex string (with 0x prefix).

func GetAddressFromPrivKey

func GetAddressFromPrivKey(privateKey *ecdsa.PrivateKey) (address common.Address, err error)

GetAddressFromPrivKey() returns the ethereum common.Address from a ecdsa.PrivateKey

func GetFromAddress

func GetFromAddress(tx *types.Transaction) (*common.Address, error)

GetFromAddress extracts the signer address from the public key of a signed ethereum transaction

func GetSignatureAndSigner

func GetSignatureAndSigner(tx *types.Transaction) (signature []byte, signer types.Signer)

GetSignatureAndSigner returns the signature and signer from a signed ethereum transaction

func HexStringToBytes32

func HexStringToBytes32(dataStr string) ([]byte, error)

HexStringToBytes32 converts a hex string to a byte array of length 32.

If input string is not 64 characters long returns an error.

Used to convert 256 bits keys and addresses to byte array.

func IsValidHexAddress

func IsValidHexAddress(iaddress interface{}) bool

IsValidHexAddress checks if the given address is a valid ethereum hex address.

func IsValidHexPrivKey

func IsValidHexPrivKey(privKey string) bool

IsValidHexPrivKey checks if the given private key is a valid hex ecdsa private key.

func IsValidWeiAmount

func IsValidWeiAmount(weiAmount string) bool

IsValidWeiAmount() checks if a string represents a valid wei amount.

func NewEthereumTx

func NewEthereumTx() *types.Transaction

NewEthereumTx() creates a new unsigned ethereum transaction with default parameters.

func PrivToPubKey

func PrivToPubKey(privKeyHex string) (string, error)

PrivToPubKey converts a ECDSA private key to a Ethereum public key.

func PubKeyToAddress

func PubKeyToAddress(pubKeyHex string) (string, error)

PubKeyToAddress converts a public key to an Ethereum address.

func ReadJSONResult

func ReadJSONResult(resp *http.Response, result interface{}) error

ReadJSONResult reads the JSON response from the given http response and unmarshals the result into the given result interface.

func RemoveHexPrefix

func RemoveHexPrefix(hex string) string

func SignEthereumTx

func SignEthereumTx(tx *types.Transaction, signer types.Signer, privKeyHex string) (*types.Transaction, error)

SignEthereumTx() signs an ethereum transaction with a private key.

Params: - tx: the unsigned transaction types.Transaction - signer: the signer types.Signer - privKeyHex: the private key hex string of the signer

func VerifyTxSignature

func VerifyTxSignature(tx *types.Transaction, pubKeyHex string) bool

VerifyTxSignature() verifies the signature of a signed ethereum transaction against a public key.

Params: - tx: the signed transaction types.Transaction - pubKeyHex: the public key hex string of the signer

Types

type JSONRPCError

type JSONRPCError struct {
	JSONRPC string `json:"jsonrpc"`
	Code    int    `json:"code"`
	Message string `json:"message"`
	// Data    string `json:"data"`
	Data json.RawMessage `json:"data"`
	ID   int             `json:"id"`
}

http://www.jsonrpc.org/specification#error_object

func NewJSONRPCResponseError

func NewJSONRPCResponseError(id, code int, message string, data json.RawMessage) *JSONRPCError

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string `json:"jsonrpc"`
	Method  string `json:"method"`
	// Params  []interface{} `json:"params"`
	Params []json.RawMessage `json:"params"`
	ID     int               `json:"id"`
}

http://www.jsonrpc.org/specification#request_object

func NewJSONRPCRequest

func NewJSONRPCRequest(id int, method string, params []json.RawMessage) *JSONRPCRequest

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC string          `json:"jsonrpc"`
	Result  json.RawMessage `json:"result"`
	// Error   string `json:"error"`
	Error *JSONRPCError `json:"error"`
	ID    int           `json:"id"`
}

http://www.jsonrpc.org/specification#response_object

func NewJSONRPCResponse

func NewJSONRPCResponse(id int, result json.RawMessage, err *JSONRPCError) *JSONRPCResponse

Jump to

Keyboard shortcuts

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