decred.org/dcrdex@v1.0.5/server/asset/btc/tx.go (about) 1 // This code is available on the terms of the project LICENSE.md file, 2 // also available online at https://blueoakcouncil.org/license/1.0.0. 3 4 package btc 5 6 import ( 7 "decred.org/dcrdex/dex" 8 "github.com/btcsuite/btcd/btcjson" 9 "github.com/btcsuite/btcd/chaincfg/chainhash" 10 ) 11 12 // Tx is information about a transaction. It must satisfy the asset.DEXTx 13 // interface to be DEX-compatible. 14 type Tx struct { 15 // Because a Tx's validity and block info can change after creation, keep a 16 // Backend around to query the state of the tx and update the block info. 17 btc *Backend 18 // The height and hash of the transaction's best known block. 19 blockHash chainhash.Hash 20 height int64 21 // The transaction hash. 22 hash chainhash.Hash 23 // Transaction inputs and outputs. 24 ins []txIn 25 outs []txOut 26 isCoinbase bool 27 // Used to conditionally skip block lookups on mempool transactions during 28 // calls to Confirmations. 29 lastLookup *chainhash.Hash 30 // The calculated transaction fee rate, in satoshis/vbyte 31 feeRate uint64 32 inputSum uint64 33 // raw is the raw tx bytes. 34 raw []byte 35 } 36 37 // A txIn holds information about a transaction input, mainly to verify which 38 // previous outpoint is being spent. 39 type txIn struct { 40 prevTx chainhash.Hash 41 vout uint32 42 value uint64 43 } 44 45 // A txOut holds information about a transaction output. 46 type txOut struct { 47 value uint64 48 pkScript []byte 49 } 50 51 // JoinSplit represents a Zcash JoinSplit. 52 // https://zips.z.cash/protocol/canopy.pdf section 4.11 53 type JoinSplit struct { 54 // Old = input 55 Old uint64 `json:"vpub_oldZat"` 56 // New = output 57 New uint64 `json:"vpub_newZat"` 58 } 59 60 // VerboseTxExtended is a subset of *btcjson.TxRawResult, with the addition of 61 // some asset-specific fields. 62 type VerboseTxExtended struct { 63 Raw dex.Bytes `json:"hex"` 64 Hex string 65 Txid string `json:"txid"` 66 Size int32 `json:"size,omitempty"` 67 Vsize int32 `json:"vsize,omitempty"` 68 Vin []*btcjson.Vin `json:"vin"` 69 Vout []*btcjson.Vout `json:"vout"` 70 BlockHash string `json:"blockhash,omitempty"` 71 Confirmations uint64 `json:"confirmations,omitempty"` 72 73 // Zcash-specific fields. 74 75 VJoinSplit []*JoinSplit `json:"vjoinsplit"` 76 ValueBalanceSapling int64 `json:"valueBalanceZat"` // Sapling pool 77 // ValueBalanceOrchard is disabled until zcashd encodes valueBalanceOrchard. 78 ValueBalanceOrchard int64 `json:"valueBalanceOrchardZat"` // Orchard pool 79 80 // Other fields that could be used but aren't right now. 81 82 // Hash string `json:"hash,omitempty"` 83 // Weight int32 `json:"weight,omitempty"` 84 // Version uint32 `json:"version"` 85 // LockTime uint32 `json:"locktime"` 86 // Time int64 `json:"time,omitempty"` 87 // Blocktime int64 `json:"blocktime,omitempty"` 88 } 89 90 // Currently disabled because the verbose getrawtransaction results for Zcash 91 // do not include the valueBalanceOrchard yet. 92 // https://github.com/zcash/zcash/pull/5969 93 // // ShieldedIO sums the Zcash shielded pool inputs and outputs. Will return 94 // // zeros for non-Zcash-protocol transactions. 95 // func (tx *VerboseTxExtended) ShieldedIO() (in, out uint64) { 96 // for _, js := range tx.VJoinSplit { 97 // in += js.New 98 // out += js.Old 99 // } 100 // if tx.ValueBalanceSapling > 0 { 101 // in += uint64(tx.ValueBalanceSapling) 102 // } else if tx.ValueBalanceSapling < 0 { 103 // out += uint64(-1 * tx.ValueBalanceSapling) 104 // } 105 // if tx.ValueBalanceOrchard > 0 { 106 // in += uint64(tx.ValueBalanceOrchard) 107 // } else if tx.ValueBalanceOrchard < 0 { 108 // out += uint64(-1 * tx.ValueBalanceOrchard) 109 // } 110 // return 111 // }