Documentation
¶
Index ¶
- Constants
- Variables
- func AddressPrefix(params *chaincfg.Params) string
- func AppendBchChecksum(prefix string, payload []byte) []byte
- func BchAddressFromBytes(addrBytes []byte, params *chaincfg.Params) (btcutil.Address, error)
- func CalculateBchBip143Sighash(subScript []byte, sigHashes *txscript.TxSigHashes, ...) []byte
- func CheckError(err error) xc.ClientError
- func DecodeBchAddress(addr string, params *chaincfg.Params) ([]byte, error)
- func DecodeBchString(address string) []byte
- func EncodePrefix(prefixString string) []byte
- func EncodeToBchString(data []byte) string
- func GetParams(cfg *xc.AssetConfig) (*chaincfg.Params, error)
- func NewAddressBuilder(asset xc.ITask) (xc.AddressBuilder, error)
- func NewBchAddressPubKey(pk []byte, params *chaincfg.Params) (*btcutil.AddressPubKeyHash, error)
- func NewSigner(asset xc.ITask) (xc.Signer, error)
- func NewTxBuilder(cfgI xc.ITask) (xc.TxBuilder, error)
- func PolyMod(v []byte) uint64
- func VerifyChecksum(prefix string, payload []byte) bool
- type AddressBuilder
- type BlockchairClient
- func (client *BlockchairClient) EstimateGas(ctx context.Context) (xc.AmountBlockchain, error)
- func (client *BlockchairClient) EstimateGasFee(ctx context.Context, numBlocks int64) (float64, error)
- func (client *BlockchairClient) FetchBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error)
- func (client *BlockchairClient) FetchNativeBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error)
- func (client *BlockchairClient) FetchTxInfo(ctx context.Context, txHash xc.TxHash) (xc.TxInfo, error)
- func (client *BlockchairClient) FetchTxInput(ctx context.Context, from xc.Address, to xc.Address) (xc.TxInput, error)
- func (client *BlockchairClient) LatestBlock(ctx context.Context) (uint64, error)
- func (client *BlockchairClient) RegisterEstimateGasCallback(estimateGas xc.EstimateGasFunc)
- func (client *BlockchairClient) SubmitTx(ctx context.Context, tx xc.Tx) error
- func (client *BlockchairClient) UnspentOutputs(ctx context.Context, minConf, maxConf int64, addr xc.Address) ([]Output, error)
- type BlockchairContext
- type ClientOptions
- type Input
- type NativeClient
- func (client *NativeClient) EstimateFeeLegacy(ctx context.Context, numBlocks int64) (float64, error)
- func (client *NativeClient) EstimateGas(ctx context.Context) (xc.AmountBlockchain, error)
- func (client *NativeClient) EstimateSmartFee(ctx context.Context, numBlocks int64) (float64, error)
- func (client *NativeClient) FetchBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error)
- func (client *NativeClient) FetchNativeBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error)
- func (client *NativeClient) FetchTxInfo(ctx context.Context, txHash xc.TxHash) (xc.TxInfo, error)
- func (client *NativeClient) FetchTxInput(ctx context.Context, from xc.Address, to xc.Address) (xc.TxInput, error)
- func (client *NativeClient) GetWalletInfo(ctx context.Context) (float64, error)
- func (client *NativeClient) ImportAddress(ctx context.Context, addr address.Address, label string, rescan bool) error
- func (client *NativeClient) LatestBlock(ctx context.Context) (uint64, error)
- func (client *NativeClient) Output(ctx context.Context, outpoint Outpoint) (Output, uint64, error)
- func (client *NativeClient) RegisterEstimateGasCallback(estimateGas xc.EstimateGasFunc)
- func (client *NativeClient) SubmitTx(ctx context.Context, txInput xc.Tx) error
- func (client *NativeClient) UnspentOutputs(ctx context.Context, minConf, maxConf int64, addr xc.Address) ([]Output, error)
- type Network
- type NetworkTriple
- type Outpoint
- type Output
- type Recipient
- type Signer
- type Tx
- func (tx *Tx) AddSignatures(signatures ...xc.TxSignature) error
- func (tx *Tx) DetectFrom() (string, xc.AmountBlockchain)
- func (tx *Tx) DetectToAndAmount(from string, expectedTo string) (string, xc.AmountBlockchain, xc.AmountBlockchain)
- func (tx *Tx) Hash() xc.TxHash
- func (tx *Tx) IsBch() bool
- func (tx *Tx) Outputs() ([]Output, error)
- func (tx *Tx) Serialize() ([]byte, error)
- func (tx *Tx) Sighashes() ([]xc.TxDataToSign, error)
- type TxBuilder
- func (txBuilder TxBuilder) NewNativeTransfer(from xc.Address, to xc.Address, amount xc.AmountBlockchain, input xc.TxInput) (xc.Tx, error)
- func (txBuilder TxBuilder) NewTokenTransfer(from xc.Address, to xc.Address, amount xc.AmountBlockchain, input xc.TxInput) (xc.Tx, error)
- func (txBuilder TxBuilder) NewTransfer(from xc.Address, to xc.Address, amount xc.AmountBlockchain, input xc.TxInput) (xc.Tx, error)
- type TxInput
Constants ¶
const SighashForkID = txscript.SigHashType(0x40)
const SighashMask = txscript.SigHashType(0x1F)
const TxVersion int32 = 2
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 ( // default timeout for client DefaultClientTimeout = time.Minute // default retry period for failed connections DefaultClientTimeoutRetry = 10 * time.Second // default host to connect to rpc node DefaultClientHost = "http://0.0.0.0:18443" // default user for rpc connection DefaultClientUser = "user" // default password for rpc connection DefaultClientPassword = "password" // default auth header for rpc connection DefaultClientAuthHeader = "" )
var NewClient = NewBlockchairClient
Functions ¶
func AddressPrefix ¶
The bch prefix is different for each network type
func AppendBchChecksum ¶
Add bch checksum to a payload https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md#checksum
func BchAddressFromBytes ¶
func CalculateBchBip143Sighash ¶
func CalculateBchBip143Sighash(subScript []byte, sigHashes *txscript.TxSigHashes, hashType txscript.SigHashType, tx *wire.MsgTx, idx int, amt int64) []byte
https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki
func CheckError ¶
func CheckError(err error) xc.ClientError
func DecodeBchAddress ¶
DecodeAddress implements the address.Decoder interface
func DecodeBchString ¶
DecodeString using Bitcoin Cash address encoding.
func EncodePrefix ¶
https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md#checksum
func EncodeToBchString ¶
White bch data as a bch encoded string
func NewAddressBuilder ¶
func NewAddressBuilder(asset xc.ITask) (xc.AddressBuilder, error)
NewAddressBuilder creates a new Bitcoin AddressBuilder
func NewBchAddressPubKey ¶
Create a new bch, btc compatible address pkh
func NewTxBuilder ¶
NewTxBuilder creates a new Bitcoin TxBuilder
func PolyMod ¶
PolyMod is the checksum alg for BCH https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md
func VerifyChecksum ¶
Verify if a bch payload is well formed
Types ¶
type AddressBuilder ¶
type AddressBuilder struct { UseLegacy bool UseScriptHash bool // contains filtered or unexported fields }
AddressBuilder for Bitcoin
func (AddressBuilder) GetAddressFromPublicKey ¶
func (ab AddressBuilder) GetAddressFromPublicKey(publicKeyBytes []byte) (xc.Address, error)
GetAddressFromPublicKey returns an Address given a public key
func (AddressBuilder) GetAllPossibleAddressesFromPublicKey ¶
func (ab AddressBuilder) GetAllPossibleAddressesFromPublicKey(publicKeyBytes []byte) ([]xc.PossibleAddress, error)
GetAllPossibleAddressesFromPublicKey returns all PossubleAddress(es) given a public key
type BlockchairClient ¶
type BlockchairClient struct { Asset *xc.AssetConfig EstimateGasFunc xc.EstimateGasFunc // contains filtered or unexported fields }
Client for Bitcoin
func NewBlockchairClient ¶
func NewBlockchairClient(cfgI xc.ITask) (*BlockchairClient, error)
NewClient returns a new Bitcoin Client
func (*BlockchairClient) EstimateGas ¶
func (client *BlockchairClient) EstimateGas(ctx context.Context) (xc.AmountBlockchain, error)
func (*BlockchairClient) EstimateGasFee ¶
func (*BlockchairClient) FetchBalance ¶
func (client *BlockchairClient) FetchBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error)
func (*BlockchairClient) FetchNativeBalance ¶
func (client *BlockchairClient) FetchNativeBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error)
func (*BlockchairClient) FetchTxInfo ¶
func (*BlockchairClient) FetchTxInput ¶
func (client *BlockchairClient) FetchTxInput(ctx context.Context, from xc.Address, to xc.Address) (xc.TxInput, error)
FetchTxInput returns tx input for a Bitcoin tx
func (*BlockchairClient) LatestBlock ¶
func (client *BlockchairClient) LatestBlock(ctx context.Context) (uint64, error)
func (*BlockchairClient) RegisterEstimateGasCallback ¶
func (client *BlockchairClient) RegisterEstimateGasCallback(estimateGas xc.EstimateGasFunc)
EstimateGas(ctx context.Context) (AmountBlockchain, error)
func (*BlockchairClient) UnspentOutputs ¶
type BlockchairContext ¶
type ClientOptions ¶
type ClientOptions struct { Timeout time.Duration TimeoutRetry time.Duration Host string User string Password string AuthHeader string AuthHeaderValue string Chaincfg *chaincfg.Params }
ClientOptions are used to parameterise the behaviour of the Client.
func DefaultClientOptions ¶
func DefaultClientOptions() ClientOptions
type NativeClient ¶
type NativeClient struct { Asset *xc.AssetConfig EstimateGasFunc xc.EstimateGasFunc // contains filtered or unexported fields }
Client for Bitcoin
func NewNativeClient ¶
func NewNativeClient(cfgI xc.ITask) (*NativeClient, error)
NewClient returns a new Bitcoin Client
func (*NativeClient) EstimateFeeLegacy ¶
func (client *NativeClient) EstimateFeeLegacy(ctx context.Context, numBlocks int64) (float64, error)
Older version of estimating fee for some forks of BTC (e.g. BCH).
func (*NativeClient) EstimateGas ¶
func (client *NativeClient) EstimateGas(ctx context.Context) (xc.AmountBlockchain, error)
func (*NativeClient) EstimateSmartFee ¶
Latest way to estimate fees on BTC
func (*NativeClient) FetchBalance ¶
func (client *NativeClient) FetchBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error)
func (*NativeClient) FetchNativeBalance ¶
func (client *NativeClient) FetchNativeBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error)
func (*NativeClient) FetchTxInfo ¶
FetchTxInfo returns tx info for a Bitcoin tx
func (*NativeClient) FetchTxInput ¶
func (client *NativeClient) FetchTxInput(ctx context.Context, from xc.Address, to xc.Address) (xc.TxInput, error)
FetchTxInput returns tx input for a Bitcoin tx
func (*NativeClient) GetWalletInfo ¶
func (client *NativeClient) GetWalletInfo(ctx context.Context) (float64, error)
func (*NativeClient) ImportAddress ¶
func (client *NativeClient) ImportAddress(ctx context.Context, addr address.Address, label string, rescan bool) error
Import an address into the RPC node to be tracked.
func (*NativeClient) LatestBlock ¶
func (client *NativeClient) LatestBlock(ctx context.Context) (uint64, error)
LatestBlock returns the height of the longest blockchain.
func (*NativeClient) RegisterEstimateGasCallback ¶
func (client *NativeClient) RegisterEstimateGasCallback(estimateGas xc.EstimateGasFunc)
EstimateGas(ctx context.Context) (AmountBlockchain, error)
func (*NativeClient) UnspentOutputs ¶
func (client *NativeClient) UnspentOutputs(ctx context.Context, minConf, maxConf int64, addr xc.Address) ([]Output, error)
UnspentOutputs spendable by the given address.
type Network ¶
type Network string
UTXO chains have mainnet, testnet, and regtest/devnet network types built in.
const Mainnet Network = "mainnet"
const Regtest Network = "regtest"
const Testnet Network = "testnet"
type NetworkTriple ¶
type NetworkTriple struct { Mainnet *chaincfg.Params Testnet *chaincfg.Params Regtest *chaincfg.Params }
var BtcNetworks *NetworkTriple = &NetworkTriple{ Mainnet: &chaincfg.MainNetParams, Testnet: &chaincfg.TestNet3Params, Regtest: &chaincfg.RegressionNetParams, }
var DogeNetworks *NetworkTriple = &NetworkTriple{ Mainnet: &chaincfg.Params{ Name: "mainnet", Net: 0xc0c0c0c0, PubKeyHashAddrID: 30, ScriptHashAddrID: 22, PrivateKeyID: 158, HDPrivateKeyID: [4]byte{0x02, 0xfa, 0xc3, 0x98}, HDPublicKeyID: [4]byte{0x02, 0xfa, 0xca, 0xfd}, Bech32HRPSegwit: "doge", }, Testnet: &chaincfg.Params{ Name: "testnet", Net: 0xfcc1b7dc, PubKeyHashAddrID: 113, ScriptHashAddrID: 196, PrivateKeyID: 241, HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, Bech32HRPSegwit: "doget", }, Regtest: &chaincfg.Params{ Name: "regtest", Net: 0xfabfb5da, PubKeyHashAddrID: 111, ScriptHashAddrID: 196, PrivateKeyID: 239, HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, Bech32HRPSegwit: "dogert", }, }
var LtcNetworks *NetworkTriple = &NetworkTriple{ Mainnet: &chaincfg.Params{ Name: "mainnet", Net: 0xfbc0b6db, PubKeyHashAddrID: 48, ScriptHashAddrID: 50, PrivateKeyID: 176, HDPrivateKeyID: [4]byte{0x04, 0x88, 0xAD, 0xE4}, HDPublicKeyID: [4]byte{0x04, 0x88, 0xB2, 0x1E}, Bech32HRPSegwit: "ltc", }, Testnet: &chaincfg.Params{ Name: "testnet", Net: 0xfdd2c8f1, PubKeyHashAddrID: 111, ScriptHashAddrID: 196, PrivateKeyID: 239, HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xCF}, Bech32HRPSegwit: "tltc", }, Regtest: &chaincfg.Params{ Name: "regtest", Net: 0xfabfb5da, PubKeyHashAddrID: 111, ScriptHashAddrID: 196, PrivateKeyID: 239, HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, Bech32HRPSegwit: "rltc", }, }
type Output ¶
type Output struct { Outpoint `json:"outpoint"` Value xc.AmountBlockchain `json:"value"` PubKeyScript []byte `json:"pubKeyScript"` }
type Recipient ¶
type Recipient struct { To xc.Address `json:"to"` Value xc.AmountBlockchain `json:"value"` }
type Signer ¶
type Signer struct { }
Signer for Bitcoin
func (*Signer) ImportPrivateKey ¶
func (signer *Signer) ImportPrivateKey(privateKey string) (xc.PrivateKey, error)
ImportPrivateKey imports a Bitcoin private key This private key should be either:
- a 32 byte hex string representing a k256 private key
- a WIF string representing a k256 private key
func (*Signer) Sign ¶
func (signer *Signer) Sign(privateKeyBytes xc.PrivateKey, data xc.TxDataToSign) (xc.TxSignature, error)
Sign a Bitcoin tx
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx for Bitcoin
func (*Tx) AddSignatures ¶
func (tx *Tx) AddSignatures(signatures ...xc.TxSignature) error
AddSignatures adds a signature to Tx
func (*Tx) DetectFrom ¶
func (tx *Tx) DetectFrom() (string, xc.AmountBlockchain)
Heuristic to determine the sender of a transaction by using the largest utxo input and taking it's spender.
func (*Tx) DetectToAndAmount ¶
func (tx *Tx) DetectToAndAmount(from string, expectedTo string) (string, xc.AmountBlockchain, xc.AmountBlockchain)
type TxBuilder ¶
type TxBuilder struct { Asset *xc.AssetConfig Params *chaincfg.Params // contains filtered or unexported fields }
TxBuilder for Bitcoin
func (TxBuilder) NewNativeTransfer ¶
func (txBuilder TxBuilder) NewNativeTransfer(from xc.Address, to xc.Address, amount xc.AmountBlockchain, input xc.TxInput) (xc.Tx, error)
NewNativeTransfer creates a new transfer for a native asset
type TxInput ¶
type TxInput struct { xc.TxInputEnvelope UnspentOutputs []Output `json:"unspent_outputs"` Inputs []Input `json:"input"` FromPublicKey []byte `json:"from_public_key"` GasPricePerByte xc.AmountBlockchain `json:"gas_price_per_byte"` }
TxInput for Bitcoin
func (*TxInput) GetGetPricePerByte ¶
func (txInput *TxInput) GetGetPricePerByte() xc.AmountBlockchain