decred.org/dcrdex@v1.0.5/server/asset/dcr/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 dcr 5 6 import ( 7 "github.com/decred/dcrd/chaincfg/chainhash" 8 ) 9 10 // Tx is information about a transaction. It must satisfy the asset.DEXTx 11 // interface to be DEX-compatible. 12 type Tx struct { 13 // The height and hash of the transaction's best known block. 14 blockHash chainhash.Hash 15 height int64 16 // The transaction hash. 17 hash chainhash.Hash 18 // Transaction inputs and outputs. 19 ins []txIn 20 outs []txOut 21 // Whether the transaction is a stake-related transaction. 22 isStake bool 23 isCoinbase bool 24 // Used to conditionally skip block lookups on mempool transactions during 25 // calls to Confirmations. 26 lastLookup *chainhash.Hash 27 // The calculated transaction fee rate, in atoms/byte 28 feeRate uint64 29 // raw is the raw tx bytes. 30 raw []byte 31 } 32 33 // A txIn holds information about a transaction input, mainly to verify which 34 // previous outpoint is being spent. 35 type txIn struct { 36 prevTx chainhash.Hash 37 vout uint32 38 value uint64 39 } 40 41 // A txOut holds information about a transaction output. 42 type txOut struct { 43 value uint64 44 version uint16 45 pkScript []byte 46 } 47 48 // A getter for a new Tx. 49 func newTransaction(txHash, blockHash, lastLookup *chainhash.Hash, blockHeight int64, 50 isStake, isCoinbase bool, ins []txIn, outs []txOut, feeRate uint64, rawTx []byte) *Tx { 51 // Set a nil blockHash to the zero hash. 52 hash := blockHash 53 if hash == nil { 54 hash = &zeroHash 55 } 56 return &Tx{ 57 blockHash: *hash, 58 height: blockHeight, 59 hash: *txHash, 60 ins: ins, 61 outs: outs, 62 isStake: isStake, 63 isCoinbase: isCoinbase, 64 lastLookup: lastLookup, 65 feeRate: feeRate, 66 raw: rawTx, 67 } 68 }