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(params *chaincfg.Params) utxo.TxBuilder
- func PolyMod(v []byte) uint64
- func VerifyChecksum(prefix string, payload []byte) bool
- type Address
- type AddressLegacy
- type AddressPubKeyHash
- type AddressScriptHash
- type Client
- type ClientOptions
- type GasEstimator
- type Tx
- type TxBuilder
Constants ¶
const SighashForkID = txscript.SigHashType(0x40)
SighashForkID used to distinguish between Bitcoin Cash and Bitcoin transactions by masking hash types.
const SighashMask = txscript.SigHashType(0x1F)
SighashMask used to mask hash types.
const Version int32 = 1
Version of Bitcoin Cash transactions supported by the multichain.
Variables ¶
var ( // Alphabet used by Bitcoin Cash to encode addresses. Alphabet = "qpzry9x8gf2tvdw0s3jn54khce6mua7l" // AlphabetReverseLookup used by Bitcoin Cash to decode addresses. AlphabetReverseLookup = func() map[rune]byte { lookup := map[rune]byte{} for i, char := range Alphabet { lookup[char] = byte(i) } return lookup }() )
var NewClient = bitcoin.NewClient
var NewGasEstimator = bitcoin.NewGasEstimator
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 ¶
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
func VerifyChecksum ¶ added in v0.2.0
VerifyChecksum verifies whether the given payload is well-formed.
https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md#checksum
Types ¶
type AddressLegacy ¶ added in v0.2.0
AddressLegacy represents a legacy Bitcoin address.
func (AddressLegacy) BitcoinAddress ¶ added in v0.2.0
func (addr AddressLegacy) BitcoinAddress() btcutil.Address
BitcoinAddress returns the address as if it was a Bitcoin address.
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) BitcoinAddress ¶ added in v0.2.0
func (addr AddressPubKeyHash) BitcoinAddress() btcutil.Address
BitcoinAddress returns the address as if it was a Bitcoin address.
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.
type AddressScriptHash ¶ added in v0.2.0
type AddressScriptHash struct { *btcutil.AddressScriptHash // contains filtered or unexported fields }
AddressScriptHash represents an address for P2SH transactions for Bitcoin Cash that is compatible with the Bitcoin-compat API.
func NewAddressScriptHash ¶ added in v0.2.0
func NewAddressScriptHash(script []byte, params *chaincfg.Params) (AddressScriptHash, error)
NewAddressScriptHash returns a new AddressScriptHash that is compatible with the Bitcoin-compat API.
func NewAddressScriptHashFromHash ¶ added in v0.2.0
func NewAddressScriptHashFromHash(scriptHash []byte, params *chaincfg.Params) (AddressScriptHash, error)
NewAddressScriptHashFromHash returns a new AddressScriptHash that is compatible with the Bitcoin-compat API.
func (AddressScriptHash) BitcoinAddress ¶ added in v0.2.0
func (addr AddressScriptHash) BitcoinAddress() btcutil.Address
BitcoinAddress returns the address as if it was a Bitcoin address.
func (AddressScriptHash) EncodeAddress ¶ added in v0.2.0
func (addr AddressScriptHash) 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 (AddressScriptHash) IsForNet ¶ added in v0.2.0
func (addr AddressScriptHash) IsForNet(params *chaincfg.Params) bool
IsForNet returns whether or not the address is associated with the passed bitcoin network.
func (AddressScriptHash) ScriptAddress ¶ added in v0.2.0
func (addr AddressScriptHash) ScriptAddress() []byte
ScriptAddress returns the raw bytes of the address to be used when inserting the address into a txout's script.
func (AddressScriptHash) String ¶ added in v0.2.0
func (addr AddressScriptHash) 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.
type ClientOptions ¶ added in v0.2.0
type ClientOptions = bitcoin.ClientOptions
func DefaultClientOptions ¶ added in v0.2.0
func DefaultClientOptions() ClientOptions
type GasEstimator ¶ added in v0.2.0
type GasEstimator = bitcoin.GasEstimator
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx represents a simple Bitcoin Cash transaction that implements the Bitcoin Compat API.
type TxBuilder ¶ added in v0.2.0
type TxBuilder struct {
// contains filtered or unexported fields
}
func (TxBuilder) BuildTx ¶ added in v0.2.0
func (txBuilder TxBuilder) BuildTx(inputs []utxo.Input, recipients []utxo.Recipient) (utxo.Tx, error)
BuildTx returns a simple Bitcoin Cash transaction that consumes the funds from the given outputs, and sends the to the given recipients. The difference in the sum value of the inputs and the sum value of the recipients is paid as a fee to the Bitcoin Cash network.
It is assumed that the required signature scripts require the SIGHASH_ALL signatures and the serialized public key:
builder := txscript.NewScriptBuilder() builder.AddData(append(signature.Serialize(), byte(txscript.SigHashAll|SighashForkID))) builder.AddData(serializedPubKey)
Outputs produced for recipients will use P2PKH, or P2SH scripts as the pubkey script, based on the format of the recipient address.