Add option TxHistoryLight to api.GetAddress
This commit is contained in:
parent
f332c0aa9e
commit
3ff1a86ab1
@ -19,6 +19,8 @@ const (
|
|||||||
Balance
|
Balance
|
||||||
// TxidHistory - balances and txids, subject to paging
|
// TxidHistory - balances and txids, subject to paging
|
||||||
TxidHistory
|
TxidHistory
|
||||||
|
// TxHistoryLight - balances and easily obtained tx data (not requiring request to backend), subject to paging
|
||||||
|
TxHistoryLight
|
||||||
// TxHistory - balances and full tx data, subject to paging
|
// TxHistory - balances and full tx data, subject to paging
|
||||||
TxHistory
|
TxHistory
|
||||||
)
|
)
|
||||||
|
|||||||
@ -564,7 +564,7 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option GetA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// get tx history if requested by option or check mempool if there are some transactions for a new address
|
// get tx history if requested by option or check mempool if there are some transactions for a new address
|
||||||
if option == TxidHistory || option == TxHistory || ba == nil {
|
if option >= TxidHistory || ba == nil {
|
||||||
// convert the address to the format defined by the parser
|
// convert the address to the format defined by the parser
|
||||||
addresses, _, err := w.chainParser.GetAddressesFromAddrDesc(addrDesc)
|
addresses, _, err := w.chainParser.GetAddressesFromAddrDesc(addrDesc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -583,7 +583,7 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option GetA
|
|||||||
ba = &db.AddrBalance{}
|
ba = &db.AddrBalance{}
|
||||||
page = 0
|
page = 0
|
||||||
}
|
}
|
||||||
if option == TxidHistory || option == TxHistory {
|
if option >= TxidHistory {
|
||||||
txc, err := w.getAddressTxids(addrDesc, false, filter)
|
txc, err := w.getAddressTxids(addrDesc, false, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Annotatef(err, "getAddressTxids %v false", addrDesc)
|
return nil, errors.Annotatef(err, "getAddressTxids %v false", addrDesc)
|
||||||
@ -601,7 +601,7 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option GetA
|
|||||||
txs = make([]*Tx, len(txm)+to-from)
|
txs = make([]*Tx, len(txm)+to-from)
|
||||||
}
|
}
|
||||||
txi := 0
|
txi := 0
|
||||||
// load mempool transactions
|
// get mempool transactions
|
||||||
for _, txid := range txm {
|
for _, txid := range txm {
|
||||||
tx, err := w.GetTransaction(txid, false, false)
|
tx, err := w.GetTransaction(txid, false, false)
|
||||||
// mempool transaction may fail
|
// mempool transaction may fail
|
||||||
@ -620,17 +620,14 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option GetA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// get confirmed transactions
|
||||||
for i := from; i < to; i++ {
|
for i := from; i < to; i++ {
|
||||||
txid := txc[i]
|
txid := txc[i]
|
||||||
if option == TxidHistory {
|
if option == TxidHistory {
|
||||||
txids[txi] = txid
|
txids[txi] = txid
|
||||||
} else {
|
} else {
|
||||||
if w.chainType == bchain.ChainEthereumType {
|
// only ChainBitcoinType supports TxHistoryLight
|
||||||
txs[txi], err = w.GetTransaction(txid, false, true)
|
if option == TxHistoryLight && w.chainType == bchain.ChainBitcoinType {
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Annotatef(err, "GetTransaction %v", txid)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ta, err := w.db.GetTxAddresses(txid)
|
ta, err := w.db.GetTxAddresses(txid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Annotatef(err, "GetTxAddresses %v", txid)
|
return nil, errors.Annotatef(err, "GetTxAddresses %v", txid)
|
||||||
@ -648,13 +645,18 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option GetA
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
txs[txi] = w.txFromTxAddress(txid, ta, bi, bestheight)
|
txs[txi] = w.txFromTxAddress(txid, ta, bi, bestheight)
|
||||||
|
} else {
|
||||||
|
txs[txi], err = w.GetTransaction(txid, false, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Annotatef(err, "GetTransaction %v", txid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
txi++
|
txi++
|
||||||
}
|
}
|
||||||
if option == TxidHistory {
|
if option == TxidHistory {
|
||||||
txids = txids[:txi]
|
txids = txids[:txi]
|
||||||
} else if option == TxHistory {
|
} else if option >= TxHistoryLight {
|
||||||
txs = txs[:txi]
|
txs = txs[:txi]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -520,7 +520,7 @@ func (s *PublicServer) explorerAddress(w http.ResponseWriter, r *http.Request) (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
address, err = s.api.GetAddress(r.URL.Path[i+1:], page, txsOnPage, api.TxHistory, &api.AddressFilter{Vout: fn})
|
address, err = s.api.GetAddress(r.URL.Path[i+1:], page, txsOnPage, api.TxHistoryLight, &api.AddressFilter{Vout: fn})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorTpl, nil, err
|
return errorTpl, nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user