diff --git a/config.yaml b/config.yaml index 6d96b0d..6956fd7 100644 --- a/config.yaml +++ b/config.yaml @@ -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: @@ -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 diff --git a/docs/spec/components/schemas/GetTxList.yaml b/docs/spec/components/schemas/GetTxList.yaml index 394e8c0..d6d8405 100644 --- a/docs/spec/components/schemas/GetTxList.yaml +++ b/docs/spec/components/schemas/GetTxList.yaml @@ -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' diff --git a/docs/spec/components/schemas/TxBlob.yaml b/docs/spec/components/schemas/TxBlob.yaml index 7d0c917..9764efa 100644 --- a/docs/spec/components/schemas/TxBlob.yaml +++ b/docs/spec/components/schemas/TxBlob.yaml @@ -3,6 +3,8 @@ required: - payment_id - tx_hash - recipient + - tx_hash_from + - tx_hash_to - network_from - network_to properties: diff --git a/internal/service/api/handlers/get_tx_lists.go b/internal/service/api/handlers/get_tx_lists.go index 322b518..7ac519e 100644 --- a/internal/service/api/handlers/get_tx_lists.go +++ b/internal/service/api/handlers/get_tx_lists.go @@ -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) } diff --git a/internal/service/core/handler/handler.go b/internal/service/core/handler/handler.go index d49192b..a7a87f6 100644 --- a/internal/service/core/handler/handler.go +++ b/internal/service/core/handler/handler.go @@ -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 { @@ -92,6 +85,7 @@ func (h *ListenerHandler) initListeners(data []config.NetInfo) error { h.addNewListener(preparedListener) } + return nil } @@ -130,6 +124,7 @@ func (h *ListenerHandler) findByNetwork(network string) listener.Listener { return l } } + return nil } @@ -143,5 +138,6 @@ func (h *ListenerHandler) findNetwork(network string) *config.NetInfo { return &l } } + return nil } diff --git a/internal/service/core/listener/listenr.go b/internal/service/core/listener/listenr.go index c182f82..f0ece8c 100644 --- a/internal/service/core/listener/listenr.go +++ b/internal/service/core/listener/listenr.go @@ -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 } @@ -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 } @@ -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, }) @@ -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 } @@ -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 { @@ -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 } @@ -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 } diff --git a/internal/service/core/listener/types.go b/internal/service/core/listener/types.go index a460f9e..2c49eaf 100644 --- a/internal/service/core/listener/types.go +++ b/internal/service/core/listener/types.go @@ -2,6 +2,8 @@ package listener import "github.com/ethereum/go-ethereum/common" +const receiverPositionOnEvent = 5 + type TxInfo struct { Recipient string PaymentID string diff --git a/resources/model_get_tx_list_relationships.go b/resources/model_get_tx_list_relationships.go index c11e049..9b6a814 100644 --- a/resources/model_get_tx_list_relationships.go +++ b/resources/model_get_tx_list_relationships.go @@ -5,5 +5,5 @@ package resources type GetTxListRelationships struct { - Data map[string]interface{} `json:"data"` + Data TxBlobRelationship `json:"data"` } diff --git a/resources/model_tx_blob.go b/resources/model_tx_blob.go index 9d176a2..fda757d 100644 --- a/resources/model_tx_blob.go +++ b/resources/model_tx_blob.go @@ -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"` }