bitcoincash

package
v0.0.0-...-d8542d3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RedeemP2PKHSigScriptSize is the worst case (largest) serialize size
	// of a transaction input script that redeems a compressed P2PKH output.
	// It is calculated as:
	//
	//   - OP_DATA_73
	//   - 72 bytes DER signature + 1 byte sighash
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	RedeemP2PKHSigScriptSize = 1 + 73 + 1 + 33

	// RedeemP2SHMultisigSigScriptSize is the worst case (largest) serialize size
	// of a transaction input script that redeems a 2 of 3 P2SH multisig output with compressed keys.
	// It is calculated as:
	//
	//   - OP_0
	//   - OP_DATA_72
	//   - 72 bytes DER signature
	//   - OP_DATA_72
	//   - 72 bytes DER signature
	//   - OP_PUSHDATA
	//   - OP_2
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP3
	//   - OP_CHECKMULTISIG
	RedeemP2SH2of3MultisigSigScriptSize = 1 + 1 + 72 + 1 + 72 + 1 + 1 + 1 + 33 + 1 + 33 + 1 + 33 + 1 + 1

	// RedeemP2SH1of2MultisigSigScriptSize is the worst case (largest) serialize size
	// of a transaction input script that redeems a 1 of 2 P2SH multisig output with compressed keys.
	// It is calculated as:
	//
	//   - OP_0
	//   - OP_DATA_72
	//   - 72 bytes DER signature
	//   - OP_PUSHDATA
	//   - OP_1
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP2
	//   - OP_CHECKMULTISIG
	RedeemP2SH1of2MultisigSigScriptSize = 1 + 1 + 72 + 1 + 1 + 1 + 33 + 1 + 33 + 1 + 1

	// RedeemP2SHMultisigTimelock1SigScriptSize is the worst case (largest) serialize size
	// of a transaction input script that redeems a compressed P2SH timelocked multisig using the timeout.
	// It is calculated as:
	//
	//   - OP_DATA_72
	//   - 72 bytes DER signature
	//   - OP_0
	//   - OP_PUSHDATA
	//   - OP_IF
	//   - OP_2
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP3
	//   - OP_CHECKMULTISIG
	//   - OP_ELSE
	//   - OP_PUSHDATA
	//   - 2 byte block height
	//   - OP_CHECKSEQUENCEVERIFY
	//   - OP_DROP
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_CHECKSIG
	//   - OP_ENDIF
	RedeemP2SHMultisigTimelock1SigScriptSize = 1 + 72 + 1 + 1 + 1 + 1 + 1 + 33 + 1 + 33 + 1 + 33 + 1 + 1 + 1 + 1 + 2 + 1 + 1 + 1 + 33 + 1 + 1

	// RedeemP2SHMultisigTimelock2SigScriptSize is the worst case (largest) serialize size
	// of a transaction input script that redeems a compressed P2SH timelocked multisig without using the timeout.
	// It is calculated as:
	//
	//   - OP_0
	//   - OP_DATA_72
	//   - 72 bytes DER signature
	//   - OP_DATA_72
	//   - 72 bytes DER signature
	//   - OP_1
	//   - OP_PUSHDATA
	//   - OP_IF
	//   - OP_2
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP3
	//   - OP_CHECKMULTISIG
	//   - OP_ELSE
	//   - OP_PUSHDATA
	//   - 2 byte block height
	//   - OP_CHECKSEQUENCEVERIFY
	//   - OP_DROP
	//   - OP_DATA_33
	//   - 33 bytes serialized compressed pubkey
	//   - OP_CHECKSIG
	//   - OP_ENDIF
	RedeemP2SHMultisigTimelock2SigScriptSize = 1 + 1 + 72 + +1 + 72 + 1 + 1 + 1 + 1 + 1 + 33 + 1 + 33 + 1 + 33 + 1 + 1 + 1 + 1 + 2 + 1 + 1 + 1 + 33 + 1 + 1

	// P2PKHPkScriptSize is the size of a transaction output script that
	// pays to a compressed pubkey hash.  It is calculated as:
	//
	//   - OP_DUP
	//   - OP_HASH160
	//   - OP_DATA_20
	//   - 20 bytes pubkey hash
	//   - OP_EQUALVERIFY
	//   - OP_CHECKSIG
	P2PKHPkScriptSize = 1 + 1 + 1 + 20 + 1 + 1

	// RedeemP2PKHInputSize is the worst case (largest) serialize size of a
	// transaction input redeeming a compressed P2PKH output.  It is
	// calculated as:
	//
	//   - 32 bytes previous tx
	//   - 4 bytes output index
	//   - 1 byte script len
	//   - signature script
	//   - 4 bytes sequence
	RedeemP2PKHInputSize = 32 + 4 + 1 + RedeemP2PKHSigScriptSize + 4

	// RedeemP2SH2of3MultisigInputSize is the worst case (largest) serialize size of a
	// transaction input redeeming a compressed P2SH 2 of 3 multisig output.  It is
	// calculated as:
	//
	//   - 32 bytes previous tx
	//   - 4 bytes output index
	//   - 1 byte script len
	//   - 4 bytes sequence
	///  - witness discounted signature script
	RedeemP2SH2of3MultisigInputSize = 32 + 4 + 1 + 4 + (RedeemP2SH2of3MultisigSigScriptSize / 4)

	// RedeemP2SH1of2MultisigInputSize is the worst case (largest) serialize size of a
	// transaction input redeeming a compressed P2SH 2 of 3 multisig output.  It is
	// calculated as:
	//
	//   - 32 bytes previous tx
	//   - 4 bytes output index
	//   - 1 byte script len
	//   - 4 bytes sequence
	///  - witness discounted signature script
	RedeemP2SH1of2MultisigInputSize = 32 + 4 + 1 + 4 + (RedeemP2SH1of2MultisigSigScriptSize / 4)

	// RedeemP2SHMultisigTimelock1InputSize is the worst case (largest) serialize size of a
	// transaction input redeeming a compressed p2sh timelocked multig output with using the timeout.  It is
	// calculated as:
	//
	//   - 32 bytes previous tx
	//   - 4 bytes output index
	//   - 1 byte script len
	//   - 4 bytes sequence
	///  - witness discounted signature script
	RedeemP2SHMultisigTimelock1InputSize = 32 + 4 + 1 + 4 + (RedeemP2SHMultisigTimelock1SigScriptSize / 4)

	// RedeemP2SHMultisigTimelock2InputSize is the worst case (largest) serialize size of a
	// transaction input redeeming a compressed P2SH timelocked multisig output without using the timeout.  It is
	// calculated as:
	//
	//   - 32 bytes previous tx
	//   - 4 bytes output index
	//   - 1 byte script len
	//   - 4 bytes sequence
	///  - witness discounted signature script
	RedeemP2SHMultisigTimelock2InputSize = 32 + 4 + 1 + 4 + (RedeemP2SHMultisigTimelock2SigScriptSize / 4)

	// P2PKHOutputSize is the serialize size of a transaction output with a
	// P2PKH output script.  It is calculated as:
	//
	//   - 8 bytes output value
	//   - 1 byte compact int encoding value 25
	//   - 25 bytes P2PKH output script
	P2PKHOutputSize = 8 + 1 + P2PKHPkScriptSize
)

Worst case script and input/output size estimates.

Variables

View Source
var (
	BitcoinCashCurrencyDefinition = wi.CurrencyDefinition{
		Code:         "BCH",
		Divisibility: 8,
	}
)

Functions

func EstimateSerializeSize

func EstimateSerializeSize(inputCount int, txOuts []*wire.TxOut, addChangeOutput bool, inputType InputType) int

EstimateSerializeSize returns a worst case serialize size estimate for a signed transaction that spends inputCount number of compressed P2PKH outputs and contains each transaction output from txOuts. The estimated size is incremented for an additional P2PKH change output if addChangeOutput is true.

func SumOutputSerializeSizes

func SumOutputSerializeSizes(outputs []*wire.TxOut) (serializeSize int)

SumOutputSerializeSizes sums up the serialized size of the supplied outputs.

Types

type BitcoinCashPriceFetcher

type BitcoinCashPriceFetcher struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewBitcoinCashPriceFetcher

func NewBitcoinCashPriceFetcher(dialer proxy.Dialer) *BitcoinCashPriceFetcher

func (*BitcoinCashPriceFetcher) GetAllRates

func (b *BitcoinCashPriceFetcher) GetAllRates(cacheOK bool) (map[string]float64, error)

func (*BitcoinCashPriceFetcher) GetExchangeRate

func (b *BitcoinCashPriceFetcher) GetExchangeRate(currencyCode string) (float64, error)

func (*BitcoinCashPriceFetcher) GetLatestRate

func (b *BitcoinCashPriceFetcher) GetLatestRate(currencyCode string) (float64, error)

func (*BitcoinCashPriceFetcher) Run

func (b *BitcoinCashPriceFetcher) Run()

func (*BitcoinCashPriceFetcher) UnitsPerCoin

func (b *BitcoinCashPriceFetcher) UnitsPerCoin() int64

type BitcoinCashWallet

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

func NewBitcoinCashWallet

func NewBitcoinCashWallet(cfg config.CoinConfig, mnemonic string, params *chaincfg.Params, proxy proxy.Dialer, cache cache.Cacher, disableExchangeRates bool) (*BitcoinCashWallet, error)

func (*BitcoinCashWallet) AddTransactionListener

func (w *BitcoinCashWallet) AddTransactionListener(callback func(wi.TransactionCallback))

func (*BitcoinCashWallet) AddWatchedAddresses

func (w *BitcoinCashWallet) AddWatchedAddresses(addrs ...btcutil.Address) error

func (*BitcoinCashWallet) AddWatchedScript

func (w *BitcoinCashWallet) AddWatchedScript(script []byte) error

func (*BitcoinCashWallet) AddressToScript

func (w *BitcoinCashWallet) AddressToScript(addr btcutil.Address) ([]byte, error)

func (*BitcoinCashWallet) AssociateTransactionWithOrder

func (w *BitcoinCashWallet) AssociateTransactionWithOrder(cb wi.TransactionCallback)

AssociateTransactionWithOrder used for ORDER_PAYMENT message

func (*BitcoinCashWallet) Balance

func (*BitcoinCashWallet) Broadcast

func (w *BitcoinCashWallet) Broadcast(tx *wire.MsgTx) error

Build a client.Transaction so we can ingest it into the wallet service then broadcast

func (*BitcoinCashWallet) BumpFee

func (w *BitcoinCashWallet) BumpFee(txid chainhash.Hash) (*chainhash.Hash, error)

func (*BitcoinCashWallet) ChainTip

func (w *BitcoinCashWallet) ChainTip() (uint32, chainhash.Hash)

func (*BitcoinCashWallet) ChildKey

func (w *BitcoinCashWallet) ChildKey(keyBytes []byte, chaincode []byte, isPrivateKey bool) (*hd.ExtendedKey, error)

func (*BitcoinCashWallet) Close

func (w *BitcoinCashWallet) Close()

func (*BitcoinCashWallet) CreateMultisigSignature

func (w *BitcoinCashWallet) CreateMultisigSignature(ins []wi.TransactionInput, outs []wi.TransactionOutput, key *hd.ExtendedKey, redeemScript []byte, feePerByte big.Int) ([]wi.Signature, error)

func (*BitcoinCashWallet) CurrencyCode

func (w *BitcoinCashWallet) CurrencyCode() string

func (*BitcoinCashWallet) CurrentAddress

func (w *BitcoinCashWallet) CurrentAddress(purpose wi.KeyPurpose) btcutil.Address

func (*BitcoinCashWallet) DecodeAddress

func (w *BitcoinCashWallet) DecodeAddress(addr string) (btcutil.Address, error)

func (*BitcoinCashWallet) DumpTables

func (w *BitcoinCashWallet) DumpTables(wr io.Writer)

func (*BitcoinCashWallet) EstimateFee

func (w *BitcoinCashWallet) EstimateFee(ins []wi.TransactionInput, outs []wi.TransactionOutput, feePerByte big.Int) big.Int

func (*BitcoinCashWallet) EstimateSpendFee

func (w *BitcoinCashWallet) EstimateSpendFee(amount big.Int, feeLevel wi.FeeLevel) (big.Int, error)

func (*BitcoinCashWallet) ExchangeRates

func (w *BitcoinCashWallet) ExchangeRates() wi.ExchangeRates

func (*BitcoinCashWallet) GenerateMultisigScript

func (w *BitcoinCashWallet) GenerateMultisigScript(keys []hd.ExtendedKey, threshold int, timeout time.Duration, timeoutKey *hd.ExtendedKey) (addr btcutil.Address, redeemScript []byte, err error)

func (*BitcoinCashWallet) GetConfirmations

func (w *BitcoinCashWallet) GetConfirmations(txid chainhash.Hash) (uint32, uint32, error)

func (*BitcoinCashWallet) GetFeePerByte

func (w *BitcoinCashWallet) GetFeePerByte(feeLevel wi.FeeLevel) big.Int

func (*BitcoinCashWallet) GetTransaction

func (w *BitcoinCashWallet) GetTransaction(txid chainhash.Hash) (wi.Txn, error)

func (*BitcoinCashWallet) HasKey

func (w *BitcoinCashWallet) HasKey(addr btcutil.Address) bool

func (*BitcoinCashWallet) IsDust

func (w *BitcoinCashWallet) IsDust(amount big.Int) bool

func (*BitcoinCashWallet) MasterPrivateKey

func (w *BitcoinCashWallet) MasterPrivateKey() *hd.ExtendedKey

func (*BitcoinCashWallet) MasterPublicKey

func (w *BitcoinCashWallet) MasterPublicKey() *hd.ExtendedKey

func (*BitcoinCashWallet) Multisign

func (w *BitcoinCashWallet) Multisign(ins []wi.TransactionInput, outs []wi.TransactionOutput, sigs1 []wi.Signature, sigs2 []wi.Signature, redeemScript []byte, feePerByte big.Int, broadcast bool) ([]byte, error)

func (*BitcoinCashWallet) NewAddress

func (w *BitcoinCashWallet) NewAddress(purpose wi.KeyPurpose) btcutil.Address

func (*BitcoinCashWallet) Params

func (w *BitcoinCashWallet) Params() *chaincfg.Params

func (*BitcoinCashWallet) ReSyncBlockchain

func (w *BitcoinCashWallet) ReSyncBlockchain(fromTime time.Time)

func (*BitcoinCashWallet) ScriptToAddress

func (w *BitcoinCashWallet) ScriptToAddress(script []byte) (btcutil.Address, error)

func (*BitcoinCashWallet) Spend

func (w *BitcoinCashWallet) Spend(amount big.Int, addr btcutil.Address, feeLevel wi.FeeLevel, referenceID string, spendAll bool) (*chainhash.Hash, error)

func (*BitcoinCashWallet) Start

func (w *BitcoinCashWallet) Start()

func (*BitcoinCashWallet) SweepAddress

func (w *BitcoinCashWallet) SweepAddress(ins []wi.TransactionInput, address *btcutil.Address, key *hd.ExtendedKey, redeemScript *[]byte, feeLevel wi.FeeLevel) (*chainhash.Hash, error)

func (*BitcoinCashWallet) Transactions

func (w *BitcoinCashWallet) Transactions() ([]wi.Txn, error)

type ExchangeRateDecoder

type ExchangeRateDecoder interface {
	// contains filtered or unexported methods
}

type ExchangeRateProvider

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

type InputType

type InputType int
const (
	P2PKH InputType = iota
	P2SH_1of2_Multisig
	P2SH_2of3_Multisig
	P2SH_Multisig_Timelock_1Sig
	P2SH_Multisig_Timelock_2Sigs
)

type OpenBazaarDecoder

type OpenBazaarDecoder struct{}

Jump to

Keyboard shortcuts

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