Skip to content

Commit

Permalink
Support address history indexing (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantudor authored Oct 18, 2020
1 parent 0b7c488 commit 8f083a5
Show file tree
Hide file tree
Showing 39 changed files with 631 additions and 837 deletions.
File renamed without changes.
28 changes: 0 additions & 28 deletions Dockerfile.addressValidator

This file was deleted.

28 changes: 0 additions & 28 deletions Dockerfile.cfundValidator

This file was deleted.

30 changes: 0 additions & 30 deletions Dockerfile.indexerCli

This file was deleted.

11 changes: 1 addition & 10 deletions bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,5 @@ dingo -src=./internal/config/di -dest=./generated

export DOCKER_BUILDKIT=1

docker build -f ./Dockerfile.indexerd . -t navexplorer/indexer:$tag
docker build -f ./Dockerfile . -t navexplorer/indexer:$tag
docker push navexplorer/indexer:$tag

#docker build -f ./Dockerfile.indexerCli . -t navexplorer/indexer-cli:$tag
#docker push navexplorer/indexer-cli:$tag

docker build -f ./Dockerfile.addressValidator . -t navexplorer/address-validator:$tag
docker push navexplorer/address-validator:$tag

#docker build -f ./Dockerfile.cfundValidator . -t navexplorer/cfund-validator:$tag
#docker push navexplorer/cfund-validator:$tag
18 changes: 16 additions & 2 deletions cmd/address-validator/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
package main

import (
"github.com/NavExplorer/navexplorer-indexer-go/internal/validator"
"github.com/NavExplorer/navexplorer-indexer-go/generated/dic"
"github.com/NavExplorer/navexplorer-indexer-go/internal/config"
"github.com/sarulabs/dingo/v3"
"os"
)

func main() {
new(validator.AddressValidator).Execute()
config.Init()

container, _ := dic.NewContainer(dingo.App)
container.GetElastic().InstallMappings()

addressRepo := container.GetAddressRepo()
rewinder := container.GetAddressRewinder()

address, err := addressRepo.GetAddress(os.Args[1])
if err == nil {
rewinder.ResetAddress(address)
}
}
9 changes: 0 additions & 9 deletions cmd/cfund-validator/main.go

This file was deleted.

39 changes: 39 additions & 0 deletions cmd/soft-fork/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"github.com/NavExplorer/navexplorer-indexer-go/generated/dic"
"github.com/NavExplorer/navexplorer-indexer-go/internal/config"
"github.com/sarulabs/dingo/v3"
log "github.com/sirupsen/logrus"
)

var container *dic.Container

func main() {
config.Init()

container, _ = dic.NewContainer(dingo.App)
container.GetElastic().InstallMappings()
container.GetSoftforkService().InitSoftForks()
bestBlock, err := container.GetBlockRepo().GetBestBlock()
if err != nil {
log.Fatal(err)
}

for i := 1; i <= int(bestBlock.Height); i += 2016 {
blocks, err := container.GetBlockRepo().GetBlocksBetweenHeight(uint64(i), uint64(i+2016))
if err != nil {
log.Fatal(err)
}
for _, block := range blocks {
container.GetSoftforkIndexer().Index(block)
}
container.GetElastic().Persist()
}
container.GetElastic().Persist()
//block, err := container.GetBlockRepo().GetBlockByHeight()
//if err == nil {
// log.Info("Rewind SoftForks to height: ", block.Height)
//// container.GetSoftforkRewinder().Rewind(block.Height - 10)
//}
}
49 changes: 10 additions & 39 deletions config/mappings/address.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"mappings": {
"_source": {
"excludes": ["rich_list"]
},
"properties": {
"hash": {
"type": "text",
Expand All @@ -11,47 +14,15 @@
}
},
"height": {"type": "long"},
"balance": {"type": "long"},
"received": {
"type": "long"
},
"receivedCount": {
"type": "long"
},
"sent": {
"type": "long"
},
"sentCount": {
"type": "long"
},
"staked": {
"type": "long"
},
"stakedCount": {
"type": "long"
},
"coldReceived": {
"type": "long"
},
"coldReceivedCount": {
"type": "long"
},
"coldSent": {
"type": "long"
},
"coldSentCount": {
"type": "long"
},
"coldStaked": {
"type": "long"
"spendable": {"type": "long"},
"stakabout": {"type": "long"},
"voting_weight": {"type": "long"},
"created_time": {
"type": "date"
},
"coldStakedCount": {
"created_block": {
"type": "long"
},
"coldBalance": {
"type": "long"
},
"position": {"type": "long"}
}
}
},
"settings": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"mappings": {
"properties": {
"hash": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
"height": {
"type": "long"
},
"txindex": {
"type": "integer"
},
"time": {
"type": "date"
},
"txid": {
"type": "text",
Expand All @@ -19,16 +19,7 @@
}
}
},
"height": {
"type": "long"
},
"index": {
"type": "integer"
},
"time": {
"type": "date"
},
"type": {
"address": {
"type": "text",
"fields": {
"keyword": {
Expand All @@ -37,13 +28,31 @@
}
}
},
"input": {"type": "long"},
"output": {"type": "long"},
"total": {"type": "long"},
"changes": {
"type": "nested",
"properties": {
"spendable": {"type": "long"},
"stakable": {"type": "long"},
"voting_weight": {"type": "long"}
}
},
"balance": {
"type": "long"
"type": "nested",
"properties": {
"spendable": {"type": "long"},
"stakable": {"type": "long"},
"voting_weight": {"type": "long"}
}
},
"is_stake": {
"type": "boolean"
},
"is_cfund_payout": {
"type": "boolean"
},
"cold": {"type": "boolean"}
"is_stake_payout": {
"type": "boolean"
}
}
},
"settings":{
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ module github.com/NavExplorer/navexplorer-indexer-go
go 1.13

require (
github.com/NavExplorer/navcoind-go v0.1.8-0.20200527214456-804845973a06
github.com/NavExplorer/subscriber v0.0.0-20200601212953-3a6c48dd3d5d
github.com/NavExplorer/navcoind-go v0.1.8-0.20200709223613-3322962ba291
github.com/NavExplorer/subscriber v0.0.0-20200923000930-1321b56838fc
github.com/certifi/gocertifi v0.0.0-20200211180108-c7c1fbc02894 // indirect
github.com/dgraph-io/badger/v2 v2.0.3 // indirect
github.com/getsentry/raven-go v0.2.0
github.com/gosimple/slug v1.9.0
github.com/joho/godotenv v1.3.0
github.com/mr-tron/base58 v1.2.0
github.com/olivere/elastic/v7 v7.0.9
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/sarulabs/dingo/v3 v3.1.0
github.com/sirupsen/logrus v1.6.0
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5 // indirect
github.com/streadway/amqp v0.0.0-20200108173154-1c71cc93ed71
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4
gopkg.in/natefinch/lumberjack.v2 v2.0.0
)
Loading

0 comments on commit 8f083a5

Please sign in to comment.