Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertCashToSlpAddress(addr Address, params *chaincfg.Params) (bchutil.Address, error)
- func ConvertSlpToCashAddress(addr Address, params *chaincfg.Params) (bchutil.Address, error)
- func DecodeCashAddress(str string) (string, []byte, error)
- func GetSlpTokenID(tx *wire.MsgTx) ([]byte, error)
- func GetSlpVersionType(slpPkScript []byte) (*uint8, error)
- type Address
- type AddressPubKey
- func (a *AddressPubKey) AddressPubKeyHash() *AddressPubKeyHash
- func (a *AddressPubKey) EncodeAddress() string
- func (a *AddressPubKey) Format() PubKeyFormat
- func (a *AddressPubKey) IsForNet(net *chaincfg.Params) bool
- func (a *AddressPubKey) PubKey() *bchec.PublicKey
- func (a *AddressPubKey) ScriptAddress() []byte
- func (a *AddressPubKey) SetFormat(pkFormat PubKeyFormat)
- func (a *AddressPubKey) String() string
- type AddressPubKeyHash
- type AddressScriptHash
- type AddressType
- type LegacyAddressPubKeyHash
- type LegacyAddressScriptHash
- type PubKeyFormat
Constants ¶
const Charset string = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
Charset is the base32 character set for the cashaddr.
Variables ¶
var ( // ErrChecksumMismatch describes an error where decoding failed due // to a bad checksum. ErrChecksumMismatch = errors.New("checksum mismatch") // ErrUnknownAddressType describes an error where an address can not // decoded as a specific address type due to the string encoding // begining with an identifier byte unknown to any standard or // registered (via chaincfg.Register) network. ErrUnknownAddressType = errors.New("unknown address type") // ErrAddressCollision describes an error where an address can not // be uniquely determined as either a pay-to-pubkey-hash or // pay-to-script-hash address since the leading identifier is used for // describing both address kinds, but for different networks. Rather // than assuming or defaulting to one or the other, this error is // returned and the caller must decide how to decode the address. ErrAddressCollision = errors.New("address collision") // ErrInvalidFormat describes an error where decoding failed due to invalid version ErrInvalidFormat = errors.New("invalid format: version and/or checksum bytes missing") )
var CharsetRev = [128]int8{}/* 128 elements not displayed */
CharsetRev is the cashaddr character set for decoding.
Functions ¶
func ConvertCashToSlpAddress ¶
ConvertCashToSlpAddress converts a cash formatted address to slp formatted address
func ConvertSlpToCashAddress ¶
ConvertSlpToCashAddress converts an slp formatted address to cash formatted address
func DecodeCashAddress ¶
DecodeCashAddress decodes a cashaddr string and returns the prefix and data element.
func GetSlpTokenID ¶
GetSlpTokenID returns the Token ID regardless of SLP version/type
func GetSlpVersionType ¶
GetSlpVersionType returns the SLP version number regardless of version/type
Types ¶
type Address ¶
type Address interface { // String returns the string encoding of the transaction output // destination. // // Please note that String differs subtly from EncodeAddress: String // will return the value as a string without any conversion, while // EncodeAddress may convert destination types (for example, // converting pubkeys to P2PKH addresses) before encoding as a // payment address string. String() string // EncodeAddress returns the string encoding of the payment address // associated with the Address value. See the comment on String // for how this method differs from String. EncodeAddress() string // ScriptAddress returns the raw bytes of the address to be used // when inserting the address into a txout's script. ScriptAddress() []byte // IsForNet returns whether or not the address is associated with the // passed bitcoin network. IsForNet(*chaincfg.Params) bool }
Address is an interface type for any type of destination a transaction output may spend to. This includes pay-to-pubkey (P2PK), pay-to-pubkey-hash (P2PKH), and pay-to-script-hash (P2SH). Address is designed to be generic enough that other kinds of addresses may be added in the future without changing the decoding and encoding API.
func DecodeAddress ¶
func DecodeAddress(addr string, defaultNet *chaincfg.Params, returnBchutilType bool) (Address, error)
DecodeAddress decodes the string encoding of an address and returns the Address if addr is a valid encoding for a known address type.
The result Address type is either bchutil or goslp depending on the value of the forceBchutilType parameter.
The bitcoin network the address is associated with is extracted if possible. When the address does not encode the network, such as in the case of a raw public key, the address will be associated with the passed defaultNet.
type AddressPubKey ¶
type AddressPubKey struct {
// contains filtered or unexported fields
}
AddressPubKey is an Address for a pay-to-pubkey transaction.
func NewAddressPubKey ¶
func NewAddressPubKey(serializedPubKey []byte, net *chaincfg.Params) (*AddressPubKey, error)
NewAddressPubKey returns a new AddressPubKey which represents a pay-to-pubkey address. The serializedPubKey parameter must be a valid pubkey and can be uncompressed, compressed, or hybrid.
func (*AddressPubKey) AddressPubKeyHash ¶
func (a *AddressPubKey) AddressPubKeyHash() *AddressPubKeyHash
AddressPubKeyHash returns the pay-to-pubkey address converted to a pay-to-pubkey-hash address. Note that the public key format (uncompressed, compressed, etc) will change the resulting address. This is expected since pay-to-pubkey-hash is a hash of the serialized public key which obviously differs with the format. At the time of this writing, most Bitcoin addresses are pay-to-pubkey-hash constructed from the uncompressed public key.
func (*AddressPubKey) EncodeAddress ¶
func (a *AddressPubKey) EncodeAddress() string
EncodeAddress returns the string encoding of the public key as a pay-to-pubkey-hash. Note that the public key format (uncompressed, compressed, etc) will change the resulting address. This is expected since pay-to-pubkey-hash is a hash of the serialized public key which obviously differs with the format. At the time of this writing, most Bitcoin addresses are pay-to-pubkey-hash constructed from the uncompressed public key.
Part of the Address interface.
func (*AddressPubKey) Format ¶
func (a *AddressPubKey) Format() PubKeyFormat
Format returns the format (uncompressed, compressed, etc) of the pay-to-pubkey address.
func (*AddressPubKey) IsForNet ¶
func (a *AddressPubKey) IsForNet(net *chaincfg.Params) bool
IsForNet returns whether or not the pay-to-pubkey address is associated with the passed bitcoin network.
func (*AddressPubKey) PubKey ¶
func (a *AddressPubKey) PubKey() *bchec.PublicKey
PubKey returns the underlying public key for the address.
func (*AddressPubKey) ScriptAddress ¶
func (a *AddressPubKey) ScriptAddress() []byte
ScriptAddress returns the bytes to be included in a txout script to pay to a public key. Setting the public key format will affect the output of this function accordingly. Part of the Address interface.
func (*AddressPubKey) SetFormat ¶
func (a *AddressPubKey) SetFormat(pkFormat PubKeyFormat)
SetFormat sets the format (uncompressed, compressed, etc) of the pay-to-pubkey address.
func (*AddressPubKey) String ¶
func (a *AddressPubKey) String() string
String returns the hex-encoded human-readable string for the pay-to-pubkey address. This is not the same as calling EncodeAddress.
type AddressPubKeyHash ¶
type AddressPubKeyHash struct {
// contains filtered or unexported fields
}
AddressPubKeyHash is an Address for a pay-to-pubkey-hash (P2PKH) transaction.
func NewAddressPubKeyHash ¶
func NewAddressPubKeyHash(pkHash []byte, net *chaincfg.Params) (*AddressPubKeyHash, error)
NewAddressPubKeyHash returns a new AddressPubKeyHash. pkHash mustbe 20 bytes.
func (*AddressPubKeyHash) EncodeAddress ¶
func (a *AddressPubKeyHash) EncodeAddress() string
EncodeAddress returns the string encoding of a pay-to-pubkey-hash address. Part of the Address interface.
func (*AddressPubKeyHash) Hash160 ¶
func (a *AddressPubKeyHash) Hash160() *[ripemd160.Size]byte
Hash160 returns the underlying array of the pubkey hash. This can be useful when an array is more appropiate than a slice (for example, when used as map keys).
func (*AddressPubKeyHash) IsForNet ¶
func (a *AddressPubKeyHash) IsForNet(net *chaincfg.Params) bool
IsForNet returns whether or not the pay-to-pubkey-hash address is associated with the passed bitcoin cash network.
func (*AddressPubKeyHash) ScriptAddress ¶
func (a *AddressPubKeyHash) ScriptAddress() []byte
ScriptAddress returns the bytes to be included in a txout script to pay to a pubkey hash. Part of the Address interface.
func (*AddressPubKeyHash) String ¶
func (a *AddressPubKeyHash) String() string
String returns a human-readable string for the pay-to-pubkey-hash address. This is equivalent to calling EncodeAddress, but is provided so the type can be used as a fmt.Stringer.
type AddressScriptHash ¶
type AddressScriptHash struct {
// contains filtered or unexported fields
}
AddressScriptHash is an Address for a pay-to-script-hash (P2SH) transaction.
func NewAddressScriptHash ¶
func NewAddressScriptHash(serializedScript []byte, net *chaincfg.Params) (*AddressScriptHash, error)
NewAddressScriptHash returns a new AddressScriptHash.
func NewAddressScriptHashFromHash ¶
func NewAddressScriptHashFromHash(scriptHash []byte, net *chaincfg.Params) (*AddressScriptHash, error)
NewAddressScriptHashFromHash returns a new AddressScriptHash. scriptHash must be 20 bytes.
func (*AddressScriptHash) EncodeAddress ¶
func (a *AddressScriptHash) EncodeAddress() string
EncodeAddress returns the string encoding of a pay-to-script-hash address. Part of the Address interface.
func (*AddressScriptHash) Hash160 ¶
func (a *AddressScriptHash) Hash160() *[ripemd160.Size]byte
Hash160 returns the underlying array of the script hash. This can be useful when an array is more appropiate than a slice (for example, when used as map keys).
func (*AddressScriptHash) IsForNet ¶
func (a *AddressScriptHash) IsForNet(net *chaincfg.Params) bool
IsForNet returns whether or not the pay-to-script-hash address is associated with the passed bitcoin cash network.
func (*AddressScriptHash) ScriptAddress ¶
func (a *AddressScriptHash) ScriptAddress() []byte
ScriptAddress returns the bytes to be included in a txout script to pay to a script hash. Part of the Address interface.
func (*AddressScriptHash) String ¶
func (a *AddressScriptHash) String() string
String returns a human-readable string for the pay-to-script-hash address. This is equivalent to calling EncodeAddress, but is provided so the type can be used as a fmt.Stringer.
type AddressType ¶
type AddressType int
AddressType represents the type of address and is used when encoding the cashaddr.
const ( // AddrTypePayToPubKeyHash is the numeric identifier for // a cashaddr PayToPubkeyHash address AddrTypePayToPubKeyHash AddressType = 0 // AddrTypePayToScriptHash is the numeric identifier for // a cashaddr PayToPubkeyHash address AddrTypePayToScriptHash AddressType = 1 )
type LegacyAddressPubKeyHash ¶
type LegacyAddressPubKeyHash struct {
// contains filtered or unexported fields
}
LegacyAddressPubKeyHash is an Address for a pay-to-pubkey-hash (P2PKH) transaction in the legacy format.
func NewLegacyAddressPubKeyHash ¶
func NewLegacyAddressPubKeyHash(pkHash []byte, net *chaincfg.Params) (*LegacyAddressPubKeyHash, error)
NewLegacyAddressPubKeyHash returns a new AddressPubKeyHash in the legacy format. pkHash mustbe 20 bytes.
func (*LegacyAddressPubKeyHash) EncodeAddress ¶
func (a *LegacyAddressPubKeyHash) EncodeAddress() string
EncodeAddress returns the string encoding of a pay-to-pubkey-hash address. Part of the Address interface.
func (*LegacyAddressPubKeyHash) Hash160 ¶
func (a *LegacyAddressPubKeyHash) Hash160() *[ripemd160.Size]byte
Hash160 returns the underlying array of the pubkey hash. This can be useful when an array is more appropiate than a slice (for example, when used as map keys).
func (*LegacyAddressPubKeyHash) IsForNet ¶
func (a *LegacyAddressPubKeyHash) IsForNet(net *chaincfg.Params) bool
IsForNet returns whether or not the pay-to-pubkey-hash address is associated with the passed bitcoin network.
func (*LegacyAddressPubKeyHash) ScriptAddress ¶
func (a *LegacyAddressPubKeyHash) ScriptAddress() []byte
ScriptAddress returns the bytes to be included in a txout script to pay to a pubkey hash. Part of the Address interface.
func (*LegacyAddressPubKeyHash) String ¶
func (a *LegacyAddressPubKeyHash) String() string
String returns a human-readable string for the pay-to-pubkey-hash address. This is equivalent to calling EncodeAddress, but is provided so the type can be used as a fmt.Stringer.
type LegacyAddressScriptHash ¶
type LegacyAddressScriptHash struct {
// contains filtered or unexported fields
}
LegacyAddressScriptHash is an Address for a pay-to-script-hash (P2SH) transaction in legacy format.
func NewLegacyAddressScriptHash ¶
func NewLegacyAddressScriptHash(serializedScript []byte, net *chaincfg.Params) (*LegacyAddressScriptHash, error)
NewLegacyAddressScriptHash returns a new LegacyAddressScriptHash.
func NewLegacyAddressScriptHashFromHash ¶
func NewLegacyAddressScriptHashFromHash(scriptHash []byte, net *chaincfg.Params) (*LegacyAddressScriptHash, error)
NewLegacyAddressScriptHashFromHash returns a new AddressScriptHash. scriptHash must be 20 bytes.
func (*LegacyAddressScriptHash) EncodeAddress ¶
func (a *LegacyAddressScriptHash) EncodeAddress() string
EncodeAddress returns the string encoding of a pay-to-script-hash address. Part of the Address interface.
func (*LegacyAddressScriptHash) Hash160 ¶
func (a *LegacyAddressScriptHash) Hash160() *[ripemd160.Size]byte
Hash160 returns the underlying array of the script hash. This can be useful when an array is more appropiate than a slice (for example, when used as map keys).
func (*LegacyAddressScriptHash) IsForNet ¶
func (a *LegacyAddressScriptHash) IsForNet(net *chaincfg.Params) bool
IsForNet returns whether or not the pay-to-script-hash address is associated with the passed bitcoin network.
func (*LegacyAddressScriptHash) ScriptAddress ¶
func (a *LegacyAddressScriptHash) ScriptAddress() []byte
ScriptAddress returns the bytes to be included in a txout script to pay to a script hash. Part of the Address interface.
func (*LegacyAddressScriptHash) String ¶
func (a *LegacyAddressScriptHash) String() string
String returns a human-readable string for the pay-to-script-hash address. This is equivalent to calling EncodeAddress, but is provided so the type can be used as a fmt.Stringer.
type PubKeyFormat ¶
type PubKeyFormat int
PubKeyFormat describes what format to use for a pay-to-pubkey address.
const ( // PKFUncompressed indicates the pay-to-pubkey address format is an // uncompressed public key. PKFUncompressed PubKeyFormat = iota // PKFCompressed indicates the pay-to-pubkey address format is a // compressed public key. PKFCompressed // PKFHybrid indicates the pay-to-pubkey address format is a hybrid // public key. PKFHybrid )