@@ -6,10 +6,13 @@ import (
66 "github.com/coinbase/rosetta-sdk-go/types"
77 "github.com/onrik/ethrpc"
88 "log"
9+ "math/big"
10+ "sync"
911)
1012
1113type Proxy struct {
12- c * ethrpc.EthRPC
14+ c * ethrpc.EthRPC
15+ wg sync.WaitGroup
1316}
1417
1518func New (url string ) * Proxy {
@@ -20,7 +23,7 @@ func New(url string) *Proxy {
2023 log .Fatal (err )
2124 }
2225 fmt .Println (version )
23- return & Proxy {client }
26+ return & Proxy {c : client }
2427}
2528
2629// Needed if the client needs to perform some action before connecting
@@ -41,15 +44,31 @@ func (oc *Proxy) Ready() error {
4144// Balances fetches the balance of the given address
4245// if height is not nil, then the balance will be displayed
4346// at the provided height, otherwise last block balance will be returned
44- func (oc * Proxy ) Balances (ctx context.Context , addr string , height * int64 ) (* types.AccountBalanceResponse , error ) {
45- balance , e := oc .c .EthGetBalance (addr , "latest" )
46- if e != nil {
47- return & types.AccountBalanceResponse {}, e
47+ func (oc * Proxy ) Balances (ctx context.Context , addr string , height * int64 ) (res * types.AccountBalanceResponse , err error ) {
48+ var (
49+ r * types.BlockResponse
50+ e1 , e2 error
51+ balance big.Int
52+ )
53+ oc .wg .Add (2 )
54+ go func () {
55+ defer oc .wg .Done ()
56+ balance , e1 = oc .c .EthGetBalance (addr , "latest" )
57+ }()
58+
59+ go func () {
60+ defer oc .wg .Done ()
61+ r , e2 = oc .CurrentBlock (ctx )
62+ }()
63+
64+ oc .wg .Wait ()
65+
66+ if e1 != nil {
67+ return & types.AccountBalanceResponse {}, e1
4868 }
4969
50- r , e := oc .CurrentBlock (ctx )
51- if e != nil {
52- return & types.AccountBalanceResponse {}, e
70+ if e2 != nil {
71+ return & types.AccountBalanceResponse {}, e2
5372 }
5473
5574 fmt .Printf ("account : %s, balance : %s, index : %v, hash : %s\n " , addr , balance .String (), r .Block .BlockIdentifier .Index , r .Block .BlockIdentifier .Hash )
0 commit comments