Skip to content

Commit

Permalink
update indexer: index all txs
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCherepovskyi committed Aug 25, 2023
1 parent f386b1e commit 153a595
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 5,554 deletions.
4 changes: 0 additions & 4 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ networks:
rpc: "https://sepolia.infura.io/v3/"


api:
endpoint: "https://api.rarify.tokend.io/v1/chains"
auto_init: true

meta_data:
header: "66613161666237613a"
footer: "3b"
Expand Down
3 changes: 2 additions & 1 deletion internal/assets/migrations/001_initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ CREATE TABLE transactions (
network_from VARCHAR(10),
value_to numeric,
timestamp_to timestamp,
PRIMARY KEY (tx_hash_from, network_from)
currency VARCHAR(10),
PRIMARY KEY (payment_id)
);


Expand Down
40 changes: 0 additions & 40 deletions internal/config/api.go

This file was deleted.

4 changes: 1 addition & 3 deletions internal/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Config interface {
types.Copuser
NetworkConfiger
MetaDataConfiger
APIConfiger

ChainListenerConfiger
comfig.Listenerer
}
Expand All @@ -25,7 +25,6 @@ type config struct {
types.Copuser
comfig.Listenerer
NetworkConfiger
APIConfiger
MetaDataConfiger
ChainListenerConfiger
getter kv.Getter
Expand All @@ -35,7 +34,6 @@ func New(getter kv.Getter) Config {
return &config{
getter: getter,
MetaDataConfiger: NewMetaDataConfiger(getter),
APIConfiger: NewAPIConfiger(getter),
NetworkConfiger: NewNetworkConfiger(getter),
Databaser: pgdb.NewDatabaser(getter),
Copuser: copus.NewCopuser(getter),
Expand Down
6 changes: 6 additions & 0 deletions internal/data/pg/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ func (q *TransactionsQ) FilterByNotReady() data.TransactionsQ {

return q
}
func (q *TransactionsQ) FilterByNetworkFrom(networkFrom int32) data.TransactionsQ {
q.sql = q.sql.Where(sq.Eq{txHashFromField: networkFrom})
q.upd = q.upd.Where(sq.Eq{txHashFromField: networkFrom})

return q
}

func (q *TransactionsQ) Page(pageParams pgdb.OffsetPageParams) data.TransactionsQ {
q.sql = pageParams.ApplyTo(q.sql, idField)
Expand Down
6 changes: 4 additions & 2 deletions internal/data/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
type TransactionsQ interface {
New() TransactionsQ
Insert(data *Transactions) error
FilterByRecipient(address string) TransactionsQ
Select() ([]Transactions, error)
Page(pageParams pgdb.OffsetPageParams) TransactionsQ
FilterByPaymentID(paymentID string) TransactionsQ
Update(data *Transactions) error
FilterByReady() TransactionsQ
FilterByNotReady() TransactionsQ
FilterByNetworkFrom(networkFrom int32) TransactionsQ
FilterByRecipient(address string) TransactionsQ
FilterByPaymentID(paymentID string) TransactionsQ
}

type Transactions struct {
Expand All @@ -26,5 +27,6 @@ type Transactions struct {
Recipient string `db:"recipient" structs:"recipient"`
Sender string `db:"sender" structs:"sender"`
ValueTo string `db:"value_to" structs:"value_to"`
Currency string `db:"currency" structs:"currency"`
TimestampTo time.Time `db:"timestamp_to" structs:"timestamp_to"`
}
2 changes: 1 addition & 1 deletion internal/service/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s *service) run() error {
s.log.Info("Service started")

r := s.router()
listenHandler := handler.NewHandler(s.log, s.cfg.Network().NetInfoList, s.cfg.API(), pg.NewMasterQ(s.cfg.DB()), s.cfg.MetaData(), s.cfg.ChainListener())
listenHandler := handler.NewHandler(s.log, s.cfg.Network().NetInfoList, pg.NewMasterQ(s.cfg.DB()), s.cfg.MetaData(), s.cfg.ChainListener())
if err := listenHandler.Init(); err != nil {
return errors.Wrap(err, "failed to init listeners")
}
Expand Down
37 changes: 4 additions & 33 deletions internal/service/core/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/dl-only-tokens/back-listener/internal/config"
"github.com/dl-only-tokens/back-listener/internal/data"
"github.com/dl-only-tokens/back-listener/internal/service/core/listener"
"github.com/dl-only-tokens/back-listener/internal/service/core/rarimo"
"github.com/pkg/errors"
"gitlab.com/distributed_lab/logan/v3"
"math/big"
Expand All @@ -18,16 +17,14 @@ type Handler interface {
Init() error
}

func NewHandler(log *logan.Entry, networker []config.NetInfo, rarimoApi *config.API, masterQ data.MasterQ, metaData *config.MetaData, chainListener *config.ChainListener) Handler {
func NewHandler(log *logan.Entry, networker []config.NetInfo, masterQ data.MasterQ, metaData *config.MetaData, chainListener *config.ChainListener) Handler {
return &ListenerHandler{
Listeners: make([]listener.Listener, 0),
ctx: context.Background(),
log: log,
supportNetworks: networker,
pauseTime: chainListener.PauseTime,
rarimoAPI: rarimoApi.Endpoint,
masterQ: masterQ,
isAutoInit: rarimoApi.IsAutoInit,
txMetaData: metaData,
abiPath: chainListener.AbiPath,
healthCheckChan: make(chan listener.Listener),
Expand All @@ -48,13 +45,6 @@ func (h *ListenerHandler) Run() {
}

func (h *ListenerHandler) Init() error {
if h.isAutoInit {
if err := h.autoInitContracts(); err != nil {
return errors.Wrap(err, "failed to do auto init")
}
return nil
}

if err := h.initListeners(h.supportNetworks); err != nil {
return errors.Wrap(err, "failed to do auto init")
}
Expand All @@ -63,32 +53,18 @@ func (h *ListenerHandler) Init() error {

}

func (h *ListenerHandler) autoInitContracts() error {
rarimoHandler := rarimo.NewRarimoHandler(h.rarimoAPI)
networks, err := rarimoHandler.GetContractsAddresses()
if err != nil {
return errors.Wrap(err, "failed to get contract list")
}

if err = h.initListeners(networks); err != nil {
return errors.Wrap(err, "failed to initListeners")
}

return nil
}

func (h *ListenerHandler) initListeners(data []config.NetInfo) error {
for _, network := range data {

preparedListener, err := h.prepareNewListener(network.Name, network.Address, false)
preparedListener, err := h.prepareNewListener(network.Name, false)
if err != nil {
h.log.WithError(err).Error("failed to connect to rpc")
continue
}

h.addNewListener(preparedListener)

preparedListener, err = h.prepareNewListener(network.Name, network.Address, true)
preparedListener, err = h.prepareNewListener(network.Name, true)
if err != nil {
h.log.WithError(err).Error("failed to connect to rpc")
continue
Expand All @@ -100,18 +76,13 @@ func (h *ListenerHandler) initListeners(data []config.NetInfo) error {
return nil
}

func (h *ListenerHandler) prepareNewListener(network string, address string, isIndexer bool) (listener.Listener, error) {
func (h *ListenerHandler) prepareNewListener(network string, isIndexer bool) (listener.Listener, error) {
netInfo := h.findNetwork(network)
if netInfo == nil {
return nil, errors.New(fmt.Sprintf("unsupported network: %s", network))
}

if len(address) == 0 {
return nil, errors.New("address is empty")
}

info := listener.EthInfo{
Address: address,
RPC: netInfo.Rpc,
ChainID: netInfo.ChainID,
NetworkName: network,
Expand Down
5 changes: 0 additions & 5 deletions internal/service/core/handler/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (
"gitlab.com/distributed_lab/logan/v3"
)

const (
ChanIsClosed = iota
)

type ListenerHandler struct {
Listeners []listener.Listener
supportNetworks []config.NetInfo
Expand All @@ -21,7 +17,6 @@ type ListenerHandler struct {
healthCheckChan chan listener.Listener
rarimoAPI string
masterQ data.MasterQ
isAutoInit bool
txMetaData *config.MetaData
abiPath string
}
Loading

0 comments on commit 153a595

Please sign in to comment.