Skip to content

Commit

Permalink
Update Address Valdiator to single address
Browse files Browse the repository at this point in the history
  • Loading branch information
dantudor committed Aug 13, 2020
1 parent c0057b3 commit 0c33749
Showing 1 changed file with 26 additions and 35 deletions.
61 changes: 26 additions & 35 deletions internal/validator/addressValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/NavExplorer/navexplorer-indexer-go/internal/config"
"github.com/NavExplorer/navexplorer-indexer-go/internal/elastic_cache"
"github.com/NavExplorer/navexplorer-indexer-go/internal/service/address"
"github.com/NavExplorer/navexplorer-indexer-go/pkg/explorer"
"github.com/sarulabs/dingo/v3"
log "github.com/sirupsen/logrus"
"time"
Expand All @@ -21,44 +22,34 @@ func (v *AddressValidator) Execute() {
config.Init()
container, _ = dic.NewContainer(dingo.App)

log.Info("Loading all addresses")
addresses, err := container.GetAddressRepo().GetAllAddresses()
if err != nil {
log.WithError(err).Fatal("Failed to get all addresses")
}
log.Infof("Validating %d addresses", len(addresses))

for idx, a := range addresses {
if a.Height < 4233114 || a.ValidatedAt != 0 {
continue
}
log.Infof("%d - %s", idx, a.Hash)
a := &explorer.Address{Hash: "NaLKtxjrxQYa3e2J1kprqoHG4SYMj9Xnw1"}
log.Infof("Validating address: %s", a.Hash)

address.ResetAddress(a)
if txs, err := container.GetBlockRepo().GetAllTransactionsThatIncludeAddress(a.Hash); err == nil {
log.Infof("Loaded block transactions")
for _, tx := range txs {
block, err := container.GetBlockRepo().GetBlockByHeight(tx.Height)
if err != nil {
log.WithError(err).Fatalf("Failed to get block at height %d", tx.Height)
}
addressTxs := container.GetAddressIndexer().GenerateAddressTransactions(a, tx, block)
for _, addressTx := range addressTxs {
address.ApplyTxToAddress(a, addressTx)
_, err = container.GetElastic().Client.Index().
Index(elastic_cache.AddressTransactionIndex.Get()).
BodyJson(addressTx).
Id(addressTx.Slug()).
Do(context.Background())
}
address.ResetAddress(a)
if txs, err := container.GetBlockRepo().GetAllTransactionsThatIncludeAddress(a.Hash); err == nil {
log.Infof("Loaded block transactions")
for _, tx := range txs {
block, err := container.GetBlockRepo().GetBlockByHeight(tx.Height)
if err != nil {
log.WithError(err).Fatalf("Failed to get block at height %d", tx.Height)
}
addressTxs := container.GetAddressIndexer().GenerateAddressTransactions(a, tx, block)
for _, addressTx := range addressTxs {
address.ApplyTxToAddress(a, addressTx)
_, err = container.GetElastic().Client.Index().
Index(elastic_cache.AddressTransactionIndex.Get()).
BodyJson(addressTx).
Id(addressTx.Slug()).
Do(context.Background())
}
}

a.ValidatedAt = uint64(time.Now().Unix())
_, err = container.GetElastic().Client.Index().
Index(elastic_cache.AddressIndex.Get()).
BodyJson(a).
Id(a.Slug()).
Do(context.Background())
a.ValidatedAt = uint64(time.Now().Unix())
_, err = container.GetElastic().Client.Index().
Index(elastic_cache.AddressIndex.Get()).
BodyJson(a).
Id(a.Slug()).
Do(context.Background())
}
}
}

0 comments on commit 0c33749

Please sign in to comment.