Documentation ¶
Overview ¶
Package txhelpers contains helper functions for working with transactions and blocks (e.g. checking for a transaction in a block).
Index ¶
- Constants
- Variables
- func AddressValidation(address string, params *chaincfg.Params) (stdaddr.Address, AddressType, AddressError)
- func BlockConsumesOutpointWithAddresses(block *dcrutil.Block, addrs map[string]TxAction, c RawTransactionGetter, ...) map[string][]*dcrutil.Tx
- func BlockReceivesToAddresses(block *dcrutil.Block, addrs map[string]TxAction, params *chaincfg.Params, ...) map[string][]*dcrutil.Tx
- func BuildStakeTree(blocks map[int64]*dcrutil.Block, netParams *chaincfg.Params, ...) (database.DB, []int64, error)
- func CalcMeanVotingBlocks(params *chaincfg.Params) int64
- func DCP0010ActivationHeight(params *chaincfg.Params, bci *chainjson.GetBlockChainInfoResult) int64
- func DetermineTxType(msgTx *wire.MsgTx, treasuryActive bool) stake.TxType
- func DetermineTxTypeString(msgTx *wire.MsgTx, treasuryActive bool) string
- func EstimateInputSize(scriptSize int) int
- func EstimateOutputSize(scriptSize int) int
- func EstimateSerializeSize(inputScriptSizes []int, txOuts []*wire.TxOut, changeScriptSize int) int
- func EstimateSerializeSizeFromScriptSizes(inputScriptSizes, outputScriptSizes []int, changeScriptSize int) int
- func FeeForSerializeSize(relayFeePerKb dcrutil.Amount, txSerializeSize int) dcrutil.Amount
- func FeeInfoBlock(block *dcrutil.Block) *chainjson.FeeInfoBlock
- func FeeRate(amtIn, amtOut, sizeBytes int64) int64
- func FeeRateInfoBlock(block *dcrutil.Block) *chainjson.FeeInfoBlock
- func FilterHashSlice(s []chainhash.Hash, doRemove func(h chainhash.Hash) bool) []chainhash.Hash
- func GenesisTxHash(params *chaincfg.Params) chainhash.Hash
- func GetDifficultyRatio(bits uint32, params *chaincfg.Params) float64
- func HashInSlice(h chainhash.Hash, list []chainhash.Hash) bool
- func IncludesStakeTx(txHash *chainhash.Hash, block *dcrutil.Block) (int, int8)
- func IncludesTx(txHash *chainhash.Hash, block *dcrutil.Block) (int, int8)
- func IsCoinBaseTx(tx *wire.MsgTx) bool
- func IsMixTx(tx *wire.MsgTx) (isMix bool, mixDenom int64, mixCount uint32)
- func IsMixedSplitTx(tx *wire.MsgTx, relayFeeRate, ticketPrice int64) (isMix bool, ticketOutAmt int64, numTickets uint32)
- func IsSSRtx(tx *wire.MsgTx) bool
- func IsStakeTx(msgTx *wire.MsgTx, treasuryActive bool) bool
- func IsTreasuryActive(net wire.CurrencyNet, height int64) bool
- func IsZeroHash(hash chainhash.Hash) bool
- func IsZeroHashP2PHKAddress(checkAddressString string, params *chaincfg.Params) bool
- func IsZeroHashStr(hash string) bool
- func MedianAmount(s []dcrutil.Amount) dcrutil.Amount
- func MedianCoin(s []float64) float64
- func MsgTxFromHex(txhex string) (*wire.MsgTx, error)
- func MsgTxToHex(msgTx *wire.MsgTx) (string, error)
- func OutPointAddresses(outPoint *wire.OutPoint, c RawTransactionGetter, params *chaincfg.Params) ([]string, dcrutil.Amount, error)
- func OutPointAddressesFromString(txid string, index uint32, tree int8, c RawTransactionGetter, ...) ([]string, dcrutil.Amount, error)
- func RevokedTicketsInBlock(bl *dcrutil.Block) []chainhash.Hash
- func RewardsAtBlock(blockIdx int64, votes uint16, p *chaincfg.Params, useDCP0010 bool) (work, stake, tax int64)
- func SSGenVoteBits(tx *wire.MsgTx) (uint16, error)
- func SSGenVoteBlockValid(msgTx *wire.MsgTx) (BlockValidation, []*TSpendVote, uint16, error)
- func SSGenVoteChoices(tx *wire.MsgTx, params *chaincfg.Params) (BlockValidation, uint32, uint16, []*VoteChoice, []*TSpendVote, error)
- func SSTXInBlock(block *dcrutil.Block) []*dcrutil.Tx
- func SubsidySplitStakeVer(params *chaincfg.Params) (uint32, bool)
- func TicketTxnsInBlock(bl *dcrutil.Block) ([]chainhash.Hash, []*dcrutil.Tx)
- func TicketsInBlock(bl *dcrutil.Block) ([]chainhash.Hash, []*wire.MsgTx)
- func TicketsSpentInBlock(bl *dcrutil.Block) []chainhash.Hash
- func TotalOutFromMsgTx(msgTx *wire.MsgTx) dcrutil.Amount
- func TotalVout(vouts []chainjson.Vout) dcrutil.Amount
- func TxConsumesOutpointWithAddress(msgTx *wire.MsgTx, addr string, c VerboseTransactionPromiseGetter, ...) (prevOuts []PrevOut, prevTxs []*TxWithBlockData)
- func TxFee(msgTx *wire.MsgTx) dcrutil.Amount
- func TxFeeRate(msgTx *wire.MsgTx) (dcrutil.Amount, dcrutil.Amount)
- func TxInvolvesAddress(msgTx *wire.MsgTx, addr string, c VerboseTransactionPromiseGetter, ...) (outpoints []*wire.OutPoint, prevOuts []PrevOut, prevTxs []*TxWithBlockData)
- func TxIsRegular(txType int) bool
- func TxIsRevoke(txType int) bool
- func TxIsTAdd(txType int) bool
- func TxIsTSpend(txType int) bool
- func TxIsTicket(txType int) bool
- func TxIsTreasuryBase(txType int) bool
- func TxIsVote(txType int) bool
- func TxOutpointsByAddr(txAddrOuts MempoolAddressStore, msgTx *wire.MsgTx, params *chaincfg.Params, ...) (newOuts int, addrs map[string]bool)
- func TxPaysToAddress(msgTx *wire.MsgTx, addr string, params *chaincfg.Params, treasuryActive bool) (outpoints []*wire.OutPoint)
- func TxPrevOutsByAddr(txAddrOuts MempoolAddressStore, txnsStore TxnsStore, msgTx *wire.MsgTx, ...) (newPrevOuts int, addrs map[string]bool, valsIn []int64)
- func TxTree(msgTx *wire.MsgTx, treasuryActive bool) int8
- func TxTypeToString(txType int) string
- func TxhashInSlice(txs []*dcrutil.Tx, txHash *chainhash.Hash) *dcrutil.Tx
- func UltimateSubsidy(params *chaincfg.Params, subsidySplitChangeHeight int64) int64
- func VoteBitsInBlock(block *dcrutil.Block) []stake.VoteVersionTuple
- func VoteVersion(pkScript []byte) uint32
- func VotesInBlock(bl *dcrutil.Block) []chainhash.Hash
- type AddressError
- type AddressOutpoints
- type AddressType
- type AtomicSwap
- type AtomicSwapContractPushes
- func ExtractSwapDataFromInputScript(inputScript []byte, params *chaincfg.Params) (*AtomicSwapContractPushes, []byte, []byte, bool, error)
- func ExtractSwapDataFromInputScriptHex(inputScriptHex string, params *chaincfg.Params) (*AtomicSwapContractPushes, []byte, []byte, bool, error)
- func ParseAtomicSwapContract(scriptVersion uint16, script []byte, params *chaincfg.Params) (*AtomicSwapContractPushes, error)
- type AtomicSwapData
- type BlockValidation
- type MempoolAddressStore
- type OutputSpender
- type OutputSpenderTxOut
- type PrevOut
- type RawTransactionGetter
- type ReorgData
- type TSpendVote
- type TransactionPromiseGetter
- type TxAction
- type TxAtomicSwaps
- type TxReceiver
- type TxSwapResults
- type TxWithBlockData
- type TxnsStore
- type VerboseTransactionGetter
- type VerboseTransactionPromiseGetter
- type VerboseTxReceiver
- type VoteChoice
Constants ¶
const ( TxTypeVote string = "Vote" TxTypeTicket string = "Ticket" TxTypeRevocation string = "Revocation" TxTypeRegular string = "Regular" TxTypeTreasurybase string = "Treasurybase" TxTypeTreasurySpend string = "Treasury Spend" TxTypeTreasuryAdd string = "Treasury Add" )
Transaction type constants.
const ( AddressTypeP2PK = iota AddressTypeP2PKH AddressTypeP2SH AddressTypeOther // the "alt" pkh addresses with ed25519 and schorr sigs AddressTypeUnknown )
These are the AddressType values, as returned by AddressValidation.
const DefaultRelayFeePerKb dcrutil.Amount = 1e4 // i.e. 10 atoms/B
DefaultRelayFeePerKb is the default minimum relay fee policy for a mempool. See dcrwallet/wallet/v2/txrules.DefaultRelayFeePerKb.
const (
// DefaultStakeDbName is the default database name
DefaultStakeDbName = "ffldb_stake"
)
Variables ¶
var CoinbaseFlags = "/exccd/"
var CoinbaseScript = append([]byte{0x00, 0x00}, []byte(CoinbaseFlags)...)
Functions ¶
func AddressValidation ¶
func AddressValidation(address string, params *chaincfg.Params) (stdaddr.Address, AddressType, AddressError)
AddressValidation performs several validation checks on the given address string. Initially, decoding as a Decred address is attempted. If it fails to decode, AddressErrorDecodeFailed is returned with AddressTypeUnknown. If the address decoded successfully as a Decred address, it is checked against the specified network. A final check is performed to determine if the address is the zero pubkey hash address, in which case AddressErrorZeroAddress is returned with the determined address type. If it is another address, AddressErrorNoError (nil) is returned with the determined address type.
func BlockConsumesOutpointWithAddresses ¶
func BlockConsumesOutpointWithAddresses(block *dcrutil.Block, addrs map[string]TxAction, c RawTransactionGetter, params *chaincfg.Params) map[string][]*dcrutil.Tx
BlockConsumesOutpointWithAddresses checks the specified block to see if it includes transactions that spend from outputs created using any of the addresses in addrs. The TxAction for each address is not important, but it would logically be TxMined. Both regular and stake transactions are checked. The RPC client is used to get the PreviousOutPoint for each TxIn of each transaction in the block, from which the address is obtained from the PkScript of that output. chaincfg Params is required to decode the script.
func BlockReceivesToAddresses ¶
func BlockReceivesToAddresses(block *dcrutil.Block, addrs map[string]TxAction, params *chaincfg.Params, treasuryActive bool) map[string][]*dcrutil.Tx
BlockReceivesToAddresses checks a block for transactions paying to the specified addresses, and creates a map of addresses to a slice of dcrutil.Tx involving the address.
func BuildStakeTree ¶
func BuildStakeTree(blocks map[int64]*dcrutil.Block, netParams *chaincfg.Params, nodeClient RawTransactionGetter, poolRequiredHeight int64, DBName ...string) (database.DB, []int64, error)
BuildStakeTree returns a database with a stake tree
func CalcMeanVotingBlocks ¶
func CalcMeanVotingBlocks(params *chaincfg.Params) int64
CalcMeanVotingBlocks computes the average number of blocks a ticket will be live before voting. The expected block (aka mean) of the probability distribution is given by:
sum(B * P(B)), B=1 to 40960
Where B is the block number and P(B) is the probability of voting at block B. For more information see: https://github.com/EXCCoin/exccdata/issues/471#issuecomment-390063025
func DCP0010ActivationHeight ¶
func DCP0010ActivationHeight(params *chaincfg.Params, bci *chainjson.GetBlockChainInfoResult) int64
DCP0010ActivationHeight indicates the height at which the "changesubsidysplit" consensus change activates for the provided getblockchaininfo result.
func DetermineTxType ¶
func DetermineTxTypeString ¶
DetermineTxTypeString returns a string representing the transaction type given a wire.MsgTx struct. If the caller does not know if treasure is active for this txn, but the MsgTx is from from dcrd, it can be assumed to be valid according to consensus at height of txn and thus true can be safely used, although this may be more inefficient than necessary.
func EstimateInputSize ¶
EstimateInputSize returns the worst case serialize size estimate for a tx input:
- 32 bytes previous tx
- 4 bytes output index
- 1 byte tree
- 8 bytes amount
- 4 bytes block height
- 4 bytes block index
- the compact int representation of the script size
- the supplied script size
- 4 bytes sequence
func EstimateOutputSize ¶
EstimateOutputSize returns the worst case serialize size estimate for a tx output:
- 8 bytes amount
- 2 bytes version
- the compact int representation of the script size
- the supplied script size
func EstimateSerializeSize ¶
EstimateSerializeSize returns a worst case serialize size estimate for a signed transaction that spends a number of outputs and contains each transaction output from txOuts. The estimated size is incremented for an additional change output if changeScriptSize is greater than 0. Passing 0 does not add a change output.
func EstimateSerializeSizeFromScriptSizes ¶
func EstimateSerializeSizeFromScriptSizes(inputScriptSizes, outputScriptSizes []int, changeScriptSize int) int
EstimateSerializeSizeFromScriptSizes returns a worst case serialize size estimate for a signed transaction that spends len(inputSizes) previous outputs and pays to len(outputSizes) outputs with scripts of the provided worst-case sizes. The estimated size is incremented for an additional change output if changeScriptSize is greater than 0. Passing 0 does not add a change output.
func FeeForSerializeSize ¶
func FeeForSerializeSize(relayFeePerKb dcrutil.Amount, txSerializeSize int) dcrutil.Amount
FeeForSerializeSize calculates the required fee for a transaction of some arbitrary size given a mempool's relay fee policy.
func FeeInfoBlock ¶
func FeeInfoBlock(block *dcrutil.Block) *chainjson.FeeInfoBlock
FeeInfoBlock computes ticket fee statistics for the tickets included in the specified block.
func FeeRate ¶
FeeRate computes the fee rate in atoms/kB for a transaction provided the total amount of the transaction's inputs, the total amount of the transaction's outputs, and the size of the transaction in bytes. Note that a kB refers to 1000 bytes, not a kiB. If the size is 0, the returned fee is -1.
func FeeRateInfoBlock ¶
func FeeRateInfoBlock(block *dcrutil.Block) *chainjson.FeeInfoBlock
FeeRateInfoBlock computes ticket fee rate statistics for the tickets included in the specified block.
func FilterHashSlice ¶
FilterHashSlice removes elements from the specified if the doRemove function evaluates to true for a given element. For example, given a slice of hashes called blackList that should be removed from the slice hashList:
hashList = FilterHashSlice(hashList, func(h chainhash.Hash) bool { return HashInSlice(h, blackList) })
func GenesisTxHash ¶
GenesisTxHash returns the hash of the single coinbase transaction in the genesis block of the specified network. This transaction is hard coded, and the pubkey script for its one output only decodes for simnet.
func GetDifficultyRatio ¶
GetDifficultyRatio returns the proof-of-work difficulty as a multiple of the minimum difficulty using the passed bits field from the header of a block.
func HashInSlice ¶
HashInSlice determines if a hash exists in a slice of hashes.
func IncludesStakeTx ¶
IncludesStakeTx checks if a block contains a stake transaction hash
func IncludesTx ¶
IncludesTx checks if a block contains a transaction hash
func IsCoinBaseTx ¶
func IsMixTx ¶
IsMixTx tests if a transaction is a CSPP-mixed transaction, which must have 3 or more outputs of the same amount, which is one of the pre-defined mix denominations. mixDenom is the largest of such denominations. mixCount is the number of outputs of this denomination.
func IsMixedSplitTx ¶
func IsMixedSplitTx(tx *wire.MsgTx, relayFeeRate, ticketPrice int64) (isMix bool, ticketOutAmt int64, numTickets uint32)
IsMixedSplitTx tests if a transaction is a CSPP-mixed ticket split transaction (the transaction that creates appropriately-sized outputs to be spent by a ticket purchase). Such a transaction must have 3 or more outputs with an amount equal to the ticket price plus transaction fees, and at least as many other outputs. The expected fees to be included in the amount are based on the provided fee rate, relayFeeRate, and an assumed serialized size of a solo ticket transaction with one P2PKH input, two P2PKH outputs and one ticket commitment output.
func IsTreasuryActive ¶
func IsTreasuryActive(net wire.CurrencyNet, height int64) bool
IsTreasuryActive indicates if the decentralized treasury is active for the given network and block height.
func IsZeroHash ¶
IsZeroHash checks if the Hash is the zero hash.
func IsZeroHashP2PHKAddress ¶
IsZeroHashP2PHKAddress checks if the given address is the dummy (zero pubkey hash) address. See https://github.com/EXCCoin/exccdata/issues/358 for details.
func IsZeroHashStr ¶
IsZeroHashStr checks if the string is the zero hash string.
func MedianAmount ¶
func MedianAmount(s []dcrutil.Amount) dcrutil.Amount
MedianAmount gets the median Amount from a slice of Amounts
func MedianCoin ¶
MedianCoin gets the median DCR from a slice of float64s
func MsgTxFromHex ¶
MsgTxFromHex returns a wire.MsgTx struct built from the transaction hex string.
func MsgTxToHex ¶
MsgTxToHex returns a transaction hex string from a wire.MsgTx struct.
func OutPointAddresses ¶
func OutPointAddresses(outPoint *wire.OutPoint, c RawTransactionGetter, params *chaincfg.Params) ([]string, dcrutil.Amount, error)
OutPointAddresses gets the addresses paid to by a transaction output.
func OutPointAddressesFromString ¶
func OutPointAddressesFromString(txid string, index uint32, tree int8, c RawTransactionGetter, params *chaincfg.Params) ([]string, dcrutil.Amount, error)
OutPointAddressesFromString is the same as OutPointAddresses, but it takes the outpoint as the tx string, vout index, and tree.
func RevokedTicketsInBlock ¶
RevokedTicketsInBlock finds all the revoked tickets in the block.
func RewardsAtBlock ¶
func RewardsAtBlock(blockIdx int64, votes uint16, p *chaincfg.Params, useDCP0010 bool) (work, stake, tax int64)
RewardsAtBlock computes the PoW, PoS (per vote), and project fund subsidies at for the specified block index, assuming a certain number of votes. The stake reward is for a single vote. The total reward for the block is thus work + stake * votes + tax.
func SSGenVoteBits ¶
SSGenVoteBits returns the VoteBits of txOut[1] of a ssgen tx
func SSGenVoteBlockValid ¶
func SSGenVoteBlockValid(msgTx *wire.MsgTx) (BlockValidation, []*TSpendVote, uint16, error)
SSGenVoteBlockValid determines if a vote transaction is voting yes or no to a block, and returns the votebits in case the caller wants to check agenda votes. The error return may be ignored if the input transaction is known to be a valid ssgen (vote), otherwise it should be checked.
func SSGenVoteChoices ¶
func SSGenVoteChoices(tx *wire.MsgTx, params *chaincfg.Params) (BlockValidation, uint32, uint16, []*VoteChoice, []*TSpendVote, error)
SSGenVoteChoices gets a ssgen's vote choices (block validity and any agendas). The vote's stake version, to which the vote choices correspond, and vote bits are also returned. Note that []*VoteChoice may be an empty slice if there are no consensus deployments for the transaction's vote version. The error value may be non-nil if the tx is not a valid ssgen.
func SSTXInBlock ¶
func SSTXInBlock(block *dcrutil.Block) []*dcrutil.Tx
SSTXInBlock gets a slice containing all of the SSTX mined in a block
func SubsidySplitStakeVer ¶
SubsidySplitStakeVer locates the "changesubsidysplit" agenda item in the consensus deployments defined in the provided chain parameters. If found, the corresponding stake version is returned.
func TicketTxnsInBlock ¶
TicketTxnsInBlock finds all the new tickets in the block.
func TicketsInBlock ¶
TicketsInBlock finds all the new tickets in the block.
func TicketsSpentInBlock ¶
TicketsSpentInBlock finds all the tickets spent in the block.
func TotalOutFromMsgTx ¶
TotalOutFromMsgTx computes the total value out of a MsgTx
func TxConsumesOutpointWithAddress ¶
func TxConsumesOutpointWithAddress(msgTx *wire.MsgTx, addr string, c VerboseTransactionPromiseGetter, params *chaincfg.Params, treasuryActive bool) (prevOuts []PrevOut, prevTxs []*TxWithBlockData)
TxConsumesOutpointWithAddress checks a transaction for inputs that spend an outpoint paying to the given address. Returned are the identified input indexes and the corresponding previous outpoints determined.
func TxFeeRate ¶
TxFeeRate computes and returns the total fee in atoms and fee rate in atoms/kB for a given tx.
func TxInvolvesAddress ¶
func TxInvolvesAddress(msgTx *wire.MsgTx, addr string, c VerboseTransactionPromiseGetter, params *chaincfg.Params, treasuryActive bool) (outpoints []*wire.OutPoint, prevOuts []PrevOut, prevTxs []*TxWithBlockData)
TxInvolvesAddress checks the inputs and outputs of a transaction for involvement of the given address.
func TxIsRegular ¶
TxIsRegular indicates if the transaction type is a regular (non-stake) transaction.
func TxIsRevoke ¶
TxIsRevoke indicates if the transaction type is a revocation (ssrtx).
func TxIsTSpend ¶
TxIsTSpend indicates if the transaction type is a treasury spend (tspend).
func TxIsTicket ¶
TxIsTicket indicates if the transaction type is a ticket (sstx).
func TxIsTreasuryBase ¶
TxIsTreasuryBase indicates if the transaction type is a treasurybase.
func TxOutpointsByAddr ¶
func TxOutpointsByAddr(txAddrOuts MempoolAddressStore, msgTx *wire.MsgTx, params *chaincfg.Params, treasuryActive bool) (newOuts int, addrs map[string]bool)
TxOutpointsByAddr sets the Outpoints field for the AddressOutpoints stored in the input MempoolAddressStore. For addresses not yet present in the MempoolAddressStore, a new AddressOutpoints is added to the store. The provided MempoolAddressStore must be initialized. The number of msgTx outputs that pay to any address are counted and returned. The addresses paid to by the transaction are listed in the output addrs map, where the value of the stored bool indicates the address is new to the MempoolAddressStore.
func TxPaysToAddress ¶
func TxPaysToAddress(msgTx *wire.MsgTx, addr string, params *chaincfg.Params, treasuryActive bool) (outpoints []*wire.OutPoint)
TxPaysToAddress returns a slice of outpoints of a transaction which pay to specified address.
func TxPrevOutsByAddr ¶
func TxPrevOutsByAddr(txAddrOuts MempoolAddressStore, txnsStore TxnsStore, msgTx *wire.MsgTx, c VerboseTransactionPromiseGetter, params *chaincfg.Params, treasuryActive bool) (newPrevOuts int, addrs map[string]bool, valsIn []int64)
TxPrevOutsByAddr sets the PrevOuts field for the AddressOutpoints stored in the MempoolAddressStore. For addresses not yet present in the MempoolAddressStore, a new AddressOutpoints is added to the store. The provided MempoolAddressStore must be initialized. A VerboseTransactionPromiseGetter is required to retrieve the pkScripts for the previous outpoints. The number of consumed previous outpoints that paid addresses in the provided transaction are counted and returned. The addresses in the previous outpoints are listed in the output addrs map, where the value of the stored bool indicates the address is new to the MempoolAddressStore.
func TxTree ¶
TxTree returns for a wire.MsgTx either wire.TxTreeStake or wire.TxTreeRegular depending on the type of transaction.
func TxTypeToString ¶
TxTypeToString returns a string representation of the provided transaction type, which corresponds to the txn types defined for stake.TxType type.
func TxhashInSlice ¶
TxhashInSlice searches a slice of *dcrutil.Tx for a transaction with the hash txHash. If found, it returns the corresponding *Tx, otherwise nil.
func UltimateSubsidy ¶
UltimateSubsidy computes the total subsidy over the entire subsidy distribution period of the network, given a known height at which the subsidy split change goes into effect (DCP0010). If the height is unknown, provide -1 to perform the computation with the original subsidy split for all heights.
func VoteBitsInBlock ¶
func VoteBitsInBlock(block *dcrutil.Block) []stake.VoteVersionTuple
VoteBitsInBlock returns a list of vote bits for the votes in a block
func VoteVersion ¶
VoteVersion extracts the vote version from the input pubkey script.
func VotesInBlock ¶
VotesInBlock finds all the votes in the block.
Types ¶
type AddressError ¶
type AddressError error
AddressError is the type of error returned by AddressValidation.
var ( AddressErrorNoError AddressError AddressErrorZeroAddress AddressError = errors.New("null address") AddressErrorWrongNet AddressError = errors.New("wrong network") AddressErrorDecodeFailed AddressError = errors.New("decoding failed") AddressErrorUnknown AddressError = errors.New("unknown error") AddressErrorUnsupported AddressError = errors.New("recognized, but unsupported address type") )
type AddressOutpoints ¶
type AddressOutpoints struct { Address string Outpoints []*wire.OutPoint PrevOuts []PrevOut TxnsStore map[chainhash.Hash]*TxWithBlockData }
AddressOutpoints collects spendable and spent transactions outpoints paying to a certain address. The transactions referenced by the outpoints are stored for quick access.
func NewAddressOutpoints ¶
func NewAddressOutpoints(address string) *AddressOutpoints
NewAddressOutpoints creates a new AddressOutpoints, initializing the transaction store/cache, and setting the address string.
func (*AddressOutpoints) Merge ¶
func (a *AddressOutpoints) Merge(ao *AddressOutpoints)
Merge concatenates the outpoints of two AddressOutpoints, and merges the transactions.
func (*AddressOutpoints) Update ¶
func (a *AddressOutpoints) Update(txns []*TxWithBlockData, outpoints []*wire.OutPoint, prevOutpoint []PrevOut)
Update appends the provided outpoints, and merges the transactions.
type AddressType ¶
type AddressType int
AddressType is used to label type of an address as returned by base58.CheckDecode.
type AtomicSwap ¶
type AtomicSwap struct { ContractTxRef string `json:"contract_txref"` Contract string `json:"contract"` ContractValue float64 `json:"contract_value"` ContractAddress string `json:"contract_address"` RecipientAddress string `json:"recipient_address"` RefundAddress string `json:"refund_address"` Locktime int64 `json:"locktime"` SecretHash string `json:"secret_hash"` Secret string `json:"secret"` FormattedLocktime string `json:"formatted_locktime"` SpendTxInput string `json:"spend_tx_input"` IsRefund bool `json:"refund"` }
AtomicSwap models the contract and redemption details of an atomic swap.
func CheckTxInputForSwapInfo ¶
func CheckTxInputForSwapInfo(txraw *chainjson.TxRawResult, inputIndex uint32, params *chaincfg.Params) (*AtomicSwap, error)
CheckTxInputForSwapInfo parses the scriptsig of the provided transaction input for information about a completed atomic swap. Returns (nil, nil) if the scriptsig of the provided txin does not redeem a swap contract.
type AtomicSwapContractPushes ¶
type AtomicSwapContractPushes struct { ContractAddress stdaddr.Address `json:"contract_address"` RecipientAddress stdaddr.Address `json:"recipient_address"` RefundAddress stdaddr.Address `json:"refund_address"` Locktime int64 `json:"locktime"` SecretHash [32]byte `json:"secret_hash"` FormattedLocktime string `json:"formatted_locktime"` }
AtomicSwapContractPushes models the data pushes of an atomic swap contract.
func ExtractSwapDataFromInputScriptHex ¶
func ExtractSwapDataFromInputScriptHex(inputScriptHex string, params *chaincfg.Params) (*AtomicSwapContractPushes, []byte, []byte, bool, error)
ExtractSwapDataFromInputScript checks if a tx input redeems a swap contract and returns details of the completed swap, the contract script and a string describing the identity of the redeemer. Returns an empty contract script and nil error if the provided script does not redeem a contract. Returns a non-nil error if the script could not be parsed.
func ParseAtomicSwapContract ¶
func ParseAtomicSwapContract(scriptVersion uint16, script []byte, params *chaincfg.Params) (*AtomicSwapContractPushes, error)
ParseAtomicSwapContract checks if the provided script is an atomic swap contact and returns the data pushes of the contract.
type AtomicSwapData ¶
type AtomicSwapData struct { ContractTx *chainhash.Hash ContractVout uint32 SpendTx *chainhash.Hash SpendVin uint32 Value int64 ContractAddress string RecipientAddress string RefundAddress string Locktime int64 SecretHash [32]byte Secret []byte Contract []byte IsRefund bool }
func (*AtomicSwapData) ToAPI ¶
func (asd *AtomicSwapData) ToAPI() *AtomicSwap
type BlockValidation ¶
type BlockValidation struct { // Hash is the hash of the block being targeted (in)validated Hash chainhash.Hash // Height is the height of the block Height int64 // Validity indicates the vote is to validate (true) or invalidate (false) // the block. Validity bool }
BlockValidation models the block validation indicated by an ssgen (vote) transaction.
type MempoolAddressStore ¶
type MempoolAddressStore map[string]*AddressOutpoints
MempoolAddressStore organizes AddressOutpoints by address.
type OutputSpender ¶
type OutputSpender struct { Tx *chainjson.TxRawResult InputIndex uint32 }
OutputSpender describes a transaction input that spends an output by specifying the spending transaction and the index of the spending input.
type OutputSpenderTxOut ¶
type PrevOut ¶
PrevOut contains a transaction input's previous outpoint, the Hash of the spending (following) transaction, and input index in the transaction.
type RawTransactionGetter ¶
type RawTransactionGetter interface {
GetRawTransaction(ctx context.Context, txHash *chainhash.Hash) (*dcrutil.Tx, error)
}
RawTransactionGetter is an interface satisfied by rpcclient.Client, and required by functions that would otherwise require a rpcclient.Client just for GetRawTransaction.
type ReorgData ¶
type ReorgData struct { CommonAncestor chainhash.Hash OldChainHead chainhash.Hash OldChainHeight int32 OldChain []chainhash.Hash NewChainHead chainhash.Hash NewChainHeight int32 NewChain []chainhash.Hash WG *sync.WaitGroup }
ReorgData contains details of a chain reorganization, including the full old and new chains, and the common ancestor that should not be included in either chain. Below is the description of the reorg data with the letter indicating the various blocks in the chain:
A -> B -> C \ -> B' -> C' -> D'
CommonAncestor - Hash of A OldChainHead - Hash of C OldChainHeight - Height of C OldChain - Chain from B to C NewChainHead - Hash of D' NewChainHeight - Height of D' NewChain - Chain from B' to D'
type TSpendVote ¶
TSpendVote describes how a SSGen transaction decided on a tspend.
type TransactionPromiseGetter ¶
type TransactionPromiseGetter interface {
GetRawTransactionPromise(ctx context.Context, txHash *chainhash.Hash) TxReceiver
}
TransactionPromiseGetter is satisfied by rpcclient.Client, and required by functions that would otherwise require a rpcclient.Client just for GetRawTransactionVerboseAsync. See VerboseTransactionPromiseGetter and rpcutils.NewAsyncTxClient for more on wrapping an rpcclient.Client.
type TxAction ¶
type TxAction int32
TxAction is what is happening to the transaction (mined or inserted into mempool).
type TxAtomicSwaps ¶
type TxAtomicSwaps struct { TxID string `json:"tx_id"` Found string `json:"found"` Contracts map[uint32]*AtomicSwap `json:"contracts,omitempty"` Redemptions map[uint32]*AtomicSwap `json:"redemptions,omitempty"` Refunds map[uint32]*AtomicSwap `json:"refunds,omitempty"` }
TxAtomicSwaps defines information about completed atomic swaps that are related to a transaction.
func TxAtomicSwapsInfo ¶
func TxAtomicSwapsInfo(tx *chainjson.TxRawResult, outputSpenders map[uint32]*OutputSpender, params *chaincfg.Params) (*TxAtomicSwaps, error)
TxAtomicSwapsInfo checks the outputs of the specified transaction for possible atomic swap contracts and the inputs for possible swap redemptions or refunds. Returns all contracts, redemptions and refunds that were found.
type TxReceiver ¶
type TxReceiver interface {
Receive() (*dcrutil.Tx, error)
}
TxReceiver is satisfied by the return type from GetRawTransactionAsync (rpcclient.FutureGetRawTransactionResult).
type TxSwapResults ¶
type TxSwapResults struct { TxID chainhash.Hash Found string Contracts map[uint32]*AtomicSwapData Redemptions map[uint32]*AtomicSwapData Refunds map[uint32]*AtomicSwapData }
func MsgTxAtomicSwapsInfo ¶
func MsgTxAtomicSwapsInfo(msgTx *wire.MsgTx, outputSpenders map[uint32]*OutputSpenderTxOut, params *chaincfg.Params) (*TxSwapResults, error)
func (*TxSwapResults) ToAPI ¶
func (tsr *TxSwapResults) ToAPI() *TxAtomicSwaps
type TxWithBlockData ¶
TxWithBlockData contains a MsgTx and the block hash and height in which it was mined and Time it entered MemPool.
func (*TxWithBlockData) Confirmed ¶
func (t *TxWithBlockData) Confirmed() bool
Confirmed indicates if the transaction is confirmed (mined).
func (*TxWithBlockData) Hash ¶
func (t *TxWithBlockData) Hash() chainhash.Hash
Hash returns the chainhash.Hash of the transaction.
type TxnsStore ¶
type TxnsStore map[chainhash.Hash]*TxWithBlockData
TxnsStore allows quick lookup of a TxWithBlockData by transaction Hash.
type VerboseTransactionGetter ¶
type VerboseTransactionGetter interface {
GetRawTransactionVerbose(ctx context.Context, txHash *chainhash.Hash) (*chainjson.TxRawResult, error)
}
VerboseTransactionGetter is an interface satisfied by rpcclient.Client, and required by functions that would otherwise require a rpcclient.Client just for GetRawTransactionVerbose.
type VerboseTransactionPromiseGetter ¶
type VerboseTransactionPromiseGetter interface {
GetRawTransactionVerbosePromise(ctx context.Context, txHash *chainhash.Hash) VerboseTxReceiver
}
VerboseTransactionPromiseGetter is required by functions that would otherwise require a rpcclient.Client just for GetRawTransactionVerboseAsync. You may construct a simple wrapper for an rpcclient.Client with rpcutils.NewAsyncTxClient like:
type mempoolClient struct { *rpcclient.Client } func (cl *mempoolClient) GetRawTransactionVerbosePromise(ctx context.Context, txHash *chainhash.Hash) txhelpers.VerboseTxReceiver { return cl.Client.GetRawTransactionVerboseAsync(ctx, txHash) } var _ VerboseTransactionPromiseGetter = (*mempoolClient)(nil)
type VerboseTxReceiver ¶
type VerboseTxReceiver interface {
Receive() (*chainjson.TxRawResult, error)
}
VerboseTxReceiver is satisfied by the return type from GetRawTransactionVerboseAsync (rpcclient.FutureGetRawTransactionVerboseResult).
type VoteChoice ¶
type VoteChoice struct { // Single unique word identifying the vote. ID string `json:"id"` // Longer description of what the vote is about. Description string `json:"description"` // Usable bits for this vote. Mask uint16 `json:"mask"` // VoteVersion and VoteIndex specify which vote item is referenced by this // VoteChoice (i.e. chaincfg.Params.Deployments[VoteVersion][VoteIndex]). VoteVersion uint32 `json:"vote_version"` VoteIndex int `json:"vote_index"` // ChoiceIdx indicates the corresponding element in the vote item's []Choice ChoiceIdx int `json:"choice_index"` // Choice is the selected choice for the specified vote item Choice *chaincfg.Choice `json:"choice"` }
VoteChoice represents the choice made by a vote transaction on a single vote item in an agenda. The ID, Description, and Mask fields describe the vote item for which the choice is being made. Those are the initial fields in chaincfg.Params.Deployments[VoteVersion][VoteIndex].