Documentation ¶
Index ¶
- Constants
- Variables
- func EstimateSerializeSize(inputCount int, txOuts []*wire.TxOut, addChangeOutput bool, ...) int
- func NormalizeCurrencyCode(currencyCode string) string
- func SumOutputSerializeSizes(outputs []*wire.TxOut) (serializeSize int)
- type CMCDecoder
- type CoinGeckoDecoder
- type ExchangeRateDecoder
- type ExchangeRateProvider
- type InputType
- type PhoreWallet
- func (w *PhoreWallet) AddTransactionListener(callback func(wallet.TransactionCallback))
- func (w *PhoreWallet) AddWatchedAddresses(addrs ...btc.Address) error
- func (w *PhoreWallet) AddressToScript(addr btc.Address) ([]byte, error)
- func (w *PhoreWallet) AssociateTransactionWithOrder(cb wi.TransactionCallback)
- func (w *PhoreWallet) Balance() (wi.CurrencyValue, wi.CurrencyValue)
- func (w *PhoreWallet) Broadcast(tx *wire.MsgTx) error
- func (w *PhoreWallet) BumpFee(txid chainhash.Hash) (*chainhash.Hash, error)
- func (w *PhoreWallet) ChainTip() (uint32, chainhash.Hash)
- func (w *PhoreWallet) ChildKey(keyBytes []byte, chaincode []byte, isPrivateKey bool) (*hd.ExtendedKey, error)
- func (w *PhoreWallet) Close()
- func (w *PhoreWallet) CreateMultisigSignature(ins []wi.TransactionInput, outs []wi.TransactionOutput, key *hd.ExtendedKey, ...) ([]wi.Signature, error)
- func (w *PhoreWallet) CurrencyCode() string
- func (w *PhoreWallet) CurrentAddress(purpose wallet.KeyPurpose) btc.Address
- func (w *PhoreWallet) DecodeAddress(addr string) (btc.Address, error)
- func (w *PhoreWallet) DumpTables(wr io.Writer)
- func (w *PhoreWallet) EstimateFee(ins []wi.TransactionInput, outs []wi.TransactionOutput, feePerByte big.Int) big.Int
- func (w *PhoreWallet) EstimateSpendFee(amount big.Int, feeLevel wi.FeeLevel) (big.Int, error)
- func (w *PhoreWallet) ExchangeRates() wallet.ExchangeRates
- func (w *PhoreWallet) GenerateMultisigScript(keys []hd.ExtendedKey, threshold int, timeout time.Duration, ...) (addr btc.Address, redeemScript []byte, err error)
- func (w *PhoreWallet) GetConfirmations(txid chainhash.Hash) (uint32, uint32, error)
- func (w *PhoreWallet) GetFeePerByte(feeLevel wi.FeeLevel) big.Int
- func (w *PhoreWallet) GetTransaction(txid chainhash.Hash) (wallet.Txn, error)
- func (w *PhoreWallet) HasKey(addr btc.Address) bool
- func (w *PhoreWallet) IsDust(amount big.Int) bool
- func (w *PhoreWallet) MasterPrivateKey() *hd.ExtendedKey
- func (w *PhoreWallet) MasterPublicKey() *hd.ExtendedKey
- func (w *PhoreWallet) Multisign(ins []wi.TransactionInput, outs []wi.TransactionOutput, sigs1 []wi.Signature, ...) ([]byte, error)
- func (w *PhoreWallet) NewAddress(purpose wallet.KeyPurpose) btc.Address
- func (w *PhoreWallet) Params() *chaincfg.Params
- func (w *PhoreWallet) ReSyncBlockchain(fromDate time.Time)
- func (w *PhoreWallet) ScriptToAddress(script []byte) (btc.Address, error)
- func (w *PhoreWallet) Spend(amount big.Int, addr btc.Address, feeLevel wi.FeeLevel, referenceID string, ...) (*chainhash.Hash, error)
- func (w *PhoreWallet) Start()
- func (w *PhoreWallet) SweepAddress(ins []wallet.TransactionInput, address *btc.Address, key *hd.ExtendedKey, ...) (*chainhash.Hash, error)
- func (w *PhoreWallet) Transactions() ([]wallet.Txn, error)
- type PriceFetcher
- func (b *PriceFetcher) GetAllRates(cacheOK bool) (map[string]float64, error)
- func (b *PriceFetcher) GetExchangeRate(currencyCode string) (float64, error)
- func (b *PriceFetcher) GetLatestRate(currencyCode string) (float64, error)
- func (b *PriceFetcher) Run()
- func (b *PriceFetcher) UnitsPerCoin() int64
Constants ¶
const ( // MainNet represents the main bitcoin network. MainPhoreNet wire.BitcoinNet = 0x504852 // PHR TestPhoreNet wire.BitcoinNet = 0x545048 // TP )
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.
const SatoshiPerPHR int64 = 100000000
Variables ¶
var (
PhoreCurrencyDefinition = wi.CurrencyDefinition{
Code: "PHR",
Divisibility: 8,
}
)
var PhoreMainNetParams = chaincfg.Params{ Name: "mainPhore", Net: MainPhoreNet, DefaultPort: "11771", DNSSeeds: []chaincfg.DNSSeed{ {"dns0.phore.io", true}, {"phore.seed.rho.industries", true}, }, GenesisBlock: nil, GenesisHash: nil, PowLimit: mainPowLimit, PowLimitBits: 0x207fffff, BIP0034Height: 0, BIP0065Height: 0, BIP0066Height: 0, CoinbaseMaturity: 50, TargetTimespan: time.Minute, TargetTimePerBlock: time.Minute, RetargetAdjustmentFactor: 4, ReduceMinDifficulty: false, MinDiffReductionTime: 0, GenerateSupported: true, Checkpoints: []chaincfg.Checkpoint{}, RelayNonStdTxs: false, Bech32HRPSegwit: "ph", PubKeyHashAddrID: 0x37, ScriptHashAddrID: 0x0d, PrivateKeyID: 0xd4, HDPrivateKeyID: [4]byte{0x02, 0x2d, 0x25, 0x33}, HDPublicKeyID: [4]byte{0x02, 0x21, 0x31, 0x2b}, HDCoinType: 0x800001bc, }
var PhoreTestNetParams = chaincfg.Params{ Name: "testnetPhore", Net: TestPhoreNet, DefaultPort: "11773", DNSSeeds: []chaincfg.DNSSeed{}, GenesisBlock: nil, GenesisHash: nil, PowLimit: mainPowLimit, PowLimitBits: 0x207fffff, BIP0034Height: 0, BIP0065Height: 0, BIP0066Height: 0, CoinbaseMaturity: 50, TargetTimespan: time.Minute, TargetTimePerBlock: time.Minute, RetargetAdjustmentFactor: 4, ReduceMinDifficulty: false, MinDiffReductionTime: 0, GenerateSupported: true, Checkpoints: []chaincfg.Checkpoint{}, RelayNonStdTxs: false, Bech32HRPSegwit: "tp", PubKeyHashAddrID: 0x8B, ScriptHashAddrID: 0x13, PrivateKeyID: 0xEF, HDPrivateKeyID: [4]byte{0x3a, 0x80, 0x61, 0xa0}, HDPublicKeyID: [4]byte{0x3a, 0x80, 0x58, 0x37}, HDCoinType: 0x80000001, }
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 NormalizeCurrencyCode ¶
NormalizeCurrencyCode standardizes the format for the given currency code
func SumOutputSerializeSizes ¶
SumOutputSerializeSizes sums up the serialized size of the supplied outputs.
Types ¶
type CMCDecoder ¶
type CMCDecoder struct{}
empty structs to tag the different ExchangeRateDecoder implementations
type CoinGeckoDecoder ¶
type CoinGeckoDecoder struct{}
type ExchangeRateDecoder ¶
type ExchangeRateDecoder interface {
// contains filtered or unexported methods
}
type ExchangeRateProvider ¶
type ExchangeRateProvider struct {
// contains filtered or unexported fields
}
type PhoreWallet ¶
type PhoreWallet struct {
// contains filtered or unexported fields
}
PhoreWallet represents a wallet based on JSON-RPC and Bitcoind
func NewPhoreWallet ¶
func NewPhoreWallet(cfg config.CoinConfig, mnemonic string, params *chaincfg.Params, proxy proxy.Dialer, cache cache.Cacher, disableExchangeRates bool) (*PhoreWallet, error)
NewPhoreWallet creates a new wallet given
func (*PhoreWallet) AddTransactionListener ¶
func (w *PhoreWallet) AddTransactionListener(callback func(wallet.TransactionCallback))
AddTransactionListener adds a listener for any wallet transactions
func (*PhoreWallet) AddWatchedAddresses ¶
func (w *PhoreWallet) AddWatchedAddresses(addrs ...btc.Address) error
func (*PhoreWallet) AddressToScript ¶
func (w *PhoreWallet) AddressToScript(addr btc.Address) ([]byte, error)
AddressToScript returns the script for a given address
func (*PhoreWallet) AssociateTransactionWithOrder ¶
func (w *PhoreWallet) AssociateTransactionWithOrder(cb wi.TransactionCallback)
AssociateTransactionWithOrder used for ORDER_PAYMENT message
func (*PhoreWallet) Balance ¶
func (w *PhoreWallet) Balance() (wi.CurrencyValue, wi.CurrencyValue)
Balance returns the total balance of our addresses
func (*PhoreWallet) Broadcast ¶
func (w *PhoreWallet) Broadcast(tx *wire.MsgTx) error
Broadcast a transaction to the network
func (*PhoreWallet) ChainTip ¶
func (w *PhoreWallet) ChainTip() (uint32, chainhash.Hash)
ChainTip returns the tip of the active blockchain
func (*PhoreWallet) ChildKey ¶
func (w *PhoreWallet) ChildKey(keyBytes []byte, chaincode []byte, isPrivateKey bool) (*hd.ExtendedKey, error)
func (*PhoreWallet) CreateMultisigSignature ¶
func (w *PhoreWallet) CreateMultisigSignature(ins []wi.TransactionInput, outs []wi.TransactionOutput, key *hd.ExtendedKey, redeemScript []byte, feePerByte big.Int) ([]wi.Signature, error)
func (*PhoreWallet) CurrencyCode ¶
func (w *PhoreWallet) CurrencyCode() string
CurrencyCode returns the currency code of the wallet
func (*PhoreWallet) CurrentAddress ¶
func (w *PhoreWallet) CurrentAddress(purpose wallet.KeyPurpose) btc.Address
CurrentAddress returns an unused address
func (*PhoreWallet) DecodeAddress ¶
func (w *PhoreWallet) DecodeAddress(addr string) (btc.Address, error)
DecodeAddress decodes an address string to an address using the wallet's chain parameters
func (*PhoreWallet) DumpTables ¶
func (w *PhoreWallet) DumpTables(wr io.Writer)
func (*PhoreWallet) EstimateFee ¶
func (w *PhoreWallet) EstimateFee(ins []wi.TransactionInput, outs []wi.TransactionOutput, feePerByte big.Int) big.Int
EstimateFee estimates the fee of a transaction
func (*PhoreWallet) EstimateSpendFee ¶
func (*PhoreWallet) ExchangeRates ¶
func (w *PhoreWallet) ExchangeRates() wallet.ExchangeRates
func (*PhoreWallet) GenerateMultisigScript ¶
func (w *PhoreWallet) GenerateMultisigScript(keys []hd.ExtendedKey, threshold int, timeout time.Duration, timeoutKey *hd.ExtendedKey) (addr btc.Address, redeemScript []byte, err error)
GenerateMultisigScript generates a script representing a multisig wallet
func (*PhoreWallet) GetConfirmations ¶
GetConfirmations returns the number of confirmations and the block number where the transaction was confirmed
func (*PhoreWallet) GetFeePerByte ¶
func (w *PhoreWallet) GetFeePerByte(feeLevel wi.FeeLevel) big.Int
GetFeePerByte gets the fee in pSAT per byte
func (*PhoreWallet) GetTransaction ¶
func (w *PhoreWallet) GetTransaction(txid chainhash.Hash) (wallet.Txn, error)
GetTransaction returns the transaction given by a transaction hash
func (*PhoreWallet) HasKey ¶
func (w *PhoreWallet) HasKey(addr btc.Address) bool
HasKey returns true if we have the private key for a given address
func (*PhoreWallet) IsDust ¶
func (w *PhoreWallet) IsDust(amount big.Int) bool
IsDust determines if an amount is considered dust
func (*PhoreWallet) MasterPrivateKey ¶
func (w *PhoreWallet) MasterPrivateKey() *hd.ExtendedKey
MasterPrivateKey returns the wallet's master private key
func (*PhoreWallet) MasterPublicKey ¶
func (w *PhoreWallet) MasterPublicKey() *hd.ExtendedKey
MasterPublicKey returns the wallet's key used to derive public keys
func (*PhoreWallet) Multisign ¶
func (w *PhoreWallet) Multisign(ins []wi.TransactionInput, outs []wi.TransactionOutput, sigs1 []wi.Signature, sigs2 []wi.Signature, redeemScript []byte, feePerByte big.Int, broadcast bool) ([]byte, error)
func (*PhoreWallet) NewAddress ¶
func (w *PhoreWallet) NewAddress(purpose wallet.KeyPurpose) btc.Address
NewAddress creates a new address
func (*PhoreWallet) Params ¶
func (w *PhoreWallet) Params() *chaincfg.Params
func (*PhoreWallet) ReSyncBlockchain ¶
func (w *PhoreWallet) ReSyncBlockchain(fromDate time.Time)
ReSyncBlockchain resyncs the addresses used by the SPV wallet
func (*PhoreWallet) ScriptToAddress ¶
func (w *PhoreWallet) ScriptToAddress(script []byte) (btc.Address, error)
ScriptToAddress converts a script to an address
func (*PhoreWallet) Spend ¶
func (w *PhoreWallet) Spend(amount big.Int, addr btc.Address, feeLevel wi.FeeLevel, referenceID string, spendAll bool) (*chainhash.Hash, error)
Spend spends an amount from an address with a given fee level
func (*PhoreWallet) SweepAddress ¶
func (w *PhoreWallet) SweepAddress(ins []wallet.TransactionInput, address *btc.Address, key *hd.ExtendedKey, redeemScript *[]byte, feeLevel wallet.FeeLevel) (*chainhash.Hash, error)
SweepAddress sweeps any UTXOs from an address in a single transaction
func (*PhoreWallet) Transactions ¶
func (w *PhoreWallet) Transactions() ([]wallet.Txn, error)
Transactions returns all of the transactions relating to any of our addresses
type PriceFetcher ¶
func NewPhorePriceFetcher ¶
func NewPhorePriceFetcher(dialer proxy.Dialer) *PriceFetcher
func (*PriceFetcher) GetAllRates ¶
func (b *PriceFetcher) GetAllRates(cacheOK bool) (map[string]float64, error)
func (*PriceFetcher) GetExchangeRate ¶
func (b *PriceFetcher) GetExchangeRate(currencyCode string) (float64, error)
func (*PriceFetcher) GetLatestRate ¶
func (b *PriceFetcher) GetLatestRate(currencyCode string) (float64, error)
func (*PriceFetcher) Run ¶
func (b *PriceFetcher) Run()
func (*PriceFetcher) UnitsPerCoin ¶
func (b *PriceFetcher) UnitsPerCoin() int64