bitcoincash

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2020 License: GPL-3.0 Imports: 14 Imported by: 4

Documentation

Index

Constants

View Source
const Version int32 = 1

Version of Bitcoin Cash transactions supported by the multichain.

Variables

View Source
var Alphabet = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"

Alphabet used by Bitcoin Cash to encode addresses.

View Source
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.

View Source
var SighashForkID = txscript.SigHashType(0x40)

SighashForkID used to distinguish between Bitcoin Cash and Bitcoin transactions by masking hash types.

View Source
var SighashMask = txscript.SigHashType(0x1F)

SighashMask used to mask hash types.

Functions

func AddressPrefix

func AddressPrefix(params *chaincfg.Params) string

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

func AppendChecksum(prefix string, payload []byte) []byte

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

func DecodeString(address string) []byte

DecodeString using Bitcoin Cash address encoding.

func EncodeAddress

func EncodeAddress(version byte, hash []byte, params *chaincfg.Params) (string, error)

EncodeAddress using Bitcoin Cash address encoding, assuming that the hash data has no prefix or checksum.

func EncodePrefix

func EncodePrefix(prefixString string) []byte

EncodePrefix string into bytes.

https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md#checksum

func EncodeToString

func EncodeToString(data []byte) string

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

func PolyMod(v []byte) uint64

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.

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

Tx represents a simple Bitcoin Cash transaction that implements the Bitcoin Compat API.

func (*Tx) Hash

func (tx *Tx) Hash() pack.Bytes32

func (*Tx) Serialize

func (tx *Tx) Serialize() (pack.Bytes, error)

func (*Tx) Sighashes

func (tx *Tx) Sighashes() ([]pack.Bytes32, error)

func (*Tx) Sign

func (tx *Tx) Sign(signatures []pack.Bytes65, pubKey pack.Bytes) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL