decred.org/dcrdex@v1.0.5/client/asset/btc/wallettypes.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  )
     9  
    10  // GetBalancesResult models a successful response from the getbalances request.
    11  type GetBalancesResult struct {
    12  	Mine      Balances `json:"mine"`
    13  	WatchOnly Balances `json:"watchonly"`
    14  }
    15  
    16  // Balances is a categorical balance breakdown.
    17  type Balances struct {
    18  	Trusted   float64  `json:"trusted"`
    19  	Untrusted float64  `json:"untrusted_pending"`
    20  	Immature  float64  `json:"immature"`
    21  	Used      *float64 `json:"used,omitempty"`
    22  }
    23  
    24  // ListUnspentResult models a successful response from the listunspent request.
    25  type ListUnspentResult struct {
    26  	TxID          string    `json:"txid"`
    27  	Vout          uint32    `json:"vout"`
    28  	Address       string    `json:"address"`
    29  	Label         string    `json:"label"`
    30  	ScriptPubKey  dex.Bytes `json:"scriptPubKey"`
    31  	Amount        float64   `json:"amount"`
    32  	Confirmations uint32    `json:"confirmations"`
    33  	RedeemScript  dex.Bytes `json:"redeemScript"`
    34  	Spendable     bool      `json:"spendable"`
    35  	Solvable      bool      `json:"solvable"`
    36  	SafePtr       *bool     `json:"safe"`
    37  }
    38  
    39  func (l *ListUnspentResult) Safe() bool {
    40  	return l.SafePtr == nil || *l.SafePtr
    41  }
    42  
    43  // ListTransactionsResult is similar to the btcjson.ListTransactionsResult, but
    44  // most fields omitted.
    45  type ListTransactionsResult struct {
    46  	BlockHeight uint32   `json:"blockheight"`
    47  	BlockTime   uint64   `json:"blocktime"`
    48  	Fee         *float64 `json:"fee,omitempty"`
    49  	// Send set to true means that the inputs of the transaction were
    50  	// controlled by the wallet.
    51  	Send bool   `json:"send"`
    52  	TxID string `json:"txid"`
    53  }
    54  
    55  // SignTxResult models the data from the signrawtransaction command.
    56  type SignTxResult struct {
    57  	Hex      dex.Bytes      `json:"hex"`
    58  	Complete bool           `json:"complete"`
    59  	Errors   []*SignTxError `json:"errors"`
    60  }
    61  
    62  // SignTxError models the data that contains script verification errors from the
    63  // signrawtransaction request
    64  type SignTxError struct {
    65  	TxID      string    `json:"txid"`
    66  	Vout      uint32    `json:"vout"`
    67  	ScriptSig dex.Bytes `json:"scriptSig"`
    68  	Sequence  uint64    `json:"sequence"`
    69  	Error     string    `json:"error"`
    70  }
    71  
    72  // GetTransactionResult models the required data from the gettransaction
    73  // command. Several fields from the bitcoind/btcwallet response that are both
    74  // unneeded and difficult to satisfy are omitted. e.g. the native btcwallet and
    75  // the external Electrum backends must jump through hoops to reproduce certain
    76  // fields that are not strictly necessary.
    77  type GetTransactionResult struct {
    78  	// The meaning of Amount and Fee for "wallet" transactions is iffy (and they
    79  	// are unused), so we are going to ignore them.  We have the raw tx (Hex) if
    80  	// it is necessary to compute amounts from the inputs and outputs.
    81  	// Amount         float64   `json:"amount"`
    82  	// Fee            float64   `json:"fee"`
    83  	Confirmations uint64 `json:"confirmations"`
    84  	BlockHash     string `json:"blockhash"`
    85  	BlockIndex    int64  `json:"blockindex"` // unused, consider commenting
    86  	BlockTime     uint64 `json:"blocktime"`
    87  	// BlockHeight   uint64    `json:"blockheight"` // unused, potentially work to obtain
    88  	TxID         string    `json:"txid"`
    89  	Time         uint64    `json:"time"`
    90  	TimeReceived uint64    `json:"timereceived"`
    91  	Bytes        dex.Bytes `json:"hex"` // []byte, although it marshals/unmarshals a hex string
    92  	// BipReplaceable string    `json:"bip125-replaceable"` // unused
    93  	// Details        []*WalletTxDetails `json:"details"` // unused, and nearly impossible to satisfy in a generic interface
    94  }
    95  
    96  // RPCOutpoint is used to specify outputs to lock in calls to lockunspent.
    97  type RPCOutpoint struct {
    98  	TxID string `json:"txid"`
    99  	Vout uint32 `json:"vout"`
   100  }
   101  
   102  // GetWalletInfoResult models the data from the getwalletinfo command.
   103  type GetWalletInfoResult struct {
   104  	WalletName            string  `json:"walletname"`
   105  	WalletVersion         uint32  `json:"walletversion"`
   106  	Format                string  `json:"format"`
   107  	Balance               float64 `json:"balance"`
   108  	UnconfirmedBalance    float64 `json:"unconfirmed_balance"`
   109  	ImmatureBalance       float64 `json:"immature_balance"`
   110  	TxCount               uint32  `json:"txcount"`
   111  	KeyPoolOldest         uint64  `json:"keypoololdest"`
   112  	KeyPoolSize           uint32  `json:"keypoolsize"`
   113  	KeyPoolSizeHDInternal uint32  `json:"keypoolsize_hd_internal"`
   114  	PayTxFee              float64 `json:"paytxfee"`
   115  	HdSeedID              string  `json:"hdseedid"`
   116  	// UnlockedUntil is a pointer because for encrypted locked wallets, it will
   117  	// be zero, but for unencrypted wallets the field won't be present in the
   118  	// response.
   119  	UnlockedUntil *int64 `json:"unlocked_until"`
   120  	// HDMasterKeyID is dropped in Bitcoin Core 0.18
   121  	HdMasterKeyID     string `json:"hdmasterkeyid"`
   122  	PriveyKeysEnabled bool   `json:"private_keys_enabled"`
   123  	// AvoidReuse and Scanning were added in Bitcoin Core 0.19
   124  	AvoidReuse bool `json:"avoid_reuse"`
   125  	// Scanning is either a struct or boolean false, and since we're not using
   126  	// it, commenting avoids having to deal with marshaling for now.
   127  	// Scanning   struct {
   128  	// 	Duration uint32  `json:"duration"`
   129  	// 	Progress float32 `json:"progress"`
   130  	// } `json:"scanning"`
   131  	Descriptors bool `json:"descriptors"` // Descriptor wallets that do not support dumpprivkey
   132  }
   133  
   134  // GetAddressInfoResult models some of the data from the getaddressinfo command.
   135  type GetAddressInfoResult struct {
   136  	IsMine     bool   `json:"ismine"`
   137  	Descriptor string `json:"desc"` // e.g. "wpkh([b940190e/84'/1'/0'/0/0]0300034...)#0pfw7rck"
   138  
   139  	// The following fields are unused by DEX, but modeled here for completeness
   140  	// and debugging:
   141  
   142  	ParentDesc          string `json:"parent_desc"`         // e.g. "wpkh([b940190e/84'/1'/0']tpubDCo.../0/*)#xn4kr3dw" meaning range of external addresses
   143  	HDKeyPath           string `json:"hdkeypath"`           // e.g. "m/84'/1'/0'/0/0"
   144  	HDMasterFingerprint string `json:"hdmasterfingerprint"` // e.g. "b940190e"
   145  }
   146  
   147  type listDescriptorsResult struct {
   148  	WalletName  string `json:"wallet_name"`
   149  	Descriptors []*struct {
   150  		Descriptor string `json:"desc"` // public or private depending on private RPC arg
   151  
   152  		// The following fields are unused in this package, but they are modeled
   153  		// here for completeness and debugging:
   154  
   155  		TimeStamp int64 `json:"timestamp"` // creation time
   156  		// Active makes it the descriptor for the corresponding output
   157  		// type/externality e.g. wpkh. Must be true for "ranged" descriptors,
   158  		// which are those for address derivation. Conversely, imported single
   159  		// private keys are not active.
   160  		Active   bool    `json:"active"`
   161  		Internal bool    `json:"internal"` // i.e. change, only set when active
   162  		Range    []int64 `json:"range"`    // set for ranged descriptors, pertains to gap limit and current index
   163  		Next     int64   `json:"next"`     // next index to addresses generation; only set for ranged descriptors
   164  	} `json:"descriptors"`
   165  }