From 7f8de313a9ba2d5c41f901a4f8bb0d51d59b7f36 Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Tue, 9 Apr 2024 22:08:54 -0400 Subject: [PATCH] Adds Stringer interface to all types (#3568) * Adds Stringer interface to all types * Moves a few types out of internal * Moves MetaData to types * Fixes build and regenerates * Moves ipfspina nd reportcheck to types * Fixes build * Fixing build * Moves a few types out of internal * Upper case AppearanceTable * Moved the last type to pkg * Fixing build * Trying to remove index.AddressRecord and index.AppearanceRecord as dups * Removes index.AppearanceRecord in favor of types.SimpleAppRecord * Cleaning * Removes the idea of goOutput folder for auto-gen * Fix Typos in Comments (#3569) * modified readme.md in bin * cacheing to caching example fix * test commit again * Fix typos * Fix typos * Fix typos --------- Co-authored-by: Gary Snipes * Revert "Fix Typos in Comments (#3569)" (#3570) This reverts commit 1b95049f7380ae27f2b06b68f0066ef39f86ee57. * Cleaning --------- Co-authored-by: Gary Snipes <77077163+G-Snipes@users.noreply.github.com> Co-authored-by: Gary Snipes --- docs/content/api/openapi.yaml | 17 +- docs/content/chifra/admin.md | 1 + docs/content/data-model/accounts.md | 15 + sdk/go/abis.go | 4 +- sdk/go/blocks.go | 3 +- sdk/go/chunks.go | 4 +- sdk/go/config.go | 4 +- sdk/go/export.go | 4 +- sdk/go/init.go | 4 +- sdk/go/list.go | 3 +- sdk/go/logs.go | 3 +- sdk/go/meta.go | 6 +- sdk/go/monitors.go | 4 +- sdk/go/names.go | 3 +- sdk/go/receipts.go | 3 +- sdk/go/result.go | 11 +- sdk/go/slurp.go | 3 +- sdk/go/state.go | 3 +- sdk/go/status.go | 4 +- sdk/go/tokens.go | 4 +- sdk/go/traces.go | 3 +- sdk/go/transactions.go | 3 +- sdk/go/when.go | 3 +- src/apps/chifra/internal/abis/doc.go | 2 +- src/apps/chifra/internal/blocks/doc.go | 2 +- .../chifra/internal/blocks/handle_count.go | 4 +- src/apps/chifra/internal/blocks/output.go | 2 +- src/apps/chifra/internal/chunks/README.md | 1 + src/apps/chifra/internal/chunks/doc.go | 2 +- .../internal/chunks/handle_addresses.go | 8 +- .../chunks/handle_addresses_belongs.go | 81 +++- .../internal/chunks/handle_appearances.go | 2 +- .../chifra/internal/chunks/handle_blooms.go | 4 +- .../chifra/internal/chunks/handle_check.go | 22 +- .../internal/chunks/handle_check_deep.go | 6 +- .../internal/chunks/handle_check_hashes.go | 5 +- .../internal/chunks/handle_check_internal.go | 7 +- .../internal/chunks/handle_check_manifest.go | 6 +- .../chunks/handle_check_sequential.go | 5 +- .../internal/chunks/handle_check_sizes.go | 3 +- .../internal/chunks/handle_check_staging.go | 3 +- .../internal/chunks/handle_check_version.go | 4 +- .../chifra/internal/chunks/handle_diff.go | 3 +- .../chifra/internal/chunks/handle_index.go | 4 +- .../chifra/internal/chunks/handle_list.go | 4 +- src/apps/chifra/internal/chunks/handle_pin.go | 4 +- src/apps/chifra/internal/chunks/output.go | 14 +- .../internal/chunks/types_appearanceTable.go | 36 -- .../internal/chunks/types_chunkaddress.go | 59 --- .../internal/chunks/types_chunkbloom.go | 68 ---- .../internal/chunks/types_chunkindex.go | 65 ---- .../internal/chunks/types_chunkpinreport.go | 62 ---- src/apps/chifra/internal/config/doc.go | 2 +- src/apps/chifra/internal/config/output.go | 2 +- src/apps/chifra/internal/daemon/doc.go | 2 +- src/apps/chifra/internal/daemon/output.go | 2 +- src/apps/chifra/internal/explore/doc.go | 2 +- src/apps/chifra/internal/explore/output.go | 2 +- src/apps/chifra/internal/export/doc.go | 2 +- src/apps/chifra/internal/export/output.go | 2 +- src/apps/chifra/internal/init/doc.go | 2 +- src/apps/chifra/internal/init/output.go | 2 +- src/apps/chifra/internal/list/doc.go | 2 +- src/apps/chifra/internal/list/output.go | 2 +- src/apps/chifra/internal/logs/output.go | 2 +- .../chifra/internal/monitors/handle_clean.go | 4 +- src/apps/chifra/internal/monitors/output.go | 2 +- .../internal/monitors/types_monitorclean.go | 59 --- src/apps/chifra/internal/names/output.go | 2 +- src/apps/chifra/internal/receipts/output.go | 2 +- .../chifra/internal/scrape/notify_test.go | 2 + src/apps/chifra/internal/scrape/output.go | 2 +- .../internal/scrape/scrape_consolidate.go | 8 +- .../chifra/internal/scrape/scrape_manager.go | 2 + .../chifra/internal/scrape/scrape_prepare.go | 5 +- src/apps/chifra/internal/slurp/output.go | 2 +- src/apps/chifra/internal/state/output.go | 2 +- .../chifra/internal/status/handle_caches.go | 6 +- .../chifra/internal/status/handle_diagnose.go | 4 +- .../chifra/internal/status/handle_show.go | 192 +++++++++- src/apps/chifra/internal/status/output.go | 2 +- .../chifra/internal/status/types_cacheitem.go | 49 --- .../chifra/internal/status/types_status.go | 345 ------------------ src/apps/chifra/internal/tokens/output.go | 2 +- .../chifra/internal/traces/handle_counts.go | 4 +- src/apps/chifra/internal/traces/output.go | 2 +- .../chifra/internal/transactions/output.go | 2 +- .../chifra/internal/when/handle_ts_count.go | 4 +- .../chifra/internal/when/handle_ts_show.go | 4 +- src/apps/chifra/internal/when/output.go | 2 +- .../internal/when/types_timestampcount.go | 47 --- src/apps/chifra/pkg/filter/filter.go | 5 +- src/apps/chifra/pkg/filter/sort.go | 4 +- .../chifra/pkg/index/appearance_result.go | 5 +- src/apps/chifra/pkg/index/chunk_write.go | 9 +- .../chifra/pkg/index/index_address_record.go | 12 +- .../pkg/index/index_appearance_record.go | 14 +- src/apps/chifra/pkg/monitor/filter.go | 4 +- src/apps/chifra/pkg/monitor/monitor.go | 2 +- .../chifra/pkg/monitor/monitor_freshen.go | 7 +- src/apps/chifra/pkg/monitor/monitor_read.go | 3 +- .../chifra/pkg/monitor/monitor_remove_dups.go | 8 +- src/apps/chifra/pkg/monitor/monitor_test.go | 11 +- src/apps/chifra/pkg/monitor/monitor_write.go | 5 +- src/apps/chifra/pkg/monitor/truncate.go | 6 +- src/apps/chifra/pkg/notify/notification.go | 2 + src/apps/chifra/pkg/notify/scraper.go | 2 + src/apps/chifra/pkg/output/helpers/helpers.go | 2 + src/apps/chifra/pkg/output/json_writer.go | 2 + .../chifra/pkg/output/json_writer_test.go | 2 + src/apps/chifra/pkg/rpc/get_meta.go | 39 +- src/apps/chifra/pkg/types/types_abi.go | 7 + src/apps/chifra/pkg/types/types_appearance.go | 6 + .../chifra/pkg/types/types_appearanceTable.go | 91 +++++ .../chifra/pkg/types/types_appearancecount.go | 11 +- src/apps/chifra/pkg/types/types_block.go | 6 + .../blocks => pkg/types}/types_blockcount.go | 47 ++- src/apps/chifra/pkg/types/types_bounds.go | 6 + src/apps/chifra/pkg/types/types_cacheitem.go | 76 ++++ src/apps/chifra/pkg/types/types_chain.go | 6 + .../chifra/pkg/types/types_chunkaddress.go | 84 +++++ src/apps/chifra/pkg/types/types_chunkbloom.go | 106 ++++++ src/apps/chifra/pkg/types/types_chunkindex.go | 92 +++++ .../chifra/pkg/types/types_chunkpinreport.go | 88 +++++ .../chifra/pkg/types/types_chunkrecord.go | 10 +- src/apps/chifra/pkg/types/types_chunkstats.go | 7 + src/apps/chifra/pkg/types/types_function.go | 5 + .../chunks => pkg/types}/types_ipfspin.go | 41 ++- src/apps/chifra/pkg/types/types_log.go | 6 + src/apps/chifra/pkg/types/types_logfilter.go | 7 + src/apps/chifra/pkg/types/types_manifest.go | 7 + src/apps/chifra/pkg/types/types_metadata.go | 44 +++ src/apps/chifra/pkg/types/types_monitor.go | 7 + .../chifra/pkg/types/types_monitorclean.go | 84 +++++ src/apps/chifra/pkg/types/types_name.go | 6 + src/apps/chifra/pkg/types/types_namedblock.go | 7 + src/apps/chifra/pkg/types/types_parameter.go | 5 + src/apps/chifra/pkg/types/types_receipt.go | 6 + .../chunks => pkg/types}/types_reportcheck.go | 54 ++- src/apps/chifra/pkg/types/types_result.go | 6 + src/apps/chifra/pkg/types/types_slurp.go | 6 + src/apps/chifra/pkg/types/types_state.go | 6 + src/apps/chifra/pkg/types/types_statement.go | 6 + src/apps/chifra/pkg/types/types_status.go | 194 ++++++++++ .../when => pkg/types}/types_timestamp.go | 42 ++- .../chifra/pkg/types/types_timestampcount.go | 70 ++++ src/apps/chifra/pkg/types/types_token.go | 7 + src/apps/chifra/pkg/types/types_trace.go | 6 + .../chifra/pkg/types/types_traceaction.go | 6 + .../traces => pkg/types}/types_tracecount.go | 44 ++- .../chifra/pkg/types/types_tracefilter.go | 6 + .../chifra/pkg/types/types_traceresult.go | 6 + .../chifra/pkg/types/types_transaction.go | 6 + src/apps/chifra/pkg/types/types_withdrawal.go | 6 + src/dev_tools/goMaker/main.go | 1 - .../goMaker/templates/api/description.txt | 2 +- .../templates/classDefinitions/abi.toml | 1 - .../classDefinitions/appearance.toml | 1 - .../classDefinitions/appearancecount.toml | 1 - .../classDefinitions/appearancetable.toml | 7 + .../templates/classDefinitions/block.toml | 1 - .../classDefinitions/blockcount.toml | 1 - .../templates/classDefinitions/bounds.toml | 1 - .../templates/classDefinitions/cacheitem.toml | 1 - .../templates/classDefinitions/chain.toml | 1 - .../classDefinitions/chunkaddress.toml | 1 - .../classDefinitions/chunkbloom.toml | 1 - .../classDefinitions/chunkindex.toml | 1 - .../classDefinitions/chunkpinreport.toml | 1 - .../classDefinitions/chunkrecord.toml | 1 - .../classDefinitions/chunkstats.toml | 1 - .../fields/appearancetable.csv | 3 + .../templates/classDefinitions/function.toml | 1 - .../templates/classDefinitions/ipfspin.toml | 1 - .../templates/classDefinitions/log.toml | 1 - .../templates/classDefinitions/logfilter.toml | 1 - .../templates/classDefinitions/manifest.toml | 1 - .../templates/classDefinitions/monitor.toml | 1 - .../classDefinitions/monitorclean.toml | 1 - .../templates/classDefinitions/name.toml | 1 - .../classDefinitions/namedblock.toml | 1 - .../templates/classDefinitions/parameter.toml | 1 - .../templates/classDefinitions/receipt.toml | 1 - .../classDefinitions/reportcheck.toml | 1 - .../templates/classDefinitions/result.toml | 1 - .../templates/classDefinitions/slurp.toml | 1 - .../templates/classDefinitions/state.toml | 1 - .../templates/classDefinitions/statement.toml | 1 - .../templates/classDefinitions/status.toml | 1 - .../templates/classDefinitions/timestamp.toml | 1 - .../classDefinitions/timestampcount.toml | 1 - .../templates/classDefinitions/token.toml | 1 - .../templates/classDefinitions/trace.toml | 1 - .../classDefinitions/traceaction.toml | 1 - .../classDefinitions/tracecount.toml | 1 - .../classDefinitions/tracefilter.toml | 1 - .../classDefinitions/traceresult.toml | 1 - .../classDefinitions/transaction.toml | 1 - .../classDefinitions/withdrawal.toml | 1 - .../goMaker/templates/sdk_go_route.go.tmpl | 2 +- ..._apps_chifra_internal_route_output.go.tmpl | 2 +- ...s_chifra_internal_route_types_type.go.tmpl | 45 --- .../src_apps_chifra_pkg_types_type.go.tmpl | 5 + src/dev_tools/goMaker/types/load.go | 4 - .../goMaker/types/process_structure.go | 28 +- src/dev_tools/goMaker/types/types_member.go | 8 - .../goMaker/types/types_structure.go | 1 - test/gold/tools/ethslurp/ethslurp_help.txt | 2 +- .../tools/ethslurp/ethslurp_help_long.txt | 2 +- 209 files changed, 1803 insertions(+), 1216 deletions(-) delete mode 100644 src/apps/chifra/internal/chunks/types_appearanceTable.go delete mode 100644 src/apps/chifra/internal/chunks/types_chunkaddress.go delete mode 100644 src/apps/chifra/internal/chunks/types_chunkbloom.go delete mode 100644 src/apps/chifra/internal/chunks/types_chunkindex.go delete mode 100644 src/apps/chifra/internal/chunks/types_chunkpinreport.go delete mode 100644 src/apps/chifra/internal/monitors/types_monitorclean.go delete mode 100644 src/apps/chifra/internal/status/types_cacheitem.go delete mode 100644 src/apps/chifra/internal/status/types_status.go delete mode 100644 src/apps/chifra/internal/when/types_timestampcount.go create mode 100644 src/apps/chifra/pkg/types/types_appearanceTable.go rename src/apps/chifra/{internal/blocks => pkg/types}/types_blockcount.go (70%) create mode 100644 src/apps/chifra/pkg/types/types_cacheitem.go create mode 100644 src/apps/chifra/pkg/types/types_chunkaddress.go create mode 100644 src/apps/chifra/pkg/types/types_chunkbloom.go create mode 100644 src/apps/chifra/pkg/types/types_chunkindex.go create mode 100644 src/apps/chifra/pkg/types/types_chunkpinreport.go rename src/apps/chifra/{internal/chunks => pkg/types}/types_ipfspin.go (58%) create mode 100644 src/apps/chifra/pkg/types/types_metadata.go create mode 100644 src/apps/chifra/pkg/types/types_monitorclean.go rename src/apps/chifra/{internal/chunks => pkg/types}/types_reportcheck.go (50%) create mode 100644 src/apps/chifra/pkg/types/types_status.go rename src/apps/chifra/{internal/when => pkg/types}/types_timestamp.go (55%) create mode 100644 src/apps/chifra/pkg/types/types_timestampcount.go rename src/apps/chifra/{internal/traces => pkg/types}/types_tracecount.go (57%) create mode 100644 src/dev_tools/goMaker/templates/classDefinitions/appearancetable.toml create mode 100644 src/dev_tools/goMaker/templates/classDefinitions/fields/appearancetable.csv delete mode 100644 src/dev_tools/goMaker/templates/src_apps_chifra_internal_route_types_type.go.tmpl diff --git a/docs/content/api/openapi.yaml b/docs/content/api/openapi.yaml index 57cfff14a3..2c03668755 100644 --- a/docs/content/api/openapi.yaml +++ b/docs/content/api/openapi.yaml @@ -2690,11 +2690,12 @@ paths: schema: properties: data: - description: Produces Appearance, ChunkAddress, ChunkBloom, ChunkIndex, ChunkPinReport, ChunkRecord, ChunkStats, IpfsPin, Manifest or ReportCheck data. Corresponds to the chifra chunks command line. + description: Produces Appearance, AppearanceTable, ChunkAddress, ChunkBloom, ChunkIndex, ChunkPinReport, ChunkRecord, ChunkStats, IpfsPin, Manifest or ReportCheck data. Corresponds to the chifra chunks command line. type: array items: oneOf: - $ref: "#/components/schemas/appearance" + - $ref: "#/components/schemas/appearanceTable" - $ref: "#/components/schemas/chunkAddress" - $ref: "#/components/schemas/chunkBloom" - $ref: "#/components/schemas/chunkIndex" @@ -3011,6 +3012,20 @@ components: type: string format: datetime description: "the timestamp as a date (calculated)" + appearanceTable: + description: "an appearance table for an address" + type: object + properties: + AddressRecord: + type: object + items: + $ref: "#/components/schemas/addrRecord" + description: "the address record for these appearances" + Appearances: + type: array + items: + $ref: "#/components/schemas/appRecord" + description: "all the appearances for this address" monitor: description: "a local file indicating a user's interest in an address. Includes caches for reconicilations, transactions, and appearances as well as an optional association to named account" type: object diff --git a/docs/content/chifra/admin.md b/docs/content/chifra/admin.md index 9e6afe9e5e..4eef49e7ea 100644 --- a/docs/content/chifra/admin.md +++ b/docs/content/chifra/admin.md @@ -342,6 +342,7 @@ Notes: Data models produced by this tool: - [appearance](/data-model/accounts/#appearance) +- [appearancetable](/data-model/accounts/#appearancetable) - [chunkaddress](/data-model/admin/#chunkaddress) - [chunkbloom](/data-model/admin/#chunkbloom) - [chunkindex](/data-model/admin/#chunkindex) diff --git a/docs/content/data-model/accounts.md b/docs/content/data-model/accounts.md index c53b2e9454..f86eab1edf 100644 --- a/docs/content/data-model/accounts.md +++ b/docs/content/data-model/accounts.md @@ -58,6 +58,21 @@ Appearances consist of the following fields: | timestamp | the timestamp for this appearance | timestamp | | date | the timestamp as a date (calculated) | datetime | +## AppearanceTable + + + +The following commands produce and manage AppearanceTables: + +- [chifra chunks](/chifra/admin/#chifra-chunks) + +AppearanceTables consist of the following fields: + +| Field | Description | Type | +| ------------- | ---------------------------------------- | ----------- | +| AddressRecord | the address record for these appearances | AddrRecord | +| Appearances | all the appearances for this address | AppRecord[] | + ## Monitor A Monitor is a list of [Appearances](/data-model/accounts/#appearance) associated with a given diff --git a/sdk/go/abis.go b/sdk/go/abis.go index 5e0e7e19d2..ab21e48804 100644 --- a/sdk/go/abis.go +++ b/sdk/go/abis.go @@ -18,7 +18,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" abis "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE ) @@ -79,7 +79,7 @@ func GetAbisOptions(args []string) (*AbisOptions, error) { return &opts, nil } -func (opts *AbisOptions) Query() ([]bool, *rpc.MetaData, error) { +func (opts *AbisOptions) Query() ([]bool, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Abis(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/blocks.go b/sdk/go/blocks.go index f720df87be..3cc7c4ab0a 100644 --- a/sdk/go/blocks.go +++ b/sdk/go/blocks.go @@ -19,7 +19,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" blocks "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE @@ -96,7 +95,7 @@ func GetBlocksOptions(args []string) (*BlocksOptions, error) { return &opts, nil } -func (opts *BlocksOptions) Query() ([]types.SimpleBlock[string], *rpc.MetaData, error) { +func (opts *BlocksOptions) Query() ([]types.SimpleBlock[string], *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Blocks(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/chunks.go b/sdk/go/chunks.go index e3447658ca..474cc6aed8 100644 --- a/sdk/go/chunks.go +++ b/sdk/go/chunks.go @@ -19,7 +19,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" chunks "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE ) @@ -98,7 +98,7 @@ func GetChunksOptions(args []string) (*ChunksOptions, error) { return &opts, nil } -func (opts *ChunksOptions) Query() ([]bool, *rpc.MetaData, error) { +func (opts *ChunksOptions) Query() ([]bool, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Chunks(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/config.go b/sdk/go/config.go index 984ef63031..9d36a5eb19 100644 --- a/sdk/go/config.go +++ b/sdk/go/config.go @@ -18,7 +18,7 @@ import ( "strings" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" config "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE ) @@ -79,7 +79,7 @@ func GetConfigOptions(args []string) (*ConfigOptions, error) { return &opts, nil } -func (opts *ConfigOptions) Query() ([]bool, *rpc.MetaData, error) { +func (opts *ConfigOptions) Query() ([]bool, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Config(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/export.go b/sdk/go/export.go index 075c6ce93d..73c6d04226 100644 --- a/sdk/go/export.go +++ b/sdk/go/export.go @@ -19,7 +19,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" export "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE ) @@ -108,7 +108,7 @@ func GetExportOptions(args []string) (*ExportOptions, error) { return &opts, nil } -func (opts *ExportOptions) Query() ([]bool, *rpc.MetaData, error) { +func (opts *ExportOptions) Query() ([]bool, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Export(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/init.go b/sdk/go/init.go index 5985c409de..bb24218f78 100644 --- a/sdk/go/init.go +++ b/sdk/go/init.go @@ -18,7 +18,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" initPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE ) @@ -73,7 +73,7 @@ func GetInitOptions(args []string) (*InitOptions, error) { return &opts, nil } -func (opts *InitOptions) Query() ([]bool, *rpc.MetaData, error) { +func (opts *InitOptions) Query() ([]bool, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Init(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/list.go b/sdk/go/list.go index ad762ae73b..20b4ace325 100644 --- a/sdk/go/list.go +++ b/sdk/go/list.go @@ -18,7 +18,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" list "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE @@ -81,7 +80,7 @@ func GetListOptions(args []string) (*ListOptions, error) { return &opts, nil } -func (opts *ListOptions) Query() ([]types.SimpleAppearance, *rpc.MetaData, error) { +func (opts *ListOptions) Query() ([]types.SimpleAppearance, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.List(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/logs.go b/sdk/go/logs.go index 05cc7aebdf..280b215b8d 100644 --- a/sdk/go/logs.go +++ b/sdk/go/logs.go @@ -17,7 +17,6 @@ import ( "log" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" logs "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE @@ -72,7 +71,7 @@ func GetLogsOptions(args []string) (*LogsOptions, error) { return &opts, nil } -func (opts *LogsOptions) Query() ([]types.SimpleLog, *rpc.MetaData, error) { +func (opts *LogsOptions) Query() ([]types.SimpleLog, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Logs(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/meta.go b/sdk/go/meta.go index 82c3b41420..31036a31a6 100644 --- a/sdk/go/meta.go +++ b/sdk/go/meta.go @@ -1,10 +1,8 @@ package sdk -import ( - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" -) +import "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" -func GetMetaData() (*rpc.MetaData, error) { +func GetMetaData() (*types.MetaData, error) { unused := BlocksOptions{ BlockIds: []string{"1"}, Hashes: true, diff --git a/sdk/go/monitors.go b/sdk/go/monitors.go index b789b121ad..07b5e455f1 100644 --- a/sdk/go/monitors.go +++ b/sdk/go/monitors.go @@ -17,7 +17,7 @@ import ( "log" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" monitors "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE ) @@ -79,7 +79,7 @@ func GetMonitorsOptions(args []string) (*MonitorsOptions, error) { return &opts, nil } -func (opts *MonitorsOptions) Query() ([]bool, *rpc.MetaData, error) { +func (opts *MonitorsOptions) Query() ([]bool, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Monitors(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/names.go b/sdk/go/names.go index 54da0373f6..6810b5f969 100644 --- a/sdk/go/names.go +++ b/sdk/go/names.go @@ -18,7 +18,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" names "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE @@ -86,7 +85,7 @@ func GetNamesOptions(args []string) (*NamesOptions, error) { return &opts, nil } -func (opts *NamesOptions) Query() ([]types.SimpleName, *rpc.MetaData, error) { +func (opts *NamesOptions) Query() ([]types.SimpleName, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Names(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/receipts.go b/sdk/go/receipts.go index 46250295b8..f9697ac218 100644 --- a/sdk/go/receipts.go +++ b/sdk/go/receipts.go @@ -17,7 +17,6 @@ import ( "log" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" receipts "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE @@ -70,7 +69,7 @@ func GetReceiptsOptions(args []string) (*ReceiptsOptions, error) { return &opts, nil } -func (opts *ReceiptsOptions) Query() ([]types.SimpleReceipt, *rpc.MetaData, error) { +func (opts *ReceiptsOptions) Query() ([]types.SimpleReceipt, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Receipts(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/result.go b/sdk/go/result.go index a0276feee1..bb142a4836 100644 --- a/sdk/go/result.go +++ b/sdk/go/result.go @@ -1,13 +1,8 @@ package sdk -import "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" - -// type abisResult struct { -// Data []bool `json:"data"` -// Meta rpc.MetaData `json:"meta"` -// } +import "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" type Result[T any] struct { - Data []T `json:"data"` - Meta rpc.MetaData `json:"meta"` + Data []T `json:"data"` + Meta types.MetaData `json:"meta"` } diff --git a/sdk/go/slurp.go b/sdk/go/slurp.go index 90d93e60cc..3fa726b7da 100644 --- a/sdk/go/slurp.go +++ b/sdk/go/slurp.go @@ -18,7 +18,6 @@ import ( "strings" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" slurp "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE @@ -97,7 +96,7 @@ func GetSlurpOptions(args []string) (*SlurpOptions, error) { return &opts, nil } -func (opts *SlurpOptions) Query() ([]types.SimpleSlurp, *rpc.MetaData, error) { +func (opts *SlurpOptions) Query() ([]types.SimpleSlurp, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Slurp(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/state.go b/sdk/go/state.go index 519352a93b..50faf15505 100644 --- a/sdk/go/state.go +++ b/sdk/go/state.go @@ -19,7 +19,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" state "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE @@ -91,7 +90,7 @@ func GetStateOptions(args []string) (*StateOptions, error) { return &opts, nil } -func (opts *StateOptions) Query() ([]types.SimpleState, *rpc.MetaData, error) { +func (opts *StateOptions) Query() ([]types.SimpleState, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.State(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/status.go b/sdk/go/status.go index 1733ce923a..37402fc6ee 100644 --- a/sdk/go/status.go +++ b/sdk/go/status.go @@ -18,7 +18,7 @@ import ( "strings" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" status "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE ) @@ -82,7 +82,7 @@ func GetStatusOptions(args []string) (*StatusOptions, error) { return &opts, nil } -func (opts *StatusOptions) Query() ([]bool, *rpc.MetaData, error) { +func (opts *StatusOptions) Query() ([]bool, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Status(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/tokens.go b/sdk/go/tokens.go index afecbe6c3e..1a609e88db 100644 --- a/sdk/go/tokens.go +++ b/sdk/go/tokens.go @@ -18,7 +18,7 @@ import ( "strings" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" tokens "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE ) @@ -83,7 +83,7 @@ func GetTokensOptions(args []string) (*TokensOptions, error) { return &opts, nil } -func (opts *TokensOptions) Query() ([]bool, *rpc.MetaData, error) { +func (opts *TokensOptions) Query() ([]bool, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Tokens(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/traces.go b/sdk/go/traces.go index e5e5ec5562..569d9f3a08 100644 --- a/sdk/go/traces.go +++ b/sdk/go/traces.go @@ -17,7 +17,6 @@ import ( "log" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" traces "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE @@ -72,7 +71,7 @@ func GetTracesOptions(args []string) (*TracesOptions, error) { return &opts, nil } -func (opts *TracesOptions) Query() ([]types.SimpleTrace, *rpc.MetaData, error) { +func (opts *TracesOptions) Query() ([]types.SimpleTrace, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Traces(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/transactions.go b/sdk/go/transactions.go index 40f199fd3c..df65998ed6 100644 --- a/sdk/go/transactions.go +++ b/sdk/go/transactions.go @@ -18,7 +18,6 @@ import ( "strings" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" transactions "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE @@ -88,7 +87,7 @@ func GetTransactionsOptions(args []string) (*TransactionsOptions, error) { return &opts, nil } -func (opts *TransactionsOptions) Query() ([]types.SimpleTransaction, *rpc.MetaData, error) { +func (opts *TransactionsOptions) Query() ([]types.SimpleTransaction, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.Transactions(&buffer); err != nil { logger.Fatal(err) diff --git a/sdk/go/when.go b/sdk/go/when.go index b71aee1d6d..2856b6acc8 100644 --- a/sdk/go/when.go +++ b/sdk/go/when.go @@ -18,7 +18,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" when "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk" // EXISTING_CODE @@ -78,7 +77,7 @@ func GetWhenOptions(args []string) (*WhenOptions, error) { return &opts, nil } -func (opts *WhenOptions) Query() ([]types.SimpleNamedBlock, *rpc.MetaData, error) { +func (opts *WhenOptions) Query() ([]types.SimpleNamedBlock, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.When(&buffer); err != nil { logger.Fatal(err) diff --git a/src/apps/chifra/internal/abis/doc.go b/src/apps/chifra/internal/abis/doc.go index 58567c7d81..9e9abe5e1b 100644 --- a/src/apps/chifra/internal/abis/doc.go +++ b/src/apps/chifra/internal/abis/doc.go @@ -6,5 +6,5 @@ * the code inside of 'EXISTING_CODE' tags. */ -// Package abisPkg handles the chifra abis command. The tool retrieves one or more ABI files for the given address(es). It searches for ABIs, sequentially, in the following locations: - the current working folder, - the TrueBlocks local cache, - Etherscan, - (in the future) ENS and Sourcify. While this tool may be used from the command line, its primary purpose is in support of the --articulate option for tools such as chifra export and chifra logs. If possible, the tool will follow proxied addresses searching for the ABI, but that does not always work. In that case, you may use the --proxy_for option. The --known option prints a list of semi-standard function signatures such as the ERC20 standard, ERC 721 standard, various functions from OpenZeppelin, various Uniswap functions, etc. As an optimization, the known signatures are searched first during articulation. The --encode option generates a 32-byte encoding for a given cannonical function or event signature. For functions, you may manually extract the first four bytes of the hash. The --find option is experimental. Please see the notes below for more information. +// The chifra abis tool retrieves one or more ABI files for the given address(es). It searches for ABIs, sequentially, in the following locations: - the current working folder, - the TrueBlocks local cache, - Etherscan, - (in the future) ENS and Sourcify. While this tool may be used from the command line, its primary purpose is in support of the --articulate option for tools such as chifra export and chifra logs. If possible, the tool will follow proxied addresses searching for the ABI, but that does not always work. In that case, you may use the --proxy_for option. The --known option prints a list of semi-standard function signatures such as the ERC20 standard, ERC 721 standard, various functions from OpenZeppelin, various Uniswap functions, etc. As an optimization, the known signatures are searched first during articulation. The --encode option generates a 32-byte encoding for a given cannonical function or event signature. For functions, you may manually extract the first four bytes of the hash. The --find option is experimental. Please see the notes below for more information. package abisPkg diff --git a/src/apps/chifra/internal/blocks/doc.go b/src/apps/chifra/internal/blocks/doc.go index 88b92f02de..ae3c91b499 100644 --- a/src/apps/chifra/internal/blocks/doc.go +++ b/src/apps/chifra/internal/blocks/doc.go @@ -6,5 +6,5 @@ * the code inside of 'EXISTING_CODE' tags. */ -// Package blocksPkg handles the chifra blocks command. It retrieves block data from your Ethereum node or, if previously cached, from the TrueBlocks cache. You may specify multiple blocks per invocation. By default, queries the full transactional details of the block (including receipts). You may optionally retrieve only the transaction hashes in the block (which is significantly faster). Additionally, you may also use this tool to retrieve uncle blocks at a give height. Another useful feature of is the ability to extract address appearances from a block. TrueBlocks uses a similar feature internally to build its index of appearances. This type of data is very insightful when studying end user behavior and chain-wide adoption analysis. +// The chifra blocks tool retrieves block data from your Ethereum node or, if previously cached, from the TrueBlocks cache. You may specify multiple blocks per invocation. By default, chifra blocks queries the full transactional details of the block (including receipts). You may optionally retrieve only the transaction hashes in the block (which is significantly faster). Additionally, you may also use this tool to retrieve uncle blocks at a give height. Another useful feature of chifra blocks is the ability to extract address appearances from a block. TrueBlocks uses a similar feature internally to build its index of appearances. This type of data is very insightful when studying end user behavior and chain-wide adoption analysis. package blocksPkg diff --git a/src/apps/chifra/internal/blocks/handle_count.go b/src/apps/chifra/internal/blocks/handle_count.go index 95fbeccec0..dea2efdbfa 100644 --- a/src/apps/chifra/internal/blocks/handle_count.go +++ b/src/apps/chifra/internal/blocks/handle_count.go @@ -18,7 +18,7 @@ func (opts *BlocksOptions) HandleCounts() error { chain := opts.Globals.Chain ctx, cancel := context.WithCancel(context.Background()) - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawBlockCount], errorChan chan error) { for _, br := range opts.BlockIds { blockNums, err := br.ResolveBlocks(chain) if err != nil { @@ -41,7 +41,7 @@ func (opts *BlocksOptions) HandleCounts() error { return } - blockCount := simpleBlockCount{ + blockCount := types.SimpleBlockCount{ BlockNumber: block.BlockNumber, Timestamp: block.Timestamp, TransactionsCnt: uint64(len(block.Transactions)), diff --git a/src/apps/chifra/internal/blocks/output.go b/src/apps/chifra/internal/blocks/output.go index 9034714fb9..c6930b9d81 100644 --- a/src/apps/chifra/internal/blocks/output.go +++ b/src/apps/chifra/internal/blocks/output.go @@ -42,7 +42,7 @@ func ServeBlocks(w http.ResponseWriter, r *http.Request) error { return err } -// BlocksInternal handles the internal workings of the blocks command. Returns an error. +// BlocksInternal handles the internal workings of the blocks command. Returns an error. func (opts *BlocksOptions) BlocksInternal() error { var err error if err = opts.validateBlocks(); err != nil { diff --git a/src/apps/chifra/internal/chunks/README.md b/src/apps/chifra/internal/chunks/README.md index 12fedcf7ea..c4f040d87c 100644 --- a/src/apps/chifra/internal/chunks/README.md +++ b/src/apps/chifra/internal/chunks/README.md @@ -51,6 +51,7 @@ Notes: Data models produced by this tool: - [appearance](/data-model/accounts/#appearance) +- [appearancetable](/data-model/accounts/#appearancetable) - [chunkaddress](/data-model/admin/#chunkaddress) - [chunkbloom](/data-model/admin/#chunkbloom) - [chunkindex](/data-model/admin/#chunkindex) diff --git a/src/apps/chifra/internal/chunks/doc.go b/src/apps/chifra/internal/chunks/doc.go index bb2e33ba05..6d44e7ddc7 100644 --- a/src/apps/chifra/internal/chunks/doc.go +++ b/src/apps/chifra/internal/chunks/doc.go @@ -6,5 +6,5 @@ * the code inside of 'EXISTING_CODE' tags. */ -// Package chunksPkg handles the chifra chunks command. It provides tools for interacting with, checking the validity of, cleaning up, and analyzing the Unchained Index. It provides options to list pins, the Manifest, summary data on the index, Bloom filters, addresses, and appearances. While still in its early stages, this tool will eventually allow users to clean their local index, clean their remote index, study the indexes, etc. Stay tuned. +// The chifra chunks routine provides tools for interacting with, checking the validity of, cleaning up, and analyzing the Unchained Index. It provides options to list pins, the Manifest, summary data on the index, Bloom filters, addresses, and appearances. While still in its early stages, this tool will eventually allow users to clean their local index, clean their remote index, study the indexes, etc. Stay tuned. package chunksPkg diff --git a/src/apps/chifra/internal/chunks/handle_addresses.go b/src/apps/chifra/internal/chunks/handle_addresses.go index c61dfde1c7..0d706d9e31 100644 --- a/src/apps/chifra/internal/chunks/handle_addresses.go +++ b/src/apps/chifra/internal/chunks/handle_addresses.go @@ -23,11 +23,11 @@ func (opts *ChunksOptions) HandleAddresses(blockNums []uint64) error { chain := opts.Globals.Chain been_here := 0 ctx, cancel := context.WithCancel(context.Background()) - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawChunkAddress], errorChan chan error) { var showAddresses func(walker *walk.CacheWalker, path string, first bool) (bool, error) if opts.Globals.Verbose { showAddresses = func(walker *walk.CacheWalker, path string, first bool) (bool, error) { - return opts.handleResolvedRecords(modelChan, walker, path, first) + return opts.handleResolvedRecords1(modelChan, walker, path, first) } } else { showAddresses = func(walker *walk.CacheWalker, path string, first bool) (bool, error) { @@ -69,12 +69,12 @@ func (opts *ChunksOptions) HandleAddresses(blockNums []uint64) error { continue } - obj := index.AddressRecord{} + obj := types.SimpleAddrRecord{} if err := binary.Read(indexChunk.File, binary.LittleEndian, &obj); err != nil { return false, err } - s := simpleChunkAddress{ + s := types.SimpleChunkAddress{ Address: obj.Address, Range: indexChunk.Range.String(), Offset: uint64(obj.Offset), diff --git a/src/apps/chifra/internal/chunks/handle_addresses_belongs.go b/src/apps/chifra/internal/chunks/handle_addresses_belongs.go index 778f1d4be6..7bf270be07 100644 --- a/src/apps/chifra/internal/chunks/handle_addresses_belongs.go +++ b/src/apps/chifra/internal/chunks/handle_addresses_belongs.go @@ -23,7 +23,7 @@ func (opts *ChunksOptions) HandleIndexBelongs(blockNums []uint64) error { chain := opts.Globals.Chain ctx, cancel := context.WithCancel(context.Background()) - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawAppearanceTable], errorChan chan error) { showAddressesBelongs := func(walker *walk.CacheWalker, path string, first bool) (bool, error) { return opts.handleResolvedRecords(modelChan, walker, path, first) } @@ -47,7 +47,7 @@ func (opts *ChunksOptions) HandleIndexBelongs(blockNums []uint64) error { // handleResolvedRecords is a helper function for HandleIndexBelongs and verbose versions of // HandleAddresses and HandleAppearances. It is called once for each chunk in the index and // depends on the values of opts.Globals.Verbose and opts.Belongs. -func (opts *ChunksOptions) handleResolvedRecords(modelChan chan types.Modeler[types.RawModeler], walker *walk.CacheWalker, path string, first bool) (bool, error) { +func (opts *ChunksOptions) handleResolvedRecords(modelChan chan types.Modeler[types.RawAppearanceTable], walker *walk.CacheWalker, path string, first bool) (bool, error) { if path != index.ToBloomPath(path) { return false, fmt.Errorf("should not happen in showAddressesBelongs") } @@ -75,7 +75,7 @@ func (opts *ChunksOptions) handleResolvedRecords(modelChan chan types.Modeler[ty continue } - s := simpleAppearanceTable{} + s := types.SimpleAppearanceTable{} if err := binary.Read(indexChunk.File, binary.LittleEndian, &s.AddressRecord); err != nil { return false, err } @@ -88,8 +88,9 @@ func (opts *ChunksOptions) handleResolvedRecords(modelChan chan types.Modeler[ty if s.Appearances, err = indexChunk.ReadAppearancesAndReset(&s.AddressRecord); err != nil { return false, err } + s.AddressRecord.Count = uint32(len(s.Appearances)) if opts.FirstBlock != 0 || opts.LastBlock != utils.NOPOS { - good := []index.AppearanceRecord{} + good := []types.SimpleAppRecord{} for _, app := range s.Appearances { if uint64(app.BlockNumber) >= opts.FirstBlock && uint64(app.BlockNumber) <= opts.LastBlock { good = append(good, app) @@ -108,3 +109,75 @@ func (opts *ChunksOptions) handleResolvedRecords(modelChan chan types.Modeler[ty return true, nil } + +// handleResolvedRecords1 is a helper function for HandleIndexBelongs and verbose versions of +// HandleAddresses and HandleAppearances. It is called once for each chunk in the index and +// depends on the values of opts.Globals.Verbose and opts.Belongs. +func (opts *ChunksOptions) handleResolvedRecords1(modelChan chan types.Modeler[types.RawChunkAddress], walker *walk.CacheWalker, path string, first bool) (bool, error) { + if path != index.ToBloomPath(path) { + return false, fmt.Errorf("should not happen in showAddressesBelongs") + } + + path = index.ToIndexPath(path) + if !file.FileExists(path) { + // Bloom files exist, but index files don't. It's okay. + return true, nil + } + + indexChunk, err := index.OpenIndex(path, true /* check */) + if err != nil { + return false, err + } + defer indexChunk.Close() + + _, err = indexChunk.File.Seek(int64(index.HeaderWidth), io.SeekStart) + if err != nil { + return false, err + } + + cnt := 0 + for i := 0; i < int(indexChunk.Header.AddressCount); i++ { + if opts.Globals.TestMode && i > walker.MaxTests() { + continue + } + + s := types.SimpleAppearanceTable{} + if err := binary.Read(indexChunk.File, binary.LittleEndian, &s.AddressRecord); err != nil { + return false, err + } + + if opts.shouldShow(s.AddressRecord) { + if uint64(cnt) >= opts.MaxAddrs { + break + } + + if s.Appearances, err = indexChunk.ReadAppearancesAndReset(&s.AddressRecord); err != nil { + return false, err + } + s.AddressRecord.Count = uint32(len(s.Appearances)) + if opts.FirstBlock != 0 || opts.LastBlock != utils.NOPOS { + good := []types.SimpleAppRecord{} + for _, app := range s.Appearances { + if uint64(app.BlockNumber) >= opts.FirstBlock && uint64(app.BlockNumber) <= opts.LastBlock { + good = append(good, app) + } + } + s.Appearances = good + s.AddressRecord.Count = uint32(len(good)) + } + if len(s.Appearances) == 0 { + continue + } + ss := types.SimpleChunkAddress{ + Address: s.AddressRecord.Address, + Count: uint64(s.AddressRecord.Count), + Offset: uint64(s.AddressRecord.Offset), + // Range string `json:"range"` + } + modelChan <- &ss + cnt++ + } + } + + return true, nil +} diff --git a/src/apps/chifra/internal/chunks/handle_appearances.go b/src/apps/chifra/internal/chunks/handle_appearances.go index 71f3f533e9..2230998fdf 100644 --- a/src/apps/chifra/internal/chunks/handle_appearances.go +++ b/src/apps/chifra/internal/chunks/handle_appearances.go @@ -48,7 +48,7 @@ func (opts *ChunksOptions) HandleAppearances(blockNums []uint64) error { if opts.Globals.TestMode && i > walker.MaxTests() { continue } - rec := index.AppearanceRecord{} + rec := types.SimpleAppRecord{} if err := binary.Read(indexChunk.File, binary.LittleEndian, &rec); err != nil { return false, err } diff --git a/src/apps/chifra/internal/chunks/handle_blooms.go b/src/apps/chifra/internal/chunks/handle_blooms.go index b3fca8170c..ae2d6ae9fc 100644 --- a/src/apps/chifra/internal/chunks/handle_blooms.go +++ b/src/apps/chifra/internal/chunks/handle_blooms.go @@ -20,7 +20,7 @@ func (opts *ChunksOptions) HandleBlooms(blockNums []uint64) error { chain := opts.Globals.Chain ctx, cancel := context.WithCancel(context.Background()) - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawChunkBloom], errorChan chan error) { showBloom := func(walker *walk.CacheWalker, path string, first bool) (bool, error) { if path != index.ToBloomPath(path) { return false, fmt.Errorf("should not happen in showBloom") @@ -42,7 +42,7 @@ func (opts *ChunksOptions) HandleBlooms(blockNums []uint64) error { return false, err } - s := simpleChunkBloom{ + s := types.SimpleChunkBloom{ Magic: fmt.Sprintf("0x%x", bl.Header.Magic), Hash: bl.Header.Hash, Size: stats.BloomSz, diff --git a/src/apps/chifra/internal/chunks/handle_check.go b/src/apps/chifra/internal/chunks/handle_check.go index f7391334d6..82971e41d2 100644 --- a/src/apps/chifra/internal/chunks/handle_check.go +++ b/src/apps/chifra/internal/chunks/handle_check.go @@ -121,63 +121,63 @@ func (opts *ChunksOptions) check(blockNums []uint64, silent bool) (error, bool) return remoteArray[i] < remoteArray[j] }) - reports := []simpleReportCheck{} + reports := []types.SimpleReportCheck{} allowMissing := config.GetScrape(chain).AllowMissing - seq := simpleReportCheck{Reason: "Filenames sequential"} + seq := types.SimpleReportCheck{Reason: "Filenames sequential"} if err := opts.CheckSequential(fileNames, cacheArray, remoteArray, allowMissing, &seq); err != nil { return err, false } reports = append(reports, seq) - intern := simpleReportCheck{Reason: "Internally consistent"} + intern := types.SimpleReportCheck{Reason: "Internally consistent"} if err := opts.CheckInternal(fileNames, blockNums, &intern); err != nil { return err, false } reports = append(reports, intern) - version := simpleReportCheck{Reason: "Correct version"} + version := types.SimpleReportCheck{Reason: "Correct version"} if err := opts.CheckVersion(fileNames, blockNums, &version); err != nil { return err, false } reports = append(reports, version) - con := simpleReportCheck{Reason: "Consistent hashes"} + con := types.SimpleReportCheck{Reason: "Consistent hashes"} if err := opts.CheckHashes(cacheManifest, remoteManifest, &con); err != nil { return err, false } reports = append(reports, con) - sizes := simpleReportCheck{Reason: "Check file sizes"} + sizes := types.SimpleReportCheck{Reason: "Check file sizes"} if err := opts.CheckSizes(fileNames, blockNums, cacheManifest, remoteManifest, &sizes); err != nil { return err, false } reports = append(reports, sizes) // compare with çached manifest with files on disc - d2c := simpleReportCheck{Reason: "Disc files to cached manifest"} + d2c := types.SimpleReportCheck{Reason: "Disc files to cached manifest"} if err := opts.CheckManifest(fnArray, cacheArray, &d2c); err != nil { return err, false } reports = append(reports, d2c) // compare with remote manifest with files on disc - d2r := simpleReportCheck{Reason: "Disc files to remote manifest"} + d2r := types.SimpleReportCheck{Reason: "Disc files to remote manifest"} if err := opts.CheckManifest(fnArray, remoteArray, &d2r); err != nil { return err, false } reports = append(reports, d2r) // compare remote manifest to cached manifest - r2c := simpleReportCheck{Reason: "Remote manifest to cached manifest"} + r2c := types.SimpleReportCheck{Reason: "Remote manifest to cached manifest"} if err := opts.CheckManifest(remoteArray, cacheArray, &r2c); err != nil { return err, false } reports = append(reports, r2c) if opts.Deep { - deep := simpleReportCheck{Reason: "Deep checks for " + opts.Mode} + deep := types.SimpleReportCheck{Reason: "Deep checks for " + opts.Mode} if err := opts.CheckDeep(cacheManifest, &deep); err != nil { return err, false } @@ -197,7 +197,7 @@ func (opts *ChunksOptions) check(blockNums []uint64, silent bool) (error, bool) } ctx := context.Background() - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawReportCheck], errorChan chan error) { for _, report := range reports { if !silent { modelChan <- &report diff --git a/src/apps/chifra/internal/chunks/handle_check_deep.go b/src/apps/chifra/internal/chunks/handle_check_deep.go index ebd5d7c6d1..4b7a977947 100644 --- a/src/apps/chifra/internal/chunks/handle_check_deep.go +++ b/src/apps/chifra/internal/chunks/handle_check_deep.go @@ -25,7 +25,7 @@ import ( type reporter struct { chunk *types.SimpleChunkRecord - report *simpleReportCheck + report *types.SimpleReportCheck mutex *sync.Mutex } @@ -33,7 +33,7 @@ type reporter struct { // that all addresses in the index return true when checked against its corresponding // Bloom filter. In `manifest` mode, it checks that each IPFS hash in the manifest is // actually pinned. The later requires a locally running IPFS node. -func (opts *ChunksOptions) CheckDeep(cacheMan *manifest.Manifest, report *simpleReportCheck) error { +func (opts *ChunksOptions) CheckDeep(cacheMan *manifest.Manifest, report *types.SimpleReportCheck) error { chain := opts.Globals.Chain testMode := opts.Globals.TestMode nErrors := 0 @@ -79,7 +79,7 @@ func (opts *ChunksOptions) CheckDeep(cacheMan *manifest.Manifest, report *simple } for i := 0; i < int(indexChunk.Header.AddressCount); i++ { - obj := index.AddressRecord{} + obj := types.SimpleAddrRecord{} if err := binary.Read(indexChunk.File, binary.LittleEndian, &obj); err != nil { return err } diff --git a/src/apps/chifra/internal/chunks/handle_check_hashes.go b/src/apps/chifra/internal/chunks/handle_check_hashes.go index 9cb6f25301..1a696bc14c 100644 --- a/src/apps/chifra/internal/chunks/handle_check_hashes.go +++ b/src/apps/chifra/internal/chunks/handle_check_hashes.go @@ -8,11 +8,12 @@ import ( "fmt" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/manifest" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) // CheckHashes looks at all the hashes in both the locally cached manifest and the manifest retrieved from // the smart contract and simply checks the lengths of the bloom and index IPFS hashes. -func (opts *ChunksOptions) CheckHashes(cacheMan *manifest.Manifest, contractMan *manifest.Manifest, report *simpleReportCheck) error { +func (opts *ChunksOptions) CheckHashes(cacheMan *manifest.Manifest, contractMan *manifest.Manifest, report *types.SimpleReportCheck) error { if err := opts.checkHashes("cache", cacheMan, report); err != nil { return err } @@ -24,7 +25,7 @@ func (opts *ChunksOptions) CheckHashes(cacheMan *manifest.Manifest, contractMan return nil } -func (opts *ChunksOptions) checkHashes(which string, man *manifest.Manifest, report *simpleReportCheck) error { +func (opts *ChunksOptions) checkHashes(which string, man *manifest.Manifest, report *types.SimpleReportCheck) error { for _, chunk := range man.Chunks { report.VisitedCnt++ report.CheckedCnt++ diff --git a/src/apps/chifra/internal/chunks/handle_check_internal.go b/src/apps/chifra/internal/chunks/handle_check_internal.go index 47285585a1..fc9316ed8e 100644 --- a/src/apps/chifra/internal/chunks/handle_check_internal.go +++ b/src/apps/chifra/internal/chunks/handle_check_internal.go @@ -12,12 +12,13 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) // CheckInternal reads the header of each chunk on disc looking for the Magic number and // the hash of the spec version for expected values. -func (opts *ChunksOptions) CheckInternal(fileNames []string, blockNums []uint64, report *simpleReportCheck) error { +func (opts *ChunksOptions) CheckInternal(fileNames []string, blockNums []uint64, report *types.SimpleReportCheck) error { for _, fileName := range fileNames { opts.checkIndexChunkInternal(fileName, false /* check version */, report) // opts.checkBloomInternal(testId, fileName, report) @@ -25,7 +26,7 @@ func (opts *ChunksOptions) CheckInternal(fileNames []string, blockNums []uint64, return nil } -func (opts *ChunksOptions) checkIndexChunkInternal(fileName string, checkVersion bool, report *simpleReportCheck) { +func (opts *ChunksOptions) checkIndexChunkInternal(fileName string, checkVersion bool, report *types.SimpleReportCheck) { report.VisitedCnt++ report.CheckedCnt++ @@ -50,7 +51,7 @@ func (opts *ChunksOptions) checkIndexChunkInternal(fileName string, checkVersion indexChunk.Close() } -func (opts *ChunksOptions) checkSnaps(fileName string, indexChunk *index.Index, report *simpleReportCheck) { +func (opts *ChunksOptions) checkSnaps(fileName string, indexChunk *index.Index, report *types.SimpleReportCheck) { report.VisitedCnt++ report.CheckedCnt++ diff --git a/src/apps/chifra/internal/chunks/handle_check_manifest.go b/src/apps/chifra/internal/chunks/handle_check_manifest.go index 61c65e2115..d06bdd5862 100644 --- a/src/apps/chifra/internal/chunks/handle_check_manifest.go +++ b/src/apps/chifra/internal/chunks/handle_check_manifest.go @@ -7,6 +7,8 @@ package chunksPkg import ( "fmt" "strings" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) type CompareState struct { @@ -23,7 +25,7 @@ type CompareState struct { // CheckManifest takes two arrays (either onDisc vs. LocalManifest, onDisc vs. RemoteManifest, or LocalManifest // vs. RemoteManifest) and compares them for equality. If everything is up to date, all three arrays should // be identical. Only the block ranges are in the arrays. -func (opts *ChunksOptions) CheckManifest(arrayA, arrayB []string, report *simpleReportCheck) error { +func (opts *ChunksOptions) CheckManifest(arrayA, arrayB []string, report *types.SimpleReportCheck) error { comp := CompareState{ testMode: opts.Globals.TestMode, details: opts.Globals.Verbose, @@ -45,7 +47,7 @@ func (opts *ChunksOptions) CheckManifest(arrayA, arrayB []string, report *simple } // TODO: Can this be made concurrent? -func (comp *CompareState) checkArrays(report *simpleReportCheck) error { +func (comp *CompareState) checkArrays(report *types.SimpleReportCheck) error { marker := "" if comp.testMode { marker = " (testing)" diff --git a/src/apps/chifra/internal/chunks/handle_check_sequential.go b/src/apps/chifra/internal/chunks/handle_check_sequential.go index 300b4d442d..6eb0d8d2af 100644 --- a/src/apps/chifra/internal/chunks/handle_check_sequential.go +++ b/src/apps/chifra/internal/chunks/handle_check_sequential.go @@ -8,6 +8,7 @@ import ( "fmt" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) @@ -16,7 +17,7 @@ import ( // for allow_missing chains where gaps are allowed.) It also makes sure than snap-to-grids // happen where they should and that non-snaps have at least appsPerChunks records and // snaps have exactly appsPerChunks records or less. -func (opts *ChunksOptions) CheckSequential(fnArray, cacheArray, remoteArray []string, allowMissing bool, report *simpleReportCheck) error { +func (opts *ChunksOptions) CheckSequential(fnArray, cacheArray, remoteArray []string, allowMissing bool, report *types.SimpleReportCheck) error { if err := opts.checkSequential("disc", fnArray, allowMissing, report); err != nil { return err } @@ -33,7 +34,7 @@ func (opts *ChunksOptions) CheckSequential(fnArray, cacheArray, remoteArray []st } // TODO: Can this be made concurrent? -func (opts *ChunksOptions) checkSequential(which string, array []string, allowMissing bool, report *simpleReportCheck) error { +func (opts *ChunksOptions) checkSequential(which string, array []string, allowMissing bool, report *types.SimpleReportCheck) error { prev := base.NotARange for _, item := range array { var fR base.FileRange diff --git a/src/apps/chifra/internal/chunks/handle_check_sizes.go b/src/apps/chifra/internal/chunks/handle_check_sizes.go index c72c813639..4e5a3f155d 100644 --- a/src/apps/chifra/internal/chunks/handle_check_sizes.go +++ b/src/apps/chifra/internal/chunks/handle_check_sizes.go @@ -11,10 +11,11 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/manifest" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) // CheckSizes compares the file on disc to the file size suggested in the manifest -func (opts *ChunksOptions) CheckSizes(fileNames []string, blockNums []uint64, cacheManifest *manifest.Manifest, remoteManifest *manifest.Manifest, report *simpleReportCheck) error { +func (opts *ChunksOptions) CheckSizes(fileNames []string, blockNums []uint64, cacheManifest *manifest.Manifest, remoteManifest *manifest.Manifest, report *types.SimpleReportCheck) error { // Figure out which manifest we're going to check against theManifest := cacheManifest diff --git a/src/apps/chifra/internal/chunks/handle_check_staging.go b/src/apps/chifra/internal/chunks/handle_check_staging.go index 41e0b6083d..f67eb534b2 100644 --- a/src/apps/chifra/internal/chunks/handle_check_staging.go +++ b/src/apps/chifra/internal/chunks/handle_check_staging.go @@ -13,6 +13,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) // CheckStaging checks the staging file which should be names first-second.txt @@ -20,7 +21,7 @@ import ( // 2. Makes sure the first < last // 3. Makes sure that the first block inside is == first if allow_missing == false, > otherwise // 4. Makes sure that the last block inside is == last if allow_missing == false, < otherwise -func (opts *ChunksOptions) CheckStaging(lastBlock uint64, allow_missing bool, report *simpleReportCheck) error { +func (opts *ChunksOptions) CheckStaging(lastBlock uint64, allow_missing bool, report *types.SimpleReportCheck) error { chain := opts.Globals.Chain stagePath := index.ToStagingPath(config.PathToIndex(chain) + "staging") stageFn, _ := file.LatestFileInFolder(stagePath) diff --git a/src/apps/chifra/internal/chunks/handle_check_version.go b/src/apps/chifra/internal/chunks/handle_check_version.go index 0d781c5b88..20218825a7 100644 --- a/src/apps/chifra/internal/chunks/handle_check_version.go +++ b/src/apps/chifra/internal/chunks/handle_check_version.go @@ -4,9 +4,11 @@ package chunksPkg +import "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" + // CheckInternal reads the header of each chunk on disc looking for the Magic number and // the hash of the spec version for expected values. -func (opts *ChunksOptions) CheckVersion(fileNames []string, blockNums []uint64, report *simpleReportCheck) error { +func (opts *ChunksOptions) CheckVersion(fileNames []string, blockNums []uint64, report *types.SimpleReportCheck) error { for _, fileName := range fileNames { opts.checkIndexChunkInternal(fileName, true /* checkVersion */, report) // opts.checkBloomInternal(testId, fileName, report) diff --git a/src/apps/chifra/internal/chunks/handle_diff.go b/src/apps/chifra/internal/chunks/handle_diff.go index bace82abc3..12054fb92f 100644 --- a/src/apps/chifra/internal/chunks/handle_diff.go +++ b/src/apps/chifra/internal/chunks/handle_diff.go @@ -105,13 +105,14 @@ func (opts *ChunksOptions) exportTo(dest, source string, rd base.RangeDiff) (boo apps := make([]types.SimpleAppearance, 0, 500000) for i := 0; i < int(indexChunk.Header.AddressCount); i++ { - s := simpleAppearanceTable{} + s := types.SimpleAppearanceTable{} if err := binary.Read(indexChunk.File, binary.LittleEndian, &s.AddressRecord); err != nil { return false, err } if s.Appearances, err = indexChunk.ReadAppearancesAndReset(&s.AddressRecord); err != nil { return false, err } + s.AddressRecord.Count = uint32(len(s.Appearances)) for _, app := range s.Appearances { apps = append(apps, types.SimpleAppearance{ Address: s.AddressRecord.Address, diff --git a/src/apps/chifra/internal/chunks/handle_index.go b/src/apps/chifra/internal/chunks/handle_index.go index d38c5543da..ebc270a8cd 100644 --- a/src/apps/chifra/internal/chunks/handle_index.go +++ b/src/apps/chifra/internal/chunks/handle_index.go @@ -23,7 +23,7 @@ func (opts *ChunksOptions) HandleIndex(blockNums []uint64) error { chain := opts.Globals.Chain ctx, cancel := context.WithCancel(context.Background()) - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawChunkIndex], errorChan chan error) { showIndex := func(walker *walk.CacheWalker, fileName string, first bool) (bool, error) { if fileName != index.ToBloomPath(fileName) { return false, fmt.Errorf("should not happen in showIndex") @@ -46,7 +46,7 @@ func (opts *ChunksOptions) HandleIndex(blockNums []uint64) error { return false, err } - s := simpleChunkIndex{ + s := types.SimpleChunkIndex{ Range: rng.String(), Magic: fmt.Sprintf("0x%x", indexChunk.Header.Magic), Hash: indexChunk.Header.Hash, diff --git a/src/apps/chifra/internal/chunks/handle_list.go b/src/apps/chifra/internal/chunks/handle_list.go index 560a515eb9..0f271ebcf9 100644 --- a/src/apps/chifra/internal/chunks/handle_list.go +++ b/src/apps/chifra/internal/chunks/handle_list.go @@ -21,7 +21,7 @@ func (opts *ChunksOptions) HandleList(unused []uint64) error { } ctx := context.Background() - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawIpfsPin], errorChan chan error) { var perPage = 1000 if testMode { perPage = -100 @@ -32,7 +32,7 @@ func (opts *ChunksOptions) HandleList(unused []uint64) error { for _, line := range array { parts := strings.Split(line, "\t") if len(parts) == 5 { - s := simpleIpfsPin{ + s := types.SimpleIpfsPin{ Cid: base.IpfsHash(parts[0]), DatePinned: parts[1], FileName: parts[2], diff --git a/src/apps/chifra/internal/chunks/handle_pin.go b/src/apps/chifra/internal/chunks/handle_pin.go index 619abbab97..ab0e5109f6 100644 --- a/src/apps/chifra/internal/chunks/handle_pin.go +++ b/src/apps/chifra/internal/chunks/handle_pin.go @@ -52,9 +52,9 @@ func (opts *ChunksOptions) HandlePin(blockNums []uint64) error { } ctx, cancel := context.WithCancel(context.Background()) - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawChunkPinReport], errorChan chan error) { hash := base.BytesToHash(config.HeaderHash(config.ExpectedVersion())) - report := simpleChunkPinReport{ + report := types.SimpleChunkPinReport{ Version: config.VersionTags[hash.Hex()], Chain: chain, SpecHash: base.IpfsHash(manifest.Specification()), diff --git a/src/apps/chifra/internal/chunks/output.go b/src/apps/chifra/internal/chunks/output.go index 8fe5a25935..7ffc69a104 100644 --- a/src/apps/chifra/internal/chunks/output.go +++ b/src/apps/chifra/internal/chunks/output.go @@ -14,8 +14,6 @@ import ( "os" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/globals" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/identifiers" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" @@ -52,7 +50,7 @@ func ServeChunks(w http.ResponseWriter, r *http.Request) error { return err } -// ChunksInternal handles the internal workings of the chunks command. Returns an error. +// ChunksInternal handles the internal workings of the chunks command. Returns an error. func (opts *ChunksOptions) ChunksInternal() error { var err error if err = opts.validateChunks(); err != nil { @@ -135,7 +133,7 @@ func GetChunksOptions(args []string, g *globals.GlobalOptions) *ChunksOptions { } // EXISTING_CODE -func (opts *ChunksOptions) shouldShow(obj index.AddressRecord) bool { +func (opts *ChunksOptions) shouldShow(obj types.SimpleAddrRecord) bool { if opts.Mode == "addresses" || opts.Mode == "appearances" { return opts.Globals.Verbose } @@ -148,14 +146,6 @@ func (opts *ChunksOptions) shouldShow(obj index.AddressRecord) bool { return false } -func FormattedTag(verbose bool, hash base.Hash) string { - if tag, ok := config.VersionTags[hash.Hex()]; !ok { - return utils.FormattedHash(verbose, hash.Hex()) - } else { - return tag - } -} - func GetChunkStats(chain, path string) (s types.SimpleChunkStats, err error) { chunk, err := index.OpenChunk(path, true /* check */) if err != nil && !os.IsNotExist(err) { diff --git a/src/apps/chifra/internal/chunks/types_appearanceTable.go b/src/apps/chifra/internal/chunks/types_appearanceTable.go deleted file mode 100644 index 6f545e1bc5..0000000000 --- a/src/apps/chifra/internal/chunks/types_appearanceTable.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2021 The TrueBlocks Authors. All rights reserved. -// Use of this source code is governed by a license that can -// be found in the LICENSE file. - -package chunksPkg - -import ( - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" -) - -type simpleAppearanceTable struct { - AddressRecord index.AddressRecord `json:"addressRecord"` - Appearances []index.AppearanceRecord `json:"appearances"` -} - -func (s *simpleAppearanceTable) Raw() *types.RawModeler { - return nil -} - -func (s *simpleAppearanceTable) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { - return types.Model{ - Data: map[string]any{ - "address": s.AddressRecord.Address.Hex(), - "offset": s.AddressRecord.Offset, - "count": s.AddressRecord.Count, - "appearances": s.Appearances, - }, - Order: []string{ - "address", - "offset", - "count", - "appearances", - }, - } -} diff --git a/src/apps/chifra/internal/chunks/types_chunkaddress.go b/src/apps/chifra/internal/chunks/types_chunkaddress.go deleted file mode 100644 index 88720fb458..0000000000 --- a/src/apps/chifra/internal/chunks/types_chunkaddress.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. -// Use of this source code is governed by a license that can -// be found in the LICENSE file. -/* - * Parts of this file were auto generated. Edit only those parts of - * the code inside of 'EXISTING_CODE' tags. - */ - -package chunksPkg - -// EXISTING_CODE -import ( - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" -) - -// EXISTING_CODE - -type simpleChunkAddress struct { - Address base.Address `json:"address"` - Count uint64 `json:"count"` - Offset uint64 `json:"offset"` - Range string `json:"range"` - - // EXISTING_CODE - // EXISTING_CODE -} - -func (s *simpleChunkAddress) Raw() *types.RawModeler { - return nil -} - -func (s *simpleChunkAddress) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { - var model = map[string]interface{}{} - var order = []string{} - - // EXISTING_CODE - model = map[string]interface{}{ - "address": s.Address, - "range": s.Range, - "offset": s.Offset, - "count": s.Count, - } - order = []string{ - "address", - "range", - "offset", - "count", - } - // EXISTING_CODE - - return types.Model{ - Data: model, - Order: order, - } -} - -// EXISTING_CODE -// EXISTING_CODE diff --git a/src/apps/chifra/internal/chunks/types_chunkbloom.go b/src/apps/chifra/internal/chunks/types_chunkbloom.go deleted file mode 100644 index 6112f15fca..0000000000 --- a/src/apps/chifra/internal/chunks/types_chunkbloom.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. -// Use of this source code is governed by a license that can -// be found in the LICENSE file. -/* - * Parts of this file were auto generated. Edit only those parts of - * the code inside of 'EXISTING_CODE' tags. - */ - -package chunksPkg - -// EXISTING_CODE -import ( - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" -) - -// EXISTING_CODE - -type simpleChunkBloom struct { - ByteWidth uint64 `json:"byteWidth"` - Hash base.Hash `json:"hash"` - Magic string `json:"magic"` - NBlooms uint64 `json:"nBlooms"` - NInserted uint64 `json:"nInserted"` - Range string `json:"range"` - Size uint64 `json:"size"` - - // EXISTING_CODE - // EXISTING_CODE -} - -func (s *simpleChunkBloom) Raw() *types.RawModeler { - return nil -} - -func (s *simpleChunkBloom) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { - var model = map[string]interface{}{} - var order = []string{} - - // EXISTING_CODE - model = map[string]interface{}{ - "range": s.Range, - "magic": s.Magic, - "hash": FormattedTag(verbose, s.Hash), - "nBlooms": s.NBlooms, - "nInserted": s.NInserted, - "size": s.Size, - "byteWidth": s.ByteWidth, - } - order = []string{ - "range", - "magic", - "hash", - "nBlooms", - "nInserted", - "size", - "byteWidth", - } - // EXISTING_CODE - - return types.Model{ - Data: model, - Order: order, - } -} - -// EXISTING_CODE -// EXISTING_CODE diff --git a/src/apps/chifra/internal/chunks/types_chunkindex.go b/src/apps/chifra/internal/chunks/types_chunkindex.go deleted file mode 100644 index 15741e2d33..0000000000 --- a/src/apps/chifra/internal/chunks/types_chunkindex.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. -// Use of this source code is governed by a license that can -// be found in the LICENSE file. -/* - * Parts of this file were auto generated. Edit only those parts of - * the code inside of 'EXISTING_CODE' tags. - */ - -package chunksPkg - -// EXISTING_CODE -import ( - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" -) - -// EXISTING_CODE - -type simpleChunkIndex struct { - Hash base.Hash `json:"hash"` - Magic string `json:"magic"` - NAddresses uint64 `json:"nAddresses"` - NAppearances uint64 `json:"nAppearances"` - Range string `json:"range"` - Size uint64 `json:"size"` - - // EXISTING_CODE - // EXISTING_CODE -} - -func (s *simpleChunkIndex) Raw() *types.RawModeler { - return nil -} - -func (s *simpleChunkIndex) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { - var model = map[string]interface{}{} - var order = []string{} - - // EXISTING_CODE - model = map[string]interface{}{ - "range": s.Range, - "magic": s.Magic, - "hash": FormattedTag(verbose, s.Hash), - "nAddresses": s.NAddresses, - "nAppearances": s.NAppearances, - "fileSize": s.Size, - } - order = []string{ - "range", - "magic", - "hash", - "nAddresses", - "nAppearances", - "fileSize", - } - // EXISTING_CODE - - return types.Model{ - Data: model, - Order: order, - } -} - -// EXISTING_CODE -// EXISTING_CODE diff --git a/src/apps/chifra/internal/chunks/types_chunkpinreport.go b/src/apps/chifra/internal/chunks/types_chunkpinreport.go deleted file mode 100644 index 6e0eaa4a45..0000000000 --- a/src/apps/chifra/internal/chunks/types_chunkpinreport.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. -// Use of this source code is governed by a license that can -// be found in the LICENSE file. -/* - * Parts of this file were auto generated. Edit only those parts of - * the code inside of 'EXISTING_CODE' tags. - */ - -package chunksPkg - -// EXISTING_CODE -import ( - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" -) - -// EXISTING_CODE - -type simpleChunkPinReport struct { - Chain string `json:"chain"` - ManifestHash base.IpfsHash `json:"manifestHash"` - SpecHash base.IpfsHash `json:"specHash"` - TimestampHash base.IpfsHash `json:"timestampHash"` - Version string `json:"version"` - - // EXISTING_CODE - // EXISTING_CODE -} - -func (s *simpleChunkPinReport) Raw() *types.RawModeler { - return nil -} - -func (s *simpleChunkPinReport) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { - var model = map[string]interface{}{} - var order = []string{} - - // EXISTING_CODE - model = map[string]interface{}{ - "chain": s.Chain, - "version": s.Version, - "manifestHash": s.ManifestHash, - "timestampHash": s.TimestampHash, - "specHash": s.SpecHash, - } - order = []string{ - "chain", - "version", - "manifestHash", - "timestampHash", - "specHash", - } - // EXISTING_CODE - - return types.Model{ - Data: model, - Order: order, - } -} - -// EXISTING_CODE -// EXISTING_CODE diff --git a/src/apps/chifra/internal/config/doc.go b/src/apps/chifra/internal/config/doc.go index c0db506702..469a12214f 100644 --- a/src/apps/chifra/internal/config/doc.go +++ b/src/apps/chifra/internal/config/doc.go @@ -6,5 +6,5 @@ * the code inside of 'EXISTING_CODE' tags. */ -// Package configPkg handles the chifra config command. It allows you to manage the various TrueBlocks caches. You may list all of the caches, some of the cache, or even individual caches either in terse or full detail. The cache of interest is specified with the modes option. TrueBlocks maintains caches for the index of address appearances, named addresses, abi files, as well as other data including blockchain data, and address monitors. +// The chifra config program allows you to manage the various TrueBlocks caches. You may list all of the caches, some of the cache, or even individual caches either in terse or full detail. The cache of interest is specified with the modes option. TrueBlocks maintains caches for the index of address appearances, named addresses, abi files, as well as other data including blockchain data, and address monitors. package configPkg diff --git a/src/apps/chifra/internal/config/output.go b/src/apps/chifra/internal/config/output.go index ca5ac2f067..255b59f0f4 100644 --- a/src/apps/chifra/internal/config/output.go +++ b/src/apps/chifra/internal/config/output.go @@ -42,7 +42,7 @@ func ServeConfig(w http.ResponseWriter, r *http.Request) error { return err } -// ConfigInternal handles the internal workings of the config command. Returns an error. +// ConfigInternal handles the internal workings of the config command. Returns an error. func (opts *ConfigOptions) ConfigInternal() error { var err error if err = opts.validateConfig(); err != nil { diff --git a/src/apps/chifra/internal/daemon/doc.go b/src/apps/chifra/internal/daemon/doc.go index ccaa70320c..6831f158df 100644 --- a/src/apps/chifra/internal/daemon/doc.go +++ b/src/apps/chifra/internal/daemon/doc.go @@ -6,5 +6,5 @@ * the code inside of 'EXISTING_CODE' tags. */ -// Package daemonPkg handles the chifra daemon command. It manages chifra's API server. Each of the chifra commands along with all of its options, are provided not only by the command line, but also the API server. We call this process the flame server, which is written in Go. chifra serve is an alias for the command. In the future, this daemon may also manage other long-running processes such as chifra scrape and chifra monitors, but for now, it's only managing the API server. The --grpc option turns on a GRPC server that may speed up certain command such as chifra names, although this option is experimental and therefore not recommended for production use. If the default port for the API server is in use, you may change it with the --port option. To get help for any command, please see the API documentation on our website. But, you may also run chifra --help or chifra --help on your command line to get help. See below for an example of converting command line options to a call to the API. There's a one-to-one correspondence between the command line tools and options and the API routes and their options. +// chifra daemon manages chifra's API server. Each of the chifra commands along with all of its options, are provided not only by the command line, but also the API server. We call this process the flame server, which is written in Go. chifra serve is an alias for the chifra daemon command. In the future, this daemon may also manage other long-running processes such as chifra scrape and chifra monitors, but for now, it's only managing the API server. The --grpc option turns on a GRPC server that may speed up certain command such as chifra names, although this option is experimental and therefore not recommended for production use. If the default port for the API server is in use, you may change it with the --port option. To get help for any command, please see the API documentation on our website. But, you may also run chifra --help or chifra --help on your command line to get help. See below for an example of converting command line options to a call to the API. There's a one-to-one correspondence between the command line tools and options and the API routes and their options. package daemonPkg diff --git a/src/apps/chifra/internal/daemon/output.go b/src/apps/chifra/internal/daemon/output.go index 34aa6650a9..30473cd6d9 100644 --- a/src/apps/chifra/internal/daemon/output.go +++ b/src/apps/chifra/internal/daemon/output.go @@ -49,7 +49,7 @@ func ServeDaemon(w http.ResponseWriter, r *http.Request) error { return err } -// DaemonInternal handles the internal workings of the daemon command. Returns an error. +// DaemonInternal handles the internal workings of the daemon command. Returns an error. func (opts *DaemonOptions) DaemonInternal() error { var err error if err = opts.validateDaemon(); err != nil { diff --git a/src/apps/chifra/internal/explore/doc.go b/src/apps/chifra/internal/explore/doc.go index 1117681c78..195252c0af 100644 --- a/src/apps/chifra/internal/explore/doc.go +++ b/src/apps/chifra/internal/explore/doc.go @@ -6,5 +6,5 @@ * the code inside of 'EXISTING_CODE' tags. */ -// Package explorePkg handles the chifra explore command. It opens Etherscan (and other explorers -- including our own) to the block identifier, transaction identifier, or address you specify. It's a handy (configurable) way to open an explorer from the command line, nothing more. +// chifra explore opens Etherscan (and other explorers -- including our own) to the block identifier, transaction identifier, or address you specify. It's a handy (configurable) way to open an explorer from the command line, nothing more. package explorePkg diff --git a/src/apps/chifra/internal/explore/output.go b/src/apps/chifra/internal/explore/output.go index f06e8a3717..06b9e3660c 100644 --- a/src/apps/chifra/internal/explore/output.go +++ b/src/apps/chifra/internal/explore/output.go @@ -44,7 +44,7 @@ func ServeExplore(w http.ResponseWriter, r *http.Request) error { return err } -// ExploreInternal handles the internal workings of the explore command. Returns an error. +// ExploreInternal handles the internal workings of the explore command. Returns an error. func (opts *ExploreOptions) ExploreInternal() error { var err error if err = opts.validateExplore(); err != nil { diff --git a/src/apps/chifra/internal/export/doc.go b/src/apps/chifra/internal/export/doc.go index 1ea1ba07fe..30c7488e90 100644 --- a/src/apps/chifra/internal/export/doc.go +++ b/src/apps/chifra/internal/export/doc.go @@ -6,5 +6,5 @@ * the code inside of 'EXISTING_CODE' tags. */ -// Package exportPkg handles the chifra export command. It provides a major part of the functionality of the TrueBlocks system. Using the index of appearances created with chifra scrape and the list of transaction identifiers created with chifra list, completes the actual extraction of an address's transactional history from the node. You may use topics, fourbyte values at the start of a transaction's input data, and/or a log's source address or emitter to filter the results. You may also choose which portions of the Ethereum data structures (--transactions, --logs, --traces, etc.) as you wish. By default, the results of the extraction are delivered to your console, however, you may export the results to any database (with a little bit of work). The format of the data, its content and its destination are up to you. +// The chifra export tools provides a major part of the functionality of the TrueBlocks system. Using the index of appearances created with chifra scrape and the list of transaction identifiers created with chifra list, chifra export completes the actual extraction of an address's transactional history from the node. You may use topics, fourbyte values at the start of a transaction's input data, and/or a log's source address or emitter to filter the results. You may also choose which portions of the Ethereum data structures (--transactions, --logs, --traces, etc.) as you wish. By default, the results of the extraction are delivered to your console, however, you may export the results to any database (with a little bit of work). The format of the data, its content and its destination are up to you. package exportPkg diff --git a/src/apps/chifra/internal/export/output.go b/src/apps/chifra/internal/export/output.go index bd02dcfd68..8055694829 100644 --- a/src/apps/chifra/internal/export/output.go +++ b/src/apps/chifra/internal/export/output.go @@ -43,7 +43,7 @@ func ServeExport(w http.ResponseWriter, r *http.Request) error { return err } -// ExportInternal handles the internal workings of the export command. Returns an error. +// ExportInternal handles the internal workings of the export command. Returns an error. func (opts *ExportOptions) ExportInternal() error { var err error if err = opts.validateExport(); err != nil { diff --git a/src/apps/chifra/internal/init/doc.go b/src/apps/chifra/internal/init/doc.go index ba3c4c0a54..2b6c367c29 100644 --- a/src/apps/chifra/internal/init/doc.go +++ b/src/apps/chifra/internal/init/doc.go @@ -6,5 +6,5 @@ * the code inside of 'EXISTING_CODE' tags. */ -// Package initPkg handles the chifra init command. When invoked it reads a value from a smart contract called **The Unchained Index** (0x0c316b7042b419d07d343f2f4f5bd54ff731183d). This value (manifestHashMap) is an IPFS hash pointing to a pinned file (called the Manifest) that contains a large collection of other IPFS hashes. These other hashes point to each of the Bloom filter and Index Chunk. TrueBlocks periodically publishes the Manifest's hash to the smart contract. This makes the index available for our software to use and impossible for us to withhold. Both of these aspects of the manifest are by design. If you stop chifra init before it finishes, it will pick up again where it left off the next time you run it. Certain parts of the system (chifra list and chifra export for example) if you have not previously run chifra init or chifra scrape. You will be warned by the system until it's satisfied. If you run chifra init and allow it to complete, the next time you run chifra scrape, it will start where init finished. This means that only the blooms will be stored on your hard drive. Subsequent scraping will produce both chunks and blooms, although you can, if you wish delete chunks that are not being used. You may periodically run chifra init if you prefer not to scrape. +// When invoked, chifra init reads a value from a smart contract called **The Unchained Index** (0x0c316b7042b419d07d343f2f4f5bd54ff731183d). This value (manifestHashMap) is an IPFS hash pointing to a pinned file (called the Manifest) that contains a large collection of other IPFS hashes. These other hashes point to each of the Bloom filter and Index Chunk. TrueBlocks periodically publishes the Manifest's hash to the smart contract. This makes the index available for our software to use and impossible for us to withhold. Both of these aspects of the manifest are by design. If you stop chifra init before it finishes, it will pick up again where it left off the next time you run it. Certain parts of the system (chifra list and chifra export for example) if you have not previously run chifra init or chifra scrape. You will be warned by the system until it's satisfied. If you run chifra init and allow it to complete, the next time you run chifra scrape, it will start where init finished. This means that only the blooms will be stored on your hard drive. Subsequent scraping will produce both chunks and blooms, although you can, if you wish delete chunks that are not being used. You may periodically run chifra init if you prefer not to scrape. package initPkg diff --git a/src/apps/chifra/internal/init/output.go b/src/apps/chifra/internal/init/output.go index b6a0cf3fd7..b6c398aed5 100644 --- a/src/apps/chifra/internal/init/output.go +++ b/src/apps/chifra/internal/init/output.go @@ -42,7 +42,7 @@ func ServeInit(w http.ResponseWriter, r *http.Request) error { return err } -// InitInternal handles the internal workings of the init command. Returns an error. +// InitInternal handles the internal workings of the init command. Returns an error. func (opts *InitOptions) InitInternal() error { var err error if err = opts.validateInit(); err != nil { diff --git a/src/apps/chifra/internal/list/doc.go b/src/apps/chifra/internal/list/doc.go index 8b53e8cfce..c3da5eb0e3 100644 --- a/src/apps/chifra/internal/list/doc.go +++ b/src/apps/chifra/internal/list/doc.go @@ -6,5 +6,5 @@ * the code inside of 'EXISTING_CODE' tags. */ -// Package listPkg handles the chifra list command. It takes one or more addresses, queries the index of appearances, and builds TrueBlocks monitors. A TrueBlocks monitor is a file that contains blockNumber.transactionIndex pairs (transaction identifiers) representing the history of the address. Because TrueBlocks only extracts data from the Ethereum node when it's requested, the first time you list an address it takes about a minute. Subsequent queries are much faster because TrueBlocks caches the results. Note that chifra list only queries the index, it does not extract the full transactional details. You may use chifra export for that. +// chifra list takes one or more addresses, queries the index of appearances, and builds TrueBlocks monitors. A TrueBlocks monitor is a file that contains blockNumber.transactionIndex pairs (transaction identifiers) representing the history of the address. Because TrueBlocks only extracts data from the Ethereum node when it's requested, the first time you list an address it takes about a minute. Subsequent queries are much faster because TrueBlocks caches the results. Note that chifra list only queries the index, it does not extract the full transactional details. You may use chifra export for that. package listPkg diff --git a/src/apps/chifra/internal/list/output.go b/src/apps/chifra/internal/list/output.go index d798a10e4a..2e8f3c4ff9 100644 --- a/src/apps/chifra/internal/list/output.go +++ b/src/apps/chifra/internal/list/output.go @@ -43,7 +43,7 @@ func ServeList(w http.ResponseWriter, r *http.Request) error { return err } -// ListInternal handles the internal workings of the list command. Returns an error. +// ListInternal handles the internal workings of the list command. Returns an error. func (opts *ListOptions) ListInternal() error { var err error if err = opts.validateList(); err != nil { diff --git a/src/apps/chifra/internal/logs/output.go b/src/apps/chifra/internal/logs/output.go index d5b0cf7c2f..e2478dde05 100644 --- a/src/apps/chifra/internal/logs/output.go +++ b/src/apps/chifra/internal/logs/output.go @@ -42,7 +42,7 @@ func ServeLogs(w http.ResponseWriter, r *http.Request) error { return err } -// LogsInternal handles the internal workings of the logs command. Returns an error. +// LogsInternal handles the internal workings of the logs command. Returns an error. func (opts *LogsOptions) LogsInternal() error { var err error if err = opts.validateLogs(); err != nil { diff --git a/src/apps/chifra/internal/monitors/handle_clean.go b/src/apps/chifra/internal/monitors/handle_clean.go index efe8d4cb55..405870f280 100644 --- a/src/apps/chifra/internal/monitors/handle_clean.go +++ b/src/apps/chifra/internal/monitors/handle_clean.go @@ -19,10 +19,10 @@ func (opts *MonitorsOptions) HandleClean() error { _, monArray := monitor.GetMonitorMap(chain) ctx := context.Background() - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawMonitorClean], errorChan chan error) { for _, mon := range monArray { addr := mon.Address.Hex() - s := simpleMonitorClean{ + s := types.SimpleMonitorClean{ Address: mon.Address, } if testMode { diff --git a/src/apps/chifra/internal/monitors/output.go b/src/apps/chifra/internal/monitors/output.go index fe8aba7d2c..e11cc0fb98 100644 --- a/src/apps/chifra/internal/monitors/output.go +++ b/src/apps/chifra/internal/monitors/output.go @@ -64,7 +64,7 @@ func ServeMonitors(w http.ResponseWriter, r *http.Request) error { return err } -// MonitorsInternal handles the internal workings of the monitors command. Returns an error. +// MonitorsInternal handles the internal workings of the monitors command. Returns an error. func (opts *MonitorsOptions) MonitorsInternal() error { var err error if err = opts.validateMonitors(); err != nil { diff --git a/src/apps/chifra/internal/monitors/types_monitorclean.go b/src/apps/chifra/internal/monitors/types_monitorclean.go deleted file mode 100644 index 1d65318e59..0000000000 --- a/src/apps/chifra/internal/monitors/types_monitorclean.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. -// Use of this source code is governed by a license that can -// be found in the LICENSE file. -/* - * Parts of this file were auto generated. Edit only those parts of - * the code inside of 'EXISTING_CODE' tags. - */ - -package monitorsPkg - -// EXISTING_CODE -import ( - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" -) - -// EXISTING_CODE - -type simpleMonitorClean struct { - Address base.Address `json:"address"` - Dups int64 `json:"dups"` - SizeNow int64 `json:"sizeNow"` - SizeThen int64 `json:"sizeThen"` - - // EXISTING_CODE - // EXISTING_CODE -} - -func (s *simpleMonitorClean) Raw() *types.RawModeler { - return nil -} - -func (s *simpleMonitorClean) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { - var model = map[string]interface{}{} - var order = []string{} - - // EXISTING_CODE - model = map[string]any{ - "address": s.Address, - "sizeNow": s.SizeNow, - "sizeThen": s.SizeThen, - "dups": s.Dups, - } - order = []string{ - "address", - "sizeNow", - "sizeThen", - "dups", - } - // EXISTING_CODE - - return types.Model{ - Data: model, - Order: order, - } -} - -// EXISTING_CODE -// EXISTING_CODE diff --git a/src/apps/chifra/internal/names/output.go b/src/apps/chifra/internal/names/output.go index fd27261150..d490bd8d00 100644 --- a/src/apps/chifra/internal/names/output.go +++ b/src/apps/chifra/internal/names/output.go @@ -54,7 +54,7 @@ func ServeNames(w http.ResponseWriter, r *http.Request) error { return err } -// NamesInternal handles the internal workings of the names command. Returns an error. +// NamesInternal handles the internal workings of the names command. Returns an error. func (opts *NamesOptions) NamesInternal() error { var err error if err = opts.validateNames(); err != nil { diff --git a/src/apps/chifra/internal/receipts/output.go b/src/apps/chifra/internal/receipts/output.go index dfa3bd3270..c3b62214c9 100644 --- a/src/apps/chifra/internal/receipts/output.go +++ b/src/apps/chifra/internal/receipts/output.go @@ -42,7 +42,7 @@ func ServeReceipts(w http.ResponseWriter, r *http.Request) error { return err } -// ReceiptsInternal handles the internal workings of the receipts command. Returns an error. +// ReceiptsInternal handles the internal workings of the receipts command. Returns an error. func (opts *ReceiptsOptions) ReceiptsInternal() error { var err error if err = opts.validateReceipts(); err != nil { diff --git a/src/apps/chifra/internal/scrape/notify_test.go b/src/apps/chifra/internal/scrape/notify_test.go index c6dd1f2785..4f10d9ec05 100644 --- a/src/apps/chifra/internal/scrape/notify_test.go +++ b/src/apps/chifra/internal/scrape/notify_test.go @@ -13,6 +13,8 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/uniq" ) +// TODO: Remove rpc.MetaData and use types.MetaData throughout + func TestNotify(t *testing.T) { results := make([]string, 0) var mutex sync.Mutex diff --git a/src/apps/chifra/internal/scrape/output.go b/src/apps/chifra/internal/scrape/output.go index 2f7114767e..99ef8759c7 100644 --- a/src/apps/chifra/internal/scrape/output.go +++ b/src/apps/chifra/internal/scrape/output.go @@ -44,7 +44,7 @@ func ServeScrape(w http.ResponseWriter, r *http.Request) error { return err } -// ScrapeInternal handles the internal workings of the scrape command. Returns an error. +// ScrapeInternal handles the internal workings of the scrape command. Returns an error. func (opts *ScrapeOptions) ScrapeInternal() error { var err error if err = opts.validateScrape(); err != nil { diff --git a/src/apps/chifra/internal/scrape/scrape_consolidate.go b/src/apps/chifra/internal/scrape/scrape_consolidate.go index 1ff608b5b8..0f3a1e0826 100644 --- a/src/apps/chifra/internal/scrape/scrape_consolidate.go +++ b/src/apps/chifra/internal/scrape/scrape_consolidate.go @@ -124,7 +124,7 @@ func (bm *BlazeManager) Consolidate(blocks []base.Blknum) (error, bool) { // reset for next chunk bm.meta, _ = bm.opts.Conn.GetMetaData(bm.IsTestMode()) - appMap = make(map[string][]index.AppearanceRecord, 0) + appMap = make(map[string][]types.SimpleAppRecord, 0) chunkRange.First = chunkRange.Last + 1 chunkRange.Last = chunkRange.Last + 1 nAppearances = 0 @@ -175,11 +175,11 @@ func (bm *BlazeManager) Consolidate(blocks []base.Blknum) (error, bool) { } // AsciiFileToAppearanceMap reads the appearances from the stage file and returns them as a map -func (bm *BlazeManager) AsciiFileToAppearanceMap(fn string) (map[string][]index.AppearanceRecord, base.FileRange, int) { +func (bm *BlazeManager) AsciiFileToAppearanceMap(fn string) (map[string][]types.SimpleAppRecord, base.FileRange, int) { appearances := file.AsciiFileToLines(fn) os.Remove(fn) // It's okay to remove this. If it fails, we'll just start over. - appMap := make(map[string][]index.AppearanceRecord, len(appearances)) + appMap := make(map[string][]types.SimpleAppRecord, len(appearances)) fileRange := base.FileRange{First: utils.NOPOS, Last: 0} if len(appearances) == 0 { @@ -199,7 +199,7 @@ func (bm *BlazeManager) AsciiFileToAppearanceMap(fn string) (map[string][]index. } fileRange.First = utils.Min(fileRange.First, bn) fileRange.Last = utils.Max(fileRange.Last, bn) - appMap[addr] = append(appMap[addr], index.AppearanceRecord{ + appMap[addr] = append(appMap[addr], types.SimpleAppRecord{ BlockNumber: uint32(bn), TransactionIndex: uint32(txid), }) diff --git a/src/apps/chifra/internal/scrape/scrape_manager.go b/src/apps/chifra/internal/scrape/scrape_manager.go index 494ebbea76..3f3ed271f6 100644 --- a/src/apps/chifra/internal/scrape/scrape_manager.go +++ b/src/apps/chifra/internal/scrape/scrape_manager.go @@ -9,6 +9,8 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/tslib" ) +// TODO: Remove rpc.MetaData and use types.MetaData throughout + // BlazeManager manages the scraper by keeping track of the progress of the scrape and // maintaining the timestamp array and processed map. The processed map helps us know // if every block was visited or not. diff --git a/src/apps/chifra/internal/scrape/scrape_prepare.go b/src/apps/chifra/internal/scrape/scrape_prepare.go index 471c9631b5..c063fe365a 100644 --- a/src/apps/chifra/internal/scrape/scrape_prepare.go +++ b/src/apps/chifra/internal/scrape/scrape_prepare.go @@ -13,6 +13,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/prefunds" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/tslib" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) // Prepare performs actions that need to be done prior to entering the @@ -45,10 +46,10 @@ func (opts *ScrapeOptions) Prepare() (ok bool, err error) { return false, err } - appMap := make(map[string][]index.AppearanceRecord, len(prefunds)) + appMap := make(map[string][]types.SimpleAppRecord, len(prefunds)) for i, prefund := range prefunds { addr := prefund.Address.Hex() - appMap[addr] = append(appMap[addr], index.AppearanceRecord{ + appMap[addr] = append(appMap[addr], types.SimpleAppRecord{ BlockNumber: 0, TransactionIndex: uint32(i), }) diff --git a/src/apps/chifra/internal/slurp/output.go b/src/apps/chifra/internal/slurp/output.go index 9c63cee5e8..25e1363a42 100644 --- a/src/apps/chifra/internal/slurp/output.go +++ b/src/apps/chifra/internal/slurp/output.go @@ -42,7 +42,7 @@ func ServeSlurp(w http.ResponseWriter, r *http.Request) error { return err } -// SlurpInternal handles the internal workings of the slurp command. Returns an error. +// SlurpInternal handles the internal workings of the slurp command. Returns an error. func (opts *SlurpOptions) SlurpInternal() error { var err error if err = opts.validateSlurp(); err != nil { diff --git a/src/apps/chifra/internal/state/output.go b/src/apps/chifra/internal/state/output.go index fbaba6bda7..fc3316fe46 100644 --- a/src/apps/chifra/internal/state/output.go +++ b/src/apps/chifra/internal/state/output.go @@ -42,7 +42,7 @@ func ServeState(w http.ResponseWriter, r *http.Request) error { return err } -// StateInternal handles the internal workings of the state command. Returns an error. +// StateInternal handles the internal workings of the state command. Returns an error. func (opts *StateOptions) StateInternal() error { var err error if err = opts.validateState(); err != nil { diff --git a/src/apps/chifra/internal/status/handle_caches.go b/src/apps/chifra/internal/status/handle_caches.go index aed3edeb1a..323b43fb0d 100644 --- a/src/apps/chifra/internal/status/handle_caches.go +++ b/src/apps/chifra/internal/status/handle_caches.go @@ -22,16 +22,16 @@ func (opts *StatusOptions) HandleCaches() error { testMode := opts.Globals.TestMode ctx := context.Background() - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawStatus], errorChan chan error) { now := time.Now() filenameChan := make(chan walk.CacheFileInfo) var nRoutines int - counterMap := make(map[walk.CacheType]*simpleCacheItem) + counterMap := make(map[walk.CacheType]*types.SimpleCacheItem) nRoutines = len(opts.ModeTypes) for _, mT := range opts.ModeTypes { - counterMap[mT] = &simpleCacheItem{ + counterMap[mT] = &types.SimpleCacheItem{ CacheItemType: walk.CacheName(mT), Items: make([]any, 0), LastCached: now.Format("2006-01-02 15:04:05"), diff --git a/src/apps/chifra/internal/status/handle_diagnose.go b/src/apps/chifra/internal/status/handle_diagnose.go index f30a439a02..a688d9a68b 100644 --- a/src/apps/chifra/internal/status/handle_diagnose.go +++ b/src/apps/chifra/internal/status/handle_diagnose.go @@ -12,7 +12,7 @@ func (opts *StatusOptions) HandleDiagnose() error { testMode := opts.Globals.TestMode ctx := context.Background() - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawStatus], errorChan chan error) { s, err := opts.GetSimpleStatus(opts.Diagnose) if err != nil { errorChan <- err @@ -20,7 +20,7 @@ func (opts *StatusOptions) HandleDiagnose() error { } // We want to short circuit the output in the non-json case - if s.toTemplate(opts.Globals.Writer, testMode, opts.Diagnose, logger.LogTimerOn(), opts.Globals.Format) { + if toTemplate(s, opts.Globals.Writer, testMode, opts.Diagnose, logger.LogTimerOn(), opts.Globals.Format) { return } diff --git a/src/apps/chifra/internal/status/handle_show.go b/src/apps/chifra/internal/status/handle_show.go index ae98f8a1e2..8fff58c922 100644 --- a/src/apps/chifra/internal/status/handle_show.go +++ b/src/apps/chifra/internal/status/handle_show.go @@ -2,17 +2,27 @@ package statusPkg import ( "context" + "fmt" + "io" + "strings" + "text/template" + "time" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/colors" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/tslib" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/version" ) func (opts *StatusOptions) HandleShow() error { testMode := opts.Globals.TestMode ctx := context.Background() - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawStatus], errorChan chan error) { s, err := opts.GetSimpleStatus(opts.Diagnose) if err != nil { errorChan <- err @@ -20,7 +30,7 @@ func (opts *StatusOptions) HandleShow() error { } // We want to short circuit the output in the non-json case - if s.toTemplate(opts.Globals.Writer, testMode, opts.Diagnose, logger.LogTimerOn(), opts.Globals.Format) { + if toTemplate(s, opts.Globals.Writer, testMode, opts.Diagnose, logger.LogTimerOn(), opts.Globals.Format) { return } @@ -32,3 +42,181 @@ func (opts *StatusOptions) HandleShow() error { } return output.StreamMany(ctx, fetchData, opts.Globals.OutputOptsWithExtra(extra)) } + +func ToProgress(chain string, diagnose bool, meta *types.MetaData) string { + nTs, _ := tslib.NTimestamps(chain) // when the file has one record, the block is zero, etc. + if nTs > 0 { + nTs-- + } + format := "%d, %d, %d, %d ts: %d" + return fmt.Sprintf(format, meta.Latest, meta.Finalized, meta.Staging, meta.Unripe, nTs) +} + +func (opts *StatusOptions) GetSimpleStatus(diagnose bool) (*types.SimpleStatus, error) { + chain := opts.Globals.Chain + testMode := opts.Globals.TestMode + + meta, err := opts.Conn.GetMetaData(false) + if err != nil { + return nil, err + } + diffs := &types.MetaData{ + Latest: 0, + Finalized: meta.Latest - meta.Finalized, + Staging: meta.Latest - meta.Staging, + Unripe: meta.Latest - meta.Unripe, + Ripe: meta.Latest - meta.Ripe, + } + + vers, err := opts.Conn.GetClientVersion() + if err != nil { + return nil, err + } + + provider := config.GetChain(chain).RpcProvider + s := &types.SimpleStatus{ + ClientVersion: vers, + Version: version.LibraryVersion, + RpcProvider: provider, + RootConfig: config.PathToRootConfig(), + ChainConfig: config.MustGetPathToChainConfig(chain), + CachePath: config.PathToCache(chain), + IndexPath: config.PathToIndex(chain), + Progress: ToProgress(chain, diagnose, meta), + IsTesting: testMode, + IsApi: opts.Globals.IsApiMode(), + IsArchive: opts.Conn.IsNodeArchive(), + IsTracing: opts.Conn.IsNodeTracing(), + HasEsKey: validate.HasArticulationKey(true), + HasPinKey: len(config.GetKey("pinata").ApiKey) > 0 || len(config.GetKey("pinata").Secret) > 0, + Chain: chain, + NetworkId: fmt.Sprint(meta.NetworkId), + ChainId: fmt.Sprint(meta.ChainId), + Meta: meta, + Diffs: diffs, + // Finalized: meta.Latest - meta.Finalized, + // Staging: meta.Latest - meta.Staging, + // Unripe: meta.Latest - meta.Unripe, + // Ripe: meta.Latest - meta.Ripe, + } + + if testMode { + s.ClientVersion = "Client version" + s.Version = "GHC-TrueBlocks//vers-beta--git-hash---git-ts-" + s.RpcProvider = "--providers--" + s.RootConfig = "--paths--" + s.ChainConfig = "--paths--" + s.CachePath = "--paths--" + s.IndexPath = "--paths--" + s.Progress = "--client--, --final--, --staging--, --unripe-- ts: --ts--" + s.HasPinKey = false // the test machine doesn't have a key + } + + return s, nil +} + +func toTemplate(s *types.SimpleStatus, w io.Writer, testMode, diagnose, logTimerOn bool, format string) bool { + if format == "json" { + return false + } + + var timeDatePart string + if logTimerOn { + now := time.Now() + timeDatePart = now.Format("02-01|15:04:05.000 ") + } else { + timeDatePart = "INFO[DATE|TIME] " + } + + table := templateStr + table = strings.Replace(table, "[CLIENT]", getClientTemplate(), -1) + table = strings.Replace(table, "[VERSION]", getVersionTemplate(), -1) + table = strings.Replace(table, "[IDS]", getIdTemplate(), -1) + table = strings.Replace(table, "[PROGRESS]", getProgress(s, testMode, diagnose), -1) + table = strings.Replace(table, "INFO ", timeDatePart+colors.Green, -1) + table = strings.Replace(table, "[RED]", colors.Red, -1) + table = strings.Replace(table, "[GREEN]", colors.Green, -1) + table = strings.Replace(table, "[OFF]", colors.Off, -1) + table = strings.Replace(table, ":", ":"+colors.Off, -1) + + t, err := template.New("status").Parse(table) + if err != nil { + logger.Fatal("should not happen ==> bad template.", err) + return false + } + + _ = t.Execute(w, s) + return true +} + +func getClientTemplate() string { + archive := "{{if .IsArchive}}[GREEN]archive[OFF]{{else}}[RED]no archive[OFF]{{end}}" + testing := "{{if .IsTesting}}[GREEN]testing[OFF], {{end}}" + tracing := "{{if .IsTracing}}[GREEN]tracing[OFF]{{else}}[RED]no tracing[OFF]{{end}}" + return "{{.ClientVersion}} (" + archive + ", " + testing + tracing + ")" +} + +func getVersionTemplate() string { + esKey := "{{if .HasEsKey}}[GREEN]eskey[OFF]{{else}}[RED]no eskey[OFF]{{end}}" + pinKey := "{{if .HasPinKey}}[GREEN]pinkey[OFF]{{else}}[RED]no pinkey[OFF]{{end}}" + return "{{.Version}} (" + esKey + ", " + pinKey + ")" +} + +func getIdTemplate() string { + networkId := "{{if eq .NetworkId \"0\"}}[RED]{{.NetworkId}}[OFF]{{else}}[GREEN]{{.NetworkId}}[OFF]{{end}}" + chainId := "{{if eq .ChainId \"0\"}}[RED]{{.ChainId}}[OFF]{{else}}[GREEN]{{.ChainId}}[OFF]{{end}}" + return networkId + "/" + chainId +} + +func getProgress(s *types.SimpleStatus, testMode, diagnose bool) string { + if diagnose { + if testMode { + return "--diagnostics--" + } + nTs, _ := tslib.NTimestamps(s.Meta.Chain) // when the file has one record, the block is zero, etc. + if nTs > 0 { + nTs-- + } + nTsDiff := s.Meta.Latest - nTs + if nTs > s.Meta.Latest { + nTsDiff = 0 + } + ret := ` +INFO [OFF] Chain Head [GREEN]{{.Meta.Latest}}[OFF] +INFO [OFF] Finalized [GREEN]{{.Meta.Finalized}}[OFF] ([GREEN]{{.Diffs.Finalized}}[OFF] behind head) +INFO [OFF] Stage [GREEN]{{.Meta.Staging}}[OFF] ([GREEN]{{.Diffs.Staging}}[OFF] behind head) +INFO [OFF] Indexing [GREEN]{{.Meta.Unripe}}[OFF] ([GREEN]{{.Diffs.Unripe}}[OFF] behind head) +INFO [OFF] Timestamps [GREEN]{nTs}[OFF] ([GREEN]{nTsDiff}[OFF] behind head) +` + ret = strings.Replace(ret, "{nTs}", fmt.Sprint(nTs), -1) + ret = strings.Replace(ret, "{nTsDiff}", fmt.Sprint(nTsDiff), -1) + return ret + } + + return " {{.Progress}}" +} + +const templateStr = `INFO Client: [CLIENT] +INFO TrueBlocks: [VERSION] +INFO RPC Provider: {{.RpcProvider}} - {{.Chain}} ([IDS]) +INFO Root Config Path: {{.RootConfig}} +INFO Chain Config Path: {{.ChainConfig}} +INFO Cache Path: {{.CachePath}} +INFO Index Path: {{.IndexPath}} +INFO Progress:[PROGRESS] +` + +/* +TODO: Better diagnostics (see #3209) +TODO: When Node synced, successfull chifra init but scraper not running +TODO: +TODO: WARN: Index is behind the chain head, but scraper is not running. +TODO: WARN: This means chifra is not aware of latest transactions and can return incomplete data. +TODO: WARN: Run `chifra daemon --scrape index` to solve the issue. +TODO: +TODO: Node is not syncing +TODO: +TODO: WARN: Your node seems to be syncing. During this state it can refuse queries from chifra +TODO: WARN: or return incomplete data. If you observe such issues, please wait until your node +TODO: WARN: is fully synced and your index catches up to the chain head. +*/ diff --git a/src/apps/chifra/internal/status/output.go b/src/apps/chifra/internal/status/output.go index b7f6ea4dd2..f2944d7579 100644 --- a/src/apps/chifra/internal/status/output.go +++ b/src/apps/chifra/internal/status/output.go @@ -42,7 +42,7 @@ func ServeStatus(w http.ResponseWriter, r *http.Request) error { return err } -// StatusInternal handles the internal workings of the status command. Returns an error. +// StatusInternal handles the internal workings of the status command. Returns an error. func (opts *StatusOptions) StatusInternal() error { var err error if err = opts.validateStatus(); err != nil { diff --git a/src/apps/chifra/internal/status/types_cacheitem.go b/src/apps/chifra/internal/status/types_cacheitem.go deleted file mode 100644 index cff1dd0992..0000000000 --- a/src/apps/chifra/internal/status/types_cacheitem.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. -// Use of this source code is governed by a license that can -// be found in the LICENSE file. -/* - * Parts of this file were auto generated. Edit only those parts of - * the code inside of 'EXISTING_CODE' tags. - */ - -package statusPkg - -// EXISTING_CODE -import ( - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" -) - -// EXISTING_CODE - -type simpleCacheItem struct { - Items []any `json:"items"` - LastCached string `json:"lastCached,omitempty"` - NFiles uint64 `json:"nFiles"` - NFolders uint64 `json:"nFolders"` - Path string `json:"path"` - SizeInBytes int64 `json:"sizeInBytes"` - CacheItemType string `json:"type"` - - // EXISTING_CODE - // EXISTING_CODE -} - -func (s *simpleCacheItem) Raw() *types.RawModeler { - return nil -} - -func (s *simpleCacheItem) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { - var model = map[string]interface{}{} - var order = []string{} - - // EXISTING_CODE - // EXISTING_CODE - - return types.Model{ - Data: model, - Order: order, - } -} - -// EXISTING_CODE -// EXISTING_CODE diff --git a/src/apps/chifra/internal/status/types_status.go b/src/apps/chifra/internal/status/types_status.go deleted file mode 100644 index 456272d52a..0000000000 --- a/src/apps/chifra/internal/status/types_status.go +++ /dev/null @@ -1,345 +0,0 @@ -// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. -// Use of this source code is governed by a license that can -// be found in the LICENSE file. -/* - * Parts of this file were auto generated. Edit only those parts of - * the code inside of 'EXISTING_CODE' tags. - */ - -package statusPkg - -// EXISTING_CODE -import ( - "fmt" - "io" - "sort" - "strings" - "text/template" - "time" - - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/colors" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/tslib" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/version" -) - -// EXISTING_CODE - -type simpleStatus struct { - CachePath string `json:"cachePath,omitempty"` - Caches []simpleCacheItem `json:"caches"` - Chain string `json:"chain,omitempty"` - ChainConfig string `json:"chainConfig,omitempty"` - ChainId string `json:"chainId,omitempty"` - Chains []types.SimpleChain `json:"chains"` - ClientVersion string `json:"clientVersion,omitempty"` - HasEsKey bool `json:"hasEsKey,omitempty"` - HasPinKey bool `json:"hasPinKey,omitempty"` - IndexPath string `json:"indexPath,omitempty"` - IsApi bool `json:"isApi,omitempty"` - IsArchive bool `json:"isArchive,omitempty"` - IsScraping bool `json:"isScraping,omitempty"` - IsTesting bool `json:"isTesting,omitempty"` - IsTracing bool `json:"isTracing,omitempty"` - NetworkId string `json:"networkId,omitempty"` - Progress string `json:"progress,omitempty"` - RootConfig string `json:"rootConfig,omitempty"` - RpcProvider string `json:"rpcProvider,omitempty"` - Version string `json:"version,omitempty"` - - // EXISTING_CODE - Meta *rpc.MetaData `json:"meta,omitempty"` - Diffs *rpc.MetaData `json:"diffs,omitempty"` - // EXISTING_CODE -} - -func (s *simpleStatus) Raw() *types.RawModeler { - return nil -} - -func (s *simpleStatus) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { - var model = map[string]interface{}{} - var order = []string{} - - // EXISTING_CODE - model = map[string]interface{}{ - "cachePath": s.CachePath, - "chainConfig": s.ChainConfig, - "clientVersion": s.ClientVersion, - "hasEsKey": s.HasEsKey, - "hasPinKey": s.HasPinKey, - "indexPath": s.IndexPath, - "isApi": s.IsApi, - "isArchive": s.IsArchive, - "isTesting": s.IsTesting, - "isTracing": s.IsTracing, - "rootConfig": s.RootConfig, - "rpcProvider": s.RpcProvider, - "trueblocksVersion": s.Version, - } - order = []string{ - "cachePath", - "chainConfig", - "clientVersion", - "hasEsKey", - "hasPinKey", - "indexPath", - "isApi", - "isArchive", - "isTesting", - "isTracing", - "rootConfig", - "rpcProvider", - "trueblocksVersion", - } - - if extraOptions != nil && extraOptions["showProgress"] == true { - model["progress"] = s.Progress - order = append(order, "progress") - } - - testMode := extraOptions["testMode"] == true - if len(s.Caches) > 0 { - if testMode { - for i := 0; i < len(s.Caches); i++ { - s.Caches[i].Path = "--paths--" - s.Caches[i].LastCached = "--lastCached--" - s.Caches[i].NFiles = 123 - s.Caches[i].NFolders = 456 - s.Caches[i].SizeInBytes = 789 - } - } - model["caches"] = s.Caches - order = append(order, "caches") - } - - if extraOptions["chains"] == true { - var chains []types.SimpleChain - if extraOptions["testMode"] == true { - ch := types.SimpleChain{ - Chain: "testChain", - ChainId: 12345, - LocalExplorer: "http://localhost:8080", - RpcProvider: "http://localhost:8545", - Symbol: "ETH", - } - chains = append(chains, ch) - } else { - chainArray := config.GetChains() - for _, chain := range chainArray { - ch := types.SimpleChain{ - Chain: chain.Chain, - ChainId: utils.MustParseUint(chain.ChainId), - LocalExplorer: chain.LocalExplorer, - RemoteExplorer: chain.RemoteExplorer, - RpcProvider: chain.RpcProvider, - IpfsGateway: chain.IpfsGateway, - Symbol: chain.Symbol, - } - chains = append(chains, ch) - } - sort.Slice(chains, func(i, j int) bool { - if chains[i].ChainId == chains[j].ChainId { - return chains[i].Chain < chains[j].Chain - } - return chains[i].ChainId < chains[j].ChainId - }) - } - model["chains"] = chains - order = append(order, "chains") - } - // EXISTING_CODE - - return types.Model{ - Data: model, - Order: order, - } -} - -// EXISTING_CODE -// - -func ToProgress(chain string, diagnose bool, meta *rpc.MetaData) string { - nTs, _ := tslib.NTimestamps(chain) // when the file has one record, the block is zero, etc. - if nTs > 0 { - nTs-- - } - format := "%d, %d, %d, %d ts: %d" - return fmt.Sprintf(format, meta.Latest, meta.Finalized, meta.Staging, meta.Unripe, nTs) -} - -func (opts *StatusOptions) GetSimpleStatus(diagnose bool) (*simpleStatus, error) { - chain := opts.Globals.Chain - testMode := opts.Globals.TestMode - - meta, err := opts.Conn.GetMetaData(false) - if err != nil { - return nil, err - } - diffs := &rpc.MetaData{ - Latest: 0, - Finalized: meta.Latest - meta.Finalized, - Staging: meta.Latest - meta.Staging, - Unripe: meta.Latest - meta.Unripe, - Ripe: meta.Latest - meta.Ripe, - } - - vers, err := opts.Conn.GetClientVersion() - if err != nil { - return nil, err - } - - provider := config.GetChain(chain).RpcProvider - s := &simpleStatus{ - ClientVersion: vers, - Version: version.LibraryVersion, - RpcProvider: provider, - RootConfig: config.PathToRootConfig(), - ChainConfig: config.MustGetPathToChainConfig(chain), - CachePath: config.PathToCache(chain), - IndexPath: config.PathToIndex(chain), - Progress: ToProgress(chain, diagnose, meta), - IsTesting: testMode, - IsApi: opts.Globals.IsApiMode(), - IsArchive: opts.Conn.IsNodeArchive(), - IsTracing: opts.Conn.IsNodeTracing(), - HasEsKey: validate.HasArticulationKey(true), - HasPinKey: len(config.GetKey("pinata").ApiKey) > 0 || len(config.GetKey("pinata").Secret) > 0, - Chain: chain, - NetworkId: fmt.Sprint(meta.NetworkId), - ChainId: fmt.Sprint(meta.ChainId), - Meta: meta, - Diffs: diffs, - // Finalized: meta.Latest - meta.Finalized, - // Staging: meta.Latest - meta.Staging, - // Unripe: meta.Latest - meta.Unripe, - // Ripe: meta.Latest - meta.Ripe, - } - - if testMode { - s.ClientVersion = "Client version" - s.Version = "GHC-TrueBlocks//vers-beta--git-hash---git-ts-" - s.RpcProvider = "--providers--" - s.RootConfig = "--paths--" - s.ChainConfig = "--paths--" - s.CachePath = "--paths--" - s.IndexPath = "--paths--" - s.Progress = "--client--, --final--, --staging--, --unripe-- ts: --ts--" - s.HasPinKey = false // the test machine doesn't have a key - } - - return s, nil -} - -func (s *simpleStatus) toTemplate(w io.Writer, testMode, diagnose, logTimerOn bool, format string) bool { - if format == "json" { - return false - } - - var timeDatePart string - if logTimerOn { - now := time.Now() - timeDatePart = now.Format("02-01|15:04:05.000 ") - } else { - timeDatePart = "INFO[DATE|TIME] " - } - - table := templateStr - table = strings.Replace(table, "[CLIENT]", getClientTemplate(), -1) - table = strings.Replace(table, "[VERSION]", getVersionTemplate(), -1) - table = strings.Replace(table, "[IDS]", getIdTemplate(), -1) - table = strings.Replace(table, "[PROGRESS]", s.getProgress(testMode, diagnose), -1) - table = strings.Replace(table, "INFO ", timeDatePart+colors.Green, -1) - table = strings.Replace(table, "[RED]", colors.Red, -1) - table = strings.Replace(table, "[GREEN]", colors.Green, -1) - table = strings.Replace(table, "[OFF]", colors.Off, -1) - table = strings.Replace(table, ":", ":"+colors.Off, -1) - - t, err := template.New("status").Parse(table) - if err != nil { - logger.Fatal("should not happen ==> bad template.", err) - return false - } - - _ = t.Execute(w, s) - return true -} - -func getClientTemplate() string { - archive := "{{if .IsArchive}}[GREEN]archive[OFF]{{else}}[RED]no archive[OFF]{{end}}" - testing := "{{if .IsTesting}}[GREEN]testing[OFF], {{end}}" - tracing := "{{if .IsTracing}}[GREEN]tracing[OFF]{{else}}[RED]no tracing[OFF]{{end}}" - return "{{.ClientVersion}} (" + archive + ", " + testing + tracing + ")" -} - -func getVersionTemplate() string { - esKey := "{{if .HasEsKey}}[GREEN]eskey[OFF]{{else}}[RED]no eskey[OFF]{{end}}" - pinKey := "{{if .HasPinKey}}[GREEN]pinkey[OFF]{{else}}[RED]no pinkey[OFF]{{end}}" - return "{{.Version}} (" + esKey + ", " + pinKey + ")" -} - -func getIdTemplate() string { - networkId := "{{if eq .NetworkId \"0\"}}[RED]{{.NetworkId}}[OFF]{{else}}[GREEN]{{.NetworkId}}[OFF]{{end}}" - chainId := "{{if eq .ChainId \"0\"}}[RED]{{.ChainId}}[OFF]{{else}}[GREEN]{{.ChainId}}[OFF]{{end}}" - return networkId + "/" + chainId -} - -func (s *simpleStatus) getProgress(testMode, diagnose bool) string { - if diagnose { - if testMode { - return "--diagnostics--" - } - nTs, _ := tslib.NTimestamps(s.Meta.Chain) // when the file has one record, the block is zero, etc. - if nTs > 0 { - nTs-- - } - nTsDiff := s.Meta.Latest - nTs - if nTs > s.Meta.Latest { - nTsDiff = 0 - } - ret := ` -INFO [OFF] Chain Head [GREEN]{{.Meta.Latest}}[OFF] -INFO [OFF] Finalized [GREEN]{{.Meta.Finalized}}[OFF] ([GREEN]{{.Diffs.Finalized}}[OFF] behind head) -INFO [OFF] Stage [GREEN]{{.Meta.Staging}}[OFF] ([GREEN]{{.Diffs.Staging}}[OFF] behind head) -INFO [OFF] Indexing [GREEN]{{.Meta.Unripe}}[OFF] ([GREEN]{{.Diffs.Unripe}}[OFF] behind head) -INFO [OFF] Timestamps [GREEN]{nTs}[OFF] ([GREEN]{nTsDiff}[OFF] behind head) -` - ret = strings.Replace(ret, "{nTs}", fmt.Sprint(nTs), -1) - ret = strings.Replace(ret, "{nTsDiff}", fmt.Sprint(nTsDiff), -1) - return ret - } - - return " {{.Progress}}" -} - -const templateStr = `INFO Client: [CLIENT] -INFO TrueBlocks: [VERSION] -INFO RPC Provider: {{.RpcProvider}} - {{.Chain}} ([IDS]) -INFO Root Config Path: {{.RootConfig}} -INFO Chain Config Path: {{.ChainConfig}} -INFO Cache Path: {{.CachePath}} -INFO Index Path: {{.IndexPath}} -INFO Progress:[PROGRESS] -` - -/* -TODO: Better diagnostics (see #3209) -TODO: When Node synced, successfull chifra init but scraper not running -TODO: -TODO: WARN: Index is behind the chain head, but scraper is not running. -TODO: WARN: This means chifra is not aware of latest transactions and can return incomplete data. -TODO: WARN: Run `chifra daemon --scrape index` to solve the issue. -TODO: -TODO: Node is not syncing -TODO: -TODO: WARN: Your node seems to be syncing. During this state it can refuse queries from chifra -TODO: WARN: or return incomplete data. If you observe such issues, please wait until your node -TODO: WARN: is fully synced and your index catches up to the chain head. -*/ - -// EXISTING_CODE diff --git a/src/apps/chifra/internal/tokens/output.go b/src/apps/chifra/internal/tokens/output.go index 901883920b..e92a5e8d26 100644 --- a/src/apps/chifra/internal/tokens/output.go +++ b/src/apps/chifra/internal/tokens/output.go @@ -42,7 +42,7 @@ func ServeTokens(w http.ResponseWriter, r *http.Request) error { return err } -// TokensInternal handles the internal workings of the tokens command. Returns an error. +// TokensInternal handles the internal workings of the tokens command. Returns an error. func (opts *TokensOptions) TokensInternal() error { var err error if err = opts.validateTokens(); err != nil { diff --git a/src/apps/chifra/internal/traces/handle_counts.go b/src/apps/chifra/internal/traces/handle_counts.go index 832ef3ee21..8d9cad829f 100644 --- a/src/apps/chifra/internal/traces/handle_counts.go +++ b/src/apps/chifra/internal/traces/handle_counts.go @@ -22,7 +22,7 @@ func (opts *TracesOptions) HandleCounts() error { nErrors := 0 ctx, cancel := context.WithCancel(context.Background()) - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawTraceCount], errorChan chan error) { apps, _, err := identifiers.IdsToApps(chain, opts.TransactionIds) if err != nil { errorChan <- err @@ -87,7 +87,7 @@ func (opts *TracesOptions) HandleCounts() error { }) for _, item := range items { - counter := simpleTraceCount{ + counter := types.SimpleTraceCount{ BlockNumber: uint64(item.BlockNumber), TransactionIndex: uint64(item.TransactionIndex), TransactionHash: item.Hash, diff --git a/src/apps/chifra/internal/traces/output.go b/src/apps/chifra/internal/traces/output.go index 89c50a25b1..c8ac787217 100644 --- a/src/apps/chifra/internal/traces/output.go +++ b/src/apps/chifra/internal/traces/output.go @@ -42,7 +42,7 @@ func ServeTraces(w http.ResponseWriter, r *http.Request) error { return err } -// TracesInternal handles the internal workings of the traces command. Returns an error. +// TracesInternal handles the internal workings of the traces command. Returns an error. func (opts *TracesOptions) TracesInternal() error { var err error if err = opts.validateTraces(); err != nil { diff --git a/src/apps/chifra/internal/transactions/output.go b/src/apps/chifra/internal/transactions/output.go index e5161548f2..f7faa68190 100644 --- a/src/apps/chifra/internal/transactions/output.go +++ b/src/apps/chifra/internal/transactions/output.go @@ -42,7 +42,7 @@ func ServeTransactions(w http.ResponseWriter, r *http.Request) error { return err } -// TransactionsInternal handles the internal workings of the transactions command. Returns an error. +// TransactionsInternal handles the internal workings of the transactions command. Returns an error. func (opts *TransactionsOptions) TransactionsInternal() error { var err error if err = opts.validateTransactions(); err != nil { diff --git a/src/apps/chifra/internal/when/handle_ts_count.go b/src/apps/chifra/internal/when/handle_ts_count.go index 349697825a..7df9d88711 100644 --- a/src/apps/chifra/internal/when/handle_ts_count.go +++ b/src/apps/chifra/internal/when/handle_ts_count.go @@ -17,7 +17,7 @@ func (opts *WhenOptions) HandleTimestampCount() error { testMode := opts.Globals.TestMode ctx := context.Background() - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawTimestampCount], errorChan chan error) { if count, err := tslib.NTimestamps(chain); err != nil { errorChan <- err return @@ -27,7 +27,7 @@ func (opts *WhenOptions) HandleTimestampCount() error { count = 5000000 } - s := simpleTimestampCount{ + s := types.SimpleTimestampCount{ Count: count, } diff --git a/src/apps/chifra/internal/when/handle_ts_show.go b/src/apps/chifra/internal/when/handle_ts_show.go index cf6a993261..ac761b4b89 100644 --- a/src/apps/chifra/internal/when/handle_ts_show.go +++ b/src/apps/chifra/internal/when/handle_ts_show.go @@ -31,14 +31,14 @@ func (opts *WhenOptions) HandleTimestampsShow() error { ctx := context.Background() prev := base.Timestamp(0) - fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { + fetchData := func(modelChan chan types.Modeler[types.RawTimestamp], errorChan chan error) { for bn := uint64(0); bn < cnt; bn++ { if len(bnMap) == 0 || bnMap[bn] { ts, err := tslib.FromBn(chain, bn) if err != nil { errorChan <- err } - s := simpleTimestamp{ + s := types.SimpleTimestamp{ BlockNumber: uint64(ts.Bn), Timestamp: base.Timestamp(ts.Ts), Diff: base.Timestamp(ts.Ts) - prev, diff --git a/src/apps/chifra/internal/when/output.go b/src/apps/chifra/internal/when/output.go index 4352520cd5..db4d70642f 100644 --- a/src/apps/chifra/internal/when/output.go +++ b/src/apps/chifra/internal/when/output.go @@ -43,7 +43,7 @@ func ServeWhen(w http.ResponseWriter, r *http.Request) error { return err } -// WhenInternal handles the internal workings of the when command. Returns an error. +// WhenInternal handles the internal workings of the when command. Returns an error. func (opts *WhenOptions) WhenInternal() error { var err error if err = opts.validateWhen(); err != nil { diff --git a/src/apps/chifra/internal/when/types_timestampcount.go b/src/apps/chifra/internal/when/types_timestampcount.go deleted file mode 100644 index b2f226ca4f..0000000000 --- a/src/apps/chifra/internal/when/types_timestampcount.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. -// Use of this source code is governed by a license that can -// be found in the LICENSE file. -/* - * Parts of this file were auto generated. Edit only those parts of - * the code inside of 'EXISTING_CODE' tags. - */ - -package whenPkg - -// EXISTING_CODE -import "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" - -// EXISTING_CODE - -type simpleTimestampCount struct { - Count uint64 `json:"count"` - - // EXISTING_CODE - // EXISTING_CODE -} - -func (s *simpleTimestampCount) Raw() *types.RawModeler { - return nil -} - -func (s *simpleTimestampCount) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { - var model = map[string]interface{}{} - var order = []string{} - - // EXISTING_CODE - model = map[string]interface{}{ - "count": s.Count, - } - order = []string{ - "count", - } - // EXISTING_CODE - - return types.Model{ - Data: model, - Order: order, - } -} - -// EXISTING_CODE -// EXISTING_CODE diff --git a/src/apps/chifra/pkg/filter/filter.go b/src/apps/chifra/pkg/filter/filter.go index 63a779001f..e79a0434c1 100644 --- a/src/apps/chifra/pkg/filter/filter.go +++ b/src/apps/chifra/pkg/filter/filter.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) @@ -69,7 +68,7 @@ func (f *AppearanceFilter) GetOuterBounds() base.BlockRange { } // ApplyFilter checks to see if the appearance intersects with the user-supplied --first_block/--last_block pair (if any) -func (f *AppearanceFilter) ApplyFilter(app *index.AppearanceRecord) (passed, finished bool) { +func (f *AppearanceFilter) ApplyFilter(app *types.SimpleAppRecord) (passed, finished bool) { appRange := base.FileRange{First: uint64(app.BlockNumber), Last: uint64(app.BlockNumber)} // --first_block/--last_block if !appRange.Intersects(base.FileRange(f.exportRange)) { return false, false @@ -78,7 +77,7 @@ func (f *AppearanceFilter) ApplyFilter(app *index.AppearanceRecord) (passed, fin } // ApplyRangeFilter checks to see if the appearance intersects with the user-supplied --first_block/--last_block pair (if any) -func (f *AppearanceFilter) ApplyRangeFilter(app *index.AppearanceRecord) (passed, finished bool) { +func (f *AppearanceFilter) ApplyRangeFilter(app *types.SimpleAppRecord) (passed, finished bool) { appRange := base.FileRange{First: uint64(app.BlockNumber), Last: uint64(app.BlockNumber)} // --first_block/--last_block return appRange.Intersects(base.FileRange(f.exportRange)), false } diff --git a/src/apps/chifra/pkg/filter/sort.go b/src/apps/chifra/pkg/filter/sort.go index 9813b8dcf7..88acb7fb90 100644 --- a/src/apps/chifra/pkg/filter/sort.go +++ b/src/apps/chifra/pkg/filter/sort.go @@ -3,7 +3,7 @@ package filter import ( "sort" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) type AppearanceSort int @@ -14,7 +14,7 @@ const ( Reversed ) -func (f *AppearanceFilter) Sort(fromDisc []index.AppearanceRecord) { +func (f *AppearanceFilter) Sort(fromDisc []types.SimpleAppRecord) { if f.sortBy == Sorted || f.sortBy == Reversed { sort.Slice(fromDisc, func(i, j int) bool { if f.sortBy == Reversed { diff --git a/src/apps/chifra/pkg/index/appearance_result.go b/src/apps/chifra/pkg/index/appearance_result.go index 9c863ffab2..bef21dd865 100644 --- a/src/apps/chifra/pkg/index/appearance_result.go +++ b/src/apps/chifra/pkg/index/appearance_result.go @@ -5,13 +5,14 @@ import ( "io" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) // AppearanceResult carries the appearances found in a single Index for the given address. type AppearanceResult struct { Address base.Address Range base.FileRange - AppRecords *[]AppearanceRecord + AppRecords *[]types.SimpleAppRecord Err error } @@ -31,7 +32,7 @@ func (chunk *Index) ReadAppearances(address base.Address) *AppearanceResult { return &ret } - addressRecord := AddressRecord{} + addressRecord := types.SimpleAddrRecord{} if err := binary.Read(chunk.File, binary.LittleEndian, &addressRecord); err != nil { ret.Err = err return &ret diff --git a/src/apps/chifra/pkg/index/chunk_write.go b/src/apps/chifra/pkg/index/chunk_write.go index 87113349cc..ed115269b6 100644 --- a/src/apps/chifra/pkg/index/chunk_write.go +++ b/src/apps/chifra/pkg/index/chunk_write.go @@ -13,6 +13,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) type writeReport struct { @@ -32,13 +33,13 @@ func (c *writeReport) Report() { logger.Info(colors.ColoredWith(fmt.Sprintf(report, c.nAddresses, c.nAppearances, c.Range, c.FileSize, c.Range.Span()), colors.BrightBlue)) } -func (chunk *Chunk) Write(chain string, publisher base.Address, fileName string, addrAppearanceMap map[string][]AppearanceRecord, nApps int) (*writeReport, error) { +func (chunk *Chunk) Write(chain string, publisher base.Address, fileName string, addrAppearanceMap map[string][]types.SimpleAppRecord, nApps int) (*writeReport, error) { // We're going to build two tables. An addressTable and an appearanceTable. We do this as we spin // through the map // Create space for the two tables... - addressTable := make([]AddressRecord, 0, len(addrAppearanceMap)) - appearanceTable := make([]AppearanceRecord, 0, nApps) + addressTable := make([]types.SimpleAddrRecord, 0, len(addrAppearanceMap)) + appearanceTable := make([]types.SimpleAppRecord, 0, nApps) // We want to sort the items in the map by address (maps in GoLang are not sorted) sorted := []string{} @@ -64,7 +65,7 @@ func (chunk *Chunk) Write(chain string, publisher base.Address, fileName string, bl.InsertAddress(address) // ...and append the record to the addressTable. - addressTable = append(addressTable, AddressRecord{ + addressTable = append(addressTable, types.SimpleAddrRecord{ Address: address, Offset: offset, Count: uint32(len(apps)), diff --git a/src/apps/chifra/pkg/index/index_address_record.go b/src/apps/chifra/pkg/index/index_address_record.go index b110c7a6ed..1e416ec033 100644 --- a/src/apps/chifra/pkg/index/index_address_record.go +++ b/src/apps/chifra/pkg/index/index_address_record.go @@ -8,6 +8,7 @@ import ( "sort" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) const ( @@ -15,13 +16,6 @@ const ( AddrRecordWidth = 28 ) -// AddressRecord is a single record in the Address table -type AddressRecord struct { - Address base.Address `json:"address"` - Offset uint32 `json:"offset"` - Count uint32 `json:"count"` -} - func (chunk *Index) searchForAddressRecord(address base.Address) int { compareFunc := func(pos int) bool { if pos == -1 { @@ -39,7 +33,7 @@ func (chunk *Index) searchForAddressRecord(address base.Address) int { return false } - addressRec := AddressRecord{} + addressRec := types.SimpleAddrRecord{} if err = binary.Read(chunk.File, binary.LittleEndian, &addressRec); err != nil { fmt.Println(err) return false @@ -52,7 +46,7 @@ func (chunk *Index) searchForAddressRecord(address base.Address) int { readLocation := int64(HeaderWidth + pos*AddrRecordWidth) _, _ = chunk.File.Seek(readLocation, io.SeekStart) - rec := AddressRecord{} + rec := types.SimpleAddrRecord{} if err := binary.Read(chunk.File, binary.LittleEndian, &rec); err != nil { return -1 } diff --git a/src/apps/chifra/pkg/index/index_appearance_record.go b/src/apps/chifra/pkg/index/index_appearance_record.go index c4b1d4023b..be89fa736a 100644 --- a/src/apps/chifra/pkg/index/index_appearance_record.go +++ b/src/apps/chifra/pkg/index/index_appearance_record.go @@ -3,6 +3,8 @@ package index import ( "encoding/binary" "io" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) const ( @@ -10,13 +12,7 @@ const ( AppRecordWidth = 8 ) -// AppearanceRecord is a single record in the Appearance table -type AppearanceRecord struct { - BlockNumber uint32 `json:"blockNumber"` - TransactionIndex uint32 `json:"transactionIndex"` -} - -func (chunk *Index) ReadAppearancesAndReset(addrRecord *AddressRecord) (apps []AppearanceRecord, err error) { +func (chunk *Index) ReadAppearancesAndReset(addrRecord *types.SimpleAddrRecord) (apps []types.SimpleAppRecord, err error) { offset, err := chunk.File.Seek(0, io.SeekCurrent) if err != nil { return apps, err @@ -35,7 +31,7 @@ func (chunk *Index) ReadAppearancesAndReset(addrRecord *AddressRecord) (apps []A return apps, nil } -func (chunk *Index) readAppearanceRecords(addrRecord *AddressRecord) (apps []AppearanceRecord, err error) { +func (chunk *Index) readAppearanceRecords(addrRecord *types.SimpleAddrRecord) (apps []types.SimpleAppRecord, err error) { readLocation := int64(HeaderWidth + AddrRecordWidth*chunk.Header.AddressCount + AppRecordWidth*addrRecord.Offset) _, err = chunk.File.Seek(readLocation, io.SeekStart) @@ -43,7 +39,7 @@ func (chunk *Index) readAppearanceRecords(addrRecord *AddressRecord) (apps []App return } - apps = make([]AppearanceRecord, addrRecord.Count) + apps = make([]types.SimpleAppRecord, addrRecord.Count) err = binary.Read(chunk.File, binary.LittleEndian, &apps) return diff --git a/src/apps/chifra/pkg/monitor/filter.go b/src/apps/chifra/pkg/monitor/filter.go index a532f9c3c3..d0420588c2 100644 --- a/src/apps/chifra/pkg/monitor/filter.go +++ b/src/apps/chifra/pkg/monitor/filter.go @@ -13,7 +13,7 @@ import ( ) func (mon *Monitor) ReadAndFilterAppearances(filt *filter.AppearanceFilter, withCount bool) (apps []types.SimpleAppearance, cnt int, err error) { - readAppearances := func(apps *[]index.AppearanceRecord) (err error) { + readAppearances := func(apps *[]types.SimpleAppRecord) (err error) { if int64(len(*apps)) > mon.Count() { err = fmt.Errorf("array is larger than the size of the file (%d,%d)", len(*apps), mon.Count()) return @@ -48,7 +48,7 @@ func (mon *Monitor) ReadAndFilterAppearances(filt *filter.AppearanceFilter, with return nil, 0, nil } - fromDisc := make([]index.AppearanceRecord, mon.Count()) + fromDisc := make([]types.SimpleAppRecord, mon.Count()) if err := readAppearances(&fromDisc); err != nil { mon.Close() return nil, 0, err diff --git a/src/apps/chifra/pkg/monitor/monitor.go b/src/apps/chifra/pkg/monitor/monitor.go index 180228eac5..093097d71f 100644 --- a/src/apps/chifra/pkg/monitor/monitor.go +++ b/src/apps/chifra/pkg/monitor/monitor.go @@ -22,7 +22,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) -// Header is the header of the Monitor file. Note that it's the same width as an index.AppearanceRecord +// Header is the header of the Monitor file. Note that it's the same width as an types.SimpleAppRecord // therefor one should not change its size type Header struct { Magic uint16 `json:"-"` diff --git a/src/apps/chifra/pkg/monitor/monitor_freshen.go b/src/apps/chifra/pkg/monitor/monitor_freshen.go index da03a6c88e..e9a6ec01bb 100644 --- a/src/apps/chifra/pkg/monitor/monitor_freshen.go +++ b/src/apps/chifra/pkg/monitor/monitor_freshen.go @@ -23,6 +23,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/manifest" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/sigintTrap" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/walk" @@ -377,13 +378,13 @@ const ( endOfTxId = 42 + 1 + 9 + 1 + 5 ) -func getAppearances(addrStr string, lines []string, lastVisited uint32, found int) *[]index.AppearanceRecord { - results := make([]index.AppearanceRecord, 0, 1000) +func getAppearances(addrStr string, lines []string, lastVisited uint32, found int) *[]types.SimpleAppRecord { + results := make([]types.SimpleAppRecord, 0, 1000) for idx := found; idx < len(lines); idx++ { if !strings.HasPrefix(lines[idx], addrStr) { break } - r := index.AppearanceRecord{ + r := types.SimpleAppRecord{ BlockNumber: uint32(globals.ToUint64(lines[idx][startOfBlockNum:endOfBlockNum])), TransactionIndex: uint32(globals.ToUint64(lines[idx][startOfTxId:endOfTxId])), } diff --git a/src/apps/chifra/pkg/monitor/monitor_read.go b/src/apps/chifra/pkg/monitor/monitor_read.go index 0a06bbb29d..05dfb1e9d1 100644 --- a/src/apps/chifra/pkg/monitor/monitor_read.go +++ b/src/apps/chifra/pkg/monitor/monitor_read.go @@ -12,6 +12,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) // ReadMonitorHeader reads the monitor's header and returns without closing the file @@ -31,7 +32,7 @@ func (mon *Monitor) ReadMonitorHeader() (err error) { } // ReadAppearanceAt returns the appearance at the one-based index. The file remains open. -func (mon *Monitor) ReadAppearanceAt(idx int64, app *index.AppearanceRecord) (err error) { +func (mon *Monitor) ReadAppearanceAt(idx int64, app *types.SimpleAppRecord) (err error) { if idx == 0 || idx > mon.Count() { // the file contains a header one record wide, so a one-based index eases caller code err = fmt.Errorf("index out of range in ReadAppearanceAt[%d]", idx) diff --git a/src/apps/chifra/pkg/monitor/monitor_remove_dups.go b/src/apps/chifra/pkg/monitor/monitor_remove_dups.go index 741a9943e0..a243f8c794 100644 --- a/src/apps/chifra/pkg/monitor/monitor_remove_dups.go +++ b/src/apps/chifra/pkg/monitor/monitor_remove_dups.go @@ -6,7 +6,7 @@ package monitor import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/filter" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) func (mon *Monitor) RemoveDups() (int64, int64, error) { @@ -25,10 +25,10 @@ func (mon *Monitor) RemoveDups() (int64, int64, error) { cntBefore := mon.Count() cntAfter := cntBefore - var prev index.AppearanceRecord - deDupped := make([]index.AppearanceRecord, 0, mon.Count()) + var prev types.SimpleAppRecord + deDupped := make([]types.SimpleAppRecord, 0, mon.Count()) for i, app := range apps { - iApp := index.AppearanceRecord{ + iApp := types.SimpleAppRecord{ BlockNumber: app.BlockNumber, TransactionIndex: app.TransactionIndex, } diff --git a/src/apps/chifra/pkg/monitor/monitor_test.go b/src/apps/chifra/pkg/monitor/monitor_test.go index 9c9a8646c4..7f158de7cd 100644 --- a/src/apps/chifra/pkg/monitor/monitor_test.go +++ b/src/apps/chifra/pkg/monitor/monitor_test.go @@ -12,7 +12,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/filter" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) @@ -51,25 +50,25 @@ func Test_Monitor_ReadApp(t *testing.T) { RemoveTestMonitor(&mon, t) }() - var got index.AppearanceRecord + var got types.SimpleAppRecord err := mon.ReadAppearanceAt(0, &got) if err == nil { t.Error("Should have been 'index out of range in ReadAppearanceAt[0]' error") } - expected := index.AppearanceRecord{BlockNumber: 1001001, TransactionIndex: 0} + expected := types.SimpleAppRecord{BlockNumber: 1001001, TransactionIndex: 0} err = mon.ReadAppearanceAt(1, &got) if got != expected || err != nil { t.Error("Expected:", expected, "Got:", got, err) } - expected = index.AppearanceRecord{BlockNumber: 1001002, TransactionIndex: 1} + expected = types.SimpleAppRecord{BlockNumber: 1001002, TransactionIndex: 1} err = mon.ReadAppearanceAt(2, &got) if got != expected || err != nil { t.Error("Expected:", expected, "Got:", got, err) } - expected = index.AppearanceRecord{BlockNumber: 1001003, TransactionIndex: 2} + expected = types.SimpleAppRecord{BlockNumber: 1001003, TransactionIndex: 2} err = mon.ReadAppearanceAt(mon.Count(), &got) if got != expected || err != nil { t.Error("Expected:", expected, "Got:", got, err) @@ -229,7 +228,7 @@ func RemoveTestMonitor(mon *Monitor, t *testing.T) { const nTests = 3 -var testApps = []index.AppearanceRecord{ +var testApps = []types.SimpleAppRecord{ {BlockNumber: 1001001, TransactionIndex: 0}, {BlockNumber: 1001002, TransactionIndex: 1}, {BlockNumber: 1001003, TransactionIndex: 2}, diff --git a/src/apps/chifra/pkg/monitor/monitor_write.go b/src/apps/chifra/pkg/monitor/monitor_write.go index 438995310f..a99e1740c1 100644 --- a/src/apps/chifra/pkg/monitor/monitor_write.go +++ b/src/apps/chifra/pkg/monitor/monitor_write.go @@ -11,6 +11,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) // TODO: Protect against overwriting files on disc @@ -36,7 +37,7 @@ func (mon *Monitor) WriteMonHeader(deleted bool, lastScanned uint32, force bool) // WriteAppearancesAppend appends appearances to the end of the file, updates the header with // lastScanned (if later) and returns the number of records written. Note that we should // be writing to a temporary file. -func (mon *Monitor) WriteAppearancesAppend(lastScanned uint32, apps *[]index.AppearanceRecord) error { +func (mon *Monitor) WriteAppearancesAppend(lastScanned uint32, apps *[]types.SimpleAppRecord) error { if !mon.Staged { logger.Fatal("should not happen ==> trying to write to a non-staged file") @@ -64,7 +65,7 @@ func (mon *Monitor) WriteAppearancesAppend(lastScanned uint32, apps *[]index.App // TODO: Protect against overwriting files on disc // WriteAppearances writes appearances to a Monitor -func (mon *Monitor) WriteAppearances(apps []index.AppearanceRecord, append bool) (int64, error) { +func (mon *Monitor) WriteAppearances(apps []types.SimpleAppRecord, append bool) (int64, error) { var f *os.File var err error path := mon.Path() diff --git a/src/apps/chifra/pkg/monitor/truncate.go b/src/apps/chifra/pkg/monitor/truncate.go index 552b606914..bc6a539007 100644 --- a/src/apps/chifra/pkg/monitor/truncate.go +++ b/src/apps/chifra/pkg/monitor/truncate.go @@ -2,7 +2,7 @@ package monitor import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/filter" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) @@ -19,10 +19,10 @@ func (mon *Monitor) TruncateTo(chain string, num uint32) (bool, error) { return false, nil } else { - var keep []index.AppearanceRecord + var keep []types.SimpleAppRecord for _, app := range apps { if app.BlockNumber <= num { - keep = append(keep, index.AppearanceRecord{ + keep = append(keep, types.SimpleAppRecord{ BlockNumber: app.BlockNumber, TransactionIndex: app.TransactionIndex, }) diff --git a/src/apps/chifra/pkg/notify/notification.go b/src/apps/chifra/pkg/notify/notification.go index 6827bcc355..661ed93750 100644 --- a/src/apps/chifra/pkg/notify/notification.go +++ b/src/apps/chifra/pkg/notify/notification.go @@ -2,6 +2,8 @@ package notify import "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" +// TODO: Remove rpc.MetaData and use types.MetaData throughout + type Message string type Notification[T NotificationPayload] struct { diff --git a/src/apps/chifra/pkg/notify/scraper.go b/src/apps/chifra/pkg/notify/scraper.go index 8e12f5ae08..e53cae566f 100644 --- a/src/apps/chifra/pkg/notify/scraper.go +++ b/src/apps/chifra/pkg/notify/scraper.go @@ -7,6 +7,8 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/uniq" ) +// TODO: Remove rpc.MetaData and use types.MetaData throughout + const ( MessageChunkWritten Message = "chunkWritten" MessageStageUpdated Message = "stageUpdated" diff --git a/src/apps/chifra/pkg/output/helpers/helpers.go b/src/apps/chifra/pkg/output/helpers/helpers.go index a09bafedf9..aec8beb53f 100644 --- a/src/apps/chifra/pkg/output/helpers/helpers.go +++ b/src/apps/chifra/pkg/output/helpers/helpers.go @@ -11,6 +11,8 @@ import ( "github.com/spf13/cobra" ) +// TODO: Remove rpc.MetaData and use types.MetaData throughout + var discardWriter = io.Writer(nil) func init() { diff --git a/src/apps/chifra/pkg/output/json_writer.go b/src/apps/chifra/pkg/output/json_writer.go index 8dcbf70397..4cf1b8d4dc 100644 --- a/src/apps/chifra/pkg/output/json_writer.go +++ b/src/apps/chifra/pkg/output/json_writer.go @@ -10,6 +10,8 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" ) +// TODO: Remove rpc.MetaData and use types.MetaData throughout + type FieldType int var comma = "," diff --git a/src/apps/chifra/pkg/output/json_writer_test.go b/src/apps/chifra/pkg/output/json_writer_test.go index f5b94fa0e3..70d883854f 100644 --- a/src/apps/chifra/pkg/output/json_writer_test.go +++ b/src/apps/chifra/pkg/output/json_writer_test.go @@ -10,6 +10,8 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" ) +// TODO: Remove rpc.MetaData and use types.MetaData throughout + func helperReportStringMismatch(t *testing.T, expected, result string) { for i, ch := range expected { if result[i] != byte(ch) { diff --git a/src/apps/chifra/pkg/rpc/get_meta.go b/src/apps/chifra/pkg/rpc/get_meta.go index 69df0123a3..bf20f5834d 100644 --- a/src/apps/chifra/pkg/rpc/get_meta.go +++ b/src/apps/chifra/pkg/rpc/get_meta.go @@ -6,23 +6,13 @@ package rpc import ( "context" - "encoding/json" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/walk" ) -type MetaData struct { - Latest uint64 `json:"client"` - Finalized uint64 `json:"finalized"` - Staging uint64 `json:"staging"` - Ripe uint64 `json:"ripe"` - Unripe uint64 `json:"unripe"` - ChainId uint64 `json:"chainId,omitempty"` - NetworkId uint64 `json:"networkId,omitempty"` - Chain string `json:"chain,omitempty"` -} +// TODO: use types.MetaData throughout func (conn *Connection) GetMetaData(testmode bool) (*MetaData, error) { chainId, networkId, err := conn.GetClientIDs() @@ -86,27 +76,6 @@ func (conn *Connection) GetMetaData(testmode bool) (*MetaData, error) { return &meta, nil } -func (m *MetaData) String() string { - ret, _ := json.MarshalIndent(m, "", " ") - return string(ret) -} +// TODO: Remove rpc.MetaData and use types.MetaData throughout -// Highest returns the height of the index (i.e., max between the finalized, staging, and ripe indexes). -func (m *MetaData) IndexHeight() base.Blknum { - return utils.Max(m.Finalized, utils.Max(m.Staging, m.Ripe)) -} - -// NextIndexHeight returns the block after the height of the index. -func (m *MetaData) NextIndexHeight() base.Blknum { - return m.IndexHeight() + 1 -} - -// ChainHeight returns the block after the height of the index. -func (m *MetaData) ChainHeight() base.Blknum { - return m.Latest -} - -// StageHieght returns the highest block that's been staged -func (m *MetaData) StageHeight() base.Blknum { - return m.Staging -} +type MetaData = types.MetaData diff --git a/src/apps/chifra/pkg/types/types_abi.go b/src/apps/chifra/pkg/types/types_abi.go index 59f2ba66bb..e5257e45cc 100644 --- a/src/apps/chifra/pkg/types/types_abi.go +++ b/src/apps/chifra/pkg/types/types_abi.go @@ -10,6 +10,8 @@ package types // EXISTING_CODE import ( + "encoding/json" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" ) @@ -30,6 +32,11 @@ type SimpleAbi struct { // EXISTING_CODE } +func (s *SimpleAbi) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleAbi) Raw() *RawAbi { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_appearance.go b/src/apps/chifra/pkg/types/types_appearance.go index cc885e3b51..87953c15e0 100644 --- a/src/apps/chifra/pkg/types/types_appearance.go +++ b/src/apps/chifra/pkg/types/types_appearance.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "fmt" "sort" @@ -51,6 +52,11 @@ type SimpleAppearance struct { // EXISTING_CODE } +func (s *SimpleAppearance) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleAppearance) Raw() *RawAppearance { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_appearanceTable.go b/src/apps/chifra/pkg/types/types_appearanceTable.go new file mode 100644 index 0000000000..62754fb9b3 --- /dev/null +++ b/src/apps/chifra/pkg/types/types_appearanceTable.go @@ -0,0 +1,91 @@ +// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. +// Use of this source code is governed by a license that can +// be found in the LICENSE file. +/* + * Parts of this file were auto generated. Edit only those parts of + * the code inside of 'EXISTING_CODE' tags. + */ + +package types + +// EXISTING_CODE +import ( + "encoding/json" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" +) + +type SimpleAddrRecord struct { + Address base.Address `json:"address"` + Offset uint32 `json:"offset"` + Count uint32 `json:"count"` +} + +type SimpleAppRecord struct { + BlockNumber uint32 `json:"blockNumber"` + TransactionIndex uint32 `json:"transactionIndex"` +} + +// EXISTING_CODE + +type RawAppearanceTable struct { + AddressRecord string `json:"AddressRecord"` + Appearances []string `json:"Appearances"` + // EXISTING_CODE + // EXISTING_CODE +} + +type SimpleAppearanceTable struct { + AddressRecord SimpleAddrRecord `json:"AddressRecord"` + Appearances []SimpleAppRecord `json:"Appearances"` + raw *RawAppearanceTable `json:"-"` + // EXISTING_CODE + // EXISTING_CODE +} + +func (s *SimpleAppearanceTable) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *SimpleAppearanceTable) Raw() *RawAppearanceTable { + return s.raw +} + +func (s *SimpleAppearanceTable) SetRaw(raw *RawAppearanceTable) { + s.raw = raw +} + +func (s *SimpleAppearanceTable) Model(chain, format string, verbose bool, extraOptions map[string]any) Model { + var model = map[string]interface{}{} + var order = []string{} + + // EXISTING_CODE + model = map[string]any{ + "address": s.AddressRecord.Address.Hex(), + "offset": s.AddressRecord.Offset, + "count": s.AddressRecord.Count, + "appearances": s.Appearances, + } + order = []string{ + "address", + "offset", + "count", + "appearances", + } + // EXISTING_CODE + + return Model{ + Data: model, + Order: order, + } +} + +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *SimpleAppearanceTable) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + +// EXISTING_CODE +// EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_appearancecount.go b/src/apps/chifra/pkg/types/types_appearancecount.go index f2620bd8f4..c9ce523e87 100644 --- a/src/apps/chifra/pkg/types/types_appearancecount.go +++ b/src/apps/chifra/pkg/types/types_appearancecount.go @@ -9,7 +9,11 @@ package types // EXISTING_CODE -import "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" +import ( + "encoding/json" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" +) // EXISTING_CODE @@ -30,6 +34,11 @@ type SimpleAppearanceCount struct { // EXISTING_CODE } +func (s *SimpleAppearanceCount) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleAppearanceCount) Raw() *RawAppearanceCount { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_block.go b/src/apps/chifra/pkg/types/types_block.go index 28422fb968..3a9d8ffbbe 100644 --- a/src/apps/chifra/pkg/types/types_block.go +++ b/src/apps/chifra/pkg/types/types_block.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "fmt" "io" "path/filepath" @@ -68,6 +69,11 @@ type SimpleBlock[Tx string | SimpleTransaction] struct { // EXISTING_CODE } +func (s *SimpleBlock[Tx]) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleBlock[Tx]) Raw() *RawBlock { return s.raw } diff --git a/src/apps/chifra/internal/blocks/types_blockcount.go b/src/apps/chifra/pkg/types/types_blockcount.go similarity index 70% rename from src/apps/chifra/internal/blocks/types_blockcount.go rename to src/apps/chifra/pkg/types/types_blockcount.go index f35afb638f..937204bf6d 100644 --- a/src/apps/chifra/internal/blocks/types_blockcount.go +++ b/src/apps/chifra/pkg/types/types_blockcount.go @@ -6,18 +6,32 @@ * the code inside of 'EXISTING_CODE' tags. */ -package blocksPkg +package types // EXISTING_CODE import ( + "encoding/json" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) // EXISTING_CODE -type simpleBlockCount struct { +type RawBlockCount struct { + AddressCnt string `json:"addressCnt"` + BlockNumber string `json:"blockNumber"` + LogsCnt string `json:"logsCnt"` + Timestamp string `json:"timestamp"` + TracesCnt string `json:"tracesCnt"` + TransactionsCnt string `json:"transactionsCnt"` + UnclesCnt string `json:"unclesCnt"` + WithdrawalsCnt string `json:"withdrawalsCnt"` + // EXISTING_CODE + // EXISTING_CODE +} + +type SimpleBlockCount struct { AddressCnt uint64 `json:"addressCnt,omitempty"` BlockNumber base.Blknum `json:"blockNumber"` LogsCnt uint64 `json:"logsCnt,omitempty"` @@ -26,16 +40,25 @@ type simpleBlockCount struct { TransactionsCnt uint64 `json:"transactionsCnt"` UnclesCnt uint64 `json:"unclesCnt,omitempty"` WithdrawalsCnt uint64 `json:"withdrawalsCnt,omitempty"` - + raw *RawBlockCount `json:"-"` // EXISTING_CODE // EXISTING_CODE } -func (s *simpleBlockCount) Raw() *types.RawModeler { - return nil +func (s *SimpleBlockCount) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *SimpleBlockCount) Raw() *RawBlockCount { + return s.raw +} + +func (s *SimpleBlockCount) SetRaw(raw *RawBlockCount) { + s.raw = raw } -func (s *simpleBlockCount) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { +func (s *SimpleBlockCount) Model(chain, format string, verbose bool, extraOptions map[string]any) Model { var model = map[string]interface{}{} var order = []string{} @@ -104,15 +127,21 @@ func (s *simpleBlockCount) Model(chain, format string, verbose bool, extraOption } // EXISTING_CODE - return types.Model{ + return Model{ Data: model, Order: order, } } -func (s *simpleBlockCount) Date() string { +func (s *SimpleBlockCount) Date() string { return utils.FormattedDate(s.Timestamp) } +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *SimpleBlockCount) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + // EXISTING_CODE // EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_bounds.go b/src/apps/chifra/pkg/types/types_bounds.go index 479d05c6c3..cffa69319c 100644 --- a/src/apps/chifra/pkg/types/types_bounds.go +++ b/src/apps/chifra/pkg/types/types_bounds.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "fmt" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" @@ -39,6 +40,11 @@ type SimpleBounds struct { // EXISTING_CODE } +func (s *SimpleBounds) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleBounds) Raw() *RawBounds { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_cacheitem.go b/src/apps/chifra/pkg/types/types_cacheitem.go new file mode 100644 index 0000000000..cc8b6b5229 --- /dev/null +++ b/src/apps/chifra/pkg/types/types_cacheitem.go @@ -0,0 +1,76 @@ +// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. +// Use of this source code is governed by a license that can +// be found in the LICENSE file. +/* + * Parts of this file were auto generated. Edit only those parts of + * the code inside of 'EXISTING_CODE' tags. + */ + +package types + +// EXISTING_CODE +import ( + "encoding/json" +) + +// EXISTING_CODE + +type RawCacheItem struct { + Items []string `json:"items"` + LastCached string `json:"lastCached"` + NFiles string `json:"nFiles"` + NFolders string `json:"nFolders"` + Path string `json:"path"` + SizeInBytes string `json:"sizeInBytes"` + CacheItemType string `json:"type"` + // EXISTING_CODE + // EXISTING_CODE +} + +type SimpleCacheItem struct { + Items []any `json:"items"` + LastCached string `json:"lastCached,omitempty"` + NFiles uint64 `json:"nFiles"` + NFolders uint64 `json:"nFolders"` + Path string `json:"path"` + SizeInBytes int64 `json:"sizeInBytes"` + CacheItemType string `json:"type"` + raw *RawCacheItem `json:"-"` + // EXISTING_CODE + // EXISTING_CODE +} + +func (s *SimpleCacheItem) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *SimpleCacheItem) Raw() *RawCacheItem { + return s.raw +} + +func (s *SimpleCacheItem) SetRaw(raw *RawCacheItem) { + s.raw = raw +} + +func (s *SimpleCacheItem) Model(chain, format string, verbose bool, extraOptions map[string]any) Model { + var model = map[string]interface{}{} + var order = []string{} + + // EXISTING_CODE + // EXISTING_CODE + + return Model{ + Data: model, + Order: order, + } +} + +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *SimpleCacheItem) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + +// EXISTING_CODE +// EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_chain.go b/src/apps/chifra/pkg/types/types_chain.go index 6bb124dddb..15b9e9dadb 100644 --- a/src/apps/chifra/pkg/types/types_chain.go +++ b/src/apps/chifra/pkg/types/types_chain.go @@ -9,6 +9,7 @@ package types // EXISTING_CODE +import "encoding/json" // EXISTING_CODE @@ -37,6 +38,11 @@ type SimpleChain struct { // EXISTING_CODE } +func (s *SimpleChain) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleChain) Raw() *RawChain { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_chunkaddress.go b/src/apps/chifra/pkg/types/types_chunkaddress.go new file mode 100644 index 0000000000..9a1858dce5 --- /dev/null +++ b/src/apps/chifra/pkg/types/types_chunkaddress.go @@ -0,0 +1,84 @@ +// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. +// Use of this source code is governed by a license that can +// be found in the LICENSE file. +/* + * Parts of this file were auto generated. Edit only those parts of + * the code inside of 'EXISTING_CODE' tags. + */ + +package types + +// EXISTING_CODE +import ( + "encoding/json" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" +) + +// EXISTING_CODE + +type RawChunkAddress struct { + Address string `json:"address"` + Count string `json:"count"` + Offset string `json:"offset"` + Range string `json:"range"` + // EXISTING_CODE + // EXISTING_CODE +} + +type SimpleChunkAddress struct { + Address base.Address `json:"address"` + Count uint64 `json:"count"` + Offset uint64 `json:"offset"` + Range string `json:"range"` + raw *RawChunkAddress `json:"-"` + // EXISTING_CODE + // EXISTING_CODE +} + +func (s *SimpleChunkAddress) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *SimpleChunkAddress) Raw() *RawChunkAddress { + return s.raw +} + +func (s *SimpleChunkAddress) SetRaw(raw *RawChunkAddress) { + s.raw = raw +} + +func (s *SimpleChunkAddress) Model(chain, format string, verbose bool, extraOptions map[string]any) Model { + var model = map[string]interface{}{} + var order = []string{} + + // EXISTING_CODE + model = map[string]interface{}{ + "address": s.Address, + "range": s.Range, + "offset": s.Offset, + "count": s.Count, + } + order = []string{ + "address", + "range", + "offset", + "count", + } + // EXISTING_CODE + + return Model{ + Data: model, + Order: order, + } +} + +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *SimpleChunkAddress) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + +// EXISTING_CODE +// EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_chunkbloom.go b/src/apps/chifra/pkg/types/types_chunkbloom.go new file mode 100644 index 0000000000..62361f75bf --- /dev/null +++ b/src/apps/chifra/pkg/types/types_chunkbloom.go @@ -0,0 +1,106 @@ +// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. +// Use of this source code is governed by a license that can +// be found in the LICENSE file. +/* + * Parts of this file were auto generated. Edit only those parts of + * the code inside of 'EXISTING_CODE' tags. + */ + +package types + +// EXISTING_CODE +import ( + "encoding/json" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" +) + +// EXISTING_CODE + +type RawChunkBloom struct { + ByteWidth string `json:"byteWidth"` + Hash string `json:"hash"` + Magic string `json:"magic"` + NBlooms string `json:"nBlooms"` + NInserted string `json:"nInserted"` + Range string `json:"range"` + Size string `json:"size"` + // EXISTING_CODE + // EXISTING_CODE +} + +type SimpleChunkBloom struct { + ByteWidth uint64 `json:"byteWidth"` + Hash base.Hash `json:"hash"` + Magic string `json:"magic"` + NBlooms uint64 `json:"nBlooms"` + NInserted uint64 `json:"nInserted"` + Range string `json:"range"` + Size uint64 `json:"size"` + raw *RawChunkBloom `json:"-"` + // EXISTING_CODE + // EXISTING_CODE +} + +func (s *SimpleChunkBloom) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *SimpleChunkBloom) Raw() *RawChunkBloom { + return s.raw +} + +func (s *SimpleChunkBloom) SetRaw(raw *RawChunkBloom) { + s.raw = raw +} + +func (s *SimpleChunkBloom) Model(chain, format string, verbose bool, extraOptions map[string]any) Model { + var model = map[string]interface{}{} + var order = []string{} + + // EXISTING_CODE + model = map[string]interface{}{ + "range": s.Range, + "magic": s.Magic, + "hash": FormattedTag(verbose, s.Hash), + "nBlooms": s.NBlooms, + "nInserted": s.NInserted, + "size": s.Size, + "byteWidth": s.ByteWidth, + } + order = []string{ + "range", + "magic", + "hash", + "nBlooms", + "nInserted", + "size", + "byteWidth", + } + // EXISTING_CODE + + return Model{ + Data: model, + Order: order, + } +} + +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *SimpleChunkBloom) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + +// EXISTING_CODE +func FormattedTag(verbose bool, hash base.Hash) string { + if tag, ok := config.VersionTags[hash.Hex()]; !ok { + return utils.FormattedHash(verbose, hash.Hex()) + } else { + return tag + } +} + +// EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_chunkindex.go b/src/apps/chifra/pkg/types/types_chunkindex.go new file mode 100644 index 0000000000..ca06f1cf1d --- /dev/null +++ b/src/apps/chifra/pkg/types/types_chunkindex.go @@ -0,0 +1,92 @@ +// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. +// Use of this source code is governed by a license that can +// be found in the LICENSE file. +/* + * Parts of this file were auto generated. Edit only those parts of + * the code inside of 'EXISTING_CODE' tags. + */ + +package types + +// EXISTING_CODE +import ( + "encoding/json" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" +) + +// EXISTING_CODE + +type RawChunkIndex struct { + Hash string `json:"hash"` + Magic string `json:"magic"` + NAddresses string `json:"nAddresses"` + NAppearances string `json:"nAppearances"` + Range string `json:"range"` + Size string `json:"size"` + // EXISTING_CODE + // EXISTING_CODE +} + +type SimpleChunkIndex struct { + Hash base.Hash `json:"hash"` + Magic string `json:"magic"` + NAddresses uint64 `json:"nAddresses"` + NAppearances uint64 `json:"nAppearances"` + Range string `json:"range"` + Size uint64 `json:"size"` + raw *RawChunkIndex `json:"-"` + // EXISTING_CODE + // EXISTING_CODE +} + +func (s *SimpleChunkIndex) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *SimpleChunkIndex) Raw() *RawChunkIndex { + return s.raw +} + +func (s *SimpleChunkIndex) SetRaw(raw *RawChunkIndex) { + s.raw = raw +} + +func (s *SimpleChunkIndex) Model(chain, format string, verbose bool, extraOptions map[string]any) Model { + var model = map[string]interface{}{} + var order = []string{} + + // EXISTING_CODE + model = map[string]interface{}{ + "range": s.Range, + "magic": s.Magic, + "hash": FormattedTag(verbose, s.Hash), + "nAddresses": s.NAddresses, + "nAppearances": s.NAppearances, + "fileSize": s.Size, + } + order = []string{ + "range", + "magic", + "hash", + "nAddresses", + "nAppearances", + "fileSize", + } + // EXISTING_CODE + + return Model{ + Data: model, + Order: order, + } +} + +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *SimpleChunkIndex) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + +// EXISTING_CODE +// EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_chunkpinreport.go b/src/apps/chifra/pkg/types/types_chunkpinreport.go new file mode 100644 index 0000000000..50d366948a --- /dev/null +++ b/src/apps/chifra/pkg/types/types_chunkpinreport.go @@ -0,0 +1,88 @@ +// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. +// Use of this source code is governed by a license that can +// be found in the LICENSE file. +/* + * Parts of this file were auto generated. Edit only those parts of + * the code inside of 'EXISTING_CODE' tags. + */ + +package types + +// EXISTING_CODE +import ( + "encoding/json" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" +) + +// EXISTING_CODE + +type RawChunkPinReport struct { + Chain string `json:"chain"` + ManifestHash string `json:"manifestHash"` + SpecHash string `json:"specHash"` + TimestampHash string `json:"timestampHash"` + Version string `json:"version"` + // EXISTING_CODE + // EXISTING_CODE +} + +type SimpleChunkPinReport struct { + Chain string `json:"chain"` + ManifestHash base.IpfsHash `json:"manifestHash"` + SpecHash base.IpfsHash `json:"specHash"` + TimestampHash base.IpfsHash `json:"timestampHash"` + Version string `json:"version"` + raw *RawChunkPinReport `json:"-"` + // EXISTING_CODE + // EXISTING_CODE +} + +func (s *SimpleChunkPinReport) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *SimpleChunkPinReport) Raw() *RawChunkPinReport { + return s.raw +} + +func (s *SimpleChunkPinReport) SetRaw(raw *RawChunkPinReport) { + s.raw = raw +} + +func (s *SimpleChunkPinReport) Model(chain, format string, verbose bool, extraOptions map[string]any) Model { + var model = map[string]interface{}{} + var order = []string{} + + // EXISTING_CODE + model = map[string]interface{}{ + "chain": s.Chain, + "version": s.Version, + "manifestHash": s.ManifestHash, + "timestampHash": s.TimestampHash, + "specHash": s.SpecHash, + } + order = []string{ + "chain", + "version", + "manifestHash", + "timestampHash", + "specHash", + } + // EXISTING_CODE + + return Model{ + Data: model, + Order: order, + } +} + +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *SimpleChunkPinReport) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + +// EXISTING_CODE +// EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_chunkrecord.go b/src/apps/chifra/pkg/types/types_chunkrecord.go index dc4b06f4a7..51a49dc108 100644 --- a/src/apps/chifra/pkg/types/types_chunkrecord.go +++ b/src/apps/chifra/pkg/types/types_chunkrecord.go @@ -38,6 +38,11 @@ type SimpleChunkRecord struct { // EXISTING_CODE } +func (s *SimpleChunkRecord) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleChunkRecord) Raw() *RawChunkRecord { return s.raw } @@ -80,9 +85,4 @@ func (s *SimpleChunkRecord) FinishUnmarshal() { } // EXISTING_CODE -func (s *SimpleChunkRecord) String() string { - bytes, _ := json.MarshalIndent(s, "", " ") - return string(bytes) -} - // EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_chunkstats.go b/src/apps/chifra/pkg/types/types_chunkstats.go index 0243ecb015..e5c2b3d5cc 100644 --- a/src/apps/chifra/pkg/types/types_chunkstats.go +++ b/src/apps/chifra/pkg/types/types_chunkstats.go @@ -9,6 +9,8 @@ package types // EXISTING_CODE +import "encoding/json" + // EXISTING_CODE type RawChunkStats struct { @@ -48,6 +50,11 @@ type SimpleChunkStats struct { // EXISTING_CODE } +func (s *SimpleChunkStats) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleChunkStats) Raw() *RawChunkStats { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_function.go b/src/apps/chifra/pkg/types/types_function.go index 9c469726b8..fd3a304b09 100644 --- a/src/apps/chifra/pkg/types/types_function.go +++ b/src/apps/chifra/pkg/types/types_function.go @@ -59,6 +59,11 @@ type SimpleFunction struct { // EXISTING_CODE } +func (s *SimpleFunction) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleFunction) Raw() *RawFunction { return s.raw } diff --git a/src/apps/chifra/internal/chunks/types_ipfspin.go b/src/apps/chifra/pkg/types/types_ipfspin.go similarity index 58% rename from src/apps/chifra/internal/chunks/types_ipfspin.go rename to src/apps/chifra/pkg/types/types_ipfspin.go index efd22d5a9a..3f340a7516 100644 --- a/src/apps/chifra/internal/chunks/types_ipfspin.go +++ b/src/apps/chifra/pkg/types/types_ipfspin.go @@ -6,34 +6,53 @@ * the code inside of 'EXISTING_CODE' tags. */ -package chunksPkg +package types // EXISTING_CODE import ( + "encoding/json" "strings" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) // EXISTING_CODE -type simpleIpfsPin struct { +type RawIpfsPin struct { + Cid string `json:"cid"` + DatePinned string `json:"datePinned"` + FileName string `json:"fileName"` + Size string `json:"size"` + Status string `json:"status"` + // EXISTING_CODE + // EXISTING_CODE +} + +type SimpleIpfsPin struct { Cid base.IpfsHash `json:"cid"` DatePinned string `json:"datePinned"` FileName string `json:"fileName"` Size int64 `json:"size"` Status string `json:"status"` - + raw *RawIpfsPin `json:"-"` // EXISTING_CODE // EXISTING_CODE } -func (s *simpleIpfsPin) Raw() *types.RawModeler { - return nil +func (s *SimpleIpfsPin) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *SimpleIpfsPin) Raw() *RawIpfsPin { + return s.raw } -func (s *simpleIpfsPin) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { +func (s *SimpleIpfsPin) SetRaw(raw *RawIpfsPin) { + s.raw = raw +} + +func (s *SimpleIpfsPin) Model(chain, format string, verbose bool, extraOptions map[string]any) Model { var model = map[string]interface{}{} var order = []string{} @@ -54,12 +73,18 @@ func (s *simpleIpfsPin) Model(chain, format string, verbose bool, extraOptions m } // EXISTING_CODE - return types.Model{ + return Model{ Data: model, Order: order, } } +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *SimpleIpfsPin) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + // EXISTING_CODE func cleanDate(date string) string { parts := strings.Split(date, ".") diff --git a/src/apps/chifra/pkg/types/types_log.go b/src/apps/chifra/pkg/types/types_log.go index 3d7f393680..cecb3cf432 100644 --- a/src/apps/chifra/pkg/types/types_log.go +++ b/src/apps/chifra/pkg/types/types_log.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "fmt" "io" "path/filepath" @@ -53,6 +54,11 @@ type SimpleLog struct { // EXISTING_CODE } +func (s *SimpleLog) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleLog) Raw() *RawLog { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_logfilter.go b/src/apps/chifra/pkg/types/types_logfilter.go index 113769944d..477a315a25 100644 --- a/src/apps/chifra/pkg/types/types_logfilter.go +++ b/src/apps/chifra/pkg/types/types_logfilter.go @@ -10,6 +10,8 @@ package types // EXISTING_CODE import ( + "encoding/json" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" ) @@ -36,6 +38,11 @@ type SimpleLogFilter struct { // EXISTING_CODE } +func (s *SimpleLogFilter) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleLogFilter) Raw() *RawLogFilter { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_manifest.go b/src/apps/chifra/pkg/types/types_manifest.go index 5d719e050e..a866568d93 100644 --- a/src/apps/chifra/pkg/types/types_manifest.go +++ b/src/apps/chifra/pkg/types/types_manifest.go @@ -10,6 +10,8 @@ package types // EXISTING_CODE import ( + "encoding/json" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" ) @@ -34,6 +36,11 @@ type SimpleManifest struct { // EXISTING_CODE } +func (s *SimpleManifest) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleManifest) Raw() *RawManifest { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_metadata.go b/src/apps/chifra/pkg/types/types_metadata.go new file mode 100644 index 0000000000..541e78f08f --- /dev/null +++ b/src/apps/chifra/pkg/types/types_metadata.go @@ -0,0 +1,44 @@ +package types + +import ( + "encoding/json" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" +) + +type MetaData struct { + Latest uint64 `json:"client"` + Finalized uint64 `json:"finalized"` + Staging uint64 `json:"staging"` + Ripe uint64 `json:"ripe"` + Unripe uint64 `json:"unripe"` + ChainId uint64 `json:"chainId,omitempty"` + NetworkId uint64 `json:"networkId,omitempty"` + Chain string `json:"chain,omitempty"` +} + +func (m *MetaData) String() string { + ret, _ := json.MarshalIndent(m, "", " ") + return string(ret) +} + +// Highest returns the height of the index (i.e., max between the finalized, staging, and ripe indexes). +func (m *MetaData) IndexHeight() base.Blknum { + return utils.Max(m.Finalized, utils.Max(m.Staging, m.Ripe)) +} + +// NextIndexHeight returns the block after the height of the index. +func (m *MetaData) NextIndexHeight() base.Blknum { + return m.IndexHeight() + 1 +} + +// ChainHeight returns the block after the height of the index. +func (m *MetaData) ChainHeight() base.Blknum { + return m.Latest +} + +// StageHieght returns the highest block that's been staged +func (m *MetaData) StageHeight() base.Blknum { + return m.Staging +} diff --git a/src/apps/chifra/pkg/types/types_monitor.go b/src/apps/chifra/pkg/types/types_monitor.go index 61f210c073..62ac824ed7 100644 --- a/src/apps/chifra/pkg/types/types_monitor.go +++ b/src/apps/chifra/pkg/types/types_monitor.go @@ -10,6 +10,8 @@ package types // EXISTING_CODE import ( + "encoding/json" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" ) @@ -31,6 +33,11 @@ type SimpleMonitor struct { // EXISTING_CODE } +func (s *SimpleMonitor) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleMonitor) Raw() *RawMonitor { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_monitorclean.go b/src/apps/chifra/pkg/types/types_monitorclean.go new file mode 100644 index 0000000000..d6ffa988d0 --- /dev/null +++ b/src/apps/chifra/pkg/types/types_monitorclean.go @@ -0,0 +1,84 @@ +// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. +// Use of this source code is governed by a license that can +// be found in the LICENSE file. +/* + * Parts of this file were auto generated. Edit only those parts of + * the code inside of 'EXISTING_CODE' tags. + */ + +package types + +// EXISTING_CODE +import ( + "encoding/json" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" +) + +// EXISTING_CODE + +type RawMonitorClean struct { + Address string `json:"address"` + Dups string `json:"dups"` + SizeNow string `json:"sizeNow"` + SizeThen string `json:"sizeThen"` + // EXISTING_CODE + // EXISTING_CODE +} + +type SimpleMonitorClean struct { + Address base.Address `json:"address"` + Dups int64 `json:"dups"` + SizeNow int64 `json:"sizeNow"` + SizeThen int64 `json:"sizeThen"` + raw *RawMonitorClean `json:"-"` + // EXISTING_CODE + // EXISTING_CODE +} + +func (s *SimpleMonitorClean) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *SimpleMonitorClean) Raw() *RawMonitorClean { + return s.raw +} + +func (s *SimpleMonitorClean) SetRaw(raw *RawMonitorClean) { + s.raw = raw +} + +func (s *SimpleMonitorClean) Model(chain, format string, verbose bool, extraOptions map[string]any) Model { + var model = map[string]interface{}{} + var order = []string{} + + // EXISTING_CODE + model = map[string]any{ + "address": s.Address, + "sizeNow": s.SizeNow, + "sizeThen": s.SizeThen, + "dups": s.Dups, + } + order = []string{ + "address", + "sizeNow", + "sizeThen", + "dups", + } + // EXISTING_CODE + + return Model{ + Data: model, + Order: order, + } +} + +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *SimpleMonitorClean) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + +// EXISTING_CODE +// EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_name.go b/src/apps/chifra/pkg/types/types_name.go index c29f910386..7973118081 100644 --- a/src/apps/chifra/pkg/types/types_name.go +++ b/src/apps/chifra/pkg/types/types_name.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "strings" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" @@ -57,6 +58,11 @@ type SimpleName struct { // EXISTING_CODE } +func (s *SimpleName) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleName) Raw() *RawName { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_namedblock.go b/src/apps/chifra/pkg/types/types_namedblock.go index bddc27877a..26fc2a403c 100644 --- a/src/apps/chifra/pkg/types/types_namedblock.go +++ b/src/apps/chifra/pkg/types/types_namedblock.go @@ -10,6 +10,8 @@ package types // EXISTING_CODE import ( + "encoding/json" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) @@ -37,6 +39,11 @@ type SimpleNamedBlock struct { // EXISTING_CODE } +func (s *SimpleNamedBlock) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleNamedBlock) Raw() *RawNamedBlock { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_parameter.go b/src/apps/chifra/pkg/types/types_parameter.go index 7ef3f116b3..55e143f3e3 100644 --- a/src/apps/chifra/pkg/types/types_parameter.go +++ b/src/apps/chifra/pkg/types/types_parameter.go @@ -44,6 +44,11 @@ type SimpleParameter struct { // EXISTING_CODE } +func (s *SimpleParameter) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleParameter) Raw() *RawParameter { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_receipt.go b/src/apps/chifra/pkg/types/types_receipt.go index 500932ef2e..8cd2cc234c 100644 --- a/src/apps/chifra/pkg/types/types_receipt.go +++ b/src/apps/chifra/pkg/types/types_receipt.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "fmt" "io" "path/filepath" @@ -60,6 +61,11 @@ type SimpleReceipt struct { // EXISTING_CODE } +func (s *SimpleReceipt) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleReceipt) Raw() *RawReceipt { return s.raw } diff --git a/src/apps/chifra/internal/chunks/types_reportcheck.go b/src/apps/chifra/pkg/types/types_reportcheck.go similarity index 50% rename from src/apps/chifra/internal/chunks/types_reportcheck.go rename to src/apps/chifra/pkg/types/types_reportcheck.go index 0a24deb4af..57bc4e2610 100644 --- a/src/apps/chifra/internal/chunks/types_reportcheck.go +++ b/src/apps/chifra/pkg/types/types_reportcheck.go @@ -6,32 +6,56 @@ * the code inside of 'EXISTING_CODE' tags. */ -package chunksPkg +package types // EXISTING_CODE -import "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" +import ( + "encoding/json" +) // EXISTING_CODE -type simpleReportCheck struct { - CheckedCnt uint32 `json:"checkedCnt"` - FailedCnt uint32 `json:"failedCnt"` +type RawReportCheck struct { + CheckedCnt string `json:"checkedCnt"` + FailedCnt string `json:"failedCnt"` MsgStrings []string `json:"msgStrings"` - PassedCnt uint32 `json:"passedCnt"` + PassedCnt string `json:"passedCnt"` Reason string `json:"reason"` Result string `json:"result"` - SkippedCnt uint32 `json:"skippedCnt"` - VisitedCnt uint32 `json:"visitedCnt"` + SkippedCnt string `json:"skippedCnt"` + VisitedCnt string `json:"visitedCnt"` + // EXISTING_CODE + // EXISTING_CODE +} +type SimpleReportCheck struct { + CheckedCnt uint32 `json:"checkedCnt"` + FailedCnt uint32 `json:"failedCnt"` + MsgStrings []string `json:"msgStrings"` + PassedCnt uint32 `json:"passedCnt"` + Reason string `json:"reason"` + Result string `json:"result"` + SkippedCnt uint32 `json:"skippedCnt"` + VisitedCnt uint32 `json:"visitedCnt"` + raw *RawReportCheck `json:"-"` // EXISTING_CODE // EXISTING_CODE } -func (s *simpleReportCheck) Raw() *types.RawModeler { - return nil +func (s *SimpleReportCheck) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) } -func (s *simpleReportCheck) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { +func (s *SimpleReportCheck) Raw() *RawReportCheck { + return s.raw +} + +func (s *SimpleReportCheck) SetRaw(raw *RawReportCheck) { + s.raw = raw +} + +func (s *SimpleReportCheck) Model(chain, format string, verbose bool, extraOptions map[string]any) Model { var model = map[string]interface{}{} var order = []string{} @@ -68,11 +92,17 @@ func (s *simpleReportCheck) Model(chain, format string, verbose bool, extraOptio } // EXISTING_CODE - return types.Model{ + return Model{ Data: model, Order: order, } } +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *SimpleReportCheck) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + // EXISTING_CODE // EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_result.go b/src/apps/chifra/pkg/types/types_result.go index b54bb99b2f..13eb775a38 100644 --- a/src/apps/chifra/pkg/types/types_result.go +++ b/src/apps/chifra/pkg/types/types_result.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "fmt" "io" "path/filepath" @@ -50,6 +51,11 @@ type SimpleResult struct { // EXISTING_CODE } +func (s *SimpleResult) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleResult) Raw() *RawResult { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_slurp.go b/src/apps/chifra/pkg/types/types_slurp.go index a87b5d7c92..d0fc86b725 100644 --- a/src/apps/chifra/pkg/types/types_slurp.go +++ b/src/apps/chifra/pkg/types/types_slurp.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "fmt" "io" "path/filepath" @@ -83,6 +84,11 @@ type SimpleSlurp struct { // EXISTING_CODE } +func (s *SimpleSlurp) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleSlurp) Raw() *RawSlurp { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_state.go b/src/apps/chifra/pkg/types/types_state.go index 6931a9a72a..e60396fdae 100644 --- a/src/apps/chifra/pkg/types/types_state.go +++ b/src/apps/chifra/pkg/types/types_state.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "fmt" "io" "path/filepath" @@ -51,6 +52,11 @@ type SimpleState struct { // EXISTING_CODE } +func (s *SimpleState) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleState) Raw() *RawState { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_statement.go b/src/apps/chifra/pkg/types/types_statement.go index d9e810c6ad..34f5ffffca 100644 --- a/src/apps/chifra/pkg/types/types_statement.go +++ b/src/apps/chifra/pkg/types/types_statement.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "fmt" "io" "path/filepath" @@ -98,6 +99,11 @@ type SimpleStatement struct { // EXISTING_CODE } +func (s *SimpleStatement) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleStatement) Raw() *RawStatement { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_status.go b/src/apps/chifra/pkg/types/types_status.go new file mode 100644 index 0000000000..d78a02cf1c --- /dev/null +++ b/src/apps/chifra/pkg/types/types_status.go @@ -0,0 +1,194 @@ +// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. +// Use of this source code is governed by a license that can +// be found in the LICENSE file. +/* + * Parts of this file were auto generated. Edit only those parts of + * the code inside of 'EXISTING_CODE' tags. + */ + +package types + +// EXISTING_CODE +import ( + "encoding/json" + "sort" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" +) + +// EXISTING_CODE + +type RawStatus struct { + CachePath string `json:"cachePath"` + Caches []string `json:"caches"` + Chain string `json:"chain"` + ChainConfig string `json:"chainConfig"` + ChainId string `json:"chainId"` + Chains []string `json:"chains"` + ClientVersion string `json:"clientVersion"` + HasEsKey string `json:"hasEsKey"` + HasPinKey string `json:"hasPinKey"` + IndexPath string `json:"indexPath"` + IsApi string `json:"isApi"` + IsArchive string `json:"isArchive"` + IsScraping string `json:"isScraping"` + IsTesting string `json:"isTesting"` + IsTracing string `json:"isTracing"` + NetworkId string `json:"networkId"` + Progress string `json:"progress"` + RootConfig string `json:"rootConfig"` + RpcProvider string `json:"rpcProvider"` + Version string `json:"version"` + // EXISTING_CODE + // EXISTING_CODE +} + +type SimpleStatus struct { + CachePath string `json:"cachePath,omitempty"` + Caches []SimpleCacheItem `json:"caches"` + Chain string `json:"chain,omitempty"` + ChainConfig string `json:"chainConfig,omitempty"` + ChainId string `json:"chainId,omitempty"` + Chains []SimpleChain `json:"chains"` + ClientVersion string `json:"clientVersion,omitempty"` + HasEsKey bool `json:"hasEsKey,omitempty"` + HasPinKey bool `json:"hasPinKey,omitempty"` + IndexPath string `json:"indexPath,omitempty"` + IsApi bool `json:"isApi,omitempty"` + IsArchive bool `json:"isArchive,omitempty"` + IsScraping bool `json:"isScraping,omitempty"` + IsTesting bool `json:"isTesting,omitempty"` + IsTracing bool `json:"isTracing,omitempty"` + NetworkId string `json:"networkId,omitempty"` + Progress string `json:"progress,omitempty"` + RootConfig string `json:"rootConfig,omitempty"` + RpcProvider string `json:"rpcProvider,omitempty"` + Version string `json:"version,omitempty"` + raw *RawStatus `json:"-"` + // EXISTING_CODE + Meta *MetaData `json:"meta,omitempty"` + Diffs *MetaData `json:"diffs,omitempty"` + // EXISTING_CODE +} + +func (s *SimpleStatus) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *SimpleStatus) Raw() *RawStatus { + return s.raw +} + +func (s *SimpleStatus) SetRaw(raw *RawStatus) { + s.raw = raw +} + +func (s *SimpleStatus) Model(chain, format string, verbose bool, extraOptions map[string]any) Model { + var model = map[string]interface{}{} + var order = []string{} + + // EXISTING_CODE + model = map[string]interface{}{ + "cachePath": s.CachePath, + "chainConfig": s.ChainConfig, + "clientVersion": s.ClientVersion, + "hasEsKey": s.HasEsKey, + "hasPinKey": s.HasPinKey, + "indexPath": s.IndexPath, + "isApi": s.IsApi, + "isArchive": s.IsArchive, + "isTesting": s.IsTesting, + "isTracing": s.IsTracing, + "rootConfig": s.RootConfig, + "rpcProvider": s.RpcProvider, + "trueblocksVersion": s.Version, + } + order = []string{ + "cachePath", + "chainConfig", + "clientVersion", + "hasEsKey", + "hasPinKey", + "indexPath", + "isApi", + "isArchive", + "isTesting", + "isTracing", + "rootConfig", + "rpcProvider", + "trueblocksVersion", + } + + if extraOptions != nil && extraOptions["showProgress"] == true { + model["progress"] = s.Progress + order = append(order, "progress") + } + + testMode := extraOptions["testMode"] == true + if len(s.Caches) > 0 { + if testMode { + for i := 0; i < len(s.Caches); i++ { + s.Caches[i].Path = "--paths--" + s.Caches[i].LastCached = "--lastCached--" + s.Caches[i].NFiles = 123 + s.Caches[i].NFolders = 456 + s.Caches[i].SizeInBytes = 789 + } + } + model["caches"] = s.Caches + order = append(order, "caches") + } + + if extraOptions["chains"] == true { + var chains []SimpleChain + if extraOptions["testMode"] == true { + ch := SimpleChain{ + Chain: "testChain", + ChainId: 12345, + LocalExplorer: "http://localhost:8080", + RpcProvider: "http://localhost:8545", + Symbol: "ETH", + } + chains = append(chains, ch) + } else { + chainArray := config.GetChains() + for _, chain := range chainArray { + ch := SimpleChain{ + Chain: chain.Chain, + ChainId: utils.MustParseUint(chain.ChainId), + LocalExplorer: chain.LocalExplorer, + RemoteExplorer: chain.RemoteExplorer, + RpcProvider: chain.RpcProvider, + IpfsGateway: chain.IpfsGateway, + Symbol: chain.Symbol, + } + chains = append(chains, ch) + } + sort.Slice(chains, func(i, j int) bool { + if chains[i].ChainId == chains[j].ChainId { + return chains[i].Chain < chains[j].Chain + } + return chains[i].ChainId < chains[j].ChainId + }) + } + model["chains"] = chains + order = append(order, "chains") + } + // EXISTING_CODE + + return Model{ + Data: model, + Order: order, + } +} + +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *SimpleStatus) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + +// EXISTING_CODE +// EXISTING_CODE diff --git a/src/apps/chifra/internal/when/types_timestamp.go b/src/apps/chifra/pkg/types/types_timestamp.go similarity index 55% rename from src/apps/chifra/internal/when/types_timestamp.go rename to src/apps/chifra/pkg/types/types_timestamp.go index 51a995081f..a5d88ab554 100644 --- a/src/apps/chifra/internal/when/types_timestamp.go +++ b/src/apps/chifra/pkg/types/types_timestamp.go @@ -6,31 +6,49 @@ * the code inside of 'EXISTING_CODE' tags. */ -package whenPkg +package types // EXISTING_CODE import ( + "encoding/json" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) // EXISTING_CODE -type simpleTimestamp struct { +type RawTimestamp struct { + BlockNumber string `json:"blockNumber"` + Diff string `json:"diff"` + Timestamp string `json:"timestamp"` + // EXISTING_CODE + // EXISTING_CODE +} + +type SimpleTimestamp struct { BlockNumber base.Blknum `json:"blockNumber"` Diff int64 `json:"diff"` Timestamp base.Timestamp `json:"timestamp"` - + raw *RawTimestamp `json:"-"` // EXISTING_CODE // EXISTING_CODE } -func (s *simpleTimestamp) Raw() *types.RawModeler { - return nil +func (s *SimpleTimestamp) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *SimpleTimestamp) Raw() *RawTimestamp { + return s.raw +} + +func (s *SimpleTimestamp) SetRaw(raw *RawTimestamp) { + s.raw = raw } -func (s *simpleTimestamp) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { +func (s *SimpleTimestamp) Model(chain, format string, verbose bool, extraOptions map[string]any) Model { var model = map[string]interface{}{} var order = []string{} @@ -47,15 +65,21 @@ func (s *simpleTimestamp) Model(chain, format string, verbose bool, extraOptions } // EXISTING_CODE - return types.Model{ + return Model{ Data: model, Order: order, } } -func (s *simpleTimestamp) Date() string { +func (s *SimpleTimestamp) Date() string { return utils.FormattedDate(s.Timestamp) } +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *SimpleTimestamp) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + // EXISTING_CODE // EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_timestampcount.go b/src/apps/chifra/pkg/types/types_timestampcount.go new file mode 100644 index 0000000000..d63de9c808 --- /dev/null +++ b/src/apps/chifra/pkg/types/types_timestampcount.go @@ -0,0 +1,70 @@ +// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. +// Use of this source code is governed by a license that can +// be found in the LICENSE file. +/* + * Parts of this file were auto generated. Edit only those parts of + * the code inside of 'EXISTING_CODE' tags. + */ + +package types + +// EXISTING_CODE +import ( + "encoding/json" +) + +// EXISTING_CODE + +type RawTimestampCount struct { + Count string `json:"count"` + // EXISTING_CODE + // EXISTING_CODE +} + +type SimpleTimestampCount struct { + Count uint64 `json:"count"` + raw *RawTimestampCount `json:"-"` + // EXISTING_CODE + // EXISTING_CODE +} + +func (s *SimpleTimestampCount) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *SimpleTimestampCount) Raw() *RawTimestampCount { + return s.raw +} + +func (s *SimpleTimestampCount) SetRaw(raw *RawTimestampCount) { + s.raw = raw +} + +func (s *SimpleTimestampCount) Model(chain, format string, verbose bool, extraOptions map[string]any) Model { + var model = map[string]interface{}{} + var order = []string{} + + // EXISTING_CODE + model = map[string]interface{}{ + "count": s.Count, + } + order = []string{ + "count", + } + // EXISTING_CODE + + return Model{ + Data: model, + Order: order, + } +} + +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *SimpleTimestampCount) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + +// EXISTING_CODE +// EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_token.go b/src/apps/chifra/pkg/types/types_token.go index ebe6692e32..efa3c40506 100644 --- a/src/apps/chifra/pkg/types/types_token.go +++ b/src/apps/chifra/pkg/types/types_token.go @@ -10,6 +10,8 @@ package types // EXISTING_CODE import ( + "encoding/json" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) @@ -53,6 +55,11 @@ type SimpleToken struct { // EXISTING_CODE } +func (s *SimpleToken) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleToken) Raw() *RawToken { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_trace.go b/src/apps/chifra/pkg/types/types_trace.go index 39c6f9fd22..932ca909a2 100644 --- a/src/apps/chifra/pkg/types/types_trace.go +++ b/src/apps/chifra/pkg/types/types_trace.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "fmt" "io" "path/filepath" @@ -60,6 +61,11 @@ type SimpleTrace struct { // EXISTING_CODE } +func (s *SimpleTrace) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleTrace) Raw() *RawTrace { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_traceaction.go b/src/apps/chifra/pkg/types/types_traceaction.go index e2e68c2bd7..d029ea27c0 100644 --- a/src/apps/chifra/pkg/types/types_traceaction.go +++ b/src/apps/chifra/pkg/types/types_traceaction.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "io" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" @@ -56,6 +57,11 @@ type SimpleTraceAction struct { // EXISTING_CODE } +func (s *SimpleTraceAction) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleTraceAction) Raw() *RawTraceAction { return s.raw } diff --git a/src/apps/chifra/internal/traces/types_tracecount.go b/src/apps/chifra/pkg/types/types_tracecount.go similarity index 57% rename from src/apps/chifra/internal/traces/types_tracecount.go rename to src/apps/chifra/pkg/types/types_tracecount.go index 611cff9f35..b9a78e3c2b 100644 --- a/src/apps/chifra/internal/traces/types_tracecount.go +++ b/src/apps/chifra/pkg/types/types_tracecount.go @@ -6,33 +6,53 @@ * the code inside of 'EXISTING_CODE' tags. */ -package tracesPkg +package types // EXISTING_CODE import ( + "encoding/json" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) // EXISTING_CODE -type simpleTraceCount struct { +type RawTraceCount struct { + BlockNumber string `json:"blockNumber"` + Timestamp string `json:"timestamp"` + TracesCnt string `json:"tracesCnt"` + TransactionHash string `json:"transactionHash"` + TransactionIndex string `json:"transactionIndex"` + // EXISTING_CODE + // EXISTING_CODE +} + +type SimpleTraceCount struct { BlockNumber base.Blknum `json:"blockNumber"` Timestamp base.Timestamp `json:"timestamp"` TracesCnt uint64 `json:"tracesCnt"` TransactionHash base.Hash `json:"transactionHash"` TransactionIndex base.Blknum `json:"transactionIndex"` - + raw *RawTraceCount `json:"-"` // EXISTING_CODE // EXISTING_CODE } -func (s *simpleTraceCount) Raw() *types.RawModeler { - return nil +func (s *SimpleTraceCount) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + +func (s *SimpleTraceCount) Raw() *RawTraceCount { + return s.raw +} + +func (s *SimpleTraceCount) SetRaw(raw *RawTraceCount) { + s.raw = raw } -func (s *simpleTraceCount) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { +func (s *SimpleTraceCount) Model(chain, format string, verbose bool, extraOptions map[string]any) Model { var model = map[string]interface{}{} var order = []string{} @@ -53,15 +73,21 @@ func (s *simpleTraceCount) Model(chain, format string, verbose bool, extraOption } // EXISTING_CODE - return types.Model{ + return Model{ Data: model, Order: order, } } -func (s *simpleTraceCount) Date() string { +func (s *SimpleTraceCount) Date() string { return utils.FormattedDate(s.Timestamp) } +// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen +func (s *SimpleTraceCount) FinishUnmarshal() { + // EXISTING_CODE + // EXISTING_CODE +} + // EXISTING_CODE // EXISTING_CODE diff --git a/src/apps/chifra/pkg/types/types_tracefilter.go b/src/apps/chifra/pkg/types/types_tracefilter.go index 482119595d..745bb69e99 100644 --- a/src/apps/chifra/pkg/types/types_tracefilter.go +++ b/src/apps/chifra/pkg/types/types_tracefilter.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "fmt" "strings" @@ -42,6 +43,11 @@ type SimpleTraceFilter struct { // EXISTING_CODE } +func (s *SimpleTraceFilter) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleTraceFilter) Raw() *RawTraceFilter { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_traceresult.go b/src/apps/chifra/pkg/types/types_traceresult.go index ab33c1821a..67c5b78d51 100644 --- a/src/apps/chifra/pkg/types/types_traceresult.go +++ b/src/apps/chifra/pkg/types/types_traceresult.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "io" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" @@ -39,6 +40,11 @@ type SimpleTraceResult struct { // EXISTING_CODE } +func (s *SimpleTraceResult) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleTraceResult) Raw() *RawTraceResult { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_transaction.go b/src/apps/chifra/pkg/types/types_transaction.go index bd34eed01d..a48a54499b 100644 --- a/src/apps/chifra/pkg/types/types_transaction.go +++ b/src/apps/chifra/pkg/types/types_transaction.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "fmt" "io" "path/filepath" @@ -98,6 +99,11 @@ type SimpleTransaction struct { // EXISTING_CODE } +func (s *SimpleTransaction) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleTransaction) Raw() *RawTransaction { return s.raw } diff --git a/src/apps/chifra/pkg/types/types_withdrawal.go b/src/apps/chifra/pkg/types/types_withdrawal.go index 4b25c6ab28..cbe194cce3 100644 --- a/src/apps/chifra/pkg/types/types_withdrawal.go +++ b/src/apps/chifra/pkg/types/types_withdrawal.go @@ -10,6 +10,7 @@ package types // EXISTING_CODE import ( + "encoding/json" "fmt" "io" "path/filepath" @@ -45,6 +46,11 @@ type SimpleWithdrawal struct { // EXISTING_CODE } +func (s *SimpleWithdrawal) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *SimpleWithdrawal) Raw() *RawWithdrawal { return s.raw } diff --git a/src/dev_tools/goMaker/main.go b/src/dev_tools/goMaker/main.go index 6c84b676fe..44cf9a7da6 100644 --- a/src/dev_tools/goMaker/main.go +++ b/src/dev_tools/goMaker/main.go @@ -49,7 +49,6 @@ var cbTemplates = []types.Generator{ Templates: []string{ "src_dev+tools_goMaker_generated_model+type.md.tmpl", "src_apps_chifra_pkg_types_type.go.tmpl", - "src_apps_chifra_internal_route_types_type.go.tmpl", }, }, { diff --git a/src/dev_tools/goMaker/templates/api/description.txt b/src/dev_tools/goMaker/templates/api/description.txt index aa4fc7cb8e..ede1080831 100644 --- a/src/dev_tools/goMaker/templates/api/description.txt +++ b/src/dev_tools/goMaker/templates/api/description.txt @@ -47,7 +47,7 @@ "http://localhost:8080/blocks?blocks=100-110&cache=true" ``` - Cacheing speeds up repeat queries significantly. The cache options are + Caching speeds up repeat queries significantly. The cache options are particularly useful for calls to data-rich endpoints, like most endpoints in the "Accounts" collection. diff --git a/src/dev_tools/goMaker/templates/classDefinitions/abi.toml b/src/dev_tools/goMaker/templates/classDefinitions/abi.toml index 62e304ba0a..8fba0c3af5 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/abi.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/abi.toml @@ -4,4 +4,3 @@ doc_descr = "a human-readable representation of a Solidity smart contract" doc_route = "503-abi" produced_by = "abis" - go_output = "src/apps/chifra/pkg/types" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/appearance.toml b/src/dev_tools/goMaker/templates/classDefinitions/appearance.toml index 0101be3bd5..eae54beed0 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/appearance.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/appearance.toml @@ -5,4 +5,3 @@ doc_descr = "an appearance (``) of an address anywhere on the chain (note that in some cases, not all fields will appear depending on the command)" doc_route = "103-appearance" produced_by = "list, export, blocks, chunks" - go_output = "src/apps/chifra/pkg/types" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/appearancecount.toml b/src/dev_tools/goMaker/templates/classDefinitions/appearancecount.toml index 4254426284..b20ddbb89b 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/appearancecount.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/appearancecount.toml @@ -4,4 +4,3 @@ doc_descr = "the number of records, file size, and last visited block for a given monitor" doc_route = "112-appearanceCount" produced_by = "list, export" - go_output = "src/apps/chifra/pkg/types" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/appearancetable.toml b/src/dev_tools/goMaker/templates/classDefinitions/appearancetable.toml new file mode 100644 index 0000000000..674fa9873d --- /dev/null +++ b/src/dev_tools/goMaker/templates/classDefinitions/appearancetable.toml @@ -0,0 +1,7 @@ +[settings] + class = "CAppearanceTable" + contained_by = "Monitor" + doc_group = "01-Accounts" + doc_descr = "an appearance table for an address" + doc_route = "103-appearanceTable" + produced_by = "chunks" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/block.toml b/src/dev_tools/goMaker/templates/classDefinitions/block.toml index 4aa96b9b5c..0194dba127 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/block.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/block.toml @@ -4,7 +4,6 @@ doc_descr = "block data as returned from the RPC (with slight enhancements)" doc_route = "203-block" produced_by = "blocks, when" - go_output = "src/apps/chifra/pkg/types" go_model = "Block[Tx]" cache_type = "cacheable" cache_by = "block" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/blockcount.toml b/src/dev_tools/goMaker/templates/classDefinitions/blockcount.toml index 8367a13667..d0f26e9b37 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/blockcount.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/blockcount.toml @@ -4,4 +4,3 @@ doc_descr = "counts of various parts of the block data such as tx_count, trace_count, etc." doc_route = "236-blockCount" produced_by = "blocks" - go_output = "src/apps/chifra/internal/blocks" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/bounds.toml b/src/dev_tools/goMaker/templates/classDefinitions/bounds.toml index 9d394e404f..7cfcc38e41 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/bounds.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/bounds.toml @@ -4,4 +4,3 @@ doc_descr = "show first block and last block an address appears in along with timestamps and dates" doc_route = "115-bounds" produced_by = "list" - go_output = "src/apps/chifra/pkg/types" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/cacheitem.toml b/src/dev_tools/goMaker/templates/classDefinitions/cacheitem.toml index 4376459a60..8b23c21492 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/cacheitem.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/cacheitem.toml @@ -5,4 +5,3 @@ doc_descr = "a single entry in the results of a status query when `--verbose` is enabled" doc_route = "430-cacheItem" produced_by = "status" - go_output = "src/apps/chifra/internal/status" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/chain.toml b/src/dev_tools/goMaker/templates/classDefinitions/chain.toml index 92664f405e..a45a6cf52b 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/chain.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/chain.toml @@ -5,4 +5,3 @@ doc_descr = "a configuration item carrying information about a single chain" doc_route = "439-chain" produced_by = "status, config" - go_output = "src/apps/chifra/pkg/types" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/chunkaddress.toml b/src/dev_tools/goMaker/templates/classDefinitions/chunkaddress.toml index 5db40576c0..be9d943f6c 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/chunkaddress.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/chunkaddress.toml @@ -4,4 +4,3 @@ doc_descr = "internal-use only data model detailing a single address record in the address table of an index chunk" doc_route = "418-chunkAddress" produced_by = "chunks" - go_output = "src/apps/chifra/internal/chunks" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/chunkbloom.toml b/src/dev_tools/goMaker/templates/classDefinitions/chunkbloom.toml index 6e48d802b2..3c7bd13fd2 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/chunkbloom.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/chunkbloom.toml @@ -4,4 +4,3 @@ doc_descr = "internal-use only data model detailing a single bloom filter file" doc_route = "415-chunkBloom" produced_by = "chunks" - go_output = "src/apps/chifra/internal/chunks" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/chunkindex.toml b/src/dev_tools/goMaker/templates/classDefinitions/chunkindex.toml index 3adc6e53f5..7d297955db 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/chunkindex.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/chunkindex.toml @@ -4,4 +4,3 @@ doc_descr = "internal-use only data model detailing a single index chunk file" doc_route = "412-chunkIndex" produced_by = "chunks" - go_output = "src/apps/chifra/internal/chunks" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/chunkpinreport.toml b/src/dev_tools/goMaker/templates/classDefinitions/chunkpinreport.toml index 31e57d1416..19d4eace58 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/chunkpinreport.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/chunkpinreport.toml @@ -4,4 +4,3 @@ doc_descr = "a JSON object containing the results of pinning the Unchained Index" doc_route = "436-chunkPinReport" produced_by = "chunks" - go_output = "src/apps/chifra/internal/chunks" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/chunkrecord.toml b/src/dev_tools/goMaker/templates/classDefinitions/chunkrecord.toml index 25d17906d5..f866816647 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/chunkrecord.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/chunkrecord.toml @@ -5,4 +5,3 @@ doc_descr = "a single record in the manifest detailing the IPFS hases and file sizes for each bloom filter and index chunk" doc_route = "409-chunkRecord" produced_by = "chunks, init, scrape" - go_output = "src/apps/chifra/pkg/types" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/chunkstats.toml b/src/dev_tools/goMaker/templates/classDefinitions/chunkstats.toml index 6522641f04..007f98c867 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/chunkstats.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/chunkstats.toml @@ -4,4 +4,3 @@ doc_descr = "summary statistics about an Unchained Index bloom filter and index chunk" doc_route = "424-chunkStats" produced_by = "chunks" - go_output = "src/apps/chifra/pkg/types" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/fields/appearancetable.csv b/src/dev_tools/goMaker/templates/classDefinitions/fields/appearancetable.csv new file mode 100644 index 0000000000..bad6920699 --- /dev/null +++ b/src/dev_tools/goMaker/templates/classDefinitions/fields/appearancetable.csv @@ -0,0 +1,3 @@ +name ,type ,strDefault ,attributes ,docOrder ,description +AddressRecord ,AddrRecord , , , 1 ,the address record for these appearances +Appearances ,[]AppRecord , , , 2 ,all the appearances for this address diff --git a/src/dev_tools/goMaker/templates/classDefinitions/function.toml b/src/dev_tools/goMaker/templates/classDefinitions/function.toml index c2d1ae81a7..2ca89eb2ed 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/function.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/function.toml @@ -5,5 +5,4 @@ doc_descr = "a human-readable representation of a Solidity function call or event" doc_route = "506-function" produced_by = "abis, export" - go_output = "src/apps/chifra/pkg/types" cache_type = "marshal_only" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/ipfspin.toml b/src/dev_tools/goMaker/templates/classDefinitions/ipfspin.toml index 743f9f4d88..16f3fd751e 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/ipfspin.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/ipfspin.toml @@ -4,4 +4,3 @@ doc_descr = "internal-use only data model detailing a single remote or local ipfs pinned file" doc_route = "421-ipfsPin" produced_by = "chunks" - go_output = "src/apps/chifra/internal/chunks" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/log.toml b/src/dev_tools/goMaker/templates/classDefinitions/log.toml index 292bc431ae..f49e8bd9dc 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/log.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/log.toml @@ -5,7 +5,6 @@ doc_descr = "log data as returned from the RPC (with slight enhancements)" doc_route = "215-log" produced_by = "logs, export, blocks" - go_output = "src/apps/chifra/pkg/types" cache_type = "cacheable" cache_by = "block" cache_as = "group" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/logfilter.toml b/src/dev_tools/goMaker/templates/classDefinitions/logfilter.toml index 7484d594a0..da42a7fa7d 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/logfilter.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/logfilter.toml @@ -4,4 +4,3 @@ doc_descr = "used by the fast path log queries for various commands" doc_route = "218-logFilter" produced_by = "blocks, logs" - go_output = "src/apps/chifra/pkg/types" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/manifest.toml b/src/dev_tools/goMaker/templates/classDefinitions/manifest.toml index f58afa9956..b3d7bd3656 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/manifest.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/manifest.toml @@ -4,4 +4,3 @@ doc_descr = "a JSON object containing records for each bloom filter and index chunk in the Unchained Index" doc_route = "406-manifest" produced_by = "chunks, init, scrape" - go_output = "src/apps/chifra/pkg/types" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/monitor.toml b/src/dev_tools/goMaker/templates/classDefinitions/monitor.toml index 67e619145e..58373d5066 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/monitor.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/monitor.toml @@ -5,4 +5,3 @@ doc_descr = "a local file indicating a user's interest in an address. Includes caches for reconicilations, transactions, and appearances as well as an optional association to named account" doc_route = "106-monitor" produced_by = "monitors, list, export" - go_output = "src/apps/chifra/pkg/types" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/monitorclean.toml b/src/dev_tools/goMaker/templates/classDefinitions/monitorclean.toml index 42c44d20ef..14711e474d 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/monitorclean.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/monitorclean.toml @@ -4,4 +4,3 @@ doc_descr = "report on cleaning dups out of monitors" doc_route = "427-monitorClean" produced_by = "monitors" - go_output = "src/apps/chifra/internal/monitors" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/name.toml b/src/dev_tools/goMaker/templates/classDefinitions/name.toml index 5749f1a021..a760733c04 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/name.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/name.toml @@ -4,4 +4,3 @@ doc_descr = "an association between a human-readable name and an address used throughout TrueBlocks" doc_route = "109-name" produced_by = "names" - go_output = "src/apps/chifra/pkg/types" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/namedblock.toml b/src/dev_tools/goMaker/templates/classDefinitions/namedblock.toml index d3beb722b2..37754b1831 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/namedblock.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/namedblock.toml @@ -4,4 +4,3 @@ doc_descr = "a block that has been given a particular name such as `first` or `latest`" doc_route = "239-namedBlock" produced_by = "when" - go_output = "src/apps/chifra/pkg/types" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/parameter.toml b/src/dev_tools/goMaker/templates/classDefinitions/parameter.toml index 9252bfcc18..0cc3616073 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/parameter.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/parameter.toml @@ -5,5 +5,4 @@ doc_descr = "an input or output parameter to a Solidity function or event" doc_route = "509-parameter" produced_by = "abis, export" - go_output = "src/apps/chifra/pkg/types" cache_type = "marshal_only" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/receipt.toml b/src/dev_tools/goMaker/templates/classDefinitions/receipt.toml index edd9e0ab51..0d24b4e1d5 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/receipt.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/receipt.toml @@ -5,7 +5,6 @@ doc_descr = "receipt data as returned from the RPC (with slight enhancements)" doc_route = "212-receipt" produced_by = "receipts, export" - go_output = "src/apps/chifra/pkg/types" cache_type = "cacheable" cache_by = "block" cache_as = "group" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/reportcheck.toml b/src/dev_tools/goMaker/templates/classDefinitions/reportcheck.toml index 147b3455ca..f16725e4c8 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/reportcheck.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/reportcheck.toml @@ -4,4 +4,3 @@ doc_descr = "report on checking contents of chunks" doc_route = "433-reportCheck" produced_by = "chunks" - go_output = "src/apps/chifra/internal/chunks" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/result.toml b/src/dev_tools/goMaker/templates/classDefinitions/result.toml index cfe62252ac..1d6339a37e 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/result.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/result.toml @@ -4,6 +4,5 @@ doc_descr = "the result (articulated if possible, as bytes otherwise) of a call to a smart contract" doc_route = "309-result" produced_by = "state" - go_output = "src/apps/chifra/pkg/types" cache_type = "cacheable" cache_by = "address,block,fourbyte" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/slurp.toml b/src/dev_tools/goMaker/templates/classDefinitions/slurp.toml index ee05c00495..27e678d958 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/slurp.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/slurp.toml @@ -4,7 +4,6 @@ doc_descr = "transaction data as returned from by Etherscan" doc_route = "512-slurp" produced_by = "slurp" - go_output = "src/apps/chifra/pkg/types" cache_type = "cacheable" cache_by = "address,tx" cache_as = "group" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/state.toml b/src/dev_tools/goMaker/templates/classDefinitions/state.toml index 5b13d1fac2..f6f03df528 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/state.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/state.toml @@ -4,6 +4,5 @@ doc_descr = "the state of an Ethereum account (EOA or smart contract) on-chain" doc_route = "303-state" produced_by = "state" - go_output = "src/apps/chifra/pkg/types" cache_type = "cacheable" cache_by = "address,block" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/statement.toml b/src/dev_tools/goMaker/templates/classDefinitions/statement.toml index cbbb71ad47..1b64b03c85 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/statement.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/statement.toml @@ -5,7 +5,6 @@ doc_descr = "a statement, including all inflows and outflows, for a single transfer of an asset (including ETH) to or from a given address" doc_route = "118-statement" produced_by = "export" - go_output = "src/apps/chifra/pkg/types" cache_type = "cacheable" cache_by = "address,tx" cache_as = "group" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/status.toml b/src/dev_tools/goMaker/templates/classDefinitions/status.toml index 9289036a73..70c0a08f3d 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/status.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/status.toml @@ -4,4 +4,3 @@ doc_descr = "status-related data about the TrueBlocks system including the server and local binary caches" doc_route = "403-status" produced_by = "status" - go_output = "src/apps/chifra/internal/status" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/timestamp.toml b/src/dev_tools/goMaker/templates/classDefinitions/timestamp.toml index 2bf87550b3..bb0e9ec849 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/timestamp.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/timestamp.toml @@ -4,4 +4,3 @@ doc_descr = "the timestamp, date and difference in timestamp of previous block produced by chifra when" doc_route = "242-timestamp" produced_by = "when" - go_output = "src/apps/chifra/internal/when" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/timestampcount.toml b/src/dev_tools/goMaker/templates/classDefinitions/timestampcount.toml index b34481b706..d4e70e3123 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/timestampcount.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/timestampcount.toml @@ -4,4 +4,3 @@ doc_descr = "the number of timestamps in the timestamps database" doc_route = "245-timestampCount" produced_by = "when" - go_output = "src/apps/chifra/internal/when" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/token.toml b/src/dev_tools/goMaker/templates/classDefinitions/token.toml index 5c8a99c845..cb13b2ce4c 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/token.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/token.toml @@ -4,4 +4,3 @@ doc_descr = "on-chain token-related data such as totalSupply, symbol, decimals, and individual balances for a given address at a given block" doc_route = "306-token" produced_by = "tokens, export" - go_output = "src/apps/chifra/pkg/types" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/trace.toml b/src/dev_tools/goMaker/templates/classDefinitions/trace.toml index 8f97d6d699..ba8688c83f 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/trace.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/trace.toml @@ -5,7 +5,6 @@ doc_descr = "trace data as returned from the RPC (with slight enhancements)" doc_route = "221-trace" produced_by = "traces, export, blocks" - go_output = "src/apps/chifra/pkg/types" cache_type = "cacheable" cache_by = "tx" cache_as = "group" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/traceaction.toml b/src/dev_tools/goMaker/templates/classDefinitions/traceaction.toml index 86337489aa..0bea5539d4 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/traceaction.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/traceaction.toml @@ -5,5 +5,4 @@ doc_descr = "trace action data as returned from the RPC (with slight enhancements)" doc_route = "224-traceAction" produced_by = "traces, export, blocks" - go_output = "src/apps/chifra/pkg/types" cache_type = "marshal_only" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/tracecount.toml b/src/dev_tools/goMaker/templates/classDefinitions/tracecount.toml index 61c3cca44b..269365581c 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/tracecount.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/tracecount.toml @@ -4,4 +4,3 @@ doc_descr = "counts the number of traces in a transaction" doc_route = "230-traceCount" produced_by = "traces" - go_output = "src/apps/chifra/internal/traces" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/tracefilter.toml b/src/dev_tools/goMaker/templates/classDefinitions/tracefilter.toml index aff8b983e3..8fd7c7fda9 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/tracefilter.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/tracefilter.toml @@ -4,4 +4,3 @@ doc_descr = "used by chifra traces --filter option to query for traces" doc_route = "233-traceFilter" produced_by = "traces" - go_output = "src/apps/chifra/pkg/types" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/traceresult.toml b/src/dev_tools/goMaker/templates/classDefinitions/traceresult.toml index 2dbe56cd66..cb383db691 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/traceresult.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/traceresult.toml @@ -5,5 +5,4 @@ doc_descr = "trace result data as returned from the RPC (with slight enhancements)" doc_route = "227-traceResult" produced_by = "traces, export, blocks" - go_output = "src/apps/chifra/pkg/types" cache_type = "marshal_only" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/transaction.toml b/src/dev_tools/goMaker/templates/classDefinitions/transaction.toml index b83435272c..0fc27c41e4 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/transaction.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/transaction.toml @@ -5,6 +5,5 @@ doc_descr = "transaction data as returned from the RPC (with slight enhancements)" doc_route = "206-transaction" produced_by = "transactions, export" - go_output = "src/apps/chifra/pkg/types" cache_type = "cacheable" cache_by = "tx" diff --git a/src/dev_tools/goMaker/templates/classDefinitions/withdrawal.toml b/src/dev_tools/goMaker/templates/classDefinitions/withdrawal.toml index ef0637e5ba..1a71f85ad9 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/withdrawal.toml +++ b/src/dev_tools/goMaker/templates/classDefinitions/withdrawal.toml @@ -5,7 +5,6 @@ doc_descr = "withdrawal record for post-Shanghai withdrawals from the consensus layer" doc_route = "209-withdrawal" produced_by = "blocks" - go_output = "src/apps/chifra/pkg/types" cache_type = "cacheable" cache_by = "block" cache_as = "group" diff --git a/src/dev_tools/goMaker/templates/sdk_go_route.go.tmpl b/src/dev_tools/goMaker/templates/sdk_go_route.go.tmpl index a9e20ae621..6b3e2cfa7b 100644 --- a/src/dev_tools/goMaker/templates/sdk_go_route.go.tmpl +++ b/src/dev_tools/goMaker/templates/sdk_go_route.go.tmpl @@ -57,7 +57,7 @@ func Get{{.Proper}}Options(args []string) (*{{.Proper}}Options, error) { return &opts, nil } -func (opts *{{.Proper}}Options) Query() ([]{{.Returns}}, *rpc.MetaData, error) { +func (opts *{{.Proper}}Options) Query() ([]{{.Returns}}, *types.MetaData, error) { buffer := bytes.Buffer{} if err := opts.{{.Proper}}(&buffer); err != nil { logger.Fatal(err) diff --git a/src/dev_tools/goMaker/templates/src_apps_chifra_internal_route_output.go.tmpl b/src/dev_tools/goMaker/templates/src_apps_chifra_internal_route_output.go.tmpl index b659a0caae..3d4e6cdc2f 100644 --- a/src/dev_tools/goMaker/templates/src_apps_chifra_internal_route_output.go.tmpl +++ b/src/dev_tools/goMaker/templates/src_apps_chifra_internal_route_output.go.tmpl @@ -33,7 +33,7 @@ func Serve{{.Proper}}(w http.ResponseWriter, r *http.Request) error { return err } -// {{.Proper}}Internal handles the internal workings of the {{.Route}} command. Returns an error. +// {{.Proper}}Internal handles the internal workings of the {{.Route}} command. Returns an error. func (opts *{{.Proper}}Options) {{.Proper}}Internal() error { var err error if err = opts.validate{{.Proper}}(); err != nil { diff --git a/src/dev_tools/goMaker/templates/src_apps_chifra_internal_route_types_type.go.tmpl b/src/dev_tools/goMaker/templates/src_apps_chifra_internal_route_types_type.go.tmpl deleted file mode 100644 index 8d4dd09ca8..0000000000 --- a/src/dev_tools/goMaker/templates/src_apps_chifra_internal_route_types_type.go.tmpl +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. -// Use of this source code is governed by a license that can -// be found in the LICENSE file. -/* - * Parts of this file were auto generated. Edit only those parts of - * the code inside of 'EXISTING_CODE' tags. - */ - -package {{.Route}}Pkg - -// EXISTING_CODE -// EXISTING_CODE - -type simple{{.Class}} struct { -{{range .Members}}{{if .IsSimpField}}{{.GoName}} {{.GoType}} {{.Tag}} -{{end}}{{end}} - // EXISTING_CODE - // EXISTING_CODE -} - -func (s *simple{{.Class}}) Raw() *types.RawModeler { - return nil -} - -func (s *simple{{.Class}}) Model(chain, format string, verbose bool, extraOptions map[string]any) types.Model { - var model = map[string]interface{}{} - var order = []string{} - - // EXISTING_CODE - // EXISTING_CODE - - return types.Model{ - Data: model, - Order: order, - } -} - -{{if .HasTimestamp}} -func (s *simple{{.ModelName}}) Date() string { - return utils.FormattedDate(s.Timestamp) -} -{{end}} - -// EXISTING_CODE -// EXISTING_CODE diff --git a/src/dev_tools/goMaker/templates/src_apps_chifra_pkg_types_type.go.tmpl b/src/dev_tools/goMaker/templates/src_apps_chifra_pkg_types_type.go.tmpl index 0c3d6ba72d..dac189ca9d 100644 --- a/src/dev_tools/goMaker/templates/src_apps_chifra_pkg_types_type.go.tmpl +++ b/src/dev_tools/goMaker/templates/src_apps_chifra_pkg_types_type.go.tmpl @@ -24,6 +24,11 @@ type Simple{{.ModelName2}} struct { // EXISTING_CODE } +func (s *Simple{{.ModelName}}) String() string { + bytes, _ := json.Marshal(s) + return string(bytes) +} + func (s *Simple{{.ModelName}}) Raw() *Raw{{.Class}} { return s.raw } diff --git a/src/dev_tools/goMaker/types/load.go b/src/dev_tools/goMaker/types/load.go index f7fdc77d6b..f4acbe5548 100644 --- a/src/dev_tools/goMaker/types/load.go +++ b/src/dev_tools/goMaker/types/load.go @@ -96,10 +96,6 @@ func (cb *CodeBase) LoadStructures(thePath string, structMap map[string]Structur if f.Settings.Class[0] == 'C' { f.Settings.Class = f.Settings.Class[1:] } - if f.Settings.GoOutput == "documentation only" { - f.Settings.GoOutput = "" - f.Settings.DisableGo = true - } mapKey := strings.ToLower(class) structMap[mapKey] = f.Settings } diff --git a/src/dev_tools/goMaker/types/process_structure.go b/src/dev_tools/goMaker/types/process_structure.go index b1a0d5b612..d3b97c35c0 100644 --- a/src/dev_tools/goMaker/types/process_structure.go +++ b/src/dev_tools/goMaker/types/process_structure.go @@ -22,37 +22,13 @@ func (s *Structure) ProcessFile(source string) error { return nil } - dest := "" - isSourceInternal := strings.Contains(source, "internal") - isSourceGenerated := strings.Contains(source, "generated") - isDestInternal := strings.Contains(s.GoOutput, "internal") - - if !isSourceGenerated && (isDestInternal && !isSourceInternal || isSourceInternal && !isDestInternal) { - // fmt.Println("Mismatch", s.Class) - return nil - } else if isDestInternal { - s.Route = grabRoute(s.GoOutput) - dest = convertToDestPath(source, s.Route, s.Name(), "") - dest = strings.Replace(dest, "/types/", "/types_", -1) - // return nil - } else { - dest = convertToDestPath(source, "", s.Name(), "") - } - + dest := convertToDestPath(source, "", s.Name(), "") tmpl := file.AsciiFileToString(source) result := s.executeTemplate(source, tmpl) - dest = strings.Replace(dest, "/src/apps/chifra/pkg/types/", "/"+s.GoOutput+"/types_", -1) + dest = strings.Replace(dest, "/src/apps/chifra/pkg/types/", "/src/apps/chifra/pkg/types/types_", -1) return codeWriter.WriteCode(dest, result) } -func grabRoute(dest string) string { - if !strings.Contains(dest, "/internal/") { - return "" - } - parts := strings.Split(dest, "/") - return parts[len(parts)-1] -} - func readStructure(st *Structure, data *any) (bool, error) { st.DocDescr = strings.ReplaceAll(st.DocDescr, ",", ",") return true, nil diff --git a/src/dev_tools/goMaker/types/types_member.go b/src/dev_tools/goMaker/types/types_member.go index a12a67cc98..5073c6cdd7 100644 --- a/src/dev_tools/goMaker/types/types_member.go +++ b/src/dev_tools/goMaker/types/types_member.go @@ -197,14 +197,6 @@ func (m *Member) GoType() string { return "[]Tx" } - if m.Container() == "Status" { - if m.Type == "CacheItem" { - return "[]simpleCacheItem" - } else if m.Type == "Chain" { - return "[]types.SimpleChain" - } - } - ret := m.Type if m.IsObject() { if m.GoName() != "TokenType" { diff --git a/src/dev_tools/goMaker/types/types_structure.go b/src/dev_tools/goMaker/types/types_structure.go index a38b080cb3..5f49a4467d 100644 --- a/src/dev_tools/goMaker/types/types_structure.go +++ b/src/dev_tools/goMaker/types/types_structure.go @@ -13,7 +13,6 @@ import ( type Structure struct { Class string `json:"class,omitempty" toml:"class" csv:"class"` BaseClass string `json:"base_class,omitempty" toml:"base_class"` - GoOutput string `json:"go_output,omitempty" toml:"go_output"` DocGroup string `json:"doc_group,omitempty" toml:"doc_group" csv:"doc_group"` DocRoute string `json:"doc_route,omitempty" toml:"doc_route"` DocDescr string `json:"doc_descr,omitempty" toml:"doc_descr" csv:"doc_descr"` diff --git a/test/gold/tools/ethslurp/ethslurp_help.txt b/test/gold/tools/ethslurp/ethslurp_help.txt index 06cb4b43a5..dd39dbf731 100644 --- a/test/gold/tools/ethslurp/ethslurp_help.txt +++ b/test/gold/tools/ethslurp/ethslurp_help.txt @@ -1,6 +1,6 @@ chifra slurp -h Purpose: - Fetch data from Etherscan for any address. + Fetch data from Etherscan and other APIs for any address. Usage: chifra slurp [flags]
[address...] [block...] diff --git a/test/gold/tools/ethslurp/ethslurp_help_long.txt b/test/gold/tools/ethslurp/ethslurp_help_long.txt index 6b6fa3314b..dd01c7be7d 100644 --- a/test/gold/tools/ethslurp/ethslurp_help_long.txt +++ b/test/gold/tools/ethslurp/ethslurp_help_long.txt @@ -1,6 +1,6 @@ chifra slurp --help Purpose: - Fetch data from Etherscan for any address. + Fetch data from Etherscan and other APIs for any address. Usage: chifra slurp [flags]
[address...] [block...]