common.go raw

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