|
1 | 1 | package leader |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "bytes" |
5 | 4 | "context" |
6 | | - "fmt" |
7 | 5 | "math/big" |
8 | 6 | "strconv" |
9 | 7 | "strings" |
10 | 8 | "sync" |
11 | 9 | "time" |
12 | 10 |
|
13 | | - "github.com/ethereum/go-ethereum" |
14 | | - "github.com/ethereum/go-ethereum/accounts/abi" |
15 | 11 | "github.com/ethereum/go-ethereum/common" |
16 | 12 |
|
17 | 13 | "github.com/diadata.org/Spectra-interoperability/pkg/logger" |
@@ -288,58 +284,7 @@ func (m *OnChainMonitor) generateKey(chainID int64, contractAddress common.Addre |
288 | 284 | } |
289 | 285 |
|
290 | 286 | func (m *OnChainMonitor) getValueFromContract(dest *DestinationMonitor, symbol string) (*big.Int, uint64, error) { |
291 | | - |
292 | | - const getValueABI = `[{ |
293 | | - "inputs": [{"internalType": "string", "name": "key", "type": "string"}], |
294 | | - "name": "getValue", |
295 | | - "outputs": [ |
296 | | - {"internalType": "uint128", "name": "value", "type": "uint128"}, |
297 | | - {"internalType": "uint128", "name": "timestamp", "type": "uint128"} |
298 | | - ], |
299 | | - "stateMutability": "view", |
300 | | - "type": "function" |
301 | | - }]` |
302 | | - |
303 | | - parsedABI, err := abi.JSON(bytes.NewReader([]byte(getValueABI))) |
304 | | - if err != nil { |
305 | | - return nil, 0, fmt.Errorf("failed to parse ABI: %w", err) |
306 | | - } |
307 | | - |
308 | | - data, err := parsedABI.Pack("getValue", symbol) |
309 | | - if err != nil { |
310 | | - return nil, 0, fmt.Errorf("failed to pack input data: %w", err) |
311 | | - } |
312 | | - |
313 | | - callMsg := ethereum.CallMsg{ |
314 | | - To: &dest.ContractAddress, |
315 | | - Data: data, |
316 | | - } |
317 | | - |
318 | | - resultBytes, err := dest.Client.CallContract(m.ctx, callMsg, nil) |
319 | | - if err != nil { |
320 | | - return nil, 0, fmt.Errorf("contract call failed: %w", err) |
321 | | - } |
322 | | - |
323 | | - outputs, err := parsedABI.Unpack("getValue", resultBytes) |
324 | | - if err != nil { |
325 | | - return nil, 0, fmt.Errorf("failed to unpack result: %w", err) |
326 | | - } |
327 | | - |
328 | | - if len(outputs) != 2 { |
329 | | - return nil, 0, fmt.Errorf("unexpected number of outputs: got %d, want 2", len(outputs)) |
330 | | - } |
331 | | - |
332 | | - value, ok := outputs[0].(*big.Int) |
333 | | - if !ok { |
334 | | - return nil, 0, fmt.Errorf("failed to convert value to big.Int, got type %T: %v", outputs[0], outputs[0]) |
335 | | - } |
336 | | - |
337 | | - timestamp, ok := outputs[1].(*big.Int) |
338 | | - if !ok { |
339 | | - return nil, 0, fmt.Errorf("failed to convert timestamp to big.Int, got type %T: %v", outputs[1], outputs[1]) |
340 | | - } |
341 | | - |
342 | | - return value, timestamp.Uint64(), nil |
| 287 | + return utils.GetValueFromOracleContract(m.ctx, dest.Client, dest.ContractAddress, symbol) |
343 | 288 | } |
344 | 289 |
|
345 | 290 | func formatValue(v *big.Int) string { |
|
0 commit comments