@@ -24,6 +24,8 @@ type TimeAPI struct {
2424 S dbtypes.TimeDef
2525}
2626
27+ var _ fmt.Stringer = TimeAPI {}
28+
2729// String formats the time in a human-friendly layout.
2830func (t TimeAPI ) String () string {
2931 return t .S .String ()
@@ -34,6 +36,9 @@ func (t TimeAPI) UNIX() int64 {
3436 return t .S .UNIX ()
3537}
3638
39+ var _ json.Marshaler = (* TimeAPI )(nil )
40+ var _ json.Unmarshaler = (* TimeAPI )(nil )
41+
3742// MarshalJSON is set as the default marshalling function for TimeAPI struct.
3843func (t * TimeAPI ) MarshalJSON () ([]byte , error ) {
3944 return json .Marshal (t .S .UNIX ())
@@ -83,6 +88,7 @@ type Tx struct {
8388 Block * BlockID `json:"block,omitempty"`
8489}
8590
91+ // Vin is an alias for dcrd's rpc/jsonrpc/types/v3.Vin type.
8692type Vin = chainjson.Vin
8793
8894// TxShort models info about transaction TxID
@@ -191,7 +197,7 @@ type Vout struct {
191197 N uint32 `json:"n"`
192198 Version uint16 `json:"version"`
193199 ScriptPubKeyDecoded ScriptPubKey `json:"scriptPubKey"`
194- Spend * TxInputID `json:"spend,omitempty"`
200+ Spend * TxInputID `json:"spend,omitempty"` // unused?
195201}
196202
197203// TxInputID specifies a transaction input as hash:vin_index.
@@ -380,19 +386,104 @@ type Address struct {
380386 Transactions []* AddressTxShort `json:"address_transactions"`
381387}
382388
389+ // ScriptSig models the signature script used to redeem a transaction output.
390+ // type ScriptSig struct {
391+ // Asm string `json:"asm,omitempty"`
392+ // Hex string `json:"hex,omitempty"`
393+ // }
394+
395+ // VinShort describes a transaction input with limited detail, for the address
396+ // txn API endpoints. In particular, there is no ScriptSig or Sequence, and the
397+ // string fields for Coinbase, Stakebase, and TreasurySpend are just booleans.
398+ type VinShort struct {
399+ Coinbase bool `json:"coinbase"`
400+ Stakebase bool `json:"stakebase"`
401+ Treasurybase bool `json:"treasurybase"`
402+ TreasurySpend bool `json:"treasuryspend"`
403+ Txid string `json:"txid"`
404+ Vout uint32 `json:"vout"`
405+ Tree int8 `json:"tree"`
406+ AmountIn float64 `json:"amountin"`
407+ BlockHeight * uint32 `json:"blockheight,omitempty"`
408+ BlockIndex * uint32 `json:"blockindex,omitempty"`
409+ // No ScriptSig or Sequence
410+ }
411+
412+ // MarshalJSON is used to marshal a Vin to JSON with special handling for when
413+ // the these are generate coins (should be zero txid).
414+ func (v * VinShort ) MarshalJSON () ([]byte , error ) {
415+ switch {
416+ case v .Coinbase :
417+ generated := struct {
418+ Coinbase bool `json:"coinbase"`
419+ AmountIn float64 `json:"amountin"`
420+ }{
421+ Coinbase : true ,
422+ AmountIn : v .AmountIn ,
423+ }
424+ return json .Marshal (generated )
425+ case v .Stakebase :
426+ generated := struct {
427+ Stakebase bool `json:"stakebase"`
428+ AmountIn float64 `json:"amountin"`
429+ }{
430+ Stakebase : true ,
431+ AmountIn : v .AmountIn ,
432+ }
433+ return json .Marshal (generated )
434+ case v .Treasurybase :
435+ generated := struct {
436+ Treasurybase bool `json:"treasurybase"`
437+ AmountIn float64 `json:"amountin"`
438+ }{
439+ Treasurybase : true ,
440+ AmountIn : v .AmountIn ,
441+ }
442+ return json .Marshal (generated )
443+ case v .TreasurySpend :
444+ generated := struct {
445+ TreasurySpend bool `json:"treasuryspend"`
446+ AmountIn float64 `json:"amountin"`
447+ }{
448+ TreasurySpend : true ,
449+ AmountIn : v .AmountIn ,
450+ }
451+ return json .Marshal (generated )
452+
453+ }
454+
455+ return json .Marshal (struct {
456+ Txid string `json:"txid"`
457+ Vout uint32 `json:"vout"`
458+ Tree int8 `json:"tree"`
459+ AmountIn float64 `json:"amountin"`
460+ BlockHeight * uint32 `json:"blockheight,omitempty"`
461+ BlockIndex * uint32 `json:"blockindex,omitempty"`
462+ }{
463+ Txid : v .Txid ,
464+ Vout : v .Vout ,
465+ Tree : v .Tree ,
466+ AmountIn : v .AmountIn ,
467+ BlockHeight : v .BlockHeight ,
468+ BlockIndex : v .BlockIndex ,
469+ })
470+ }
471+
383472// AddressTxRaw is modeled from SearchRawTransactionsResult but with size in
384- // place of hex
473+ // place of hex, and a limited vin structure.
385474type AddressTxRaw struct {
386- Size int32 `json:"size"`
387- TxID string `json:"txid"`
388- Version int32 `json:"version"`
389- Locktime uint32 `json:"locktime"`
390- Vin []chainjson.VinPrevOut `json:"vin"`
391- Vout []Vout `json:"vout"`
392- Confirmations int64 `json:"confirmations"`
393- BlockHash string `json:"blockhash"`
394- Time TimeAPI `json:"time,omitempty"`
395- Blocktime TimeAPI `json:"blocktime,omitempty"`
475+ Size int32 `json:"size"`
476+ TxID string `json:"txid"`
477+ Version int32 `json:"version"`
478+ Locktime uint32 `json:"locktime"`
479+ Type int32 `json:"type"`
480+ Vin []VinShort `json:"vin"`
481+ Vout []Vout `json:"vout"`
482+ Confirmations int64 `json:"confirmations"`
483+ BlockHash string `json:"blockhash,omitempty"`
484+ Time TimeAPI `json:"time,omitempty"` // for mempool txns?
485+ Blocktime * TimeAPI `json:"blocktime,omitempty"` // vs mined?
486+ // BlockHeight int64 `json:"blockheight"`
396487}
397488
398489// AddressTxShort is a subset of AddressTxRaw with just the basic tx details
@@ -438,37 +529,6 @@ type TxRawWithTxType struct {
438529 TxType string
439530}
440531
441- // ScriptSig models the signature script used to redeem the origin transaction
442- // as a JSON object (non-coinbase txns only)
443- type ScriptSig struct {
444- Asm string `json:"asm,omitempty"`
445- Hex string `json:"hex,omitempty"`
446- }
447-
448- // PrevOut represents previous output for an input Vin.
449- type PrevOut struct {
450- Addresses []string `json:"addresses,omitempty"`
451- Value float64 `json:"value"`
452- }
453-
454- // VinPrevOut is like Vin except it includes PrevOut. It is used by
455- // searchrawtransaction
456- type VinPrevOut struct {
457- Coinbase string `json:"coinbase"`
458- Stakebase string `json:"stakebase"`
459- Txid string `json:"txid"`
460- Vout uint32 `json:"vout"`
461- Tree int8 `json:"tree"`
462- AmountIn * float64 `json:"amountin,omitempty"`
463- BlockHeight * uint32 `json:"blockheight,omitempty"`
464- BlockIndex * uint32 `json:"blockindex,omitempty"`
465- ScriptSig * ScriptSig `json:"scriptSig"`
466- PrevOut * PrevOut `json:"prevOut"`
467- Sequence uint32 `json:"sequence"`
468- }
469-
470- // end copy-paste from chainjson
471-
472532// Status indicates the state of the server. All fields are mutex protected and
473533// and should be set with the getters and setters.
474534type Status struct {
0 commit comments