diff --git a/api/client.go b/api/client.go index 6f1d6967..058faa3f 100644 --- a/api/client.go +++ b/api/client.go @@ -87,8 +87,14 @@ func (c *Client) Transactions(ids []types.TransactionID) (resp []explorer.Transa } // AddressUTXOs returns the specified address' unspent outputs. -func (c *Client) AddressUTXOs(address types.Address, limit, offset uint64) (resp AddressUTXOsResponse, err error) { - err = c.c.GET(fmt.Sprintf("/explorer/addresses/%s/utxos?limit=%d&offset=%d", address, limit, offset), &resp) +func (c *Client) AddressUTXOs(address types.Address, offset, limit uint64) (resp AddressUTXOsResponse, err error) { + err = c.c.GET(fmt.Sprintf("/explorer/addresses/%s/utxos?offset=%d&limit=%d", address, offset, limit), &resp) + return +} + +// AddressEvents returns the specified address' events. +func (c *Client) AddressEvents(address types.Address, offset, limit uint64) (resp []explorer.Event, err error) { + err = c.c.GET(fmt.Sprintf("/explorer/addresses/%s/events?offset=%d&limit=%d", address, offset, limit), &resp) return } diff --git a/api/server.go b/api/server.go index bc78febf..1881ce13 100644 --- a/api/server.go +++ b/api/server.go @@ -46,8 +46,9 @@ type ( BestTip(height uint64) (types.ChainIndex, error) Transactions(ids []types.TransactionID) ([]explorer.Transaction, error) Balance(address types.Address) (sc types.Currency, immatureSC types.Currency, sf uint64, err error) - UnspentSiacoinOutputs(address types.Address, limit, offset uint64) ([]explorer.SiacoinOutput, error) - UnspentSiafundOutputs(address types.Address, limit, offset uint64) ([]explorer.SiafundOutput, error) + UnspentSiacoinOutputs(address types.Address, offset, limit uint64) ([]explorer.SiacoinOutput, error) + UnspentSiafundOutputs(address types.Address, offset, limit uint64) ([]explorer.SiafundOutput, error) + AddressEvents(address types.Address, offset, limit uint64) (events []explorer.Event, err error) Contracts(ids []types.FileContractID) (result []explorer.FileContract, err error) } ) @@ -208,11 +209,11 @@ func (s *server) explorerAddressessAddressUtxosHandler(jc jape.Context) { return } - unspentSiacoinOutputs, err := s.e.UnspentSiacoinOutputs(address, limit, offset) + unspentSiacoinOutputs, err := s.e.UnspentSiacoinOutputs(address, offset, limit) if jc.Check("failed to get unspent siacoin outputs", err) != nil { return } - unspentSiafundOutputs, err := s.e.UnspentSiafundOutputs(address, limit, offset) + unspentSiafundOutputs, err := s.e.UnspentSiafundOutputs(address, offset, limit) if jc.Check("failed to get unspent siafund outputs", err) != nil { return } @@ -241,6 +242,26 @@ func (s *server) explorerAddressessAddressBalanceHandler(jc jape.Context) { }) } +func (s *server) explorerAddressessAddressEventsHandler(jc jape.Context) { + var address types.Address + if jc.DecodeParam("address", &address) != nil { + return + } + + limit := uint64(100) + offset := uint64(0) + if jc.DecodeForm("limit", &limit) != nil || jc.DecodeForm("offset", &offset) != nil { + return + } + + events, err := s.e.AddressEvents(address, offset, limit) + if jc.Check("failed to get address events", err) != nil { + return + } + + jc.Encode(events) +} + func (s *server) explorerContractIDHandler(jc jape.Context) { errNotFound := errors.New("no contract found") @@ -295,6 +316,7 @@ func NewServer(e Explorer, cm ChainManager, s Syncer) http.Handler { "GET /explorer/transactions/:id": srv.explorerTransactionsIDHandler, "POST /explorer/transactions": srv.explorerTransactionsHandler, "GET /explorer/addresses/:address/utxos": srv.explorerAddressessAddressUtxosHandler, + "GET /explorer/addresses/:address/events": srv.explorerAddressessAddressEventsHandler, "GET /explorer/addresses/:address/balance": srv.explorerAddressessAddressBalanceHandler, "GET /explorer/contracts/:id": srv.explorerContractIDHandler, "POST /explorer/contracts": srv.explorerContractsHandler,