decred.org/dcrwallet/v3@v3.1.0/wallet/common.go (about) 1 // Copyright (c) 2016 The Decred developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package wallet 6 7 import ( 8 "time" 9 10 "github.com/decred/dcrd/chaincfg/chainhash" 11 "github.com/decred/dcrd/dcrutil/v4" 12 "github.com/decred/dcrd/txscript/v4/stdaddr" 13 "github.com/decred/dcrd/wire" 14 ) 15 16 // Note: The following common types should never reference the Wallet type. 17 // Long term goal is to move these to their own package so that the database 18 // access APIs can create them directly for the wallet to return. 19 20 // BlockIdentity identifies a block, or the lack of one (used to describe an 21 // unmined transaction). 22 type BlockIdentity struct { 23 Hash chainhash.Hash 24 Height int32 25 } 26 27 // None returns whether there is no block described by the instance. When 28 // associated with a transaction, this indicates the transaction is unmined. 29 func (b *BlockIdentity) None() bool { 30 // BUG: Because dcrwallet uses both 0 and -1 in various places to refer 31 // to an unmined transaction this must check against both and may not 32 // ever be usable to represent the genesis block. 33 return *b == BlockIdentity{Height: -1} || *b == BlockIdentity{} 34 } 35 36 // OutputKind describes a kind of transaction output. This is used to 37 // differentiate between coinbase, stakebase, and normal outputs. 38 type OutputKind byte 39 40 // Defined OutputKind constants 41 const ( 42 OutputKindNormal OutputKind = iota 43 OutputKindCoinbase 44 OutputKindStakebase // not returned by all APIs yet 45 ) 46 47 // TransactionOutput describes an output that was or is at least partially 48 // controlled by the wallet. Depending on context, this could refer to an 49 // unspent output, or a spent one. 50 type TransactionOutput struct { 51 OutPoint wire.OutPoint 52 Output wire.TxOut 53 OutputKind OutputKind 54 // These should be added later when the DB can return them more 55 // efficiently: 56 // TxLockTime uint32 57 // TxExpiry uint32 58 ContainingBlock BlockIdentity 59 ReceiveTime time.Time 60 } 61 62 // OutputRedeemer identifies the transaction input which redeems an output. 63 type OutputRedeemer struct { 64 TxHash chainhash.Hash 65 InputIndex uint32 66 } 67 68 // P2SHMultiSigOutput describes a transaction output with a pay-to-script-hash 69 // output script and an imported redemption script. Along with common details 70 // of the output, this structure also includes the P2SH address the script was 71 // created from and the number of signatures required to redeem it. 72 // 73 // TODO: Could be useful to return how many of the required signatures can be 74 // created by this wallet. 75 type P2SHMultiSigOutput struct { 76 // TODO: Add a TransactionOutput member to this struct and remove these 77 // fields which are duplicated by it. This improves consistency. Only 78 // not done now because wtxmgr APIs don't support an efficient way of 79 // fetching other Transactionoutput data together with the rest of the 80 // multisig info. 81 OutPoint wire.OutPoint 82 OutputAmount dcrutil.Amount 83 ContainingBlock BlockIdentity 84 85 P2SHAddress *stdaddr.AddressScriptHashV0 86 RedeemScript []byte 87 M, N uint8 // M of N signatures required to redeem 88 Redeemer *OutputRedeemer // nil unless spent 89 }