Documentation ¶
Index ¶
- Constants
- Variables
- func AllZero(b []byte) bool
- func BigMax(x, y *big.Int) *big.Int
- func BigMin(x, y *big.Int) *big.Int
- func BigPow(a, b int64) *big.Int
- func BigUint64(v *big.Int) (uint64, bool)
- func Byte(bigint *big.Int, padlength, n int) byte
- func Bytes2Hex(b []byte) string
- func Bytes2HexTrim(b []byte) string
- func Exp(base, exponent *big.Int) *big.Int
- func FromHex(s string) []byte
- func GetData(data []byte, start uint64, size uint64) []byte
- func GetDataBig(data []byte, start *big.Int, size *big.Int) []byte
- func Hex2Bytes(str string) []byte
- func HexToBytes(str string) ([]byte, error)
- func LeftPadBytes(slice []byte, l int) []byte
- func PaddedBigBytes(bigint *big.Int, n int) []byte
- func ReadBits(bigint *big.Int, buf []byte)
- func RightPadBytes(slice []byte, l int) []byte
- func S256(x *big.Int) *big.Int
- func SafeAdd(x, y uint64) (uint64, bool)
- func SafeMul(x, y uint64) (uint64, bool)
- func ToWordSize(size uint64) uint64
- func U256(x *big.Int) *big.Int
- func Zero(value *big.Int) bool
- type Address
- type Hash
- type Hash160Address
- type Message
Constants ¶
const ( // WordBits 一个big.Word类型取值占用多少个位 WordBits = 32 << (uint64(^big.Word(0)) >> 63) // WordBytes 一个big.Word类型取值占用多少个字节 WordBytes = WordBits / 8 )
const ( // HashLength 哈希长度 HashLength = 32 // Hash160Length Hash160格式的地址长度 Hash160Length = 20 )
Variables ¶
var ( // Big0 大数字0 Big0 = big.NewInt(0) // Big1 大数字1 Big1 = big.NewInt(1) // Big32 大数字32 Big32 = big.NewInt(32) // Big256 大数字256 Big256 = big.NewInt(256) // Big257 大数字257 Big257 = big.NewInt(257) )
常用的大整数常量定义
var ( // TT255 2的255次幂 TT255 = BigPow(2, 255) )
2的各种常用取幂结果
Functions ¶
func Bytes2HexTrim ¶
Bytes2HexTrim 将字节数组转换为16进制的字符串表示 并且将前面多余的0去除
func GetDataBig ¶
GetDataBig 返回从开始位置制定长度的数据 如果源数据不足,则剩余位置用零填充
func PaddedBigBytes ¶
PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.
func S256 ¶
S256 interprets x as a two's complement number. x must not exceed 256 bits (the result is undefined if it does) and is not modified.
S256(0) = 0 S256(1) = 1 S256(2**255) = -2**255 S256(2**256-1) = -1
func ToWordSize ¶
ToWordSize 计算制定字节长度所对应的字长度(一个字,对应32个字节,也就是256位) 如果长度不足一个字长,则补足 EVM在内存中存储时的最小单位是字长(256位),而不是字节
Types ¶
type Address ¶
type Address struct {
// contains filtered or unexported fields
}
Address 封装地址结构体,并提供各种常用操作封装 这里封装的操作主要是为了提供Address<->big.Int, Address<->[]byte 之间的互相转换 并且转换的核心是使用地址对象中的Hash160元素,因为在EVM中地址固定为[20]byte,超出此范围的地址无法正确解释执行
type Hash160Address ¶
type Hash160Address [Hash160Length]byte
Hash160Address EVM中使用的地址格式
func BytesToHash160Address ¶
func BytesToHash160Address(b []byte) Hash160Address
BytesToHash160Address 字节向地址转换
func HexToAddress ¶
func HexToAddress(s string) Hash160Address
HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.
func (Hash160Address) Hex ¶
func (h Hash160Address) Hex() string
Hex returns an EIP55-compliant hex string representation of the address.
func (*Hash160Address) SetBytes ¶
func (h *Hash160Address) SetBytes(b []byte)
SetBytes sets the address to the value of b. If b is larger than len(a) it will panic.
func (Hash160Address) String ¶
func (h Hash160Address) String() string
String implements fmt.Stringer.
func (Hash160Address) ToAddress ¶
func (h Hash160Address) ToAddress() Address
ToAddress 返回Chain33格式的地址
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message 合约交易消息模型 在EVM执行器中传递此消息,由外部Tx等价构造