util

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 17 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)
)
View Source
const (
	Key             = "key"
	NodePath        = "./data"
	NodeFile        = "./data/key"
	LatestBlockPath = "./data"
	LatestBlockFile = "./data/blockchain.json"
)
View Source
const (
	// HashLength is the expected length of the hash
	HashLength = 32
)

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 DeleteFile

func DeleteFile(path string) error

func Div

func Div(str string, pos int) string

Div cut string to new string *

eg: 1021,3->1.021

func Encode

func Encode(input []byte) string

func EncodeCheck

func EncodeCheck(input []byte) string

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 GetLocalNodeId

func GetLocalNodeId(path string) (string, error)

func Has0xPrefix

func Has0xPrefix(str string) bool

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

func Hex2Address

func Hex2Address(hex string) (string, error)

func Hex2Address2

func Hex2Address2(hex string) (string, error)

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 HexToInt

func HexToInt(hex string) (string, error)

func HexToInt2

func HexToInt2(hex string) (int64, error)

func Int2Hex added in v0.5.2

func Int2Hex(data string) (string, error)

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 NftData added in v0.5.1

func NftData(data string) (string, string, error)

func PathExists

func PathExists(path string) (bool, error)

func ReadLatestBlock

func ReadLatestBlock() ([]byte, error)

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

func WriteLatestBlock

func WriteLatestBlock(content string) error

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) Base58

func (a Address) Base58() string

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) String

func (a Address) String() string

String implements fmt.Stringer.

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