Add boolean flag isAddress vin and vout in API #209

This commit is contained in:
Martin Boehm 2019-06-19 14:15:56 +02:00
parent d6883a5f35
commit 104f6f9a9d
7 changed files with 73 additions and 64 deletions

View File

@ -101,17 +101,17 @@ func (a *Amount) AsInt64() int64 {
// Vin contains information about single transaction input // Vin contains information about single transaction input
type Vin struct { type Vin struct {
Txid string `json:"txid,omitempty"` Txid string `json:"txid,omitempty"`
Vout uint32 `json:"vout,omitempty"` Vout uint32 `json:"vout,omitempty"`
Sequence int64 `json:"sequence,omitempty"` Sequence int64 `json:"sequence,omitempty"`
N int `json:"n"` N int `json:"n"`
AddrDesc bchain.AddressDescriptor `json:"-"` AddrDesc bchain.AddressDescriptor `json:"-"`
Addresses []string `json:"addresses,omitempty"` Addresses []string `json:"addresses,omitempty"`
Searchable bool `json:"-"` IsAddress bool `json:"isAddress"`
ValueSat *Amount `json:"value,omitempty"` ValueSat *Amount `json:"value,omitempty"`
Hex string `json:"hex,omitempty"` Hex string `json:"hex,omitempty"`
Asm string `json:"asm,omitempty"` Asm string `json:"asm,omitempty"`
Coinbase string `json:"coinbase,omitempty"` Coinbase string `json:"coinbase,omitempty"`
} }
// Vout contains information about single transaction output // Vout contains information about single transaction output
@ -126,7 +126,7 @@ type Vout struct {
Asm string `json:"asm,omitempty"` Asm string `json:"asm,omitempty"`
AddrDesc bchain.AddressDescriptor `json:"-"` AddrDesc bchain.AddressDescriptor `json:"-"`
Addresses []string `json:"addresses"` Addresses []string `json:"addresses"`
Searchable bool `json:"-"` IsAddress bool `json:"isAddress"`
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
} }

View File

@ -13,26 +13,26 @@ type ScriptSigV1 struct {
// VinV1 is used for legacy api v1 // VinV1 is used for legacy api v1
type VinV1 struct { type VinV1 struct {
Txid string `json:"txid"` Txid string `json:"txid"`
Vout uint32 `json:"vout"` Vout uint32 `json:"vout"`
Sequence int64 `json:"sequence,omitempty"` Sequence int64 `json:"sequence,omitempty"`
N int `json:"n"` N int `json:"n"`
ScriptSig ScriptSigV1 `json:"scriptSig"` ScriptSig ScriptSigV1 `json:"scriptSig"`
AddrDesc bchain.AddressDescriptor `json:"-"` AddrDesc bchain.AddressDescriptor `json:"-"`
Addresses []string `json:"addresses"` Addresses []string `json:"addresses"`
Searchable bool `json:"-"` IsAddress bool `json:"-"`
Value string `json:"value"` Value string `json:"value"`
ValueSat big.Int `json:"-"` ValueSat big.Int `json:"-"`
} }
// ScriptPubKeyV1 is used for legacy api v1 // ScriptPubKeyV1 is used for legacy api v1
type ScriptPubKeyV1 struct { type ScriptPubKeyV1 struct {
Hex string `json:"hex,omitempty"` Hex string `json:"hex,omitempty"`
Asm string `json:"asm,omitempty"` Asm string `json:"asm,omitempty"`
AddrDesc bchain.AddressDescriptor `json:"-"` AddrDesc bchain.AddressDescriptor `json:"-"`
Addresses []string `json:"addresses"` Addresses []string `json:"addresses"`
Searchable bool `json:"-"` IsAddress bool `json:"-"`
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
} }
// VoutV1 is used for legacy api v1 // VoutV1 is used for legacy api v1
@ -115,12 +115,12 @@ func (w *Worker) TxToV1(tx *Tx) *TxV1 {
Asm: v.Asm, Asm: v.Asm,
Hex: v.Hex, Hex: v.Hex,
}, },
Searchable: v.Searchable, IsAddress: v.IsAddress,
Sequence: v.Sequence, Sequence: v.Sequence,
Txid: v.Txid, Txid: v.Txid,
Value: v.ValueSat.DecimalString(d), Value: v.ValueSat.DecimalString(d),
ValueSat: v.ValueSat.AsBigInt(), ValueSat: v.ValueSat.AsBigInt(),
Vout: v.Vout, Vout: v.Vout,
} }
} }
voutV1 := make([]VoutV1, len(tx.Vout)) voutV1 := make([]VoutV1, len(tx.Vout))
@ -129,12 +129,12 @@ func (w *Worker) TxToV1(tx *Tx) *TxV1 {
voutV1[i] = VoutV1{ voutV1[i] = VoutV1{
N: v.N, N: v.N,
ScriptPubKey: ScriptPubKeyV1{ ScriptPubKey: ScriptPubKeyV1{
AddrDesc: v.AddrDesc, AddrDesc: v.AddrDesc,
Addresses: v.Addresses, Addresses: v.Addresses,
Asm: v.Asm, Asm: v.Asm,
Hex: v.Hex, Hex: v.Hex,
Searchable: v.Searchable, IsAddress: v.IsAddress,
Type: v.Type, Type: v.Type,
}, },
Spent: v.Spent, Spent: v.Spent,
SpentHeight: v.SpentHeight, SpentHeight: v.SpentHeight,

View File

@ -166,7 +166,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
if err == bchain.ErrTxNotFound { if err == bchain.ErrTxNotFound {
// try to get AddrDesc using coin specific handling and continue processing the tx // try to get AddrDesc using coin specific handling and continue processing the tx
vin.AddrDesc = w.chainParser.GetAddrDescForUnknownInput(bchainTx, i) 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 { if err != nil {
glog.Warning("GetAddressesFromAddrDesc tx ", bchainVin.Txid, ", addrDesc ", vin.AddrDesc, ": ", err) 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) { if len(otx.Vout) > int(vin.Vout) {
vout := &otx.Vout[vin.Vout] vout := &otx.Vout[vin.Vout]
vin.ValueSat = (*Amount)(&vout.ValueSat) 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 { if err != nil {
glog.Errorf("getAddressesFromVout error %v, vout %+v", err, vout) 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] output := &tas.Outputs[vin.Vout]
vin.ValueSat = (*Amount)(&output.ValueSat) vin.ValueSat = (*Amount)(&output.ValueSat)
vin.AddrDesc = output.AddrDesc 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 { if err != nil {
glog.Errorf("output.Addresses error %v, tx %v, output %v", err, bchainVin.Txid, i) 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) glog.Errorf("GetAddrDescFromAddress error %v, tx %v, bchainVin %v", err, bchainTx.Txid, bchainVin)
} }
vin.Addresses = bchainVin.Addresses 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) vout.ValueSat = (*Amount)(&bchainVout.ValueSat)
valOutSat.Add(&valOutSat, &bchainVout.ValueSat) valOutSat.Add(&valOutSat, &bchainVout.ValueSat)
vout.Hex = bchainVout.ScriptPubKey.Hex 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 { if err != nil {
glog.V(2).Infof("getAddressesFromVout error %v, %v, output %v", err, bchainTx.Txid, bchainVout.N) 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.N = i
vin.ValueSat = (*Amount)(&tai.ValueSat) vin.ValueSat = (*Amount)(&tai.ValueSat)
valInSat.Add(&valInSat, &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 { if err != nil {
glog.Errorf("tai.Addresses error %v, tx %v, input %v, tai %+v", err, txid, i, tai) 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.N = i
vout.ValueSat = (*Amount)(&tao.ValueSat) vout.ValueSat = (*Amount)(&tao.ValueSat)
valOutSat.Add(&valOutSat, &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 { if err != nil {
glog.Errorf("tai.Addresses error %v, tx %v, output %v, tao %+v", err, txid, i, tao) glog.Errorf("tai.Addresses error %v, tx %v, output %v, tao %+v", err, txid, i, tao)
} }

View File

@ -131,6 +131,7 @@ Response for Bitcoin-type coins:
"addresses": [ "addresses": [
"DDhUv8JZGmSxKYV95NLnbRTUKni9cDZD3S" "DDhUv8JZGmSxKYV95NLnbRTUKni9cDZD3S"
], ],
"isAddress": true,
"value": "55795108999999", "value": "55795108999999",
"hex": "473...2c7ec77bb982" "hex": "473...2c7ec77bb982"
} }
@ -142,7 +143,8 @@ Response for Bitcoin-type coins:
"hex": "76a914feaca9d9fa7120c7c587c00c639bb18d40faadd388ac", "hex": "76a914feaca9d9fa7120c7c587c00c639bb18d40faadd388ac",
"addresses": [ "addresses": [
"DUMh1rPrXTrCN2Z9EHsLPg7b78rACHB2h7" "DUMh1rPrXTrCN2Z9EHsLPg7b78rACHB2h7"
] ],
"isAddress": true
}, },
{ {
"value": "209329999999", "value": "209329999999",
@ -150,7 +152,8 @@ Response for Bitcoin-type coins:
"hex": "76a914ea8984be785868391d92f49c14933f47c152ea0a88ac", "hex": "76a914ea8984be785868391d92f49c14933f47c152ea0a88ac",
"addresses": [ "addresses": [
"DSXDQ6rnwLX47WFRnemctoXPHA9pLMxqXn" "DSXDQ6rnwLX47WFRnemctoXPHA9pLMxqXn"
] ],
"isAddress": true
} }
], ],
"blockHash": "78d1f3de899a10dd2e580704226ebf9508e95e1706f177fc9c31c47f245d2502", "blockHash": "78d1f3de899a10dd2e580704226ebf9508e95e1706f177fc9c31c47f245d2502",
@ -174,7 +177,8 @@ Response for Ethereum-type coins. There is always only one *vin*, only one *vout
"n": 0, "n": 0,
"addresses": [ "addresses": [
"0x9c2e011c0ce0d75c2b62b9c5a0ba0a7456593803" "0x9c2e011c0ce0d75c2b62b9c5a0ba0a7456593803"
] ],
"isAddress": true
} }
], ],
"vout": [ "vout": [
@ -183,7 +187,8 @@ Response for Ethereum-type coins. There is always only one *vin*, only one *vout
"n": 0, "n": 0,
"addresses": [ "addresses": [
"0xc32ae45504ee9482db99cfa21066a59e877bc0e6" "0xc32ae45504ee9482db99cfa21066a59e877bc0e6"
] ],
"isAddress": true
} }
], ],
"blockHash": "0x39df7fb0893200e1e78c04f98691637a89b64e7a3edd96c16f2537e2fd56c414", "blockHash": "0x39df7fb0893200e1e78c04f98691637a89b64e7a3edd96c16f2537e2fd56c414",
@ -477,7 +482,8 @@ Response:
"n": 0, "n": 0,
"addresses": [ "addresses": [
"D6ravJL6Fgxtgp8k2XZZt1QfUmwwGuLwQJ" "D6ravJL6Fgxtgp8k2XZZt1QfUmwwGuLwQJ"
] ],
"isAddress": true
} }
], ],
"blockHash": "760f8ed32894ccce9c1ea11c8a019cadaa82bcb434b25c30102dd7e43f326217", "blockHash": "760f8ed32894ccce9c1ea11c8a019cadaa82bcb434b25c30102dd7e43f326217",
@ -496,6 +502,7 @@ Response:
"addresses": [ "addresses": [
"9sLa1AKzjWuNTe1CkLh5GDYyRP9enb1Spp" "9sLa1AKzjWuNTe1CkLh5GDYyRP9enb1Spp"
], ],
"isAddress": true,
"value": "1277595845202" "value": "1277595845202"
} }
], ],
@ -505,7 +512,8 @@ Response:
"n": 0, "n": 0,
"addresses": [ "addresses": [
"DMnjrbcCEoeyvr7GEn8DS4ZXQjwq7E2zQU" "DMnjrbcCEoeyvr7GEn8DS4ZXQjwq7E2zQU"
] ],
"isAddress": true
}, },
{ {
"value": "1267595845202", "value": "1267595845202",
@ -513,7 +521,8 @@ Response:
"spent": true, "spent": true,
"addresses": [ "addresses": [
"9sLa1AKzjWuNTe1CkLh5GDYyRP9enb1Spp" "9sLa1AKzjWuNTe1CkLh5GDYyRP9enb1Spp"
] ],
"isAddress": true
} }
], ],
"blockHash": "760f8ed32894ccce9c1ea11c8a019cadaa82bcb434b25c30102dd7e43f326217", "blockHash": "760f8ed32894ccce9c1ea11c8a019cadaa82bcb434b25c30102dd7e43f326217",

File diff suppressed because one or more lines are too long

View File

@ -19,7 +19,7 @@
{{- end -}} {{- end -}}
{{- range $a := $vin.Addresses -}} {{- range $a := $vin.Addresses -}}
<span class="ellipsis tx-addr"> <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> </span>
{{- else -}} {{- else -}}
<span class="tx-addr">{{- if $vin.Hex -}}Unparsed address{{- else -}}No Inputs (Newly Generated Coins){{- end -}}</span> <span class="tx-addr">{{- if $vin.Hex -}}Unparsed address{{- else -}}No Inputs (Newly Generated Coins){{- end -}}</span>
@ -51,7 +51,7 @@
<td> <td>
{{- range $a := $vout.Addresses -}} {{- range $a := $vout.Addresses -}}
<span class="ellipsis tx-addr"> <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> </span>
{{- else -}} {{- else -}}
<span class="tx-addr">Unparsed address</span> <span class="tx-addr">Unparsed address</span>

View File

@ -17,7 +17,7 @@
<td> <td>
{{- range $a := $vin.Addresses -}} {{- range $a := $vin.Addresses -}}
<span class="ellipsis tx-addr"> <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> </span>
{{- else -}} {{- else -}}
<span class="tx-addr">Unparsed address</span> <span class="tx-addr">Unparsed address</span>
@ -47,7 +47,7 @@
<td> <td>
{{- range $a := $vout.Addresses -}} {{- range $a := $vout.Addresses -}}
<span class="ellipsis tx-addr"> <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> </span>
{{- else -}} {{- else -}}
<span class="tx-addr">Unparsed address</span> <span class="tx-addr">Unparsed address</span>