tronutils

package
v0.0.0-...-7beb898 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HashLength is the expected length of the hash
	HashLength = 32
	// AddressLength is the expected length of the address
	AddressLength = 21
	// AddressLengthBase58 is the expected length of the address in base58format
	AddressLengthBase58 = 34
	// TronBytePrefix is the hex prefix to address
	TronBytePrefix = byte(0x41)
)

Variables

View Source
var EmptyString = &hexError{"empty hex string"}

Functions

func Bytes2Hex

func Bytes2Hex(d []byte) string

Bytes2Hex returns the hexadecimal encoding of d.

func BytesToHexString

func BytesToHexString(bytes []byte) string

BytesToHexString encodes bytes as a hex string.

func CopyBytes

func CopyBytes(b []byte) (copiedBytes []byte)

CopyBytes returns an exact copy of the provided bytes.

func Decode

func Decode(input string) ([]byte, error)

func DecodeCheck

func DecodeCheck(input string) ([]byte, error)

func Encode

func Encode(input []byte) string

func EncodeCheck

func EncodeCheck(input []byte) string

func FormatPrecisionNumber

func FormatPrecisionNumber(number int64, precision int) string

FormatPrecisionNumber formats an integer number (as int64) into a decimal string with the specified precision

func FormatPrecisionString

func FormatPrecisionString(number string, precision int) string

FormatPrecisionString formats a string number into a decimal string with the specified precision

func FromHex

func FromHex(s string) ([]byte, error)

FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func Has0xPrefix

func Has0xPrefix(str string) bool

Has0xPrefix validates str begins with '0x' or '0X'.

func Hex2Bytes

func Hex2Bytes(str string) ([]byte, error)

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func Hex2BytesFixed

func Hex2BytesFixed(str string, flen int) []byte

Hex2BytesFixed returns bytes of a specified fixed length flen.

func HexStringToBytes

func HexStringToBytes(input string) ([]byte, error)

HexStringToBytes hex string as bytes

func IsHex

func IsHex(str string) bool

isHex validates whether each byte is valid hexadecimal string.

func Keccak256

func Keccak256(msg []byte) []byte

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

LeftPadBytes zero-pads slice to the left up to length l.

func RightPadBytes

func RightPadBytes(slice []byte, l int) []byte

RightPadBytes zero-pads slice to the right up to length l.

func ToHex deprecated

func ToHex(b []byte) string

ToHex returns the hex representation of b, prefixed with '0x'. For empty slices, the return value is "0x0".

Deprecated: use BytesToHexString instead.

func ToHexArray

func ToHexArray(b [][]byte) []string

ToHexArray creates a array of hex-string based on []byte

func TrimLeftZeroes

func TrimLeftZeroes(s []byte) []byte

TrimLeftZeroes returns a subslice of s without leading zeroes

Types

type Address

type Address []byte

Address represents the 21 byte address of an Tron account.

func Base58ToAddress

func Base58ToAddress(s string) (Address, error)

Base58ToAddress returns Address with byte values of s.

func Base64ToAddress

func Base64ToAddress(s string) (Address, error)

Base64ToAddress returns Address with byte values of s.

func BigToAddress

func BigToAddress(b *big.Int) Address

BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.

func HexToAddress

func HexToAddress(s string) Address

HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.

func PubkeyToAddress

func PubkeyToAddress(p ecdsa.PublicKey) Address

PubkeyToAddress returns address from ecdsa public key

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes get bytes from address

func (Address) Hex

func (a Address) Hex() string

Hex get bytes from address in string

func (*Address) Scan

func (a *Address) Scan(src interface{}) error

Scan implements Scanner for database/sql.

func (Address) String

func (a Address) String() string

String implements fmt.Stringer.

func (Address) Value

func (a Address) Value() (driver.Value, error)

Value implements valuer for database/sql.

type Hash

type Hash [HashLength]byte

Hash represents the 32 byte Keccak256 hash of arbitrary data.

func BigToHash

func BigToHash(b *big.Int) Hash

BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func HexToHash

func HexToHash(s string) (Hash, error)

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func (Hash) Big

func (h Hash) Big() *big.Int

Big converts a hash to a big integer.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Hash) Hex

func (h Hash) Hex() string

Hex converts a hash to a hex string.

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (Hash) String

func (h Hash) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash) TerminalString

func (h Hash) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

Jump to

Keyboard shortcuts

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