Skip to content

Commit

Permalink
style fix, db
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCherepovskyi committed Aug 23, 2023
1 parent f518a7f commit a8fdf9b
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 39 deletions.
20 changes: 15 additions & 5 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@ networks:
keys:
- name: 'Goerli'
chain_id: 5
rpc: "https://goerli.infura.io/v3/5aabf6bd4d384c288d6f85d3d6278234"
# - name: 'Fuji'
# rpc: "https://avalanche-fuji.infura.io/v3/5aabf6bd4d384c288d6f85d3d6278234"
rpc: "https://goerli.infura.io/v3/"
- name: 'Fuji'
chain_id: 43113
rpc: "https://avalanche-fuji.infura.io/v3/"
- name: 'BSC Testnet'
chain_id: 97
rpc: "https://bsc-testnet.publicnode.com"
rpc: "https://data-seed-prebsc-2-s3.binance.org:8545/"
- name: 'Ethereum'
chain_id: 1
rpc: "https://mainnet.infura.io/v3/"
- name: 'Avalanche'
chain_id: 43114
rpc: "https://avalanche-mainnet.infura.io/v3/"
- name: 'Sepolia'
chain_id: 11155111
rpc: "https://sepolia.infura.io/v3/"


api:
Expand All @@ -30,7 +40,7 @@ meta_data:

chain_listener:
pause_time: 500
abi_path: "./pkg/contract/erc20/erc20.abi"
abi_path: "/fgo/src/github.com/dl-only-tokens/back-listener/pkg/contract/erc20/erc20.abi"

cop:
disabled: true
Expand Down
12 changes: 1 addition & 11 deletions docs/spec/components/schemas/GetTxList.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,4 @@ allOf:
- data
properties:
data:
type: object
required:
- attributes
attributes:
type: object
required:
- address:
properties:
address:
type: string
example: 0x1234.....
$ref: '#/components/schemas/TxBlobRelationship'
2 changes: 2 additions & 0 deletions docs/spec/components/schemas/TxBlob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ required:
- payment_id
- tx_hash
- recipient
- tx_hash_from
- tx_hash_to
- network_from
- network_to
properties:
Expand Down
3 changes: 2 additions & 1 deletion internal/service/api/handlers/get_tx_lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func prepareResponse(txs []data.Transactions) resources.GetTxListResponse {
NetworkTo: tx.NetworkTo,
PaymentId: tx.PaymentID,
Recipient: tx.Recipient,
//TxHash: tx.TxHash,
TxHashTo: tx.TxHashTo,
TxHashFrom: tx.TxHashFrom,
}
txBlobs = append(txBlobs, blob)
}
Expand Down
10 changes: 3 additions & 7 deletions internal/service/core/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ import (
type Handler interface {
Run()
Init() error
healthCheck()
autoInitContracts() error
initListeners(data []config.NetInfo) error
findByNetwork(network string) listener.Listener
prepareNewListener(network string, address string) (listener.Listener, error)
addNewListener(listener listener.Listener)
findNetwork(network string) *config.NetInfo
}

func NewHandler(log *logan.Entry, networker []config.NetInfo, rarimoApi *config.API, masterQ data.MasterQ, metaData *config.MetaData, chainListener *config.ChainListener) Handler {
Expand Down Expand Up @@ -92,6 +85,7 @@ func (h *ListenerHandler) initListeners(data []config.NetInfo) error {

h.addNewListener(preparedListener)
}

return nil
}

Expand Down Expand Up @@ -130,6 +124,7 @@ func (h *ListenerHandler) findByNetwork(network string) listener.Listener {
return l
}
}

return nil
}

Expand All @@ -143,5 +138,6 @@ func (h *ListenerHandler) findNetwork(network string) *config.NetInfo {
return &l
}
}

return nil
}
14 changes: 6 additions & 8 deletions internal/service/core/listener/listenr.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (l *ListenData) Run() {
case <-ticker.C:
block, err := client.BlockByNumber(context.Background(), nil)
if err != nil {
l.log.WithError(err).Error("failed to get last block ")
l.log.WithError(err).Error(l.chainName, ": failed to get last block ")
return
}

Expand Down Expand Up @@ -272,7 +272,7 @@ func (l *ListenData) parseRecipientFromEvent(events []types.Log, blockHash commo
l.log.WithError(err).Error("failed to unpack abi")
continue
}
if len(event) < 6 {
if len(event) < receiverPositionOnEvent+1 {
l.log.Error("event too short")
continue
}
Expand All @@ -284,7 +284,7 @@ func (l *ListenData) parseRecipientFromEvent(events []types.Log, blockHash commo
}

result = append(result, RecipientInfo{
Recipient: event[5].(string),
Recipient: event[receiverPositionOnEvent].(string),
TxHash: vLog.TxHash,
Sender: sender,
})
Expand All @@ -307,7 +307,7 @@ func (l *ListenData) indexContractTxs(client *ethclient.Client) {
case <-ticker.C:
block, err := client.BlockByNumber(context.Background(), nil)
if err != nil {
l.log.WithError(err).Error("failed to get last block ")
l.log.WithError(err).Error(l.chainName, ": failed to get last block ")
return
}

Expand Down Expand Up @@ -341,10 +341,6 @@ func (l *ListenData) indexContractTxs(client *ethclient.Client) {

func (l *ListenData) filteringTx(block *types.Block) map[string][]string {
result := make(map[string][]string)
if l.chainName == "BSC Testnet" {
l.log.Debug(block.NumberU64(), " ", l.chainName)
}

for _, tx := range block.Transactions() {
if tx.To() != nil && bytes.Compare(tx.To().Bytes(), hexutil.MustDecode(l.address)) == 0 {

Expand Down Expand Up @@ -372,6 +368,7 @@ func (l *ListenData) parseAddressesFromTXs(txs []data.Transactions) []string {

func (l *ListenData) packTX(firstTX data.Transactions, secondTX data.Transactions) *data.Transactions {
firstTX.TxHashTo = secondTX.TxHashTo

return &firstTX
}

Expand All @@ -385,5 +382,6 @@ func (l *ListenData) getSender(txHash string, client *ethclient.Client, blockHas
if err != nil {
return "", errors.Wrap(err, "failed to get tx")
}

return sender.Hex(), nil
}
2 changes: 2 additions & 0 deletions internal/service/core/listener/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package listener

import "github.com/ethereum/go-ethereum/common"

const receiverPositionOnEvent = 5

type TxInfo struct {
Recipient string
PaymentID string
Expand Down
2 changes: 1 addition & 1 deletion resources/model_get_tx_list_relationships.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
package resources

type GetTxListRelationships struct {
Data map[string]interface{} `json:"data"`
Data TxBlobRelationship `json:"data"`
}
12 changes: 6 additions & 6 deletions resources/model_tx_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
package resources

type TxBlob struct {
NetworkFrom string `json:"network_from"`
NetworkTo string `json:"network_to"`
PaymentId string `json:"payment_id"`
Recipient string `json:"recipient"`
TxHashFrom *string `json:"tx_hash_from"`
TxHashTo *string `json:"tx_hash_to"`
NetworkFrom string `json:"network_from"`
NetworkTo string `json:"network_to"`
PaymentId string `json:"payment_id"`
Recipient string `json:"recipient"`
TxHashFrom string `json:"tx_hash_from"`
TxHashTo string `json:"tx_hash_to"`
}

0 comments on commit a8fdf9b

Please sign in to comment.