Skip to content

Commit

Permalink
Merge pull request #3871 from TrueBlocks/feature/better-init
Browse files Browse the repository at this point in the history
Starts to improve chifra init
  • Loading branch information
tjayrush authored Aug 31, 2024
2 parents b9a248f + d7f8d02 commit e4efe9a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// error occurs the program exits.
func main() {
opts := sdk.WhenOptions{
BlockIds: []string{"0-19000000:monthly"},
BlockIds: []string{"12-1000"},
Globals: sdk.Globals{
Cache: true,
},
Expand Down
8 changes: 4 additions & 4 deletions examples/withStreaming/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
func main() {
namesMap, _ = names.LoadNamesMap("mainnet", types.Custom|types.Prefund|types.Regular, nil)

TestStreamAbis()
// TestStreamAbis()
TestStreamBlocks()
// TestStreamChunks()
// TestStreamConfig()
TestStreamExport()
// TestStreamExport()
// TestStreamInit()
// TestStreamList()
// TestStreamLogs()
// TestStreamMonitors()
TestStreamNames()
// TestStreamNames()
// TestStreamReceipts()
// TestStreamSlurp()
// TestStreamState()
Expand All @@ -27,7 +27,7 @@ func main() {
// TestStreamTraces()
// TestStreamTransactions()
// TestStreamWhen()
TestStreamProgress()
// TestStreamProgress()
}

var namesMap = map[base.Address]types.Name{}
25 changes: 14 additions & 11 deletions examples/withStreaming/streamBlocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ func TestBlocks[T BlockType](mode ...string) {
select {
case model := <-opts.RenderCtx.ModelChan:
if item, ok := model.(T); ok {
fmt.Printf("%d item: %s\r", cnt, item)
// if cnt != 0 {
// fmt.Println(",")
// }
fmt.Printf("%s\n", item) // %d item: %s\r", cnt, item)
cnt++
} else {
logger.Error("not the right type", reflect.TypeOf(model))
}
case err := <-opts.RenderCtx.ErrorChan:
logger.Error(err.Error())
}
cnt++
if opts.RenderCtx.WasCanceled() {
fmt.Println()
return
Expand All @@ -48,10 +51,10 @@ func TestBlocks[T BlockType](mode ...string) {
if _, _, err := opts.BlocksUncles(); err != nil {
logger.Error(err.Error())
}
// } else {
// if _, _, err := opts.Blocks(); err != nil {
// logger.Error(err.Error())
// }
} else {
if _, _, err := opts.Blocks(); err != nil {
logger.Error(err.Error())
}
}
case *types.LightBlock:
if _, _, err := opts.BlocksHashes(); err != nil {
Expand Down Expand Up @@ -79,10 +82,10 @@ func TestBlocks[T BlockType](mode ...string) {

func TestStreamBlocks() {
TestBlocks[*types.Block]()
TestBlocks[*types.LightBlock]()
TestBlocks[*types.Log]()
TestBlocks[*types.Trace]()
TestBlocks[*types.Block]("uncles")
// TestBlocks[*types.LightBlock]()
// TestBlocks[*types.Log]()
// TestBlocks[*types.Trace]()
// TestBlocks[*types.Block]("uncles")
// TestBlocks[*types.Appearance]()
TestBlocks[*types.Withdrawal]()
// TestBlocks[*types.Withdrawal]()
}
6 changes: 6 additions & 0 deletions sdk/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ func (opts *InitOptions) InitDryRun() ([]types.Message, *types.MetaData, error)

// No enums
// EXISTING_CODE
// Init implements the chifra init --all command.
func (opts *InitOptions) Init() ([]types.Message, *types.MetaData, error) {
in := opts.toInternal()
return queryInit[types.Message](in)
}

// EXISTING_CODE
3 changes: 3 additions & 0 deletions sdk/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ func (opts *ScrapeOptions) ScrapeDryRun() ([]types.Message, *types.MetaData, err

// No enums
// EXISTING_CODE
func (opts *ScrapeOptions) ScrapeRunOnce() ([]types.Message, *types.MetaData, error) {
return opts.ScrapeRunCount(1)
}
// EXISTING_CODE
1 change: 1 addition & 0 deletions src/apps/chifra/internal/scrape/scrape_manager_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

// Report prints out a report of the progress of the scraper.
func (bm *BlazeManager) report(nBlocks, perChunk, nChunks, nAppsNow, nAppsFound, nAddrsFound int) {
_ = nBlocks // linter
nNeeded := perChunk - base.Min(perChunk, nAppsNow)
appsPerAddr := float64(nAppsFound) / float64(nAddrsFound)
pctFull := float64(nAppsNow) / float64(perChunk)
Expand Down

0 comments on commit e4efe9a

Please sign in to comment.