Add isOwn flag to inputs and outputs in get utxo
This commit is contained in:
parent
93ea126123
commit
9b8b10b6e0
@ -111,6 +111,7 @@ type Vin struct {
|
||||
AddrDesc bchain.AddressDescriptor `json:"-"`
|
||||
Addresses []string `json:"addresses,omitempty"`
|
||||
IsAddress bool `json:"isAddress"`
|
||||
IsOwn bool `json:"isOwn,omitempty"`
|
||||
ValueSat *Amount `json:"value,omitempty"`
|
||||
Hex string `json:"hex,omitempty"`
|
||||
Asm string `json:"asm,omitempty"`
|
||||
@ -130,6 +131,7 @@ type Vout struct {
|
||||
AddrDesc bchain.AddressDescriptor `json:"-"`
|
||||
Addresses []string `json:"addresses"`
|
||||
IsAddress bool `json:"isAddress"`
|
||||
IsOwn bool `json:"isOwn,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
}
|
||||
|
||||
@ -401,7 +403,7 @@ type Block struct {
|
||||
|
||||
// BlockRaw contains raw block in hex
|
||||
type BlockRaw struct {
|
||||
Hex string `json:"hex"`
|
||||
Hex string `json:"hex"`
|
||||
}
|
||||
|
||||
// BlockbookInfo contains information about the running blockbook instance
|
||||
|
||||
@ -822,6 +822,28 @@ func (w *Worker) getAddrDescAndNormalizeAddress(address string) (bchain.AddressD
|
||||
return addrDesc, address, nil
|
||||
}
|
||||
|
||||
func isOwnAddress(address string, addresses []string) bool {
|
||||
if len(addresses) == 1 {
|
||||
return address == addresses[0]
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func setIsOwnAddress(tx *Tx, address string) {
|
||||
for j := range tx.Vin {
|
||||
vin := &tx.Vin[j]
|
||||
if isOwnAddress(address, vin.Addresses) {
|
||||
vin.IsOwn = true
|
||||
}
|
||||
}
|
||||
for j := range tx.Vout {
|
||||
vout := &tx.Vout[j]
|
||||
if isOwnAddress(address, vout.Addresses) {
|
||||
vout.IsOwn = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetAddress computes address value and gets transactions for given address
|
||||
func (w *Worker) GetAddress(address string, page int, txsOnPage int, option AccountDetails, filter *AddressFilter) (*Address, error) {
|
||||
start := time.Now()
|
||||
@ -936,6 +958,7 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option Acco
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
setIsOwnAddress(tx, address)
|
||||
txs = append(txs, tx)
|
||||
}
|
||||
}
|
||||
@ -1505,7 +1528,7 @@ func (w *Worker) getBlockHashBlockID(bid string) string {
|
||||
|
||||
// getBlockInfoFromBlockID returns block info from block height or block hash
|
||||
func (w *Worker) getBlockInfoFromBlockID(bid string) (*bchain.BlockInfo, error) {
|
||||
hash:=w.getBlockHashBlockID(bid)
|
||||
hash := w.getBlockHashBlockID(bid)
|
||||
if hash == "" {
|
||||
return nil, NewAPIError("Block not found", true)
|
||||
}
|
||||
@ -1686,7 +1709,7 @@ func (w *Worker) GetBlock(bid string, page int, txsOnPage int) (*Block, error) {
|
||||
|
||||
// GetBlock returns paged data about block
|
||||
func (w *Worker) GetBlockRaw(bid string) (*BlockRaw, error) {
|
||||
hash:=w.getBlockHashBlockID(bid)
|
||||
hash := w.getBlockHashBlockID(bid)
|
||||
if hash == "" {
|
||||
return nil, NewAPIError("Block not found", true)
|
||||
}
|
||||
|
||||
28
api/xpub.go
28
api/xpub.go
@ -277,6 +277,33 @@ func (w *Worker) tokenFromXpubAddress(data *xpubData, ad *xpubAddress, changeInd
|
||||
}
|
||||
}
|
||||
|
||||
// returns true if addresses are "own", i.e. the address belongs to the xpub
|
||||
func isOwnAddresses(xpubAddresses map[string]struct{}, addresses []string) bool {
|
||||
if len(addresses) == 1 {
|
||||
_, found := xpubAddresses[addresses[0]]
|
||||
return found
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func setIsOwnAddresses(txs []*Tx, xpubAddresses map[string]struct{}) {
|
||||
for i := range txs {
|
||||
tx := txs[i]
|
||||
for j := range tx.Vin {
|
||||
vin := &tx.Vin[j]
|
||||
if isOwnAddresses(xpubAddresses, vin.Addresses) {
|
||||
vin.IsOwn = true
|
||||
}
|
||||
}
|
||||
for j := range tx.Vout {
|
||||
vout := &tx.Vout[j]
|
||||
if isOwnAddresses(xpubAddresses, vout.Addresses) {
|
||||
vout.IsOwn = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Worker) getXpubData(xd *bchain.XpubDescriptor, page int, txsOnPage int, option AccountDetails, filter *AddressFilter, gap int) (*xpubData, uint32, bool, error) {
|
||||
if w.chainType != bchain.ChainBitcoinType {
|
||||
return nil, 0, false, ErrUnsupportedXpub
|
||||
@ -536,6 +563,7 @@ func (w *Worker) GetXpubAddress(xpub string, page int, txsOnPage int, option Acc
|
||||
}
|
||||
}
|
||||
}
|
||||
setIsOwnAddresses(txs, xpubAddresses)
|
||||
var totalReceived big.Int
|
||||
totalReceived.Add(&data.balanceSat, &data.sentSat)
|
||||
addr := Address{
|
||||
|
||||
@ -454,8 +454,6 @@ func (s *PublicServer) parseTemplates() []*template.Template {
|
||||
"formatAmount": s.formatAmount,
|
||||
"formatAmountWithDecimals": formatAmountWithDecimals,
|
||||
"setTxToTemplateData": setTxToTemplateData,
|
||||
"isOwnAddress": isOwnAddress,
|
||||
"isOwnAddresses": isOwnAddresses,
|
||||
"toJSON": toJSON,
|
||||
}
|
||||
var createTemplate func(filenames ...string) *template.Template
|
||||
@ -554,29 +552,6 @@ func setTxToTemplateData(td *TemplateData, tx *api.Tx) *TemplateData {
|
||||
return td
|
||||
}
|
||||
|
||||
// returns true if address is "own",
|
||||
// i.e. either the address of the address detail or belonging to the xpub
|
||||
func isOwnAddress(td *TemplateData, a string) bool {
|
||||
if a == td.AddrStr {
|
||||
return true
|
||||
}
|
||||
if td.Address != nil && td.Address.XPubAddresses != nil {
|
||||
if _, found := td.Address.XPubAddresses[a]; found {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// returns true if addresses are "own",
|
||||
// i.e. either the address of the address detail or belonging to the xpub
|
||||
func isOwnAddresses(td *TemplateData, addresses []string) bool {
|
||||
if len(addresses) == 1 {
|
||||
return isOwnAddress(td, addresses[0])
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *PublicServer) explorerTx(w http.ResponseWriter, r *http.Request) (tpl, *TemplateData, error) {
|
||||
var tx *api.Tx
|
||||
var err error
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -13,7 +13,7 @@
|
||||
<table class="table data-table">
|
||||
<tbody>
|
||||
{{- range $vin := $tx.Vin -}}
|
||||
<tr{{if isOwnAddresses $data $vin.Addresses}} class="tx-own"{{end}}>
|
||||
<tr{{if $vin.IsOwn}} class="tx-own"{{end}}>
|
||||
<td>
|
||||
{{- if $vin.Txid -}}
|
||||
<a class="float-left text-muted" href="/tx/{{$vin.Txid}}" title="Outpoint {{$vin.Txid}},{{$vin.Vout}}">➡ </a>
|
||||
@ -48,7 +48,7 @@
|
||||
<table class="table data-table">
|
||||
<tbody>
|
||||
{{- range $vout := $tx.Vout -}}
|
||||
<tr{{if isOwnAddresses $data $vout.Addresses}} class="tx-own"{{end}}>
|
||||
<tr{{if $vout.IsOwn}} class="tx-own"{{end}}>
|
||||
<td>
|
||||
{{- range $a := $vout.Addresses -}}
|
||||
<span class="ellipsis tx-addr">
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
<table class="table data-table">
|
||||
<tbody>
|
||||
{{- range $vin := $tx.Vin -}}
|
||||
<tr{{if isOwnAddresses $data $vin.Addresses}} class="tx-own"{{end}}>
|
||||
<tr{{if $vin.IsOwn}} class="tx-own"{{end}}>
|
||||
<td>
|
||||
{{- range $a := $vin.Addresses -}}
|
||||
<span class="ellipsis tx-addr">
|
||||
@ -43,7 +43,7 @@
|
||||
<table class="table data-table">
|
||||
<tbody>
|
||||
{{- range $vout := $tx.Vout -}}
|
||||
<tr{{if isOwnAddresses $data $vout.Addresses}} class="tx-own"{{end}}>
|
||||
<tr{{if $vout.IsOwn}} class="tx-own"{{end}}>
|
||||
<td>
|
||||
{{- range $a := $vout.Addresses -}}
|
||||
<span class="ellipsis tx-addr">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user