Documentation ¶
Overview ¶
Package common contains various helper functions.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func ByteInt32(i int32) []byte
- func Bytes2Hex(d []byte) string
- func CopyBytes(b []byte) (copiedBytes []byte)
- func FromHex(s string) []byte
- func GetInt32(b []byte, pos int) int32
- func Hex2Bytes(str string) []byte
- func Hex2BytesFixed(str string, flen int) []byte
- func IsSameBytes(s, t []byte) bool
- func LeftPadBytes(slice []byte, l int) []byte
- func PrettyJson(data interface{}) (string, error)
- func RightPadBytes(slice []byte, l int) []byte
- func SetInt32(b []byte, pos int, i int32)
- func ToHex(b []byte) stringdeprecated
- type Address
- func (h Address) Big() *big.Int
- func (z *Address) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *Address) EncodeMsg(en *msgp.Writer) (err error)
- func (h Address) EqualTo(b Address) bool
- func (h Address) Format(s fmt.State, c rune)
- func (h Address) Generate(rand *rand.Rand, size int) reflect.Value
- func (h Address) Hex() string
- func (z *Address) MarshalMsg(b []byte) (o []byte, err error)
- func (h Address) MarshalText() ([]byte, error)
- func (z *Address) Msgsize() (s int)
- func (h *Address) MustSetBytes(b []byte)
- func (h *Address) SetBytes(b []byte) error
- func (h Address) ShortString() string
- func (h Address) String() string
- func (h Address) TerminalString() string
- func (h Address) ToBytes() []byte
- func (h *Address) UnmarshalJSON(input []byte) error
- func (z *Address) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (h *Address) UnmarshalText(input []byte) error
- type Hash
- func (h Hash) Big() *big.Int
- func (h Hash) Cmp(another Hash) int
- func (z *Hash) DecodeMsg(dc *msgp.Reader) (err error)
- func (h *Hash) Empty() bool
- func (z *Hash) EncodeMsg(en *msgp.Writer) (err error)
- func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value
- func (h Hash) Hex() string
- func (z *Hash) MarshalMsg(b []byte) (o []byte, err error)
- func (h Hash) MarshalText() ([]byte, error)
- func (z *Hash) Msgsize() (s int)
- func (h *Hash) MustSetBytes(b []byte, padding Padding)
- func (h *Hash) SetBytes(b []byte) error
- func (h Hash) String() string
- func (h Hash) TerminalString() string
- func (h Hash) ToBytes() []byte
- func (h *Hash) UnmarshalJSON(input []byte) error
- func (z *Hash) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (h *Hash) UnmarshalText(input []byte) error
- type HashBytes
- type Hashes
- func (z *Hashes) DecodeMsg(dc *msgp.Reader) (err error)
- func (z Hashes) EncodeMsg(en *msgp.Writer) (err error)
- func (a Hashes) Len() int
- func (a Hashes) Less(i, j int) bool
- func (z Hashes) MarshalMsg(b []byte) (o []byte, err error)
- func (z Hashes) Msgsize() (s int)
- func (h Hashes) String() string
- func (a Hashes) Swap(i, j int)
- func (z *Hashes) UnmarshalMsg(bts []byte) (o []byte, err error)
- type IOSize
- type Padding
- type PrettyDuration
- type StorageSize
Constants ¶
const (
AddressLength = 20
)
Length of Addresses in bytes.
const (
HashLength = 32
)
Length of hash in bytes.
Variables ¶
var ( Big1 = big.NewInt(1) Big2 = big.NewInt(2) Big3 = big.NewInt(3) Big0 = big.NewInt(0) Big32 = big.NewInt(32) Big256 = big.NewInt(256) Big257 = big.NewInt(257) )
Common big integers often used
Functions ¶
func FromHex ¶
FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".
func Hex2BytesFixed ¶
Hex2BytesFixed returns bytes of a specified fixed length flen.
func IsSameBytes ¶
IsSameBytes compares two byte slice. Return true if they are the same, otherwise false.
func LeftPadBytes ¶
LeftPadBytes zero-pads slice to the left up to length l.
func PrettyJson ¶ added in v0.0.2
dont do this, see above edit
func RightPadBytes ¶
RightPadBytes zero-pads slice to the right up to length l.
Types ¶
type Address ¶ added in v0.0.2
type Address struct {
Bytes [AddressLength]byte `msgp:"bytes"`
}
Address represents the 20 byte of address.
func BigToAddress ¶ added in v0.0.2
BigToAddress sets byte representation of b to Address. If b is larger than len(h), b will be cropped from the left.
func BytesToAddress ¶ added in v0.0.2
BytesToAddress sets b to hash. If b is larger than len(h), b will be cropped from the left.
func HexToAddress ¶ added in v0.0.2
HexToAddress sets byte representation of s to Address. If b is larger than len(h), b will be cropped from the left.
func RandomAddress ¶ added in v0.0.2
func RandomAddress() Address
func StringToAddress ¶ added in v0.0.2
func (Address) Format ¶ added in v0.0.2
Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.
func (*Address) MarshalMsg ¶ added in v0.0.2
MarshalMsg implements msgp.Marshaler
func (Address) MarshalText ¶ added in v0.0.2
MarshalText returns the hex representation of h.
func (*Address) Msgsize ¶ added in v0.0.2
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Address) MustSetBytes ¶ added in v0.0.2
SetBytes sets the Address to the value of b. If b is larger than len(h), panic. It usually indicates a logic error.
func (Address) ShortString ¶ added in v0.0.2
func (Address) String ¶ added in v0.0.2
String implements the stringer interface and is used also by the logger when doing full logging into a file.
func (Address) TerminalString ¶ added in v0.0.2
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.
func (*Address) UnmarshalJSON ¶ added in v0.0.2
UnmarshalJSON parses an Address in hex syntax.
func (*Address) UnmarshalMsg ¶ added in v0.0.2
UnmarshalMsg implements msgp.Unmarshaler
func (*Address) UnmarshalText ¶ added in v0.0.2
UnmarshalText parses an Address in hex syntax.
type Hash ¶ added in v0.0.2
type Hash struct {
Bytes [HashLength]byte `msgp:"bytes"`
}
Hash represents the 32 byte of Hash.
func BigToHash ¶ added in v0.0.2
BigToHash sets byte representation of b to Hash. If b is larger than len(h), b will be cropped from the left.
func BytesToHash ¶ added in v0.0.2
BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.
func HexStringToHash ¶ added in v0.0.2
func HexToHash ¶ added in v0.0.2
HexToHash sets byte representation of s to Hash. If b is larger than len(h), b will be cropped from the left.
func RandomHash ¶ added in v0.0.2
func RandomHash() Hash
func (Hash) Cmp ¶ added in v0.0.2
Cmp compares two hashes. Returns 0 if two hashes are same. Returns -1 if the self hash is less than parameter hash. Returns 1 if the self hash is larger than parameter hash.
func (*Hash) MarshalMsg ¶ added in v0.0.2
MarshalMsg implements msgp.Marshaler
func (Hash) MarshalText ¶ added in v0.0.2
MarshalText returns the hex representation of h.
func (*Hash) Msgsize ¶ added in v0.0.2
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Hash) MustSetBytes ¶ added in v0.0.2
SetBytes sets the Hash to the value of b. If b is larger than len(h), panic. It usually indicates a logic error.
func (Hash) String ¶ added in v0.0.2
String implements the stringer interface and is used also by the logger when doing full logging into a file.
func (Hash) TerminalString ¶ added in v0.0.2
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.
func (*Hash) UnmarshalJSON ¶ added in v0.0.2
UnmarshalJSON parses an Hash in hex syntax.
func (*Hash) UnmarshalMsg ¶ added in v0.0.2
UnmarshalMsg implements msgp.Unmarshaler
func (*Hash) UnmarshalText ¶ added in v0.0.2
UnmarshalText parses an Hash in hex syntax.
type HashBytes ¶ added in v0.0.2
type HashBytes [HashLength]byte
func (*HashBytes) MarshalMsg ¶ added in v0.0.2
MarshalMsg implements msgp.Marshaler
type Hashes ¶ added in v0.0.2
type Hashes []Hash
func (Hashes) MarshalMsg ¶ added in v0.0.2
MarshalMsg implements msgp.Marshaler
type IOSize ¶ added in v0.0.2
type IOSize float64
StorageSize is a wrapper around a float value that supports user friendly formatting.
func (IOSize) TerminalString ¶ added in v0.0.2
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.
type Padding ¶ added in v0.0.2
type Padding uint
func (Padding) MarshalMsg ¶ added in v0.0.2
MarshalMsg implements msgp.Marshaler
type PrettyDuration ¶
PrettyDuration is a pretty printed version of a time.Duration value that cuts the unnecessary precision off from the formatted textual representation.
func (PrettyDuration) String ¶
func (d PrettyDuration) String() string
String implements the Stringer interface, allowing pretty printing of duration values rounded to three decimals.
type StorageSize ¶
type StorageSize float64
StorageSize is a wrapper around a float value that supports user friendly formatting.
func (StorageSize) String ¶
func (s StorageSize) String() string
String implements the stringer interface.
func (StorageSize) TerminalString ¶
func (s StorageSize) TerminalString() string
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package bitutil implements fast bitwise operations.
|
Package bitutil implements fast bitwise operations. |
bn256
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
|
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve. |
bn256/cloudflare
Package bn256 implements a particular bilinear group at the 128-bit security level.
|
Package bn256 implements a particular bilinear group at the 128-bit security level. |
bn256/google
Package bn256 implements a particular bilinear group.
|
Package bn256 implements a particular bilinear group. |
secp256k1
Package secp256k1 wraps the bitcoin secp256k1 C library.
|
Package secp256k1 wraps the bitcoin secp256k1 C library. |
Package hexutil implements hex encoding with 0x prefix.
|
Package hexutil implements hex encoding with 0x prefix. |
Package mclock is a wrapper for a monotonic clock source
|
Package mclock is a wrapper for a monotonic clock source |