From a6c01534f2ba18ca771ab4ae799276744d4863b9 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Wed, 4 Mar 2020 00:37:16 +0100 Subject: [PATCH] Add filter by contract to get address API #379 --- docs/api.md | 3 ++- server/public.go | 5 +++++ static/templates/address.html | 4 ++-- static/templates/xpub.html | 8 ++++---- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docs/api.md b/docs/api.md index 80a2c5ed..579a7ac1 100644 --- a/docs/api.md +++ b/docs/api.md @@ -290,7 +290,7 @@ Example response: Returns balances and transactions of an address. The returned transactions are sorted by block height, newest blocks first. ``` -GET /api/v2/address/
[?page=&pageSize=&from=&to=&details=] +GET /api/v2/address/
[?page=&pageSize=&from=&to=&details=&contract=] ``` The optional query parameters: @@ -303,6 +303,7 @@ The optional query parameters: - *tokenBalances*: *basic* + tokens with balances + belonging to the address (applicable only to some coins) - *txids*: *tokenBalances* + list of txids, subject to *from*, *to* filter and paging - *txs*: *tokenBalances* + list of transaction with details, subject to *from*, *to* filter and paging +- *contract*: return only transactions which affect specified contract (applicable only to coins which support contracts) Response: diff --git a/server/public.go b/server/public.go index 5f4c1b6a..1c3de30b 100644 --- a/server/public.go +++ b/server/public.go @@ -641,11 +641,13 @@ func (s *PublicServer) getAddressQueryParams(r *http.Request, accountDetails api if ec != nil { gap = 0 } + contract := r.URL.Query().Get("contract") return page, pageSize, accountDetails, &api.AddressFilter{ Vout: voutFilter, TokensToReturn: tokensToReturn, FromHeight: uint32(from), ToHeight: uint32(to), + Contract: contract, }, filterParam, gap } @@ -670,6 +672,9 @@ func (s *PublicServer) explorerAddress(w http.ResponseWriter, r *http.Request) ( data.Address = address data.Page = address.Page data.PagingRange, data.PrevPage, data.NextPage = getPagingRange(address.Page, address.TotalPages) + if filterParam == "" && filter.Vout > -1 { + filterParam = strconv.Itoa(filter.Vout) + } if filterParam != "" { data.PageParams = template.URL("&filter=" + filterParam) data.Address.Filter = filterParam diff --git a/static/templates/address.html b/static/templates/address.html index 05207f62..208a2b44 100644 --- a/static/templates/address.html +++ b/static/templates/address.html @@ -100,8 +100,8 @@

Transactions

+ -
+