@@ -12,14 +12,17 @@ import (
1212 "sync"
1313 "time"
1414
15+ "github.com/rs/zerolog/log"
16+
1517 "bisonai.com/miko/node/pkg/chain/helper"
1618 chainUtils "bisonai.com/miko/node/pkg/chain/utils"
19+ "bisonai.com/miko/node/pkg/common/types"
20+ "bisonai.com/miko/node/pkg/db"
1721 errorSentinel "bisonai.com/miko/node/pkg/error"
1822 "bisonai.com/miko/node/pkg/fetcher"
1923 "bisonai.com/miko/node/pkg/secrets"
2024 "bisonai.com/miko/node/pkg/utils/request"
2125 "bisonai.com/miko/node/pkg/utils/retrier"
22- "github.com/rs/zerolog/log"
2326)
2427
2528const (
@@ -34,10 +37,47 @@ var urls = map[string]urlEntry{
3437 "peg-por" : {
3538 "/{CHAIN}/peg-{CHAIN}.por.json" ,
3639 "/{CHAIN}/peg.por.json" ,
40+ false ,
3741 },
3842 "gp" : {
3943 "/{CHAIN}/gp-{CHAIN}.json" ,
4044 "/{CHAIN}/gp.json" ,
45+ false ,
46+ },
47+ "aapl" : {
48+ "/{CHAIN}/aapl-{CHAIN}.json" ,
49+ "/{CHAIN}/aapl.json" ,
50+ true ,
51+ },
52+ "amzn" : {
53+ "/{CHAIN}/amzn-{CHAIN}.json" ,
54+ "/{CHAIN}/amzn.json" ,
55+ true ,
56+ },
57+ "googl" : {
58+ "/{CHAIN}/googl-{CHAIN}.json" ,
59+ "/{CHAIN}/googl.json" ,
60+ true ,
61+ },
62+ "meta" : {
63+ "/{CHAIN}/meta-{CHAIN}.json" ,
64+ "/{CHAIN}/meta.json" ,
65+ true ,
66+ },
67+ "msft" : {
68+ "/{CHAIN}/msft-{CHAIN}.json" ,
69+ "/{CHAIN}/msft.json" ,
70+ true ,
71+ },
72+ "nvda" : {
73+ "/{CHAIN}/nvda-{CHAIN}.json" ,
74+ "/{CHAIN}/nvda.json" ,
75+ true ,
76+ },
77+ "tsla" : {
78+ "/{CHAIN}/tsla-{CHAIN}.json" ,
79+ "/{CHAIN}/tsla.json" ,
80+ true ,
4181 },
4282}
4383
@@ -84,6 +124,7 @@ func New(ctx context.Context) (*app, error) {
84124 definition : d ,
85125 adapter : ad ,
86126 aggregator : ag ,
127+ useProxy : u .useProxy ,
87128 }
88129
89130 entries [n ] = e
@@ -104,9 +145,15 @@ func New(ctx context.Context) (*app, error) {
104145 return nil , err
105146 }
106147
148+ proxies , err := db .QueryRows [types.Proxy ](ctx , "SELECT * FROM proxies" , nil )
149+ if err != nil {
150+ return nil , err
151+ }
152+
107153 return & app {
108154 entries : entries ,
109155 kaiaHelper : chainHelper ,
156+ proxies : proxies ,
110157 }, nil
111158}
112159
@@ -183,7 +230,7 @@ func (a *app) startJob(ctx context.Context, entry entry) {
183230}
184231
185232func (a * app ) execute (ctx context.Context , e entry ) error {
186- v , err := fetcher .FetchSingle (ctx , e .definition )
233+ v , err := fetcher .FetchSingle (ctx , e .definition , a . buildRequestOpts ( e ) ... )
187234 if err != nil {
188235 return err
189236 }
@@ -319,3 +366,26 @@ func (a *app) getRoundId(ctx context.Context, e entry) (uint32, error) {
319366
320367 return RoundID , nil
321368}
369+
370+ func (a * app ) getNextProxy () * string {
371+ a .Lock ()
372+ defer a .Unlock ()
373+
374+ if len (a .proxies ) == 0 {
375+ return nil
376+ }
377+
378+ proxy := a .proxies [a .proxyIdx % len (a .proxies )].GetProxyUrl ()
379+ a .proxyIdx ++
380+ return & proxy
381+ }
382+
383+ func (a * app ) buildRequestOpts (e entry ) []request.RequestOption {
384+ opts := []request.RequestOption {}
385+ if e .useProxy {
386+ if p := a .getNextProxy (); p != nil && * p != "" {
387+ opts = append (opts , request .WithProxy (* p ))
388+ }
389+ }
390+ return opts
391+ }
0 commit comments