balanceHistory: return all currencies if the "currency" parameter is empty
parent
5b41a37da6
commit
4b564510e0
|
@ -925,7 +925,9 @@ func (w *Worker) setFiatRateToBalanceHistories(histories BalanceHistories, curre
|
|||
} else if ticker == nil {
|
||||
continue
|
||||
}
|
||||
if len(currencies) > 0 {
|
||||
if len(currencies) == 0 {
|
||||
bh.FiatRates = ticker.Rates
|
||||
} else {
|
||||
rates := make(map[string]float64)
|
||||
for _, currency := range currencies {
|
||||
currency = strings.ToLower(currency)
|
||||
|
@ -967,11 +969,9 @@ func (w *Worker) GetBalanceHistory(address string, fromTimestamp, toTimestamp in
|
|||
}
|
||||
}
|
||||
bha := bhs.SortAndAggregate(groupBy)
|
||||
if len(currencies) > 0 {
|
||||
err = w.setFiatRateToBalanceHistories(bha, currencies)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = w.setFiatRateToBalanceHistories(bha, currencies)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
glog.Info("GetBalanceHistory ", address, ", blocks ", fromHeight, "-", toHeight, ", count ", len(bha), " finished in ", time.Since(start))
|
||||
return bha, nil
|
||||
|
|
|
@ -623,11 +623,9 @@ func (w *Worker) GetXpubBalanceHistory(xpub string, fromTimestamp, toTimestamp i
|
|||
}
|
||||
}
|
||||
bha := bhs.SortAndAggregate(groupBy)
|
||||
if len(currencies) > 0 {
|
||||
err = w.setFiatRateToBalanceHistories(bha, currencies)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = w.setFiatRateToBalanceHistories(bha, currencies)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
glog.Info("GetUtxoBalanceHistory ", xpub[:16], ", blocks ", fromHeight, "-", toHeight, ", count ", len(bha), ", finished in ", time.Since(start))
|
||||
return bha, nil
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// +build unittest
|
||||
// build unittest
|
||||
|
||||
package server
|
||||
|
||||
|
@ -767,7 +767,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
|
|||
status: http.StatusOK,
|
||||
contentType: "application/json; charset=utf-8",
|
||||
body: []string{
|
||||
`[{"time":1521514800,"txs":1,"received":"12345","sent":"0"},{"time":1521594000,"txs":1,"received":"0","sent":"12345"}]`,
|
||||
`[{"time":1521514800,"txs":1,"received":"12345","sent":"0","rates":{"eur":1301,"usd":2001}},{"time":1521594000,"txs":1,"received":"0","sent":"12345","rates":{"eur":1303,"usd":2003}}]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -776,7 +776,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
|
|||
status: http.StatusOK,
|
||||
contentType: "application/json; charset=utf-8",
|
||||
body: []string{
|
||||
`[{"time":1521514800,"txs":1,"received":"9876","sent":"0"},{"time":1521594000,"txs":1,"received":"9000","sent":"9876"}]`,
|
||||
`[{"time":1521514800,"txs":1,"received":"9876","sent":"0","rates":{"eur":1301,"usd":2001}},{"time":1521594000,"txs":1,"received":"9000","sent":"9876","rates":{"eur":1303,"usd":2003}}]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -794,7 +794,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
|
|||
status: http.StatusOK,
|
||||
contentType: "application/json; charset=utf-8",
|
||||
body: []string{
|
||||
`[{"time":1521514800,"txs":1,"received":"12345","sent":"0"}]`,
|
||||
`[{"time":1521514800,"txs":1,"received":"12345","sent":"0","rates":{"eur":1301,"usd":2001}}]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -803,7 +803,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
|
|||
status: http.StatusOK,
|
||||
contentType: "application/json; charset=utf-8",
|
||||
body: []string{
|
||||
`[{"time":1521514800,"txs":1,"received":"1","sent":"0"},{"time":1521594000,"txs":1,"received":"118641975500","sent":"1"}]`,
|
||||
`[{"time":1521514800,"txs":1,"received":"1","sent":"0","rates":{"eur":1301,"usd":2001}},{"time":1521594000,"txs":1,"received":"118641975500","sent":"1","rates":{"eur":1303,"usd":2003}}]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -812,7 +812,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
|
|||
status: http.StatusOK,
|
||||
contentType: "application/json; charset=utf-8",
|
||||
body: []string{
|
||||
`[{"time":1521514800,"txs":1,"received":"1","sent":"0"}]`,
|
||||
`[{"time":1521514800,"txs":1,"received":"1","sent":"0","rates":{"eur":1301,"usd":2001}}]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -830,7 +830,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
|
|||
status: http.StatusOK,
|
||||
contentType: "application/json; charset=utf-8",
|
||||
body: []string{
|
||||
`[{"time":1521594000,"txs":1,"received":"118641975500","sent":"1"}]`,
|
||||
`[{"time":1521594000,"txs":1,"received":"118641975500","sent":"1","rates":{"eur":1303,"usd":2003}}]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -1350,7 +1350,7 @@ func websocketTestsBitcoinType(t *testing.T, ts *httptest.Server) {
|
|||
"descriptor": "mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz",
|
||||
},
|
||||
},
|
||||
want: `{"id":"31","data":[{"time":1521514800,"txs":1,"received":"12345","sent":"0"},{"time":1521594000,"txs":1,"received":"0","sent":"12345"}]}`,
|
||||
want: `{"id":"31","data":[{"time":1521514800,"txs":1,"received":"12345","sent":"0","rates":{"eur":1301,"usd":2001}},{"time":1521594000,"txs":1,"received":"0","sent":"12345","rates":{"eur":1303,"usd":2003}}]}`,
|
||||
},
|
||||
{
|
||||
name: "websocket getBalanceHistory xpub",
|
||||
|
@ -1360,7 +1360,7 @@ func websocketTestsBitcoinType(t *testing.T, ts *httptest.Server) {
|
|||
"descriptor": dbtestdata.Xpub,
|
||||
},
|
||||
},
|
||||
want: `{"id":"32","data":[{"time":1521514800,"txs":1,"received":"1","sent":"0"},{"time":1521594000,"txs":1,"received":"118641975500","sent":"1"}]}`,
|
||||
want: `{"id":"32","data":[{"time":1521514800,"txs":1,"received":"1","sent":"0","rates":{"eur":1301,"usd":2001}},{"time":1521594000,"txs":1,"received":"118641975500","sent":"1","rates":{"eur":1303,"usd":2003}}]}`,
|
||||
},
|
||||
{
|
||||
name: "websocket getBalanceHistory xpub from=1521504000&to=1521590400 currencies=[usd]",
|
||||
|
@ -1399,7 +1399,7 @@ func websocketTestsBitcoinType(t *testing.T, ts *httptest.Server) {
|
|||
"currencies": []string{},
|
||||
},
|
||||
},
|
||||
want: `{"id":"35","data":[{"time":1521514800,"txs":1,"received":"1","sent":"0"}]}`,
|
||||
want: `{"id":"35","data":[{"time":1521514800,"txs":1,"received":"1","sent":"0","rates":{"eur":1301,"usd":2001}}]}`,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue