Skip to content

Commit 269acf4

Browse files
authored
Merge pull request #15 from Benzbeeb/patch-band-oracle-to-poa
Patch band oracle to use data from band-laozi-poa
2 parents 7590230 + 8ef4536 commit 269acf4

File tree

3 files changed

+24
-37
lines changed

3 files changed

+24
-37
lines changed

config.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ password = ""
2626
# imf = "https://www.imf.org/external/np/fin/data/rms_five.aspx?tsvflag=Y"
2727

2828
[APIs.band]
29-
active = false
30-
band = "https://terra-lcd.bandchain.org"
29+
active = true
30+
band = "https://terra-lcd-poa.bandchain.org"
3131

3232
[Options]
3333
[Options.Interval]
3434
luna = 5
3535
stables = 200
36+

price/band_fx.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package price
22

33
import (
4-
"bytes"
54
"encoding/json"
65
"fmt"
76
"io/ioutil"
@@ -17,8 +16,7 @@ import (
1716
)
1817

1918
type FxResponse struct {
20-
Height string `json:"height"`
21-
Result []Result `json:"result"`
19+
Result []Result `json:"price_results"`
2220
}
2321

2422
type Result struct {
@@ -46,9 +44,9 @@ func (ps *PriceService) fxsToUsd(logger log.Logger) {
4644
}()
4745

4846
req, err := http.NewRequest(
49-
"POST",
50-
cfg.Config.APIs.Band.Band+"/oracle/request_prices",
51-
bytes.NewBuffer([]byte(`{"symbols":["LUNA", "XDR", "MNT", "EUR", "CNY", "JPY", "GBP", "INR", "CAD", "CHF", "HKD", "SGD", "AUD"],"min_count":10,"ask_count":16}`)),
47+
"GET",
48+
cfg.Config.APIs.Band.Band+"/oracle/v1/request_prices?symbols=LUNA&symbols=XDR&symbols=MNT&symbols=EUR&symbols=CNY&symbols=JPY&symbols=GBP&symbols=INR&symbols=CAD&symbols=CHF&symbols=HKD&symbols=SGD&symbols=AUD&min_count=3&ask_count=4",
49+
nil,
5250
)
5351
req.Header.Set("Content-Type", "application/json")
5452

price/band_luna.go

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import (
1616
)
1717

1818
type BandResponse struct {
19-
Height int64 `json:"height,string"`
20-
Result BandResult `json:"result"`
19+
Request BandResult `json:"request"`
2120
}
2221

2322
type RawRequests struct {
@@ -26,28 +25,11 @@ type RawRequests struct {
2625
Calldata []byte `json:"calldata,string"`
2726
}
2827

29-
type Request struct {
30-
OracleScriptID uint64 `json:"oracle_script_id,string"`
31-
Calldata []byte `json:"calldata,string"`
32-
RequestedValidators []string `json:"requested_validators"`
33-
MinCount uint64 `json:"min_count,string"`
34-
RequestHeight uint64 `json:"request_height,string"`
35-
RequestTime time.Time `json:"request_time"`
36-
ClientID string `json:"client_id"`
37-
RawRequests []RawRequests `json:"raw_requests"`
38-
}
39-
4028
type RawReports struct {
4129
ExternalID uint64 `json:"external_id,string"`
4230
Data string `json:"data"`
4331
}
4432

45-
type Reports struct {
46-
Validator string `json:"validator"`
47-
InBeforeResolve bool `json:"in_before_resolve"`
48-
RawReports []RawReports `json:"raw_reports"`
49-
}
50-
5133
type RequestPacketData struct {
5234
ClientID string `json:"client_id"`
5335
OracleScriptID uint64 `json:"oracle_script_id,string"`
@@ -66,15 +48,22 @@ type ResponsePacketData struct {
6648
Result []byte `json:"result,string"`
6749
}
6850

69-
type Packet struct {
70-
RequestPacketData RequestPacketData `json:"request_packet_data"`
71-
ResponsePacketData ResponsePacketData `json:"response_packet_data"`
51+
type PacketResult struct {
52+
ClientID string `json:"client_id"`
53+
OracleScriptID int64 `json:"oracle_script_id,string"`
54+
Calldata []byte `json:"calldata"`
55+
AskCount uint64 `json:"ask_count,string"`
56+
MinCount uint64 `json:"min_count,string"`
57+
RequestID int64 `json:"request_id,string"`
58+
AnsCount uint64 `json:"ans_count,string"`
59+
RequestTime int64 `json:"request_time,string"`
60+
ResolveTime int64 `json:"resolve_time,string"`
61+
ResolveStatus string `json:"resolve_status"`
62+
Result []byte `json:"result,string"`
7263
}
7364

7465
type BandResult struct {
75-
Request Request `json:"request"`
76-
Reports []Reports `json:"reports"`
77-
Result Packet `json:"result"`
66+
Result PacketResult `json:"result"`
7867
}
7968

8069
type LunaPriceCallData struct {
@@ -102,7 +91,7 @@ func (lpcd *LunaPriceCallData) toBytes() []byte {
10291
var (
10392
MULTIPLIER = uint64(1000000000)
10493
LUNA_PRICE_CALLDATA = LunaPriceCallData{Multiplier: MULTIPLIER}
105-
LUNA_PRICE_END_POINT = fmt.Sprintf("/oracle/request_search?oid=13&calldata=%x&min_count=10&ask_count=16", LUNA_PRICE_CALLDATA.toBytes())
94+
LUNA_PRICE_END_POINT = fmt.Sprintf("/oracle/v1/request_search?oid=13&calldata=%x&min_count=3&ask_count=4", LUNA_PRICE_CALLDATA.toBytes())
10695
)
10796

10897
func (ps *PriceService) bandLunaToKrw(logger log.Logger) {
@@ -142,8 +131,7 @@ func (ps *PriceService) bandLunaToKrw(logger log.Logger) {
142131
}
143132

144133
var lp LunaPrice
145-
Decode(br.Result.Result.ResponsePacketData.Result, &lp)
146-
134+
Decode(br.Request.Result.Result, &lp)
147135
// Find median
148136
prices := []float64{}
149137
for _, order := range lp.OrderBooks[:4] {
@@ -159,7 +147,7 @@ func (ps *PriceService) bandLunaToKrw(logger log.Logger) {
159147
}
160148

161149
price := sdk.NewDecCoinFromDec("krw", decAmount)
162-
timestamp := int64(br.Result.Result.ResponsePacketData.ResolveTime)
150+
timestamp := int64(br.Request.Result.ResolveTime)
163151

164152
logger.Info(fmt.Sprintf("Recent luna/krw: %s, timestamp: %d", price, timestamp))
165153

0 commit comments

Comments
 (0)