generated from KyberNetwork/go-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from KyberNetwork/feat/backfill-oneinch
feat: backfill oneinch
- Loading branch information
Showing
3 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/KyberNetwork/tradelogs/pkg/parser/oneinch" | ||
"github.com/KyberNetwork/tradelogs/pkg/storage" | ||
) | ||
|
||
var ( | ||
oneinchAbi, _ = oneinch.OneinchMetaData.GetAbi() | ||
oneinchRfqEvent, _ = oneinchAbi.Events[oneinch.FilledEvent] | ||
oneinchRfqEventHash = oneinchRfqEvent.String() | ||
) | ||
|
||
type rfqOrder struct { | ||
OrderHash string `json:"order_hash" binding:"required"` | ||
BlockNumber uint64 `json:"block_number" binding:"required"` | ||
LogIndex uint64 `json:"log_index" binding:"required"` | ||
EventHash string `json:"event_hash" binding:"required"` | ||
TxHash string `json:"tx_hash" binding:"required"` | ||
Maker string `json:"maker"` | ||
Taker string `json:"taker"` | ||
MakerToken string `json:"maker_token"` | ||
TakerToken string `json:"taker_token"` | ||
MakerTokenAmount string `json:"maker_token_amount"` | ||
TakerTokenAmount string `json:"taker_token_amount"` | ||
ContractAddress string `json:"contract_address"` | ||
Timestamp uint64 `json:"timestamp"` | ||
} | ||
type BackFillOneInchRequest []rfqOrder | ||
|
||
func (rfqOrders BackFillOneInchRequest) ToTradeLogs() []storage.TradeLog { | ||
tradeLogs := make([]storage.TradeLog, 0, len(rfqOrders)) | ||
for _, order := range rfqOrders { | ||
if order.EventHash != oneinchRfqEventHash { | ||
continue | ||
} | ||
if order.LogIndex < 0 || order.BlockNumber < 0 { | ||
continue | ||
} | ||
if order.TxHash == "" { | ||
continue | ||
} | ||
tradeLogs = append(tradeLogs, storage.TradeLog{ | ||
OrderHash: order.OrderHash, | ||
BlockNumber: order.BlockNumber, | ||
LogIndex: order.LogIndex, | ||
EventHash: order.EventHash, | ||
TxHash: order.TxHash, | ||
Maker: order.Maker, | ||
Taker: order.Taker, | ||
MakerToken: order.MakerToken, | ||
TakerToken: order.TakerToken, | ||
MakerTokenAmount: order.MakerTokenAmount, | ||
TakerTokenAmount: order.TakerTokenAmount, | ||
ContractAddress: order.ContractAddress, | ||
Timestamp: order.Timestamp, | ||
}) | ||
} | ||
return tradeLogs | ||
} |