Add boolean flag isAddress vin and vout in API #209
parent
d6883a5f35
commit
104f6f9a9d
24
api/types.go
24
api/types.go
|
@ -101,17 +101,17 @@ func (a *Amount) AsInt64() int64 {
|
|||
|
||||
// Vin contains information about single transaction input
|
||||
type Vin struct {
|
||||
Txid string `json:"txid,omitempty"`
|
||||
Vout uint32 `json:"vout,omitempty"`
|
||||
Sequence int64 `json:"sequence,omitempty"`
|
||||
N int `json:"n"`
|
||||
AddrDesc bchain.AddressDescriptor `json:"-"`
|
||||
Addresses []string `json:"addresses,omitempty"`
|
||||
Searchable bool `json:"-"`
|
||||
ValueSat *Amount `json:"value,omitempty"`
|
||||
Hex string `json:"hex,omitempty"`
|
||||
Asm string `json:"asm,omitempty"`
|
||||
Coinbase string `json:"coinbase,omitempty"`
|
||||
Txid string `json:"txid,omitempty"`
|
||||
Vout uint32 `json:"vout,omitempty"`
|
||||
Sequence int64 `json:"sequence,omitempty"`
|
||||
N int `json:"n"`
|
||||
AddrDesc bchain.AddressDescriptor `json:"-"`
|
||||
Addresses []string `json:"addresses,omitempty"`
|
||||
IsAddress bool `json:"isAddress"`
|
||||
ValueSat *Amount `json:"value,omitempty"`
|
||||
Hex string `json:"hex,omitempty"`
|
||||
Asm string `json:"asm,omitempty"`
|
||||
Coinbase string `json:"coinbase,omitempty"`
|
||||
}
|
||||
|
||||
// Vout contains information about single transaction output
|
||||
|
@ -126,7 +126,7 @@ type Vout struct {
|
|||
Asm string `json:"asm,omitempty"`
|
||||
AddrDesc bchain.AddressDescriptor `json:"-"`
|
||||
Addresses []string `json:"addresses"`
|
||||
Searchable bool `json:"-"`
|
||||
IsAddress bool `json:"isAddress"`
|
||||
Type string `json:"type,omitempty"`
|
||||
}
|
||||
|
||||
|
|
|
@ -13,26 +13,26 @@ type ScriptSigV1 struct {
|
|||
|
||||
// VinV1 is used for legacy api v1
|
||||
type VinV1 struct {
|
||||
Txid string `json:"txid"`
|
||||
Vout uint32 `json:"vout"`
|
||||
Sequence int64 `json:"sequence,omitempty"`
|
||||
N int `json:"n"`
|
||||
ScriptSig ScriptSigV1 `json:"scriptSig"`
|
||||
AddrDesc bchain.AddressDescriptor `json:"-"`
|
||||
Addresses []string `json:"addresses"`
|
||||
Searchable bool `json:"-"`
|
||||
Value string `json:"value"`
|
||||
ValueSat big.Int `json:"-"`
|
||||
Txid string `json:"txid"`
|
||||
Vout uint32 `json:"vout"`
|
||||
Sequence int64 `json:"sequence,omitempty"`
|
||||
N int `json:"n"`
|
||||
ScriptSig ScriptSigV1 `json:"scriptSig"`
|
||||
AddrDesc bchain.AddressDescriptor `json:"-"`
|
||||
Addresses []string `json:"addresses"`
|
||||
IsAddress bool `json:"-"`
|
||||
Value string `json:"value"`
|
||||
ValueSat big.Int `json:"-"`
|
||||
}
|
||||
|
||||
// ScriptPubKeyV1 is used for legacy api v1
|
||||
type ScriptPubKeyV1 struct {
|
||||
Hex string `json:"hex,omitempty"`
|
||||
Asm string `json:"asm,omitempty"`
|
||||
AddrDesc bchain.AddressDescriptor `json:"-"`
|
||||
Addresses []string `json:"addresses"`
|
||||
Searchable bool `json:"-"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Hex string `json:"hex,omitempty"`
|
||||
Asm string `json:"asm,omitempty"`
|
||||
AddrDesc bchain.AddressDescriptor `json:"-"`
|
||||
Addresses []string `json:"addresses"`
|
||||
IsAddress bool `json:"-"`
|
||||
Type string `json:"type,omitempty"`
|
||||
}
|
||||
|
||||
// VoutV1 is used for legacy api v1
|
||||
|
@ -115,12 +115,12 @@ func (w *Worker) TxToV1(tx *Tx) *TxV1 {
|
|||
Asm: v.Asm,
|
||||
Hex: v.Hex,
|
||||
},
|
||||
Searchable: v.Searchable,
|
||||
Sequence: v.Sequence,
|
||||
Txid: v.Txid,
|
||||
Value: v.ValueSat.DecimalString(d),
|
||||
ValueSat: v.ValueSat.AsBigInt(),
|
||||
Vout: v.Vout,
|
||||
IsAddress: v.IsAddress,
|
||||
Sequence: v.Sequence,
|
||||
Txid: v.Txid,
|
||||
Value: v.ValueSat.DecimalString(d),
|
||||
ValueSat: v.ValueSat.AsBigInt(),
|
||||
Vout: v.Vout,
|
||||
}
|
||||
}
|
||||
voutV1 := make([]VoutV1, len(tx.Vout))
|
||||
|
@ -129,12 +129,12 @@ func (w *Worker) TxToV1(tx *Tx) *TxV1 {
|
|||
voutV1[i] = VoutV1{
|
||||
N: v.N,
|
||||
ScriptPubKey: ScriptPubKeyV1{
|
||||
AddrDesc: v.AddrDesc,
|
||||
Addresses: v.Addresses,
|
||||
Asm: v.Asm,
|
||||
Hex: v.Hex,
|
||||
Searchable: v.Searchable,
|
||||
Type: v.Type,
|
||||
AddrDesc: v.AddrDesc,
|
||||
Addresses: v.Addresses,
|
||||
Asm: v.Asm,
|
||||
Hex: v.Hex,
|
||||
IsAddress: v.IsAddress,
|
||||
Type: v.Type,
|
||||
},
|
||||
Spent: v.Spent,
|
||||
SpentHeight: v.SpentHeight,
|
||||
|
|
|
@ -166,7 +166,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
|
|||
if err == bchain.ErrTxNotFound {
|
||||
// try to get AddrDesc using coin specific handling and continue processing the tx
|
||||
vin.AddrDesc = w.chainParser.GetAddrDescForUnknownInput(bchainTx, i)
|
||||
vin.Addresses, vin.Searchable, err = w.chainParser.GetAddressesFromAddrDesc(vin.AddrDesc)
|
||||
vin.Addresses, vin.IsAddress, err = w.chainParser.GetAddressesFromAddrDesc(vin.AddrDesc)
|
||||
if err != nil {
|
||||
glog.Warning("GetAddressesFromAddrDesc tx ", bchainVin.Txid, ", addrDesc ", vin.AddrDesc, ": ", err)
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
|
|||
if len(otx.Vout) > int(vin.Vout) {
|
||||
vout := &otx.Vout[vin.Vout]
|
||||
vin.ValueSat = (*Amount)(&vout.ValueSat)
|
||||
vin.AddrDesc, vin.Addresses, vin.Searchable, err = w.getAddressesFromVout(vout)
|
||||
vin.AddrDesc, vin.Addresses, vin.IsAddress, err = w.getAddressesFromVout(vout)
|
||||
if err != nil {
|
||||
glog.Errorf("getAddressesFromVout error %v, vout %+v", err, vout)
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
|
|||
output := &tas.Outputs[vin.Vout]
|
||||
vin.ValueSat = (*Amount)(&output.ValueSat)
|
||||
vin.AddrDesc = output.AddrDesc
|
||||
vin.Addresses, vin.Searchable, err = output.Addresses(w.chainParser)
|
||||
vin.Addresses, vin.IsAddress, err = output.Addresses(w.chainParser)
|
||||
if err != nil {
|
||||
glog.Errorf("output.Addresses error %v, tx %v, output %v", err, bchainVin.Txid, i)
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
|
|||
glog.Errorf("GetAddrDescFromAddress error %v, tx %v, bchainVin %v", err, bchainTx.Txid, bchainVin)
|
||||
}
|
||||
vin.Addresses = bchainVin.Addresses
|
||||
vin.Searchable = true
|
||||
vin.IsAddress = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
|
|||
vout.ValueSat = (*Amount)(&bchainVout.ValueSat)
|
||||
valOutSat.Add(&valOutSat, &bchainVout.ValueSat)
|
||||
vout.Hex = bchainVout.ScriptPubKey.Hex
|
||||
vout.AddrDesc, vout.Addresses, vout.Searchable, err = w.getAddressesFromVout(bchainVout)
|
||||
vout.AddrDesc, vout.Addresses, vout.IsAddress, err = w.getAddressesFromVout(bchainVout)
|
||||
if err != nil {
|
||||
glog.V(2).Infof("getAddressesFromVout error %v, %v, output %v", err, bchainTx.Txid, bchainVout.N)
|
||||
}
|
||||
|
@ -433,7 +433,7 @@ func (w *Worker) txFromTxAddress(txid string, ta *db.TxAddresses, bi *db.BlockIn
|
|||
vin.N = i
|
||||
vin.ValueSat = (*Amount)(&tai.ValueSat)
|
||||
valInSat.Add(&valInSat, &tai.ValueSat)
|
||||
vin.Addresses, vin.Searchable, err = tai.Addresses(w.chainParser)
|
||||
vin.Addresses, vin.IsAddress, err = tai.Addresses(w.chainParser)
|
||||
if err != nil {
|
||||
glog.Errorf("tai.Addresses error %v, tx %v, input %v, tai %+v", err, txid, i, tai)
|
||||
}
|
||||
|
@ -445,7 +445,7 @@ func (w *Worker) txFromTxAddress(txid string, ta *db.TxAddresses, bi *db.BlockIn
|
|||
vout.N = i
|
||||
vout.ValueSat = (*Amount)(&tao.ValueSat)
|
||||
valOutSat.Add(&valOutSat, &tao.ValueSat)
|
||||
vout.Addresses, vout.Searchable, err = tao.Addresses(w.chainParser)
|
||||
vout.Addresses, vout.IsAddress, err = tao.Addresses(w.chainParser)
|
||||
if err != nil {
|
||||
glog.Errorf("tai.Addresses error %v, tx %v, output %v, tao %+v", err, txid, i, tao)
|
||||
}
|
||||
|
|
23
docs/api.md
23
docs/api.md
|
@ -131,6 +131,7 @@ Response for Bitcoin-type coins:
|
|||
"addresses": [
|
||||
"DDhUv8JZGmSxKYV95NLnbRTUKni9cDZD3S"
|
||||
],
|
||||
"isAddress": true,
|
||||
"value": "55795108999999",
|
||||
"hex": "473...2c7ec77bb982"
|
||||
}
|
||||
|
@ -142,7 +143,8 @@ Response for Bitcoin-type coins:
|
|||
"hex": "76a914feaca9d9fa7120c7c587c00c639bb18d40faadd388ac",
|
||||
"addresses": [
|
||||
"DUMh1rPrXTrCN2Z9EHsLPg7b78rACHB2h7"
|
||||
]
|
||||
],
|
||||
"isAddress": true
|
||||
},
|
||||
{
|
||||
"value": "209329999999",
|
||||
|
@ -150,7 +152,8 @@ Response for Bitcoin-type coins:
|
|||
"hex": "76a914ea8984be785868391d92f49c14933f47c152ea0a88ac",
|
||||
"addresses": [
|
||||
"DSXDQ6rnwLX47WFRnemctoXPHA9pLMxqXn"
|
||||
]
|
||||
],
|
||||
"isAddress": true
|
||||
}
|
||||
],
|
||||
"blockHash": "78d1f3de899a10dd2e580704226ebf9508e95e1706f177fc9c31c47f245d2502",
|
||||
|
@ -174,7 +177,8 @@ Response for Ethereum-type coins. There is always only one *vin*, only one *vout
|
|||
"n": 0,
|
||||
"addresses": [
|
||||
"0x9c2e011c0ce0d75c2b62b9c5a0ba0a7456593803"
|
||||
]
|
||||
],
|
||||
"isAddress": true
|
||||
}
|
||||
],
|
||||
"vout": [
|
||||
|
@ -183,7 +187,8 @@ Response for Ethereum-type coins. There is always only one *vin*, only one *vout
|
|||
"n": 0,
|
||||
"addresses": [
|
||||
"0xc32ae45504ee9482db99cfa21066a59e877bc0e6"
|
||||
]
|
||||
],
|
||||
"isAddress": true
|
||||
}
|
||||
],
|
||||
"blockHash": "0x39df7fb0893200e1e78c04f98691637a89b64e7a3edd96c16f2537e2fd56c414",
|
||||
|
@ -477,7 +482,8 @@ Response:
|
|||
"n": 0,
|
||||
"addresses": [
|
||||
"D6ravJL6Fgxtgp8k2XZZt1QfUmwwGuLwQJ"
|
||||
]
|
||||
],
|
||||
"isAddress": true
|
||||
}
|
||||
],
|
||||
"blockHash": "760f8ed32894ccce9c1ea11c8a019cadaa82bcb434b25c30102dd7e43f326217",
|
||||
|
@ -496,6 +502,7 @@ Response:
|
|||
"addresses": [
|
||||
"9sLa1AKzjWuNTe1CkLh5GDYyRP9enb1Spp"
|
||||
],
|
||||
"isAddress": true,
|
||||
"value": "1277595845202"
|
||||
}
|
||||
],
|
||||
|
@ -505,7 +512,8 @@ Response:
|
|||
"n": 0,
|
||||
"addresses": [
|
||||
"DMnjrbcCEoeyvr7GEn8DS4ZXQjwq7E2zQU"
|
||||
]
|
||||
],
|
||||
"isAddress": true
|
||||
},
|
||||
{
|
||||
"value": "1267595845202",
|
||||
|
@ -513,7 +521,8 @@ Response:
|
|||
"spent": true,
|
||||
"addresses": [
|
||||
"9sLa1AKzjWuNTe1CkLh5GDYyRP9enb1Spp"
|
||||
]
|
||||
],
|
||||
"isAddress": true
|
||||
}
|
||||
],
|
||||
"blockHash": "760f8ed32894ccce9c1ea11c8a019cadaa82bcb434b25c30102dd7e43f326217",
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -19,7 +19,7 @@
|
|||
{{- end -}}
|
||||
{{- range $a := $vin.Addresses -}}
|
||||
<span class="ellipsis tx-addr">
|
||||
{{if and (ne $a $addr) $vin.Searchable}}<a href="/address/{{$a}}">{{$a}}</a>{{else}}{{$a}}{{end}}
|
||||
{{if and (ne $a $addr) $vin.IsAddress}}<a href="/address/{{$a}}">{{$a}}</a>{{else}}{{$a}}{{end}}
|
||||
</span>
|
||||
{{- else -}}
|
||||
<span class="tx-addr">{{- if $vin.Hex -}}Unparsed address{{- else -}}No Inputs (Newly Generated Coins){{- end -}}</span>
|
||||
|
@ -51,7 +51,7 @@
|
|||
<td>
|
||||
{{- range $a := $vout.Addresses -}}
|
||||
<span class="ellipsis tx-addr">
|
||||
{{- if and (ne $a $addr) $vout.Searchable}}<a href="/address/{{$a}}">{{$a}}</a>{{else}}{{$a}}{{- end -}}
|
||||
{{- if and (ne $a $addr) $vout.IsAddress}}<a href="/address/{{$a}}">{{$a}}</a>{{else}}{{$a}}{{- end -}}
|
||||
</span>
|
||||
{{- else -}}
|
||||
<span class="tx-addr">Unparsed address</span>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<td>
|
||||
{{- range $a := $vin.Addresses -}}
|
||||
<span class="ellipsis tx-addr">
|
||||
{{if and (ne $a $addr) $vin.Searchable}}<a href="/address/{{$a}}">{{$a}}</a>{{else}}{{$a}}{{end}}
|
||||
{{if and (ne $a $addr) $vin.IsAddress}}<a href="/address/{{$a}}">{{$a}}</a>{{else}}{{$a}}{{end}}
|
||||
</span>
|
||||
{{- else -}}
|
||||
<span class="tx-addr">Unparsed address</span>
|
||||
|
@ -47,7 +47,7 @@
|
|||
<td>
|
||||
{{- range $a := $vout.Addresses -}}
|
||||
<span class="ellipsis tx-addr">
|
||||
{{- if and (ne $a $addr) $vout.Searchable}}<a href="/address/{{$a}}">{{$a}}</a>{{else}}{{$a}}{{- end -}}
|
||||
{{- if and (ne $a $addr) $vout.IsAddress}}<a href="/address/{{$a}}">{{$a}}</a>{{else}}{{$a}}{{- end -}}
|
||||
</span>
|
||||
{{- else -}}
|
||||
<span class="tx-addr">Unparsed address</span>
|
||||
|
|
Loading…
Reference in New Issue