Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
Merge pull request #3097 from NebulousLabs/fix-wallet-transaction-han…
Browse files Browse the repository at this point in the history
…dler

Fix -1 Integer Parsing
  • Loading branch information
David Vorick committed Jun 12, 2018
2 parents 51bca5a + a636eac commit bd8987c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion node/api/wallet.go
Expand Up @@ -3,6 +3,7 @@ package api
import (
"encoding/json"
"fmt"
"math"
"net/http"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -551,11 +552,18 @@ func (api *API) walletTransactionsHandler(w http.ResponseWriter, req *http.Reque
WriteError(w, Error{"parsing integer value for parameter `startheight` failed: " + err.Error()}, http.StatusBadRequest)
return
}
end, err := strconv.ParseUint(endheightStr, 10, 64)
// Parse endheightStr as an Int to account for negative numbers. If endInt is
// negative, explicitly set var end to MaxUint64.
var end uint64
endInt, err := strconv.ParseInt(endheightStr, 10, 64)
if err != nil {
WriteError(w, Error{"parsing integer value for parameter `endheight` failed: " + err.Error()}, http.StatusBadRequest)
return
}
end = uint64(endInt)
if endInt < 0 {
end = math.MaxUint64
}
confirmedTxns, err := api.wallet.Transactions(types.BlockHeight(start), types.BlockHeight(end))
if err != nil {
WriteError(w, Error{"error when calling /wallet/transactions: " + err.Error()}, http.StatusBadRequest)
Expand Down
9 changes: 9 additions & 0 deletions node/api/wallet_test.go
Expand Up @@ -677,6 +677,15 @@ func TestWalletTransactionGETid(t *testing.T) {
if len(wtg.UnconfirmedTransactions) != 2 {
t.Fatal("expecting two unconfirmed transactions in sender wallet")
}
// Check that undocumented API behaviour used in Sia-UI still works with
// current API.
err = st.getAPI("/wallet/transactions?startheight=0&endheight=-1", &wtg)
if err != nil {
t.Fatal(err)
}
if len(wtg.UnconfirmedTransactions) != 2 {
t.Fatal("expecting two unconfirmed transactions in sender wallet")
}
// Get the id of the non-change output sent to the receiving wallet.
expectedOutputID := wtg.UnconfirmedTransactions[1].Outputs[0].ID

Expand Down

0 comments on commit bd8987c

Please sign in to comment.