Commit 2bf36894 authored by Christopher Schinnerl's avatar Christopher Schinnerl

add new endpoint /wallet/seedaddrs

parent 74a879a8
......@@ -65,7 +65,7 @@ func (c *Client) WalletGet() (wg api.WalletGET, err error) {
// wallet in reverse order. That means the last generated address will be the
// first one in the slice.
func (c *Client) WalletLastAddressesGet(count uint64) (wag api.WalletAddressesGET, err error) {
err = c.get(fmt.Sprintf("/wallet/addresses?count=%v", count), &wag)
err = c.get(fmt.Sprintf("/wallet/seedaddrs?count=%v", count), &wag)
return
}
......
......@@ -118,6 +118,7 @@ func (api *API) buildHTTPRoutes(requiredUserAgent string, requiredPassword strin
router.POST("/wallet/033x", RequirePassword(api.wallet033xHandler, requiredPassword))
router.GET("/wallet/address", RequirePassword(api.walletAddressHandler, requiredPassword))
router.GET("/wallet/addresses", api.walletAddressesHandler)
router.GET("/wallet/seedaddrs", api.walletSeedAddressesHandler)
router.GET("/wallet/backup", RequirePassword(api.walletBackupHandler, requiredPassword))
router.POST("/wallet/init", RequirePassword(api.walletInitHandler, requiredPassword))
router.POST("/wallet/init/seed", RequirePassword(api.walletInitSeedHandler, requiredPassword))
......
......@@ -254,30 +254,33 @@ func (api *API) walletAddressHandler(w http.ResponseWriter, req *http.Request, _
})
}
// walletAddressHandler handles API calls to /wallet/addresses.
func (api *API) walletAddressesHandler(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
// If count is specified we return the last count addresses.
// walletSeedAddressesHandler handles the requests to /wallet/seedaddrs.
func (api *API) walletSeedAddressesHandler(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
// Parse the count argument. If it isn't specified we return as many
// addresses as possible.
count := uint64(math.MaxUint64)
c := req.FormValue("count")
if c != "" {
var count uint64
_, err := fmt.Sscan(c, &count)
if err != nil {
WriteError(w, Error{"Failed to parse count: " + err.Error()}, http.StatusBadRequest)
return
}
// Get the last count addresses.
addresses, err := api.wallet.LastAddresses(count)
if err != nil {
WriteError(w, Error{fmt.Sprintf("Error when calling /wallet/addresses: %v", err)}, http.StatusBadRequest)
return
}
// Send the response.
WriteJSON(w, WalletAddressesGET{
Addresses: addresses,
})
}
// Get the last count addresses.
addresses, err := api.wallet.LastAddresses(count)
if err != nil {
WriteError(w, Error{fmt.Sprintf("Error when calling /wallet/addresses: %v", err)}, http.StatusBadRequest)
return
}
// Send the response.
WriteJSON(w, WalletAddressesGET{
Addresses: addresses,
})
}
// If count wasn't specified we return all addresses sorted alphabetically.
// walletAddressHandler handles API calls to /wallet/addresses.
func (api *API) walletAddressesHandler(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
addresses, err := api.wallet.AllAddresses()
if err != nil {
WriteError(w, Error{fmt.Sprintf("Error when calling /wallet/addresses: %v", err)}, http.StatusBadRequest)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment