@@ -108,7 +108,7 @@ func (s *VelarScraper) mainLoop() {
108
108
case <- s .ticker .C :
109
109
err := s .Update ()
110
110
if err != nil {
111
- s .logger .Error (err )
111
+ s .logger .WithError (err ). Error ( "failed to run Update" )
112
112
}
113
113
case <- s .shutdown :
114
114
s .logger .Println ("shutting down" )
@@ -121,7 +121,6 @@ func (s *VelarScraper) mainLoop() {
121
121
func (s * VelarScraper ) Update () error {
122
122
txs , err := s .api .GetAllBlockTransactions (s .currentHeight )
123
123
if err != nil {
124
- s .logger .WithError (err ).Error ("failed to GetBlockTransactions" )
125
124
return err
126
125
}
127
126
@@ -130,10 +129,14 @@ func (s *VelarScraper) Update() error {
130
129
}
131
130
s .currentHeight += 1
132
131
133
- swapTxs := s .filterSwapTransactions (txs )
132
+ swapTxs , err := s .fetchSwapTransactions (txs )
133
+ if err != nil {
134
+ return err
135
+ }
134
136
if len (swapTxs ) == 0 {
135
137
return nil
136
138
}
139
+
137
140
pools , err := s .getPools ()
138
141
if err != nil {
139
142
s .logger .WithError (err ).Error ("failed to GetAllPoolsExchange" )
@@ -154,6 +157,17 @@ func (s *VelarScraper) Update() error {
154
157
continue
155
158
}
156
159
160
+ if swapInfo .TokenIn == "" || swapInfo .TokenOut == "" {
161
+ for _ , arg := range tx .ContractCall .FunctionArgs {
162
+ switch arg .Name {
163
+ case "token-in" :
164
+ swapInfo .TokenIn = arg .Repr [1 :]
165
+ case "token-out" :
166
+ swapInfo .TokenOut = arg .Repr [1 :]
167
+ }
168
+ }
169
+ }
170
+
157
171
diaTrade := s .handleTrade (& pool , swapInfo , tx )
158
172
s .logger .
159
173
WithField ("parentAddress" , pool .Address ).
@@ -171,7 +185,7 @@ func (s *VelarScraper) getPools() ([]dia.Pool, error) {
171
185
return s .db .GetAllPoolsExchange (s .exchangeName , 0 )
172
186
}
173
187
174
- func (s * VelarScraper ) filterSwapTransactions (txs []stackshelper.Transaction ) []stackshelper.Transaction {
188
+ func (s * VelarScraper ) fetchSwapTransactions (txs []stackshelper.Transaction ) ( []stackshelper.Transaction , error ) {
175
189
swapTxs := make ([]stackshelper.Transaction , 0 )
176
190
177
191
for _ , tx := range txs {
@@ -180,11 +194,20 @@ func (s *VelarScraper) filterSwapTransactions(txs []stackshelper.Transaction) []
180
194
strings .HasPrefix (tx .ContractCall .FunctionName , "swap" )
181
195
182
196
if isSwapTx && tx .TxStatus == "success" {
183
- swapTxs = append (swapTxs , tx )
197
+ // This is a temporary workaround introduced due to a bug in hiro stacks API.
198
+ // Results returned from /blocks/{block_height}/transactions route have empty
199
+ // `name` field in `contract_call.function_args` list.
200
+ // TODO: remove this as soon as the issue is fixed.
201
+ normalizedTx , err := s .api .GetTransactionAt (tx .TxID )
202
+ if err != nil {
203
+ return nil , err
204
+ }
205
+
206
+ swapTxs = append (swapTxs , normalizedTx )
184
207
}
185
208
}
186
209
187
- return swapTxs
210
+ return swapTxs , nil
188
211
}
189
212
190
213
func (s * VelarScraper ) handleTrade (pool * dia.Pool , swapInfo velarhelper.SwapInfo , tx stackshelper.Transaction ) * dia.Trade {
@@ -199,7 +222,6 @@ func (s *VelarScraper) handleTrade(pool *dia.Pool, swapInfo velarhelper.SwapInfo
199
222
var trade dia.Trade
200
223
201
224
if swapInfo .TokenIn == token0 .Address {
202
- log .Info ("here" )
203
225
trade .Pair = fmt .Sprintf ("%s-%s" , token1 .Symbol , token0 .Symbol )
204
226
trade .Symbol = token1 .Symbol
205
227
trade .BaseToken = token0
@@ -209,9 +231,7 @@ func (s *VelarScraper) handleTrade(pool *dia.Pool, swapInfo velarhelper.SwapInfo
209
231
amount1Out , _ := utils .StringToFloat64 (amountOut , int64 (token1 .Decimals ))
210
232
volume = amount1Out
211
233
price = amount0In / amount1Out
212
-
213
234
} else {
214
- log .Info ("there" )
215
235
trade .Pair = fmt .Sprintf ("%s-%s" , token0 .Symbol , token1 .Symbol )
216
236
trade .Symbol = token0 .Symbol
217
237
trade .BaseToken = token1
0 commit comments