Documentation
¶
Index ¶
- Constants
- Variables
- func AddressPrefix(params *chaincfg.Params) string
- func AppendChecksum(prefix string, payload []byte) []byte
- func CalculateBip143Sighash(subScript []byte, sigHashes *txscript.TxSigHashes, ...) []byte
- func DecodeString(address string) []byte
- func EncodeAddress(version byte, hash []byte, params *chaincfg.Params) (string, error)
- func EncodePrefix(prefixString string) []byte
- func EncodeToString(data []byte) string
- func NewTxBuilder() bitcoincompat.TxBuilder
- func PolyMod(v []byte) uint64
- type AddressPubKeyHash
- type Tx
Constants ¶
const Version int32 = 1
Version of Bitcoin Cash transactions supported by the multichain.
Variables ¶
var Alphabet = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
Alphabet used by Bitcoin Cash to encode addresses.
var AlphabetReverseLookup = func() map[rune]byte { lookup := map[rune]byte{} for i, char := range Alphabet { lookup[char] = byte(i) } return lookup }()
AlphabetReverseLookup used by Bitcoin Cash to decode addresses.
var SighashForkID = txscript.SigHashType(0x40)
SighashForkID used to distinguish between Bitcoin Cash and Bitcoin transactions by masking hash types.
var SighashMask = txscript.SigHashType(0x1F)
SighashMask used to mask hash types.
Functions ¶
func AddressPrefix ¶
AddressPrefix returns the string representations of an address prefix based on the network parameters: "bitcoincash" (for mainnet), "bchtest" (for testnet), and "bchreg" (for regtest). This function panics if the network parameters are not recognised.
func AppendChecksum ¶
AppendChecksum to the data payload.
https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md#checksum
func CalculateBip143Sighash ¶
func CalculateBip143Sighash(subScript []byte, sigHashes *txscript.TxSigHashes, hashType txscript.SigHashType, tx *wire.MsgTx, idx int, amt int64) []byte
CalculateBip143Sighash computes the sighash digest of a transaction's input using the new, optimized digest calculation algorithm defined in BIP0143. This function makes use of pre-calculated sighash fragments stored within the passed HashCache to eliminate duplicate hashing computations when calculating the final digest, reducing the complexity from O(N^2) to O(N). Additionally, signatures now cover the input value of the referenced unspent output. This allows offline, or hardware wallets to compute the exact amount being spent, in addition to the final transaction fee. In the case the wallet if fed an invalid input amount, the real sighash will differ causing the produced signature to be invalid.
https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki
func DecodeString ¶
DecodeString using Bitcoin Cash address encoding.
func EncodeAddress ¶
EncodeAddress using Bitcoin Cash address encoding, assuming that the hash data has no prefix or checksum.
func EncodePrefix ¶
EncodePrefix string into bytes.
https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md#checksum
func EncodeToString ¶
EncodeToString using Bitcoin Cash address encoding, assuming that the data has a prefix and checksum.
func NewTxBuilder ¶
func NewTxBuilder() bitcoincompat.TxBuilder
NewTxBuilder returns an implementation of the transaction builder interface from the Bitcoin Compat API, and exposes the functionality to build simple Bitcoin Cash transactions.
func PolyMod ¶
PolyMod is used to calculate the checksum for Bitcoin Cash addresses.
uint64_t PolyMod(const data &v) {
uint64_t c = 1;
for (uint8_t d : v) {
uint8_t c0 = c >> 35;
c = ((c & 0x07ffffffff) << 5) ^ d;
if (c0 & 0x01) c ^= 0x98f2bc8e61;
if (c0 & 0x02) c ^= 0x79b76d99e2;
if (c0 & 0x04) c ^= 0xf33e5fb3c4;
if (c0 & 0x08) c ^= 0xae2eabe2a8;
if (c0 & 0x10) c ^= 0x1e4f43e470;
}
return c ^ 1;
}
https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md
Types ¶
type AddressPubKeyHash ¶
type AddressPubKeyHash struct {
*btcutil.AddressPubKeyHash
// contains filtered or unexported fields
}
AddressPubKeyHash represents an address for P2PKH transactions for Bitcoin Cash that is compatible with the Bitcoin-compat API.
func NewAddressPubKey ¶
func NewAddressPubKey(pk []byte, params *chaincfg.Params) (AddressPubKeyHash, error)
NewAddressPubKey returns a new AddressPubKey that is compatible with the Bitcoin-compat API.
func NewAddressPubKeyHash ¶
func NewAddressPubKeyHash(pkh []byte, params *chaincfg.Params) (AddressPubKeyHash, error)
NewAddressPubKeyHash returns a new AddressPubKeyHash that is compatible with the Bitcoin-compat API.
func (AddressPubKeyHash) EncodeAddress ¶
func (addr AddressPubKeyHash) EncodeAddress() 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.
func (AddressPubKeyHash) IsForNet ¶
func (addr AddressPubKeyHash) IsForNet(params *chaincfg.Params) bool
IsForNet returns whether or not the address is associated with the passed bitcoin network.
func (AddressPubKeyHash) ScriptAddress ¶
func (addr AddressPubKeyHash) ScriptAddress() []byte
ScriptAddress returns the raw bytes of the address to be used when inserting the address into a txout's script.
func (AddressPubKeyHash) String ¶
func (addr AddressPubKeyHash) String() string
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.