Documentation ¶
Index ¶
- Constants
- Variables
- func AreEqual(first []SubnetworkID, second []SubnetworkID) bool
- func Decode(dst *SubnetworkID, src string) error
- func Less(a *SubnetworkID, b *SubnetworkID) bool
- func Sort(ids []SubnetworkID)
- func Strings(ids []SubnetworkID) []string
- func ToBig(id *SubnetworkID) *big.Int
- type SubnetworkID
Constants ¶
const IDLength = 20
IDLength of array used to store the subnetwork ID. See SubnetworkID.
const MaxStringSize = IDLength * 2
MaxStringSize is the maximum length of a SubnetworkID string.
Variables ¶
var ( // SubnetworkIDNative is the default subnetwork ID which is used for transactions without related payload data SubnetworkIDNative = &SubnetworkID{} // SubnetworkIDCoinbase is the subnetwork ID which is used for the coinbase transaction SubnetworkIDCoinbase = &SubnetworkID{1} // SubnetworkIDRegistry is the subnetwork ID which is used for adding new sub networks to the registry SubnetworkIDRegistry = &SubnetworkID{2} )
var ErrIDStrSize = fmt.Errorf("max ID string length is %d bytes", MaxStringSize)
ErrIDStrSize describes an error that indicates the caller specified an ID string that has too many characters.
Functions ¶
func AreEqual ¶
func AreEqual(first []SubnetworkID, second []SubnetworkID) bool
AreEqual returns true if both slices contain the same IDs. Either slice must not contain duplicates.
func Decode ¶
func Decode(dst *SubnetworkID, src string) error
Decode decodes the byte-reversed hexadecimal string encoding of a SubnetworkID to a destination.
func Less ¶
func Less(a *SubnetworkID, b *SubnetworkID) bool
Less returns true iff id a is less than id b
func Strings ¶
func Strings(ids []SubnetworkID) []string
Strings returns a slice of strings representing the IDs in the given slice of IDs
func ToBig ¶
func ToBig(id *SubnetworkID) *big.Int
ToBig converts a SubnetworkID into a big.Int that can be used to perform math comparisons.
Types ¶
type SubnetworkID ¶
SubnetworkID is used in several of the bitcoin messages and common structures. It typically represents ripmed160(sha256(data)).
func New ¶
func New(newID []byte) (*SubnetworkID, error)
New returns a new ID from a byte slice. An error is returned if the number of bytes passed in is not IDLength.
func NewFromStr ¶
func NewFromStr(id string) (*SubnetworkID, error)
NewFromStr creates a SubnetworkID from a string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the SubnetworkID.
func (*SubnetworkID) CloneBytes ¶
func (id *SubnetworkID) CloneBytes() []byte
CloneBytes returns a copy of the bytes which represent the ID as a byte slice.
NOTE: It is generally cheaper to just slice the ID directly thereby reusing the same bytes rather than calling this method.
func (*SubnetworkID) Cmp ¶
func (id *SubnetworkID) Cmp(target *SubnetworkID) int
Cmp compares id and target and returns:
-1 if id < target 0 if id == target +1 if id > target
func (*SubnetworkID) IsBuiltIn ¶
func (id *SubnetworkID) IsBuiltIn() bool
IsBuiltIn returns true if the subnetwork is a built in subnetwork, which means all nodes, including partial nodes, must validate it, and its transactions always use 0 gas.
func (*SubnetworkID) IsEqual ¶
func (id *SubnetworkID) IsEqual(target *SubnetworkID) bool
IsEqual returns true if target is the same as ID.
func (*SubnetworkID) SetBytes ¶
func (id *SubnetworkID) SetBytes(newID []byte) error
SetBytes sets the bytes which represent the ID. An error is returned if the number of bytes passed in is not IDLength.
func (SubnetworkID) String ¶
func (id SubnetworkID) String() string
String returns the SubnetworkID as the hexadecimal string of the byte-reversed hash.