From 8b5bdbd55abd59cc116e19b2eb70e2c2bb3efc6f Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Tue, 1 Aug 2023 00:05:30 -0400 Subject: [PATCH] Begins forcing access to the RPC through an object (#3113) * Begins forcing access to the RPC through an object * Fixing * Moves more stuff to rpcOptions * Further forcing of access to the RPC through the object * Fix * All functions in rpcClient are gated by the rpcOptions object * Creates an RPC Connection while initializing the command * Trying to get control of `opts.Globals.Chain` as `chain` * Trying to get control of the rpcOptions * More cleaning * Trying to get control of rpc connection * Adding debugging to rpcOptions * We're done for now. * Enable cache code but not implemented --- go.work.sum | 248 ++++++++++++++++++ .../chifra/internal/abis/handle_addresses.go | 10 +- src/apps/chifra/internal/abis/handle_clean.go | 8 +- src/apps/chifra/internal/abis/options.go | 16 +- .../chifra/internal/blocks/handle_count.go | 26 +- .../chifra/internal/blocks/handle_decache.go | 19 +- .../chifra/internal/blocks/handle_list.go | 7 +- .../chifra/internal/blocks/handle_logs.go | 3 +- .../chifra/internal/blocks/handle_show.go | 18 +- .../chifra/internal/blocks/handle_traces.go | 4 +- .../chifra/internal/blocks/handle_uncles.go | 13 +- .../chifra/internal/blocks/handle_uniq.go | 26 +- src/apps/chifra/internal/blocks/options.go | 15 ++ src/apps/chifra/internal/blocks/validate.go | 7 +- .../internal/chunks/handle_addresses.go | 5 +- .../chunks/handle_addresses_belongs.go | 4 +- .../internal/chunks/handle_appearances.go | 4 +- .../chifra/internal/chunks/handle_blooms.go | 6 +- .../chifra/internal/chunks/handle_check.go | 14 +- .../internal/chunks/handle_check_deep.go | 3 +- .../internal/chunks/handle_check_staging.go | 6 +- .../chifra/internal/chunks/handle_index.go | 3 +- .../chifra/internal/chunks/handle_manifest.go | 3 +- src/apps/chifra/internal/chunks/handle_pin.go | 8 +- .../chifra/internal/chunks/handle_stats.go | 5 +- .../chifra/internal/chunks/handle_truncate.go | 4 +- src/apps/chifra/internal/chunks/options.go | 16 +- src/apps/chifra/internal/chunks/output.go | 3 +- src/apps/chifra/internal/chunks/validate.go | 8 +- .../chifra/internal/config/handle_paths.go | 6 +- src/apps/chifra/internal/config/options.go | 13 + .../chifra/internal/daemon/handle_calls.go | 3 +- src/apps/chifra/internal/daemon/options.go | 13 + src/apps/chifra/internal/daemon/output.go | 5 +- src/apps/chifra/internal/explore/options.go | 16 +- src/apps/chifra/internal/explore/validate.go | 26 +- .../explore/validate_integration_test.go | 5 + .../chifra/internal/export/handle_balances.go | 12 +- .../chifra/internal/export/handle_logs.go | 9 +- .../chifra/internal/export/handle_receipts.go | 9 +- .../chifra/internal/export/handle_show.go | 10 +- .../internal/export/handle_statements.go | 10 +- .../chifra/internal/export/handle_traces.go | 9 +- src/apps/chifra/internal/export/iterate.go | 5 +- src/apps/chifra/internal/export/options.go | 26 +- src/apps/chifra/internal/export/output.go | 3 +- src/apps/chifra/internal/export/validate.go | 8 +- src/apps/chifra/internal/globals/options.go | 1 + src/apps/chifra/internal/globals/validate.go | 2 +- .../chifra/internal/init/handle_dryrun.go | 4 +- src/apps/chifra/internal/init/handle_init.go | 8 +- .../internal/init/handle_init_prepare.go | 4 +- src/apps/chifra/internal/init/options.go | 13 + .../chifra/internal/list/handle_freshen.go | 7 +- src/apps/chifra/internal/list/options.go | 16 +- src/apps/chifra/internal/list/validate.go | 7 +- src/apps/chifra/internal/logs/handle_show.go | 4 +- src/apps/chifra/internal/logs/options.go | 15 ++ src/apps/chifra/internal/logs/validate.go | 4 +- .../chifra/internal/monitors/handle_clean.go | 3 +- .../chifra/internal/monitors/handle_crud.go | 5 +- .../internal/monitors/handle_decache.go | 5 +- .../chifra/internal/monitors/handle_list.go | 2 +- src/apps/chifra/internal/monitors/options.go | 16 +- .../internal/monitors/scrape_monitor.go | 5 +- src/apps/chifra/internal/monitors/validate.go | 4 +- .../chifra/internal/names/handle_autoname.go | 12 +- .../chifra/internal/names/handle_clean.go | 19 +- src/apps/chifra/internal/names/handle_crud.go | 12 +- src/apps/chifra/internal/names/handle_tags.go | 3 +- .../chifra/internal/names/handle_terms.go | 3 +- src/apps/chifra/internal/names/options.go | 16 +- src/apps/chifra/internal/names/output_test.go | 5 + .../chifra/internal/receipts/handle_show.go | 4 +- src/apps/chifra/internal/receipts/options.go | 15 ++ src/apps/chifra/internal/receipts/validate.go | 4 +- .../internal/scrape/handle_blaze_blaze.go | 9 +- .../chifra/internal/scrape/handle_prepare.go | 16 +- .../chifra/internal/scrape/handle_scrape.go | 16 +- .../internal/scrape/handle_scrape_blaze.go | 11 +- .../scrape/handle_scrape_consolidate.go | 24 +- src/apps/chifra/internal/scrape/options.go | 13 + src/apps/chifra/internal/scrape/validate.go | 11 +- src/apps/chifra/internal/slurp/handle_show.go | 4 +- src/apps/chifra/internal/slurp/options.go | 18 +- src/apps/chifra/internal/slurp/validate.go | 6 +- src/apps/chifra/internal/state/options.go | 24 +- src/apps/chifra/internal/state/validate.go | 10 +- .../internal/status/handle_show_item.go | 2 +- src/apps/chifra/internal/status/options.go | 13 + .../chifra/internal/status/types_status.go | 8 +- .../chifra/internal/tokens/handle_parts.go | 2 +- .../chifra/internal/tokens/handle_show.go | 2 +- src/apps/chifra/internal/tokens/options.go | 18 +- src/apps/chifra/internal/tokens/validate.go | 12 +- .../chifra/internal/traces/handle_counts.go | 11 +- .../chifra/internal/traces/handle_filter.go | 5 +- .../chifra/internal/traces/handle_show.go | 8 +- src/apps/chifra/internal/traces/options.go | 15 ++ src/apps/chifra/internal/traces/validate.go | 7 +- .../transactions/handle_accountfor.go | 7 +- .../internal/transactions/handle_decache.go | 14 +- .../internal/transactions/handle_logs.go | 6 +- .../internal/transactions/handle_show.go | 16 +- .../internal/transactions/handle_uniq.go | 17 +- .../chifra/internal/transactions/options.go | 18 +- .../chifra/internal/transactions/validate.go | 7 +- .../chifra/internal/when/handle_blocks.go | 9 +- src/apps/chifra/internal/when/handle_list.go | 4 +- .../chifra/internal/when/handle_ts_check.go | 15 +- .../chifra/internal/when/handle_ts_repair.go | 12 +- .../chifra/internal/when/handle_ts_show.go | 8 +- .../internal/when/handle_ts_truncate.go | 4 +- .../chifra/internal/when/handle_ts_update.go | 13 +- src/apps/chifra/internal/when/options.go | 15 ++ src/apps/chifra/internal/when/validate.go | 4 +- .../when/validate_integration_test.go | 5 + src/apps/chifra/pkg/abi/load_abi.go | 3 +- src/apps/chifra/pkg/account/state.go | 10 +- .../pkg/account/state_integration_test.go | 4 +- src/apps/chifra/pkg/identifiers/resolve.go | 19 +- src/apps/chifra/pkg/index/uniq_appearances.go | 6 +- .../pkg/index/uniq_appearances_details.go | 4 +- src/apps/chifra/pkg/ledger/ledger.go | 2 + src/apps/chifra/pkg/ledger/stmnt_from_app.go | 5 +- .../chifra/pkg/ledger/stmnt_from_traces.go | 3 +- src/apps/chifra/pkg/ledger/stmnt_from_tx.go | 7 +- src/apps/chifra/pkg/manifest/download.go | 3 +- src/apps/chifra/pkg/output/helpers/helpers.go | 4 +- src/apps/chifra/pkg/rpcClient/client.go | 24 +- .../pkg/rpcClient/client_integration_test.go | 18 +- src/apps/chifra/pkg/rpcClient/contract.go | 14 +- .../rpcClient/contract_integration_test.go | 15 +- src/apps/chifra/pkg/rpcClient/ens.go | 4 +- src/apps/chifra/pkg/rpcClient/get_block.go | 25 +- src/apps/chifra/pkg/rpcClient/get_log.go | 16 +- src/apps/chifra/pkg/rpcClient/get_meta.go | 6 +- .../rpcClient/get_meta_integration_test.go | 6 +- src/apps/chifra/pkg/rpcClient/get_receipt.go | 11 +- src/apps/chifra/pkg/rpcClient/get_traces.go | 44 ++-- .../chifra/pkg/rpcClient/get_transaction.go | 71 +++-- src/apps/chifra/pkg/rpcClient/get_uncle.go | 10 +- src/apps/chifra/pkg/rpcClient/is_archive.go | 5 +- src/apps/chifra/pkg/rpcClient/is_tracing.go | 2 +- src/apps/chifra/pkg/rpcClient/options.go | 51 ++-- src/apps/chifra/pkg/tslib/repair.go | 3 +- src/apps/chifra/pkg/tslib/tobn.go | 3 +- src/apps/chifra/pkg/tslib/todate.go | 5 +- .../chifra/pkg/validate/blockvalidate_test.go | 5 - src/apps/chifra/pkg/version/version_test.go | 4 +- src/dev_tools/makeClass/handle_gocmds.cpp | 2 + .../makeClass/templates/blank_options.go.tmpl | 13 +- src/examples/allContracts/allContracts.go | 10 +- src/examples/findFirst/findFirst.go | 14 +- src/examples/simple/simple.go | 4 +- 155 files changed, 1244 insertions(+), 568 deletions(-) diff --git a/go.work.sum b/go.work.sum index 82e5da7d86..b5da18eb39 100644 --- a/go.work.sum +++ b/go.work.sum @@ -268,11 +268,259 @@ collectd.org v0.3.0 h1:iNBHGw1VvPJxH2B6RiFWFZ+vsjo1lCdRszBeOuwGi00= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9 h1:VpgP7xuJadIUuKccphEpTJnWhS2jkQyMt6Y7pJCD7fY= github.com/Azure/azure-pipeline-go v0.2.2 h1:6oiIS9yaG6XCCzhgAgKFfIWyo4LLCiDhZot6ltoThhY= github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 h1:qoVeMsc9/fh/yhxVaA0obYjVH/oI/ihrOoMwsLS9KSA= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 h1:E+m3SkZCN0Bf5q7YdTs5lSm2CYY3CK4spn5OmUIiQtk= +github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0 h1:Px2UA+2RvSSvv+RvJNuUB6n7rs5Wsel4dXLe90Um2n4= +github.com/Azure/azure-storage-blob-go v0.7.0 h1:MuueVOYkufCxJw5YZzF842DY2MBsp+hLuh2apKY0mck= +github.com/Azure/go-autorest/autorest v0.9.0 h1:MRvx8gncNaXJqOoLmhNjUAKh33JJF8LyxPhomEtOsjs= +github.com/Azure/go-autorest/autorest/adal v0.8.0 h1:CxTzQrySOxDnKpLjFJeZAS5Qrv/qFPkgLjx5bOAi//I= +github.com/Azure/go-autorest/autorest/date v0.2.0 h1:yW+Zlqf26583pE43KhfnhFcdmSWlm5Ew6bxipnr/tbM= +github.com/Azure/go-autorest/autorest/mocks v0.3.0 h1:qJumjCaCudz+OcqE9/XtEPfvtOjOmKaui4EOpFI6zZc= +github.com/Azure/go-autorest/logger v0.1.0 h1:ruG4BSDXONFRrZZJ2GUXDiUyVpayPmb1GnWeHDdaNKY= +github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VYyQflFE619k= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOCMdNH+CiXJVYJh5UQNCOBG7jbELc= +github.com/DATA-DOG/go-sqlmock v1.3.3 h1:CWUqKXe0s8A2z6qCgkP4Kru7wC11YoAnoupUKFDnH08= +github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= +github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= +github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg= +github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af h1:wVe6/Ea46ZMeNkQjjBW6xcqyQA/j5e0D6GytH95g0gQ= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY= github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKSc= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= +github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg= +github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db h1:nxAtV4VajJDhKysp2kdcJZsq8Ss1xSA0vZTkVHHJd0E= +github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e h1:QEF07wC0T1rKkctt1RINW/+RMTVmiwxETico2l3gxJA= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZFFEjBj46YV4rDjvGrNxb0KMWYkL2I= +github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= +github.com/aws/aws-sdk-go-v2 v1.2.0 h1:BS+UYpbsElC82gB+2E2jiCBg36i8HlubTB/dO/moQ9c= +github.com/aws/aws-sdk-go-v2/config v1.1.1 h1:ZAoq32boMzcaTW9bcUacBswAmHTbvlvDJICgHFZuECo= +github.com/aws/aws-sdk-go-v2/credentials v1.1.1 h1:NbvWIM1Mx6sNPTxowHgS2ewXCRp+NGTzUYb/96FZJbY= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.2 h1:EtEU7WRaWliitZh2nmuxEXrN0Cb8EgPUFGIoTMeqbzI= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.2 h1:4AH9fFjUlVktQMznF+YN33aWNXaR4VgDXyP28qokJC0= +github.com/aws/aws-sdk-go-v2/service/route53 v1.1.1 h1:cKr6St+CtC3/dl/rEBJvlk7A/IN5D5F02GNkGzfbtVU= +github.com/aws/aws-sdk-go-v2/service/sso v1.1.1 h1:37QubsarExl5ZuCBlnRP+7l1tNwZPBSTqpTBrPH98RU= +github.com/aws/aws-sdk-go-v2/service/sts v1.1.1 h1:TJoIfnIFubCX0ACVeJ0w46HEH5MwjwYN4iFhuYIhfIY= +github.com/aws/smithy-go v1.1.0 h1:D6CSsM3gdxaGaqXnPgOBCeL6Mophqzu7KJOu7zW78sU= +github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= +github.com/bketelsen/crypt v0.0.4 h1:w/jqZtC9YD4DS/Vp9GhWfWcCpuAL58oTnLoI8vE9YHU= +github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40 h1:y4B3+GPxKlrigF1ha5FFErxK+sr6sWxQovRMzwMhejo= +github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= +github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo= +github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ= +github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw= +github.com/btcsuite/goleveldb v1.0.0 h1:Tvd0BfvqX9o823q1j2UZ/epQo09eJh6dTcRp79ilIN4= +github.com/btcsuite/snappy-go v1.0.0 h1:ZxaA6lo2EpxGddsA8JwWOcxlzRybb444sgmeJQMJGQE= +github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 h1:R8vQdOQdZ9Y3SkEwmHoWBmX1DNXhXZqlTpq6s4tyJGc= +github.com/btcsuite/winsvc v1.0.0 h1:J9B4L7e3oqhXOcm+2IuNApwzQec85lE+QaikUcCs+dk= +github.com/c-bata/go-prompt v0.2.2 h1:uyKRz6Z6DUyj49QVijyM339UJV9yhbr70gESwbNU3e0= +github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g= +github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= +github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI= +github.com/cloudflare/cloudflare-go v0.14.0 h1:gFqGlGl/5f9UGXAaKapCGUfaTCgRKKnzu2VvzMZlOFA= +github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe h1:QQ3GSy+MqSHxm/d8nCtnAiZdYFd45cYZPs8vOOIYKfk= +github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b h1:ACGZRIr7HsgBKHsueQ1yM4WaVaXh21ynwqsF8M8tXhA= +github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= +github.com/consensys/gnark-crypto v0.9.1-0.20230105202408-1a7a29904a7c h1:llSLg4o9EgH3SrXky+Q5BqEYqV76NGKo07K5Ps2pIKo= +github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= +github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI= +github.com/crate-crypto/go-ipa v0.0.0-20220523130400-f11357ae11c7 h1:6IrxszG5G+O7zhtkWxq6+unVvnrm1fqV2Pe+T95DUzw= +github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w= +github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c h1:/ovYnF02fwL0kvspmy9AuyKg1JhdTRUgPw4nUxd9oZM= +github.com/dave/jennifer v1.2.0 h1:S15ZkFMRoJ36mGAQgWL1tnr0NQJh9rZ8qatseX/VbBc= github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= +github.com/decred/dcrd/lru v1.0.0 h1:Kbsb1SFDsIlaupWPwsPp+dkxiBY1frcS07PCPgotKz8= +github.com/deepmap/oapi-codegen v1.8.2 h1:SegyeYGcdi0jLLrpbCMoJxnUUn8GBXHsvr4rbzjuhfU= +github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= +github.com/dgryski/go-bitstream v0.0.0-20180413035011-3522498ce2c8 h1:akOQj8IVgoeFfBTzGOEQakCYshWD6RNo1M5pivFXt70= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954 h1:RMLoZVzv4GliuWafOuPuQDKSm1SJph7uCRnnS61JAn4= +github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo= +github.com/docker/docker v1.6.2 h1:HlFGsy+9/xrgMmhmN+NGhCc5SHGJ7I+kHosRR1xc/aI= +github.com/dop251/goja v0.0.0-20230122112309-96b1610dd4f7 h1:kgvzE5wLsLa7XKfV85VZl40QXaMCaeFtHpPwJ8fhotY= +github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7 h1:tYwu/z8Y0NkkzGEh3z21mSWggMg4LwLRFucLS7TjARg= +github.com/eclipse/paho.mqtt.golang v1.2.0 h1:1F8mhG9+aO5/xpdtFkW4SxOJB67ukuDC3t2y2qayIX0= +github.com/envoyproxy/go-control-plane v0.10.3 h1:xdCVXxEe0Y3FQith+0cj2irwZudqGYvecuLB1HtdexY= +github.com/envoyproxy/protoc-gen-validate v0.9.1 h1:PS7VIOgmSVhWUEeZwTe7z7zouA22Cr590PzXKbZHOVY= +github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= +github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c h1:CndMRAH4JIwxbW8KYq6Q+cGWcGHz0FjGR3QqcInWcW0= +github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90 h1:WXb3TSNmHp2vHoCroCIB1foO/yQ36swABL8aOVeDpgg= +github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 h1:IZqZOB2fydHte3kUgxrzK5E1fW7RQGeDwE8F/ZZnUYc= +github.com/gballet/go-verkle v0.0.0-20220902153445-097bd83b7732 h1:AB7YjNrzlVHsYz06zCULVV2zYCEft82P86dSmtwxKL0= +github.com/getkin/kin-openapi v0.61.0 h1:6awGqF5nG5zkVpMsAih1QH4VgzS8phTxECUWIFo7zko= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= +github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd h1:r04MMPyLHj/QwZuMJ5+7tJcBr1AQjpiAK/rZWRrQT7o= +github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31 h1:gclg6gY70GLy3PbkQ1AERPfmLMMagS60DKF78eWwLn8= +github.com/go-chi/chi/v5 v5.0.0 h1:DBPx88FjZJH3FsICfDAfIfnb7XxKIYVGG6lOPlhENAg= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 h1:QbL/5oDUmRBzO9/Z7Seo6zf912W/a6Sr4Eu0G/3Jho0= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4 h1:WtGNWLvXpe6ZudgnXrq0barxBImvnnJoMEhXAzcbM0I= +github.com/go-kit/kit v0.9.0 h1:wDJmvq38kDhkVxi50ni9ykkdUr1PKgqKOoi01fa0Mdk= +github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA= +github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= +github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY= +github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU= +github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= +github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA= +github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= +github.com/golang/geo v0.0.0-20190916061304-5b978397cfec h1:lJwO/92dFXWeXOZdoGXgptLmNLwynMSHUmU6besqtiw= +github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219 h1:utua3L2IbQJmauC5IXdEA547bcoU5dozgQAfc8Onsg4= +github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= +github.com/google/flatbuffers v1.11.0 h1:O7CEyB8Cb3/DmtxODGtLHcEvpr81Jm5qLg/hsHnxA2A= +github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa h1:Q75Upo5UN4JbPFURXZ8nLKYUvF85dyFRop/vQ0Rv+64= +github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no= +github.com/google/martian/v3 v3.2.1 h1:d8MncMlErDFTwQGBK1xhv026j9kqhvw1Qv9IbWT1VLQ= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= +github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA= +github.com/googleapis/gax-go/v2 v2.1.0 h1:6DWmvNpomjL1+3liNSZbVns3zsYzzCjm6pRBO1tLeso= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/graph-gophers/graphql-go v1.3.0 h1:Eb9x/q6MFpCLz7jBCiP/WTxjSDrYLR1QY41SORZyNJ0= +github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= +github.com/hashicorp/consul/api v1.10.1 h1:MwZJp86nlnL+6+W1Zly4JUuVn9YHhMggBirMpHGD7kw= +github.com/hashicorp/consul/sdk v0.8.0 h1:OJtKBtEjboEZvG6AOUdh4Z1Zbyu0WcxQ0qatRrZHTVU= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= +github.com/hashicorp/go-hclog v0.12.0 h1:d4QkX8FRTYaKaCZBoXYY8zJX2BXjWxurN/GA2tkrmZM= +github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= +github.com/hashicorp/go-msgpack v0.5.3 h1:zKjpN5BK/P5lMYrLmBHdBULWbJ0XpYR+7NGzqkZzoD4= +github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI= +github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc= +github.com/hashicorp/go-sockaddr v1.0.0 h1:GeH6tui99pF4NJgfnhp+L6+FfobzVW3Ah46sLo0ICXs= +github.com/hashicorp/go-syslog v1.0.0 h1:KaodqZuhUoZereWVIYmpUgZysurB1kBLX2j0MwMrUAE= +github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE= +github.com/hashicorp/go.net v0.0.1 h1:sNCoNyDEvN1xa+X0baata4RdcpKwcMS6DH+xwfqPgjw= +github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d h1:dg1dEPuWpEqDnvIw251EVy4zlP8gWbsGj4BsUKCRpYs= +github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= +github.com/hashicorp/mdns v1.0.1 h1:XFSOubp8KWB+Jd2PDyaX5xUd5bhSP/+pTDZVDMzZJM8= +github.com/hashicorp/memberlist v0.2.2 h1:5+RffWKwqJ71YPu9mWsF7ZOscZmwfasdA8kbdC7AO2g= +github.com/hashicorp/serf v0.9.5 h1:EBWvyu9tcRszt3Bxp3KNssBMP1KuHWyO51lz9+786iM= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= +github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150 h1:vlNjIqmUZ9CMAWsbURYl3a6wZbw7q5RHVvlXTNS/Bs8= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639 h1:mV02weKRL81bEnm8A0HT1/CAelMQDBuQIfLw8n+d6xI= +github.com/influxdata/flux v0.65.1 h1:77BcVUCzvN5HMm8+j9PRBQ4iZcu98Dl4Y9rf+J5vhnc= +github.com/influxdata/influxdb v1.8.3 h1:WEypI1BQFTT4teLM+1qkEcvUi0dAvopAI/ir0vAiBg8= +github.com/influxdata/influxdb-client-go/v2 v2.4.0 h1:HGBfZYStlx3Kqvsv1h2pJixbCl/jhnFtxpKFAv9Tu5k= +github.com/influxdata/influxql v1.1.1-0.20200828144457-65d3ef77d385 h1:ED4e5Cc3z5vSN2Tz2GkOHN7vs4Sxe2yds6CXvDnvZFE= +github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 h1:vilfsDSy7TDxedi9gyBkMvAirat/oRcL0lFdJBf6tdM= +github.com/influxdata/promql/v2 v2.12.0 h1:kXn3p0D7zPw16rOtfDR+wo6aaiH8tSMfhPwONTxrlEc= +github.com/influxdata/roaring v0.4.13-0.20180809181101-fc520f41fab6 h1:UzJnB7VRL4PSkUJHwsyzseGOmrO/r4yA+AuxGJxiZmA= +github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9 h1:MHTrDWmQpHq/hkq+7cw9oYAt2PqUw52TZazRA0N7PGE= +github.com/influxdata/usage-client v0.0.0-20160829180054-6d3895376368 h1:+TUUmaFa4YD1Q+7bH9o5NCHQGPMqZCYJiNW6lIIS9z4= +github.com/ipfs/go-ipfs-util v0.0.2 h1:59Sswnk1MFaiq+VcaknX7aYEyGyGDAA73ilhEK2POp8= +github.com/jbenet/go-cienv v0.1.0 h1:Vc/s0QbQtoxX8MwwSLWWh+xNNZvM3Lw7NsTcHrvvhMc= +github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0o= +github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e h1:UvSe12bq+Uj2hWd8aOlwPmoZ+CITRFrdit+sDGfAg8U= +github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= +github.com/jrick/logrotate v1.0.0 h1:lQ1bL/n9mBNeIXoTUoYRlK4dHuNJVofX9oWqBtPnSzI= +github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ= +github.com/jstemmer/go-junit-report v0.9.1 h1:6QPYqodiu3GuPL+7mfx+NwDdp2eTkp9IfEUpgAwUN0o= +github.com/jsternberg/zap-logfmt v1.0.0 h1:0Dz2s/eturmdUS34GM82JwNEdQ9hPoJgqptcEKcbpzY= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= +github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5 h1:PJr+ZMXIecYc1Ey2zucXdR73SMBtgjPgwa31099IMv0= +github.com/jwilder/encoding v0.0.0-20170811194829-b4e1701a28ef h1:2jNeR4YUziVtswNP9sEFAI913cVrzH85T+8Q6LpYbT0= +github.com/karalabe/usb v0.0.2 h1:M6QQBNxF+CQ8OFvxrT90BA0qBOXymndZnk5q235mFc4= +github.com/kisielk/errcheck v1.5.0 h1:e8esj/e4R+SAOwFwN+n3zr0nYeCyeweozKfO23MvHzY= +github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= +github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23 h1:FOOIBWrEkLgmlgGfMuZT83xIwfPDxEI2OHu6xUmJMFE= github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5 h1:2U0HzY8BJ8hVwDKIzp7y4voR9CX/nvcfymLmg2UiOio= +github.com/klauspost/crc32 v0.0.0-20161016154125-cb6bfca970f6 h1:KAZ1BW2TCmT6PRihDPpocIy1QTtsAsrx6TneU/4+CMg= +github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada h1:3L+neHp83cTjegPdCiOxVOJtRIy7/8RldvMTsyPYH10= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= +github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY= +github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= +github.com/labstack/echo/v4 v4.2.1 h1:LF5Iq7t/jrtUuSutNuiEWtB5eiHfZ5gSe2pcu5exjQw= +github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0= +github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= +github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A= +github.com/libp2p/go-msgio v0.0.6 h1:lQ7Uc0kS1wb1EfRxO2Eir/RJoHkHn7t6o+EiwsYIKJA= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8= +github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd h1:HvFwW+cm9bCbZ/+vuGNq7CRWXql8c0y8nGeYpqmpvmk= +github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d h1:oNAwILwmgWKFpuU+dXvI6dl9jG2mAWAZLX3r9s0PPiw= +github.com/mattn/go-sqlite3 v1.11.0 h1:LDdKkqtYlom37fkvqs8rMPFKAMe8+SgjbwZ6ex1/A/Q= +github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104 h1:d8RFOZ2IiFtFWBcKEHAFYJcPTf0wY5q0exFNJZVWa1U= +github.com/miekg/dns v1.1.26 h1:gPxPSwALAeHJSjarOs00QjVdV9QoBvc1D2ujQUr5BzU= +github.com/mitchellh/cli v1.1.0 h1:tEElEatulEHDeedTxwckzyYMA5c86fbmNIUL1hBIiTg= +github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdIPrefOvVG1VZ96U0= +github.com/mitchellh/gox v0.4.0 h1:lfGJxY7ToLJQjHHwi0EX6uYBdK78egf954SQl13PQJc= +github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY= +github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= +github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae h1:VeRdUYdCw49yizlSbMEn2SZ+gT+3IUKx8BqxyQdz+BY= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223 h1:F9x/1yl3T2AeKLr2AMdilSD8+f9bvMnNN8VS5iDtovc= +github.com/naoina/go-stringutil v0.1.0 h1:rCUeRUHjBjGTSHl0VC00jUPLz8/F9dDzYI70Hzifhks= +github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416 h1:shk/vn9oCoOTmwcouEdwIeOtOGA/ELRUw/GwvxwfT+0= github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= +github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= +github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c h1:Lgl0gzECD8GnQ5QCWA8o6BtfL6mDH5rQgM4/fX3avOs= +github.com/paulbellamy/ratecounter v0.2.0 h1:2L/RhJq+HA8gBQImDXtLPrDXK5qAj6ozWVK/zFXVJGs= +github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQmzR3rNLYGGz4g/UgFcjb28p/viDM= +github.com/philhofer/fwd v1.0.0 h1:UbZqGr5Y38ApvM/V/jEljVxwocdweyH+vmYvRPBnbqQ= +github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I= +github.com/pkg/sftp v1.10.1 h1:VasscCm72135zRysgrJDKsntdmPN+OuU3+nnHYA9wyc= +github.com/pkg/term v0.0.0-20180730021639-bffc007b7fd5 h1:tFwafIEMf0B7NlcxV/zJ6leBIa81D3hgGSgsE5hCkOQ= +github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= +github.com/prometheus/tsdb v0.10.0 h1:If5rVCMTp6W2SiRAQFlbpJNgVlgMEd+U2GZckwK38ic= +github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52 h1:RnWNS9Hlm8BIkjr6wx8li5abe0fr73jljLycdfemTp0= +github.com/rjeczalik/notify v0.9.2 h1:MiTWrPj55mNDHEiIX5YUSKefw/+lCQVoAFmD6oQm5w8= +github.com/rogpeppe/fastuuid v1.2.0 h1:Ppwyp6VYCF1nvBTXL3trRso7mXMlRrw9ooo375wvi2s= +github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f h1:UFr9zpz4xgTnIE5yIMtWAMngCdZ9p/+q6lTbgelo80M= +github.com/sagikazarmark/crypt v0.1.0 h1:AyO7PGna28P9TMH93Bsxd7m9QC4xE6zyGQTXCo7ZrA8= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I= +github.com/segmentio/kafka-go v0.2.0 h1:HtCSf6B4gN/87yc5qTl7WsxPKQIIGXLPPM1bMCPOsoY= +github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= +github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= +github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= +github.com/supranational/blst v0.3.8-0.20220526154634-513d2456b344 h1:m+8fKfQwCAy1QjzINvKe/pYtLjo2dl59x2w9YSEJxuY= +github.com/tinylib/msgp v1.0.2 h1:DfdQrzQa7Yh2es9SuLkixqxuXS2SxsdYn0KbdrOGWD8= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4= +github.com/willf/bitset v1.1.3 h1:ekJIKh6+YbUIVt9DfNbkR5d6aFcFTLDRyJNAACURBg8= +github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6 h1:YdYsPAZ2pC6Tow/nPZOPQ96O3hm/ToAkGsPLzedXERk= +github.com/yuin/goldmark v1.3.5 h1:dPmz1Snjq0kmkz159iL7S6WzdahUTHnHB5M56WFVifs= +go.etcd.io/etcd/api/v3 v3.5.0 h1:GsV3S+OfZEOCNXdtNkBSR7kgLobAa/SO6tCxRa0GAYw= +go.etcd.io/etcd/client/pkg/v3 v3.5.0 h1:2aQv6F436YnN7I4VbI8PPYrBhu+SmrTaADcf8Mi/6PU= +go.etcd.io/etcd/client/v2 v2.305.0 h1:ftQ0nOOHMcbMS3KIaDQ0g5Qcd6bhaBrQT6b89DfwLTs= +go.opentelemetry.io/proto/otlp v0.7.0 h1:rwOQPCuKAKmwGKq2aVNnYIibI6wnV7EvzgfTCzcdGg8= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= +go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= +go.uber.org/zap v1.17.0 h1:MTjgFu6ZLKvY6Pvaqk97GlxNBuMpV4Hy/3P6tRGlI2U= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 h1:4+4C/Iv2U4fMZBiMCc98MG1In4gJY5YRhtpDNeDeHWs= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/oauth2 v0.4.0 h1:NF0gk8LVPg1Ml7SSbGyySuoxdsXitj7TvgvuRxIMc/M= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df h1:5Pf6pFKu98ODmgnpvkJ3kFUOQGGLIzLIkbzUHp47618= +gonum.org/v1/gonum v0.6.0 h1:DJy6UzXbahnGUf1ujUNkh/NEtK14qMo2nvlBPs4U5yw= +gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0 h1:OE9mWmgKkjJyEmDAAtGMPjXu+YNeGvK9VTSHY6+Qihc= +gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b h1:Qh4dB5D/WpoUUp3lSod7qgoyEHbDGPUWjIbnqdqqe1k= +google.golang.org/api v0.56.0 h1:08F9XVYTLOGeSQb3xI9C0gXMuQanhdGed0cWFhDozbI= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 h1:M1YKkFIboKNieVO5DLUEVzQfGwJD30Nv2jfUgzb5UcE= +gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= +gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= +gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6 h1:a6cXbcDDUkSBlpnkWV1bJ+vv3mOgQEltEJ2rPxroVu0= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= +honnef.co/go/tools v0.1.3 h1:qTakTkI6ni6LFD5sBwwsdSO+AQqbSIxOauHTTQKZ/7o= +rsc.io/binaryregexp v0.2.0 h1:HfqmD5MEmC0zvwBuF187nq9mdnXjXsSivRiXN7SmRkE= +rsc.io/pdf v0.1.1 h1:k1MczvYDUvJBe93bYd7wrZLLUEcLZAuF824/I4e5Xr4= +rsc.io/quote/v3 v3.1.0 h1:9JKUTTIUgS6kzR9mK1YuGKv6Nl+DijDNIc0ghT58FaY= +rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4= +rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= diff --git a/src/apps/chifra/internal/abis/handle_addresses.go b/src/apps/chifra/internal/abis/handle_addresses.go index 48e4501814..30905fff20 100644 --- a/src/apps/chifra/internal/abis/handle_addresses.go +++ b/src/apps/chifra/internal/abis/handle_addresses.go @@ -15,9 +15,11 @@ import ( ) func (opts *AbisOptions) HandleAddresses() (err error) { + chain := opts.Globals.Chain + result := make(abi.AbiInterfaceMap) if opts.Known { - if err = abi.PreloadKnownAbis(opts.Globals.Chain, result); err != nil { + if err = abi.PreloadKnownAbis(chain, result); err != nil { return } } @@ -27,14 +29,14 @@ func (opts *AbisOptions) HandleAddresses() (err error) { // Note here, that known ABIs are not downloaded. They are only loaded from the local cache. for _, addr := range opts.Addrs { address := base.HexToAddress(addr) - if err = abi.LoadAbiFromAddress(opts.Globals.Chain, address, result); err != nil { + if err = abi.LoadAbiFromAddress(chain, address, result); err != nil { if !os.IsNotExist(err) { // The error was not due to a missing file... errorChan <- err cancel() } // Let's try to download the file from somewhere - if err := rpcClient.IsContractAt(opts.Globals.Chain, address, nil); err != nil { + if err := opts.Conn.IsContractAt(chain, address, nil); err != nil { if !errors.Is(err, rpcClient.ErrNotAContract) { errorChan <- err cancel() @@ -45,7 +47,7 @@ func (opts *AbisOptions) HandleAddresses() (err error) { } } else { // It's okay to not find the ABI. We report an error, but do not stop processing - if err = abi.DownloadAbi(opts.Globals.Chain, address, result); err != nil { + if err = abi.DownloadAbi(chain, address, result); err != nil { errorChan <- err } } diff --git a/src/apps/chifra/internal/abis/handle_clean.go b/src/apps/chifra/internal/abis/handle_clean.go index 9a15e093fb..fd1bdd0764 100644 --- a/src/apps/chifra/internal/abis/handle_clean.go +++ b/src/apps/chifra/internal/abis/handle_clean.go @@ -17,6 +17,8 @@ import ( ) func (opts *AbisOptions) HandleClean() error { + chain := opts.Globals.Chain + if opts.Globals.IsApiMode() { return fmt.Errorf("clean is not supported in API mode") } @@ -25,14 +27,14 @@ func (opts *AbisOptions) HandleClean() error { // TODO: This code is not actually used // filenameChan := make(chan cache.CacheFileInfo) // var nRoutines int = 1 - // go cache.WalkCacheFolder(context.Background(), opts.Globals.Chain, cache.Cache_Abis, nil, filenameChan) + // go cache.WalkCacheFolder(context.Background(), chain, cache.Cache_Abis, nil, filenameChan) // for result := range filenameChan { // switch result.Type { // case cache.Cache_Abis: // skip := !cache.IsCacheType(result.Path, cache.Cache_Abis, true /* checkExt */) // if !skip { // if file.FileSize(result.Path) == 0 { - // logger.Info("Removing empty abi: "+strings.Replace(result.Path, config.GetPathToCache(opts.Globals.Chain)+"abis/", "", -1), file.FileSize(result.Path)) + // logger.Info("Removing empty abi: "+strings.Replace(result.Path, config.GetPathToCache(chain)+"abis/", "", -1), file.FileSize(result.Path)) // // if err := cleanOneAbi(result.Path, ""); err != nil { // // return err // // } @@ -47,7 +49,7 @@ func (opts *AbisOptions) HandleClean() error { // } } else { for _, addr := range opts.Addrs { - if err := cleanOneAbi(config.GetPathToCache(opts.Globals.Chain)+"abis/", addr); err != nil { + if err := cleanOneAbi(config.GetPathToCache(chain)+"abis/", addr); err != nil { return err } } diff --git a/src/apps/chifra/internal/abis/options.go b/src/apps/chifra/internal/abis/options.go index 13190bd7eb..becebff703 100644 --- a/src/apps/chifra/internal/abis/options.go +++ b/src/apps/chifra/internal/abis/options.go @@ -29,6 +29,7 @@ type AbisOptions struct { Clean bool `json:"clean,omitempty"` // Remove an abi file for an address or all zero-length files if no address is given Sol bool `json:"sol,omitempty"` // Please use the `solc --abi` tool instead Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -44,6 +45,7 @@ func (opts *AbisOptions) testLog() { logger.TestLog(len(opts.Hint) > 0, "Hint: ", opts.Hint) logger.TestLog(len(opts.Encode) > 0, "Encode: ", opts.Encode) logger.TestLog(opts.Clean, "Clean: ", opts.Clean) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -84,14 +86,19 @@ func abisFinishParseApi(w http.ResponseWriter, r *http.Request) *AbisOptions { opts.Sol = true default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "abis") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE - opts.Addrs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Addrs) + opts.Addrs, _ = opts.Conn.GetAddressesFromEns(chain, opts.Addrs) // EXISTING_CODE return opts @@ -102,15 +109,20 @@ func abisFinishParse(args []string) *AbisOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE if opts.Globals.IsApiMode() { defFmt = "json" } - opts.Addrs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, args) + opts.Addrs, _ = opts.Conn.GetAddressesFromEns(chain, args) // EXISTING_CODE if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/blocks/handle_count.go b/src/apps/chifra/internal/blocks/handle_count.go index 2966c91706..05a8cdb793 100644 --- a/src/apps/chifra/internal/blocks/handle_count.go +++ b/src/apps/chifra/internal/blocks/handle_count.go @@ -16,20 +16,20 @@ import ( ) func (opts *BlocksOptions) HandleCounts() error { - rpcOptions := rpcClient.DefaultRpcOptions(&rpcClient.DefaultRpcOptionsSettings{ - Chain: opts.Globals.Chain, + chain := opts.Globals.Chain + settings := rpcClient.DefaultRpcOptionsSettings{ + Chain: chain, Opts: opts, - }) + } + opts.Conn = settings.DefaultRpcOptions() // TODO: Why does this have to dirty the caller? // If the cache is writeable, fetch the latest block timestamp so that we never // cache pending blocks - if !rpcOptions.Store.ReadOnly() { - rpcOptions.LatestBlockTimestamp = rpcClient.GetBlockTimestamp(opts.Globals.Chain, nil) + if !opts.Conn.Store.ReadOnly() { + opts.Conn.LatestBlockTimestamp = opts.Conn.GetBlockTimestamp(chain, nil) } - chain := opts.Globals.Chain - ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { for _, br := range opts.BlockIds { @@ -45,7 +45,7 @@ func (opts *BlocksOptions) HandleCounts() error { for _, bn := range blockNums { var block types.SimpleBlock[string] - if block, err = rpcClient.GetBlockHeaderByNumber(chain, bn, rpcClient.NoOptions); err != nil { + if block, err = opts.Conn.GetBlockHeaderByNumber(chain, bn); err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { continue @@ -61,7 +61,7 @@ func (opts *BlocksOptions) HandleCounts() error { } if opts.Uncles { - if blockCount.UnclesCnt, err = rpcClient.GetCountUnclesInBlock(chain, bn); err != nil { + if blockCount.UnclesCnt, err = opts.Conn.GetCountUnclesInBlock(chain, bn); err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { continue @@ -72,7 +72,7 @@ func (opts *BlocksOptions) HandleCounts() error { } if opts.Traces { - if blockCount.TracesCnt, err = rpcClient.GetCountTracesInBlock(chain, bn); err != nil { + if blockCount.TracesCnt, err = opts.Conn.GetCountTracesInBlock(chain, bn); err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { continue @@ -83,7 +83,7 @@ func (opts *BlocksOptions) HandleCounts() error { } if opts.Logs { - if blockCount.LogsCnt, err = rpcClient.GetCountLogsInBlock(chain, bn); err != nil { + if blockCount.LogsCnt, err = opts.Conn.GetCountLogsInBlock(chain, bn); err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { continue @@ -100,8 +100,8 @@ func (opts *BlocksOptions) HandleCounts() error { } addrMap := make(index.AddressBooleanMap) - ts := rpcClient.GetBlockTimestamp(chain, &bn) - if err := opts.ProcessBlockUniqs(chain, countFunc, bn, addrMap, ts, rpcOptions); err != nil { + ts := opts.Conn.GetBlockTimestamp(chain, &bn) + if err := opts.ProcessBlockUniqs(chain, countFunc, bn, addrMap, ts); err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { continue diff --git a/src/apps/chifra/internal/blocks/handle_decache.go b/src/apps/chifra/internal/blocks/handle_decache.go index e1e4603a18..ddd28d82be 100644 --- a/src/apps/chifra/internal/blocks/handle_decache.go +++ b/src/apps/chifra/internal/blocks/handle_decache.go @@ -15,18 +15,17 @@ import ( ) func (opts *BlocksOptions) HandleDecache() error { - rpcOptions := rpcClient.DefaultRpcOptions(&rpcClient.DefaultRpcOptionsSettings{ - Chain: opts.Globals.Chain, - ReadonlyCache: true, - }) + chain := opts.Globals.Chain + opts.Conn = rpcClient.NewReadOnlyConnection(chain) + toRemove := make([]cacheNew.Locator, 0) for _, br := range opts.BlockIds { - blockNums, err := br.ResolveBlocks(opts.Globals.Chain) + blockNums, err := br.ResolveBlocks(chain) if err != nil { return err } for _, bn := range blockNums { - rawBlock, err := rpcClient.GetBlockBodyByNumber(opts.Globals.Chain, bn, rpcOptions) + rawBlock, err := opts.Conn.GetBlockBodyByNumber(chain, bn) if err != nil { return err } @@ -64,7 +63,7 @@ func (opts *BlocksOptions) HandleDecache() error { return true } - rpcOptions.Store.Decache(toRemove, processorFunc) + opts.Conn.Store.Decache(toRemove, processorFunc) if itemsSeen == 0 { logger.Info("No items matching the query were found in the cache.", strings.Repeat(" ", 60)) @@ -77,12 +76,12 @@ func (opts *BlocksOptions) HandleDecache() error { // TODO: Review then remove // pairs := []base.Pair[uint32,uint32]{} // for _, br := range opts.BlockIds { - // blockNums, err := br.ResolveBlocks(opts.Globals.Chain) + // blockNums, err := br.ResolveBlocks(chain) // if err != nil { // return err // } // for _, bn := range blockNums { - // rawBlock, err := rpcClient.GetBlockBodyByNumber(opts.Globals.Chain, bn, nil) + // rawBlock, err := rpcOptions.GetBlockBodyByNumber(chain, bn) // if err != nil { // return err // } @@ -123,7 +122,7 @@ func (opts *BlocksOptions) HandleDecache() error { // } // caches := []string{"blocks", "txs", "traces"} - // if cont, err := cache.DecacheItems(opts.Globals.Chain, "", processorFunc, caches, pairs); err != nil || !cont { + // if cont, err := cache.DecacheItems(chain, "", processorFunc, caches, pairs); err != nil || !cont { // return err // } diff --git a/src/apps/chifra/internal/blocks/handle_list.go b/src/apps/chifra/internal/blocks/handle_list.go index 84892aac6d..afa586015c 100644 --- a/src/apps/chifra/internal/blocks/handle_list.go +++ b/src/apps/chifra/internal/blocks/handle_list.go @@ -9,16 +9,15 @@ import ( "errors" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/ethereum/go-ethereum" ) func (opts *BlocksOptions) HandleList() error { - var rpcOptions = rpcClient.NoOptions + chain := opts.Globals.Chain // Don't do this in the loop - meta, err := rpcClient.GetMetaData(opts.Globals.Chain, opts.Globals.TestMode) + meta, err := opts.Conn.GetMetaData(chain, opts.Globals.TestMode) if err != nil { return err } @@ -34,7 +33,7 @@ func (opts *BlocksOptions) HandleList() error { ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawBlock], errorChan chan error) { for bn := start; bn > end; bn-- { - block, err := rpcClient.GetBlockHeaderByNumber(opts.Globals.Chain, bn, rpcOptions) + block, err := opts.Conn.GetBlockHeaderByNumber(chain, bn) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { diff --git a/src/apps/chifra/internal/blocks/handle_logs.go b/src/apps/chifra/internal/blocks/handle_logs.go index adffd49959..781b3bccfe 100644 --- a/src/apps/chifra/internal/blocks/handle_logs.go +++ b/src/apps/chifra/internal/blocks/handle_logs.go @@ -12,7 +12,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/articulate" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/ethereum/go-ethereum" ) @@ -54,7 +53,7 @@ func (opts *BlocksOptions) HandleLogs() error { errorChan <- errors.New("TESTING_ONLY_filter" + fmt.Sprintf("%+v", logFilter)) } - logs, err := rpcClient.GetLogsByFilter(chain, logFilter) + logs, err := opts.Conn.GetLogsByFilter(chain, logFilter) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { diff --git a/src/apps/chifra/internal/blocks/handle_show.go b/src/apps/chifra/internal/blocks/handle_show.go index 044c329275..d8283cac9e 100644 --- a/src/apps/chifra/internal/blocks/handle_show.go +++ b/src/apps/chifra/internal/blocks/handle_show.go @@ -15,22 +15,24 @@ import ( ) func (opts *BlocksOptions) HandleShowBlocks() error { - rpcOptions := rpcClient.DefaultRpcOptions(&rpcClient.DefaultRpcOptionsSettings{ - Chain: opts.Globals.Chain, + chain := opts.Globals.Chain + settings := rpcClient.DefaultRpcOptionsSettings{ + Chain: chain, Opts: opts, - }) + } + opts.Conn = settings.DefaultRpcOptions() // TODO: Why does this have to dirty the caller? // If the cache is writeable, fetch the latest block timestamp so that we never // cache pending blocks - if !rpcOptions.Store.ReadOnly() { - rpcOptions.LatestBlockTimestamp = rpcClient.GetBlockTimestamp(opts.Globals.Chain, nil) + if !opts.Conn.Store.ReadOnly() { + opts.Conn.LatestBlockTimestamp = opts.Conn.GetBlockTimestamp(chain, nil) } ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawBlock], errorChan chan error) { for _, br := range opts.BlockIds { - blockNums, err := br.ResolveBlocks(opts.Globals.Chain) + blockNums, err := br.ResolveBlocks(chain) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { @@ -46,11 +48,11 @@ func (opts *BlocksOptions) HandleShowBlocks() error { var err error if !opts.Hashes { var b types.SimpleBlock[types.SimpleTransaction] - b, err = rpcClient.GetBlockBodyByNumber(opts.Globals.Chain, bn, rpcOptions) + b, err = opts.Conn.GetBlockBodyByNumber(chain, bn) block = &b } else { var b types.SimpleBlock[string] - b, err = rpcClient.GetBlockHeaderByNumber(opts.Globals.Chain, bn, rpcOptions) + b, err = opts.Conn.GetBlockHeaderByNumber(chain, bn) block = &b } diff --git a/src/apps/chifra/internal/blocks/handle_traces.go b/src/apps/chifra/internal/blocks/handle_traces.go index 04fca8aeea..83e71be99b 100644 --- a/src/apps/chifra/internal/blocks/handle_traces.go +++ b/src/apps/chifra/internal/blocks/handle_traces.go @@ -9,14 +9,12 @@ import ( "errors" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/ethereum/go-ethereum" ) func (opts *BlocksOptions) HandleTraces() error { chain := opts.Globals.Chain - ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawTrace], errorChan chan error) { for _, br := range opts.BlockIds { @@ -32,7 +30,7 @@ func (opts *BlocksOptions) HandleTraces() error { for _, bn := range blockNums { var traces []types.SimpleTrace - traces, err = rpcClient.GetTracesByNumber(chain, bn) + traces, err = opts.Conn.GetTracesByNumber(chain, bn) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { diff --git a/src/apps/chifra/internal/blocks/handle_uncles.go b/src/apps/chifra/internal/blocks/handle_uncles.go index 412c3e4102..723cdd8716 100644 --- a/src/apps/chifra/internal/blocks/handle_uncles.go +++ b/src/apps/chifra/internal/blocks/handle_uncles.go @@ -15,12 +15,17 @@ import ( ) func (opts *BlocksOptions) HandleUncles() error { - var rpcOptions = rpcClient.NoOptions + chain := opts.Globals.Chain + settings := rpcClient.DefaultRpcOptionsSettings{ + Chain: chain, + Opts: opts, + } + opts.Conn = settings.DefaultRpcOptions() ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawBlock], errorChan chan error) { for _, br := range opts.BlockIds { - blockNums, err := br.ResolveBlocks(opts.Globals.Chain) + blockNums, err := br.ResolveBlocks(chain) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { @@ -36,11 +41,11 @@ func (opts *BlocksOptions) HandleUncles() error { var err error if !opts.Hashes { var b types.SimpleBlock[types.SimpleTransaction] - b, err = rpcClient.GetBlockBodyByNumber(opts.Globals.Chain, bn, rpcOptions) + b, err = opts.Conn.GetBlockBodyByNumber(chain, bn) block = &b } else { var b types.SimpleBlock[string] - b, err = rpcClient.GetBlockHeaderByNumber(opts.Globals.Chain, bn, rpcOptions) + b, err = opts.Conn.GetBlockHeaderByNumber(chain, bn) block = &b } diff --git a/src/apps/chifra/internal/blocks/handle_uniq.go b/src/apps/chifra/internal/blocks/handle_uniq.go index c7faa08dd4..2a23088aa2 100644 --- a/src/apps/chifra/internal/blocks/handle_uniq.go +++ b/src/apps/chifra/internal/blocks/handle_uniq.go @@ -9,7 +9,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/names" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" "github.com/ethereum/go-ethereum" @@ -17,15 +16,12 @@ import ( func (opts *BlocksOptions) HandleUniq() (err error) { chain := opts.Globals.Chain - rpcOptions := rpcClient.DefaultRpcOptions(&rpcClient.DefaultRpcOptionsSettings{ - Chain: chain, - }) // TODO: Why does this have to dirty the caller? // If the cache is writeable, fetch the latest block timestamp so that we never // cache pending blocks - if !rpcOptions.Store.ReadOnly() { - rpcOptions.LatestBlockTimestamp = rpcClient.GetBlockTimestamp(opts.Globals.Chain, nil) + if !opts.Conn.Store.ReadOnly() { + opts.Conn.LatestBlockTimestamp = opts.Conn.GetBlockTimestamp(chain, nil) } ctx, cancel := context.WithCancel(context.Background()) @@ -36,7 +32,7 @@ func (opts *BlocksOptions) HandleUniq() (err error) { } for _, br := range opts.BlockIds { - blockNums, err := br.ResolveBlocks(opts.Globals.Chain) + blockNums, err := br.ResolveBlocks(chain) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { @@ -51,8 +47,8 @@ func (opts *BlocksOptions) HandleUniq() (err error) { logger.Info("Processing block", fmt.Sprintf("%d", bn)) } addrMap := make(index.AddressBooleanMap) - ts := rpcClient.GetBlockTimestamp(chain, &bn) - if err := opts.ProcessBlockUniqs(chain, procFunc, bn, addrMap, ts, rpcOptions); err != nil { + ts := opts.Conn.GetBlockTimestamp(chain, &bn) + if err := opts.ProcessBlockUniqs(chain, procFunc, bn, addrMap, ts); err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { continue @@ -70,9 +66,9 @@ func (opts *BlocksOptions) HandleUniq() (err error) { return output.StreamMany(ctx, fetchData, opts.Globals.OutputOptsWithExtra(extra)) } -func (opts *BlocksOptions) ProcessBlockUniqs(chain string, procFunc index.UniqProcFunc, bn uint64, addrMap index.AddressBooleanMap, ts int64, rpcOptions *rpcClient.Options) error { +func (opts *BlocksOptions) ProcessBlockUniqs(chain string, procFunc index.UniqProcFunc, bn uint64, addrMap index.AddressBooleanMap, ts int64) error { if bn == 0 { - if namesArray, err := names.LoadNamesArray(opts.Globals.Chain, names.Prefund, names.SortByAddress, []string{}); err != nil { + if namesArray, err := names.LoadNamesArray(chain, names.Prefund, names.SortByAddress, []string{}); err != nil { return err } else { for i, name := range namesArray { @@ -82,7 +78,7 @@ func (opts *BlocksOptions) ProcessBlockUniqs(chain string, procFunc index.UniqPr } } else { - if block, err := rpcClient.GetBlockBodyByNumber(chain, bn, rpcOptions); err != nil { + if block, err := opts.Conn.GetBlockBodyByNumber(chain, bn); err != nil { return err } else { miner := block.Miner.Hex() @@ -95,7 +91,7 @@ func (opts *BlocksOptions) ProcessBlockUniqs(chain string, procFunc index.UniqPr } index.StreamAppearance(procFunc, opts.Flow, "miner", miner, bn, txid, utils.NOPOS, ts, addrMap) - if uncles, err := rpcClient.GetUnclesByNumber(chain, bn); err != nil { + if uncles, err := opts.Conn.GetUnclesByNumber(chain, bn); err != nil { return err } else { for _, uncle := range uncles { @@ -112,10 +108,10 @@ func (opts *BlocksOptions) ProcessBlockUniqs(chain string, procFunc index.UniqPr } for _, trans := range block.Transactions { - if trans.Traces, err = rpcClient.GetTracesByTransactionID(opts.Globals.Chain, trans.BlockNumber, trans.TransactionIndex, rpcOptions); err != nil { + if trans.Traces, err = opts.Conn.GetTracesByTransactionID(chain, trans.BlockNumber, trans.TransactionIndex); err != nil { return err } - if err = index.UniqFromTransDetails(chain, procFunc, opts.Flow, &trans, ts, addrMap, rpcOptions); err != nil { + if err = index.UniqFromTransDetails(chain, procFunc, opts.Flow, &trans, ts, addrMap, opts.Conn); err != nil { return err } } diff --git a/src/apps/chifra/internal/blocks/options.go b/src/apps/chifra/internal/blocks/options.go index a113d6f3d5..7f4491aa06 100644 --- a/src/apps/chifra/internal/blocks/options.go +++ b/src/apps/chifra/internal/blocks/options.go @@ -16,6 +16,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/caps" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/identifiers" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) @@ -40,6 +41,7 @@ type BlocksOptions struct { List uint64 `json:"list,omitempty"` // Summary list of blocks running backwards from latest block minus num ListCount uint64 `json:"listCount,omitempty"` // The number of blocks to report for --list option Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -68,6 +70,7 @@ func (opts *BlocksOptions) testLog() { logger.TestLog(opts.Decache, "Decache: ", opts.Decache) logger.TestLog(opts.List != 0, "List: ", opts.List) logger.TestLog(opts.ListCount != 0, "ListCount: ", opts.ListCount) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -131,13 +134,19 @@ func blocksFinishParseApi(w http.ResponseWriter, r *http.Request) *BlocksOptions opts.ListCount = globals.ToUint64(value[0]) default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "blocks") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, opts.CacheTxs, opts.CacheTraces) // EXISTING_CODE return opts @@ -148,7 +157,12 @@ func blocksFinishParse(args []string) *BlocksOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, opts.CacheTxs, opts.CacheTraces) if !opts.Uniq && opts.List == 0 { defFmt = "json" } @@ -157,6 +171,7 @@ func blocksFinishParse(args []string) *BlocksOptions { if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/blocks/validate.go b/src/apps/chifra/internal/blocks/validate.go index dff5030ba6..f83f0df11d 100644 --- a/src/apps/chifra/internal/blocks/validate.go +++ b/src/apps/chifra/internal/blocks/validate.go @@ -8,11 +8,12 @@ import ( "errors" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) func (opts *BlocksOptions) validateBlocks() error { + chain := opts.Globals.Chain + opts.testLog() if opts.BadFlag != nil { @@ -39,7 +40,7 @@ func (opts *BlocksOptions) validateBlocks() error { if opts.ListCount == 0 { err := validate.ValidateIdentifiers( - opts.Globals.Chain, + chain, opts.Blocks, validate.ValidBlockIdWithRange, 1, @@ -109,7 +110,7 @@ func (opts *BlocksOptions) validateBlocks() error { return validate.Usage("The {0} option is only available with the {1} option.", "--big_range", "--logs") } - if opts.Traces && !rpcClient.IsNodeTracing(opts.Globals.TestMode, opts.Globals.Chain) { + if opts.Traces && !opts.Conn.IsNodeTracing(chain, opts.Globals.TestMode) { return validate.Usage("Tracing is required for this program to work properly.") } } diff --git a/src/apps/chifra/internal/chunks/handle_addresses.go b/src/apps/chifra/internal/chunks/handle_addresses.go index 0ed47f4bf2..f375b92baa 100644 --- a/src/apps/chifra/internal/chunks/handle_addresses.go +++ b/src/apps/chifra/internal/chunks/handle_addresses.go @@ -19,6 +19,7 @@ import ( ) 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) { @@ -37,7 +38,7 @@ func (opts *ChunksOptions) HandleAddresses(blockNums []uint64) error { if !file.FileExists(path) { // This is okay, if the user used chifra init without the --all option. Warn them and continue msg := "" - path = strings.Replace(path, config.GetPathToIndex(opts.Globals.Chain), "$indexPath", 1) + path = strings.Replace(path, config.GetPathToIndex(chain), "$indexPath", 1) if been_here < 3 { msg = fmt.Sprintf("index file %s does not exist. Run 'chifra init --all' to create it.", path) } else if been_here == 3 { @@ -88,7 +89,7 @@ func (opts *ChunksOptions) HandleAddresses(blockNums []uint64) error { } walker := index.NewCacheWalker( - opts.Globals.Chain, + chain, opts.Globals.TestMode, 10, /* maxTests */ showAddresses, diff --git a/src/apps/chifra/internal/chunks/handle_addresses_belongs.go b/src/apps/chifra/internal/chunks/handle_addresses_belongs.go index 937b668414..2f57438651 100644 --- a/src/apps/chifra/internal/chunks/handle_addresses_belongs.go +++ b/src/apps/chifra/internal/chunks/handle_addresses_belongs.go @@ -19,6 +19,8 @@ import ( // HandleIndexBelongs displays the resolved records in a chunk given a single address 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) { showAddressesBelongs := func(walker *index.CacheWalker, path string, first bool) (bool, error) { @@ -26,7 +28,7 @@ func (opts *ChunksOptions) HandleIndexBelongs(blockNums []uint64) error { } walker := index.NewCacheWalker( - opts.Globals.Chain, + chain, opts.Globals.TestMode, 10000, /* maxTests */ showAddressesBelongs, diff --git a/src/apps/chifra/internal/chunks/handle_appearances.go b/src/apps/chifra/internal/chunks/handle_appearances.go index 52118741ca..f1dc94eeaf 100644 --- a/src/apps/chifra/internal/chunks/handle_appearances.go +++ b/src/apps/chifra/internal/chunks/handle_appearances.go @@ -17,6 +17,8 @@ import ( ) func (opts *ChunksOptions) HandleAppearances(blockNums []uint64) error { + chain := opts.Globals.Chain + ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawAppearance], errorChan chan error) { showAppearances := func(walker *index.CacheWalker, path string, first bool) (bool, error) { @@ -61,7 +63,7 @@ func (opts *ChunksOptions) HandleAppearances(blockNums []uint64) error { } walker := index.NewCacheWalker( - opts.Globals.Chain, + chain, opts.Globals.TestMode, 10, /* maxTests */ showAppearances, diff --git a/src/apps/chifra/internal/chunks/handle_blooms.go b/src/apps/chifra/internal/chunks/handle_blooms.go index fcf1e5f449..a3b6eb7947 100644 --- a/src/apps/chifra/internal/chunks/handle_blooms.go +++ b/src/apps/chifra/internal/chunks/handle_blooms.go @@ -18,6 +18,8 @@ import ( ) 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) { showBloom := func(walker *index.CacheWalker, path string, first bool) (bool, error) { @@ -36,7 +38,7 @@ func (opts *ChunksOptions) HandleBlooms(blockNums []uint64) error { displayBloom(&bl, 1) } - stats, err := GetChunkStats(opts.Globals.Chain, path) + stats, err := GetChunkStats(chain, path) if err != nil { return false, err } @@ -56,7 +58,7 @@ func (opts *ChunksOptions) HandleBlooms(blockNums []uint64) error { } walker := index.NewCacheWalker( - opts.Globals.Chain, + chain, opts.Globals.TestMode, 10, /* maxTests */ showBloom, diff --git a/src/apps/chifra/internal/chunks/handle_check.go b/src/apps/chifra/internal/chunks/handle_check.go index 36378c88b6..8ea0400a3d 100644 --- a/src/apps/chifra/internal/chunks/handle_check.go +++ b/src/apps/chifra/internal/chunks/handle_check.go @@ -25,11 +25,13 @@ import ( // and manifest in the smart contract. It tries to check these three sources for // cosnsistency. Smart contract rules, so it is checked more thoroughly. func (opts *ChunksOptions) HandleCheck(blockNums []uint64) error { + chain := opts.Globals.Chain + maxTestItems := 10 filenameChan := make(chan cache.CacheFileInfo) var nRoutines = 1 - go cache.WalkCacheFolder(context.Background(), opts.Globals.Chain, cache.Index_Bloom, nil, filenameChan) + go cache.WalkCacheFolder(context.Background(), chain, cache.Index_Bloom, nil, filenameChan) fileNames := []string{} for result := range filenameChan { @@ -60,7 +62,7 @@ func (opts *ChunksOptions) HandleCheck(blockNums []uint64) error { } if len(fileNames) == 0 { - msg := fmt.Sprint("No files found to check in", config.GetPathToIndex(opts.Globals.Chain)) + msg := fmt.Sprint("No files found to check in", config.GetPathToIndex(chain)) return errors.New(msg) } @@ -68,12 +70,12 @@ func (opts *ChunksOptions) HandleCheck(blockNums []uint64) error { return fileNames[i] < fileNames[j] }) - cacheManifest, err := manifest.ReadManifest(opts.Globals.Chain, manifest.FromCache) + cacheManifest, err := manifest.ReadManifest(chain, manifest.FromCache) if err != nil { return err } - remoteManifest, err := manifest.ReadManifest(opts.Globals.Chain, manifest.FromContract) + remoteManifest, err := manifest.ReadManifest(chain, manifest.FromContract) if err != nil { return err } @@ -108,7 +110,7 @@ func (opts *ChunksOptions) HandleCheck(blockNums []uint64) error { reports := []simpleReportCheck{} - allowMissing := scrapeCfg.AllowMissing(opts.Globals.Chain) + allowMissing := scrapeCfg.AllowMissing(chain) seq := simpleReportCheck{Reason: "Filenames sequential"} if err := opts.CheckSequential(fileNames, cacheArray, remoteArray, allowMissing, &seq); err != nil { return err @@ -155,7 +157,7 @@ func (opts *ChunksOptions) HandleCheck(blockNums []uint64) error { reports = append(reports, r2c) // we only check the stage if it exists - stagePath := cache.ToStagingPath(config.GetPathToIndex(opts.Globals.Chain) + "staging") + stagePath := cache.ToStagingPath(config.GetPathToIndex(chain) + "staging") stageFn, _ := file.LatestFileInFolder(stagePath) if file.FileExists(stageFn) { stage := simpleReportCheck{Reason: "Check staging folder"} diff --git a/src/apps/chifra/internal/chunks/handle_check_deep.go b/src/apps/chifra/internal/chunks/handle_check_deep.go index e493c959f3..7051d711e0 100644 --- a/src/apps/chifra/internal/chunks/handle_check_deep.go +++ b/src/apps/chifra/internal/chunks/handle_check_deep.go @@ -34,6 +34,7 @@ type reporter struct { // 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 { + chain := opts.Globals.Chain mutex := sync.Mutex{} theMap := make(map[string]*reporter) @@ -54,7 +55,7 @@ func (opts *ChunksOptions) CheckDeep(cacheMan *manifest.Manifest, report *simple tick = 1000 procFunc = func(rangeStr string, item *reporter) (err error) { rng := base.RangeFromRangeString(item.chunk.Range) - _, path := rng.RangeToFilename(opts.Globals.Chain) + _, path := rng.RangeToFilename(chain) bloomFilename := cache.ToBloomPath(path) bl, err := bloom.NewChunkBloom(bloomFilename) if err != nil { diff --git a/src/apps/chifra/internal/chunks/handle_check_staging.go b/src/apps/chifra/internal/chunks/handle_check_staging.go index 446d28094e..8ac796d5e5 100644 --- a/src/apps/chifra/internal/chunks/handle_check_staging.go +++ b/src/apps/chifra/internal/chunks/handle_check_staging.go @@ -13,7 +13,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/cache" "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/rpcClient" ) // CheckStaging checks the staging file which should be names first-second.txt @@ -22,14 +21,15 @@ import ( // 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 { - stagePath := cache.ToStagingPath(config.GetPathToIndex(opts.Globals.Chain) + "staging") + chain := opts.Globals.Chain + stagePath := cache.ToStagingPath(config.GetPathToIndex(chain) + "staging") stageFn, _ := file.LatestFileInFolder(stagePath) if !file.FileExists(stageFn) { return nil } fileRange := base.RangeFromFilename(stageFn) - meta, err := rpcClient.GetMetaData(opts.Globals.Chain, opts.Globals.TestMode) + meta, err := opts.Conn.GetMetaData(chain, opts.Globals.TestMode) if err != nil { return err } diff --git a/src/apps/chifra/internal/chunks/handle_index.go b/src/apps/chifra/internal/chunks/handle_index.go index a0ad4dad0d..593095debf 100644 --- a/src/apps/chifra/internal/chunks/handle_index.go +++ b/src/apps/chifra/internal/chunks/handle_index.go @@ -21,6 +21,7 @@ func (opts *ChunksOptions) HandleIndex(blockNums []uint64) error { return opts.HandleIndexBelongs(blockNums) } + chain := opts.Globals.Chain ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { showIndex := func(walker *index.CacheWalker, path string, first bool) (bool, error) { @@ -58,7 +59,7 @@ func (opts *ChunksOptions) HandleIndex(blockNums []uint64) error { } walker := index.NewCacheWalker( - opts.Globals.Chain, + chain, opts.Globals.TestMode, 100, /* maxTests */ showIndex, diff --git a/src/apps/chifra/internal/chunks/handle_manifest.go b/src/apps/chifra/internal/chunks/handle_manifest.go index eaacd49a20..279ff2ed87 100644 --- a/src/apps/chifra/internal/chunks/handle_manifest.go +++ b/src/apps/chifra/internal/chunks/handle_manifest.go @@ -18,8 +18,9 @@ var sourceMap = map[bool]manifest.Source{ } func (opts *ChunksOptions) HandleManifest(blockNums []uint64) error { + chain := opts.Globals.Chain testMode := opts.Globals.TestMode - man, err := manifest.ReadManifest(opts.Globals.Chain, sourceMap[opts.Remote]) + man, err := manifest.ReadManifest(chain, sourceMap[opts.Remote]) if err != nil { return err } diff --git a/src/apps/chifra/internal/chunks/handle_pin.go b/src/apps/chifra/internal/chunks/handle_pin.go index fea32a0644..008ba9cb54 100644 --- a/src/apps/chifra/internal/chunks/handle_pin.go +++ b/src/apps/chifra/internal/chunks/handle_pin.go @@ -22,16 +22,16 @@ import ( func (opts *ChunksOptions) HandlePin(blockNums []uint64) error { firstBlock := mustParseUint(os.Getenv("TB_CHUNK_PIN_FIRST_BLOCK")) + chain := opts.Globals.Chain ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { man := simpleChunkPinReport{ Version: version.ManifestVersion, - Chain: opts.Globals.Chain, + Chain: chain, Schemas: unchained.Schemas, } var err error - chain := opts.Globals.Chain tsPath := config.GetPathToIndex(chain) + "ts.bin" if man.TsHash, err = pinning.PinItem(chain, "timestamps", tsPath, opts.Remote); err != nil { errorChan <- err @@ -61,7 +61,7 @@ func (opts *ChunksOptions) HandlePin(blockNums []uint64) error { return false, fmt.Errorf("should not happen in pinChunk") } - result, err := pinning.PinChunk(opts.Globals.Chain, path, opts.Remote) + result, err := pinning.PinChunk(chain, path, opts.Remote) if err != nil { return false, err } @@ -98,7 +98,7 @@ func (opts *ChunksOptions) HandlePin(blockNums []uint64) error { } walker := index.NewCacheWalker( - opts.Globals.Chain, + chain, opts.Globals.TestMode, 100, /* maxTests */ pinChunk, diff --git a/src/apps/chifra/internal/chunks/handle_stats.go b/src/apps/chifra/internal/chunks/handle_stats.go index e86bef3d3b..e1eaa95ead 100644 --- a/src/apps/chifra/internal/chunks/handle_stats.go +++ b/src/apps/chifra/internal/chunks/handle_stats.go @@ -15,6 +15,7 @@ import ( ) func (opts *ChunksOptions) HandleStats(blockNums []uint64) error { + chain := opts.Globals.Chain ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { showFinalizedStats := func(walker *index.CacheWalker, path string, first bool) (bool, error) { @@ -22,7 +23,7 @@ func (opts *ChunksOptions) HandleStats(blockNums []uint64) error { return false, fmt.Errorf("should not happen in showFinalizedStats") } - if s, err := GetChunkStats(opts.Globals.Chain, path); err != nil { + if s, err := GetChunkStats(chain, path); err != nil { return false, err } else { @@ -33,7 +34,7 @@ func (opts *ChunksOptions) HandleStats(blockNums []uint64) error { } walker := index.NewCacheWalker( - opts.Globals.Chain, + chain, opts.Globals.TestMode, 100, /* maxTests */ showFinalizedStats, diff --git a/src/apps/chifra/internal/chunks/handle_truncate.go b/src/apps/chifra/internal/chunks/handle_truncate.go index 4b977ad71b..83629953cd 100644 --- a/src/apps/chifra/internal/chunks/handle_truncate.go +++ b/src/apps/chifra/internal/chunks/handle_truncate.go @@ -34,7 +34,7 @@ func (opts *ChunksOptions) HandleTruncate(blockNums []uint64) error { return nil } - indexPath := config.GetPathToIndex(opts.Globals.Chain) + indexPath := config.GetPathToIndex(chain) index.CleanTemporaryFolders(indexPath, true) ctx, cancel := context.WithCancel(context.Background()) @@ -82,7 +82,7 @@ func (opts *ChunksOptions) HandleTruncate(blockNums []uint64) error { } walker := index.NewCacheWalker( - opts.Globals.Chain, + chain, opts.Globals.TestMode, 100, /* maxTests */ truncateIndex, diff --git a/src/apps/chifra/internal/chunks/options.go b/src/apps/chifra/internal/chunks/options.go index d37dcfac85..8db1f831e9 100644 --- a/src/apps/chifra/internal/chunks/options.go +++ b/src/apps/chifra/internal/chunks/options.go @@ -39,6 +39,7 @@ type ChunksOptions struct { Deep bool `json:"deep,omitempty"` // If true, dig more deeply during checking (manifest only) Sleep float64 `json:"sleep,omitempty"` // For --remote pinning only, seconds to sleep between API calls Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -65,6 +66,7 @@ func (opts *ChunksOptions) testLog() { logger.TestLog(opts.MaxAddrs != utils.NOPOS, "MaxAddrs: ", opts.MaxAddrs) logger.TestLog(opts.Deep, "Deep: ", opts.Deep) logger.TestLog(opts.Sleep != float64(0.0), "Sleep: ", opts.Sleep) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -119,15 +121,20 @@ func chunksFinishParseApi(w http.ResponseWriter, r *http.Request) *ChunksOptions opts.Sleep = globals.ToFloat64(value[0]) default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "chunks") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE // TODO: Do we know if an option is an address? If yes, we could automate this - opts.Belongs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Belongs) + opts.Belongs, _ = opts.Conn.GetAddressesFromEns(chain, opts.Belongs) // EXISTING_CODE return opts @@ -138,6 +145,10 @@ func chunksFinishParse(args []string) *ChunksOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE if len(args) > 0 { opts.Mode = args[0] @@ -151,7 +162,7 @@ func chunksFinishParse(args []string) *ChunksOptions { } } } - opts.Belongs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Belongs) + opts.Belongs, _ = opts.Conn.GetAddressesFromEns(chain, opts.Belongs) if opts.Truncate == 0 { opts.Truncate = utils.NOPOS } @@ -175,6 +186,7 @@ func chunksFinishParse(args []string) *ChunksOptions { if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/chunks/output.go b/src/apps/chifra/internal/chunks/output.go index fbf44e65d1..4045c50bbf 100644 --- a/src/apps/chifra/internal/chunks/output.go +++ b/src/apps/chifra/internal/chunks/output.go @@ -63,7 +63,8 @@ func (opts *ChunksOptions) ChunksInternal() (err error, handled bool) { handled = true - blockNums, err := identifiers.GetBlockNumbers(opts.Globals.Chain, opts.BlockIds) + chain := opts.Globals.Chain + blockNums, err := identifiers.GetBlockNumbers(chain, opts.BlockIds) if err != nil { return } diff --git a/src/apps/chifra/internal/chunks/validate.go b/src/apps/chifra/internal/chunks/validate.go index 533596a04a..91fe9bcc0e 100644 --- a/src/apps/chifra/internal/chunks/validate.go +++ b/src/apps/chifra/internal/chunks/validate.go @@ -17,6 +17,8 @@ import ( ) func (opts *ChunksOptions) validateChunks() error { + chain := opts.Globals.Chain + opts.testLog() if opts.BadFlag != nil { @@ -46,7 +48,7 @@ func (opts *ChunksOptions) validateChunks() error { if opts.Mode == "manifest" { if opts.Pin { if opts.Remote { - pinataKey, pinataSecret, estuaryKey := config.GetPinningKeys(opts.Globals.Chain) + pinataKey, pinataSecret, estuaryKey := config.GetPinningKeys(chain) if (pinataKey == "" || pinataSecret == "") && estuaryKey == "" { return validate.Usage("The {0} option requires {1}.", "--pin --remote", "an api key") } @@ -113,7 +115,7 @@ func (opts *ChunksOptions) validateChunks() error { } err = validate.ValidateIdentifiers( - opts.Globals.Chain, + chain, opts.Blocks, validate.ValidBlockIdWithRangeAndDate, 1, @@ -143,7 +145,7 @@ func (opts *ChunksOptions) validateChunks() error { } // Note that this does not return if the index is not initialized - if err := index.IndexIsInitialized(opts.Globals.Chain); err != nil { + if err := index.IndexIsInitialized(chain); err != nil { if opts.Globals.IsApiMode() { return err } else { diff --git a/src/apps/chifra/internal/config/handle_paths.go b/src/apps/chifra/internal/config/handle_paths.go index 9aac0c8e99..dd5664ef71 100644 --- a/src/apps/chifra/internal/config/handle_paths.go +++ b/src/apps/chifra/internal/config/handle_paths.go @@ -10,12 +10,14 @@ import ( // HandlePaths handles the paths command for the command line. Returns error only as per cobra. func (opts *ConfigOptions) HandlePaths() error { + chain := opts.Globals.Chain + // TODO: This needs to be a SimpleType and use StreamMany dateStr := gostradamus.Now().Format("02-01|15:04:05.000") fmt.Printf("\nchifra status --paths:\n") fmt.Println(dateStr, colors.Green+"Config Path: "+colors.Off, config.GetPathToRootConfig()) - fmt.Println(dateStr, colors.Green+"Cache Path: "+colors.Off, config.GetPathToCache(opts.Globals.Chain)) - fmt.Println(dateStr, colors.Green+"Index Path: "+colors.Off, config.GetPathToIndex(opts.Globals.Chain)) + fmt.Println(dateStr, colors.Green+"Cache Path: "+colors.Off, config.GetPathToCache(chain)) + fmt.Println(dateStr, colors.Green+"Index Path: "+colors.Off, config.GetPathToIndex(chain)) fmt.Println() return nil } diff --git a/src/apps/chifra/internal/config/options.go b/src/apps/chifra/internal/config/options.go index 4e97a7147d..afa9213a73 100644 --- a/src/apps/chifra/internal/config/options.go +++ b/src/apps/chifra/internal/config/options.go @@ -14,6 +14,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/globals" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/caps" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) @@ -22,6 +23,7 @@ type ConfigOptions struct { Mode string `json:"mode,omitempty"` // Either show or edit the configuration Paths bool `json:"paths,omitempty"` // Show the configuration paths for the system Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -33,6 +35,7 @@ var defaultConfigOptions = ConfigOptions{} func (opts *ConfigOptions) testLog() { logger.TestLog(len(opts.Mode) > 0, "Mode: ", opts.Mode) logger.TestLog(opts.Paths, "Paths: ", opts.Paths) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -54,12 +57,17 @@ func configFinishParseApi(w http.ResponseWriter, r *http.Request) *ConfigOptions opts.Paths = true default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "config") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE // EXISTING_CODE @@ -71,6 +79,10 @@ func configFinishParse(args []string) *ConfigOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE defFmt = "" for _, arg := range args { @@ -85,6 +97,7 @@ func configFinishParse(args []string) *ConfigOptions { if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/daemon/handle_calls.go b/src/apps/chifra/internal/daemon/handle_calls.go index fe365f8602..a103aa1c19 100644 --- a/src/apps/chifra/internal/daemon/handle_calls.go +++ b/src/apps/chifra/internal/daemon/handle_calls.go @@ -23,7 +23,6 @@ import ( "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/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) @@ -78,7 +77,7 @@ func CallOne(w http.ResponseWriter, r *http.Request, tbCmd, extra, apiCmd string allDogs = append(allDogs, "--verbose") } - allDogs, _ = rpcClient.GetAddressesFromEns(chain, allDogs) + allDogs, _ = GetOptions().Conn.GetAddressesFromEns(chain, allDogs) // Do the actual call cmd := exec.Command(tbCmd, allDogs...) diff --git a/src/apps/chifra/internal/daemon/options.go b/src/apps/chifra/internal/daemon/options.go index 64407f646d..3c010714c8 100644 --- a/src/apps/chifra/internal/daemon/options.go +++ b/src/apps/chifra/internal/daemon/options.go @@ -14,6 +14,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/globals" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/caps" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) @@ -25,6 +26,7 @@ type DaemonOptions struct { Monitor bool `json:"monitor,omitempty"` // Instruct the node to start the monitors tool Grpc bool `json:"grpc,omitempty"` // Run gRPC server to serve names Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -42,6 +44,7 @@ func (opts *DaemonOptions) testLog() { logger.TestLog(len(opts.Scrape) > 0, "Scrape: ", opts.Scrape) logger.TestLog(opts.Monitor, "Monitor: ", opts.Monitor) logger.TestLog(opts.Grpc, "Grpc: ", opts.Grpc) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -69,12 +72,17 @@ func daemonFinishParseApi(w http.ResponseWriter, r *http.Request) *DaemonOptions opts.Grpc = true default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "daemon") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE // EXISTING_CODE @@ -86,11 +94,16 @@ func daemonFinishParse(args []string) *DaemonOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE // EXISTING_CODE if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/daemon/output.go b/src/apps/chifra/internal/daemon/output.go index cae1254fff..85037e129c 100644 --- a/src/apps/chifra/internal/daemon/output.go +++ b/src/apps/chifra/internal/daemon/output.go @@ -19,7 +19,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" outputHelpers "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output/helpers" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/tslib" "github.com/spf13/cobra" ) @@ -82,13 +81,13 @@ func (opts *DaemonOptions) DaemonInternal() (err error, handled bool) { logger.InfoTable("Cache Path: ", config.GetPathToCache(chain)) logger.InfoTable("Index Path: ", config.GetPathToIndex(chain)) - meta, err := rpcClient.GetMetaData(chain, false) + meta, err := opts.Conn.GetMetaData(chain, false) if err != nil { msg := fmt.Sprintf("%sCould not load RPC provider: %s%s", colors.Red, err, colors.Off) logger.InfoTable("Progress:", msg) logger.Fatal("") } else { - nTs, _ := tslib.NTimestamps(opts.Globals.Chain) + nTs, _ := tslib.NTimestamps(chain) msg := fmt.Sprintf("%d, %d, %d, %d, ts: %d", meta.Latest, meta.Finalized, meta.Staging, meta.Unripe, nTs) logger.InfoTable("Progress: ", msg) } diff --git a/src/apps/chifra/internal/explore/options.go b/src/apps/chifra/internal/explore/options.go index 9ad4b35045..f1b8495ddf 100644 --- a/src/apps/chifra/internal/explore/options.go +++ b/src/apps/chifra/internal/explore/options.go @@ -25,6 +25,7 @@ type ExploreOptions struct { Local bool `json:"local,omitempty"` // Open the local TrueBlocks explorer Google bool `json:"google,omitempty"` // Search google excluding popular blockchain explorers Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -37,6 +38,7 @@ func (opts *ExploreOptions) testLog() { logger.TestLog(len(opts.Terms) > 0, "Terms: ", opts.Terms) logger.TestLog(opts.Local, "Local: ", opts.Local) logger.TestLog(opts.Google, "Google: ", opts.Google) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -63,14 +65,19 @@ func exploreFinishParseApi(w http.ResponseWriter, r *http.Request) *ExploreOptio opts.Google = true default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "explore") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE - opts.Terms, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Terms) + opts.Terms, _ = opts.Conn.GetAddressesFromEns(chain, opts.Terms) // EXISTING_CODE return opts @@ -81,12 +88,17 @@ func exploreFinishParse(args []string) *ExploreOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE - opts.Terms, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, args) + opts.Terms, _ = opts.Conn.GetAddressesFromEns(chain, args) // EXISTING_CODE if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/explore/validate.go b/src/apps/chifra/internal/explore/validate.go index f0381a0e8a..60e1e29d56 100644 --- a/src/apps/chifra/internal/explore/validate.go +++ b/src/apps/chifra/internal/explore/validate.go @@ -10,7 +10,6 @@ import ( "strings" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" "github.com/ethereum/go-ethereum" ) @@ -35,6 +34,8 @@ type ExploreUrl struct { var urls []ExploreUrl func (opts *ExploreOptions) validateExplore() error { + chain := opts.Globals.Chain + opts.testLog() if opts.BadFlag != nil { @@ -67,9 +68,9 @@ func (opts *ExploreOptions) validateExplore() error { return validate.Usage("The {0} option requires {1}.", "--google", "an address term") } - valid, _ := validate.IsValidTransId(opts.Globals.Chain, []string{arg}, validate.ValidTransId) + valid, _ := validate.IsValidTransId(chain, []string{arg}, validate.ValidTransId) if valid { - txHash, err := idToTxHash(opts.Globals.Chain, arg, validate.IsBlockHash) + txHash, err := opts.idToTxHash(chain, arg, validate.IsBlockHash) if err == nil { urls = append(urls, ExploreUrl{txHash, ExploreTx}) continue @@ -77,9 +78,9 @@ func (opts *ExploreOptions) validateExplore() error { // an error here is okay since we can't distinquish between tx hashes and block hashes... } - valid, _ = validate.IsValidBlockId(opts.Globals.Chain, []string{arg}, validate.ValidBlockIdWithRangeAndDate) + valid, _ = validate.IsValidBlockId(chain, []string{arg}, validate.ValidBlockIdWithRangeAndDate) if valid { - blockHash, err := idToBlockHash(opts.Globals.Chain, arg, validate.IsBlockHash) + blockHash, err := opts.idToBlockHash(chain, arg, validate.IsBlockHash) if err == nil { urls = append(urls, ExploreUrl{blockHash, ExploreBlock}) continue @@ -125,26 +126,27 @@ func (t ExploreType) String() string { } } -func idToBlockHash(chain, arg string, isBlockHash func(arg string) bool) (string, error) { +func (opts *ExploreOptions) idToBlockHash(chain, arg string, isBlockHash func(arg string) bool) (string, error) { if isBlockHash(arg) { - return rpcClient.GetBlockHashFromHashStr(chain, arg) + return opts.Conn.GetBlockHashFromHashStr(chain, arg) } blockNum, err := strconv.ParseUint(arg, 10, 64) if err != nil { return "", nil } - return rpcClient.GetBlockHashByNumber(chain, blockNum) + + return opts.Conn.GetBlockHashByNumber(chain, blockNum) } // idToTxHash takes a valid identifier (txHash/blockHash, blockHash.txId, blockNumber.txId) // and returns the transaction hash represented by that identifier. (If it's a valid transaction. // It may not be because transaction hashes and block hashes are both 32-byte hex) -func idToTxHash(chain, arg string, isBlockHash func(arg string) bool) (string, error) { +func (opts *ExploreOptions) idToTxHash(chain, arg string, isBlockHash func(arg string) bool) (string, error) { // simple case first if !strings.Contains(arg, ".") { // We know it's a hash, but we want to know if it's a legitimate tx on chain - return rpcClient.GetTransactionHashFromHashStr(chain, arg) + return opts.Conn.GetTransactionHashFromHashStr(chain, arg) } parts := strings.Split(arg, ".") @@ -157,7 +159,7 @@ func idToTxHash(chain, arg string, isBlockHash func(arg string) bool) (string, e if err != nil { return "", nil } - return rpcClient.GetTransactionHashByHashAndID(chain, parts[0], txId) + return opts.Conn.GetTransactionHashByHashAndID(chain, parts[0], txId) } blockNum, err := strconv.ParseUint(parts[0], 10, 64) @@ -169,5 +171,5 @@ func idToTxHash(chain, arg string, isBlockHash func(arg string) bool) (string, e return "", nil } - return rpcClient.GetTransactionHashByNumberAndID(chain, blockNum, txId) + return opts.Conn.GetTransactionHashByNumberAndID(chain, blockNum, txId) } diff --git a/src/apps/chifra/internal/explore/validate_integration_test.go b/src/apps/chifra/internal/explore/validate_integration_test.go index ed92fe4ef2..ac0b3d29ee 100644 --- a/src/apps/chifra/internal/explore/validate_integration_test.go +++ b/src/apps/chifra/internal/explore/validate_integration_test.go @@ -9,10 +9,15 @@ package explorePkg import ( "testing" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) func Test_Explore_Validate(t *testing.T) { var opts ExploreOptions + chain := utils.GetTestChain() + opts.Conn = rpcClient.NewConnection(chain, []string{}) opts.Terms = append(opts.Terms, "1001001.0") opts.Globals.Chain = "mainnet" err := opts.validateExplore() diff --git a/src/apps/chifra/internal/export/handle_balances.go b/src/apps/chifra/internal/export/handle_balances.go index ff951d1041..32f60a92ef 100644 --- a/src/apps/chifra/internal/export/handle_balances.go +++ b/src/apps/chifra/internal/export/handle_balances.go @@ -31,6 +31,11 @@ func (opts *ExportOptions) HandleBalances(monitorArray []monitor.Monitor) error base.BlockRange{First: opts.FirstBlock, Last: opts.LastBlock}, base.RecordRange{First: opts.FirstRecord, Last: opts.GetMax()}, ) + settings := rpcClient.DefaultRpcOptionsSettings{ + Chain: chain, + Opts: opts, + } + opts.Conn = settings.DefaultRpcOptions() ctx := context.Background() fetchData := func(modelChan chan types.Modeler[types.RawTokenBalance], errorChan chan error) { @@ -39,7 +44,7 @@ func (opts *ExportOptions) HandleBalances(monitorArray []monitor.Monitor) error errorChan <- err continue } else { - prevBalance, _ := rpcClient.GetBalanceAt(chain, mon.Address, filter.GetOuterBounds().First) + prevBalance, _ := opts.Conn.GetBalanceAt(chain, mon.Address, filter.GetOuterBounds().First) for index, item := range items { item := item item.PriorBalance = *prevBalance @@ -76,17 +81,18 @@ func (opts *ExportOptions) readBalances( filter *monitor.AppearanceFilter, errorChan chan error, ) ([]*types.SimpleTokenBalance, error) { + chain := opts.Globals.Chain + if txMap, cnt, err := monitor.ReadAppearancesToMap[types.SimpleTokenBalance](mon, filter); err != nil { errorChan <- err return nil, err } else if !opts.NoZero || cnt > 0 { - chain := opts.Globals.Chain showProgress := !opts.Globals.TestMode var bar = logger.NewBar(mon.Address.Hex(), showProgress, mon.Count()) // This is called concurrently, once for each appearance iterFunc := func(app types.SimpleAppearance, value *types.SimpleTokenBalance) error { - if b, err := rpcClient.GetBalanceAt(chain, mon.Address, uint64(app.BlockNumber)); err != nil { + if b, err := opts.Conn.GetBalanceAt(chain, mon.Address, uint64(app.BlockNumber)); err != nil { return err } else { value.Address = base.FAKE_ETH_ADDRESS diff --git a/src/apps/chifra/internal/export/handle_logs.go b/src/apps/chifra/internal/export/handle_logs.go index 49417336ea..c5467847f1 100644 --- a/src/apps/chifra/internal/export/handle_logs.go +++ b/src/apps/chifra/internal/export/handle_logs.go @@ -15,7 +15,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/monitor" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/names" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) @@ -31,14 +30,11 @@ func (opts *ExportOptions) HandleLogs(monitorArray []monitor.Monitor) error { base.BlockRange{First: opts.FirstBlock, Last: opts.LastBlock}, base.RecordRange{First: opts.FirstRecord, Last: opts.GetMax()}, ) - rpcOptions := rpcClient.DefaultRpcOptions(&rpcClient.DefaultRpcOptionsSettings{ - Chain: chain, - }) ctx := context.Background() fetchData := func(modelChan chan types.Modeler[types.RawLog], errorChan chan error) { for _, mon := range monitorArray { - if items, err := opts.readLogs(monitorArray, &mon, filter, errorChan, abiCache, rpcOptions); err != nil { + if items, err := opts.readLogs(monitorArray, &mon, filter, errorChan, abiCache); err != nil { errorChan <- err continue } else { @@ -74,14 +70,13 @@ func (opts *ExportOptions) readLogs( filter *monitor.AppearanceFilter, errorChan chan error, abiCache *articulate.AbiCache, - rpcOptions *rpcClient.Options, ) ([]*types.SimpleLog, error) { if txMap, cnt, err := monitor.ReadAppearancesToMap[types.SimpleTransaction](mon, filter); err != nil { errorChan <- err return nil, err } else if !opts.NoZero || cnt > 0 { chain := opts.Globals.Chain - if err := opts.readTransactions(mon, txMap, false /* readTraces */, rpcOptions); err != nil { + if err := opts.readTransactions(mon, txMap, false /* readTraces */); err != nil { return nil, err } diff --git a/src/apps/chifra/internal/export/handle_receipts.go b/src/apps/chifra/internal/export/handle_receipts.go index 8313a9fc66..3d10ec5ac2 100644 --- a/src/apps/chifra/internal/export/handle_receipts.go +++ b/src/apps/chifra/internal/export/handle_receipts.go @@ -14,7 +14,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/monitor" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/names" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) @@ -30,14 +29,11 @@ func (opts *ExportOptions) HandleReceipts(monitorArray []monitor.Monitor) error base.BlockRange{First: opts.FirstBlock, Last: opts.LastBlock}, base.RecordRange{First: opts.FirstRecord, Last: opts.GetMax()}, ) - rpcOptions := rpcClient.DefaultRpcOptions(&rpcClient.DefaultRpcOptionsSettings{ - Chain: chain, - }) ctx := context.Background() fetchData := func(modelChan chan types.Modeler[types.RawReceipt], errorChan chan error) { for _, mon := range monitorArray { - if items, err := opts.readReceipts(monitorArray, &mon, filter, errorChan, abiCache, rpcOptions); err != nil { + if items, err := opts.readReceipts(monitorArray, &mon, filter, errorChan, abiCache); err != nil { errorChan <- err continue } else { @@ -73,14 +69,13 @@ func (opts *ExportOptions) readReceipts( filter *monitor.AppearanceFilter, errorChan chan error, abiCache *articulate.AbiCache, - rpcOptions *rpcClient.Options, ) ([]*types.SimpleReceipt, error) { if txMap, cnt, err := monitor.ReadAppearancesToMap[types.SimpleTransaction](mon, filter); err != nil { errorChan <- err return nil, err } else if !opts.NoZero || cnt > 0 { chain := opts.Globals.Chain - if err := opts.readTransactions(mon, txMap, false /* readTraces */, rpcOptions); err != nil { + if err := opts.readTransactions(mon, txMap, false /* readTraces */); err != nil { return nil, err } diff --git a/src/apps/chifra/internal/export/handle_show.go b/src/apps/chifra/internal/export/handle_show.go index 900800ba7a..ee5df5ef25 100644 --- a/src/apps/chifra/internal/export/handle_show.go +++ b/src/apps/chifra/internal/export/handle_show.go @@ -37,10 +37,12 @@ func (opts *ExportOptions) HandleShow(monitorArray []monitor.Monitor) error { base.BlockRange{First: opts.FirstBlock, Last: opts.LastBlock}, base.RecordRange{First: opts.FirstRecord, Last: opts.GetMax()}, ) - rpcOptions := rpcClient.DefaultRpcOptions(&rpcClient.DefaultRpcOptionsSettings{ + settings := rpcClient.DefaultRpcOptionsSettings{ Chain: chain, Opts: opts, - }) + } + opts.Conn = settings.DefaultRpcOptions() + ledgers.Conn = opts.Conn ctx := context.Background() fetchData := func(modelChan chan types.Modeler[types.RawTransaction], errorChan chan error) { @@ -50,7 +52,7 @@ func (opts *ExportOptions) HandleShow(monitorArray []monitor.Monitor) error { BlockNumber: uint32(app.BlockNumber), TransactionIndex: uint32(app.TransactionIndex), } - if tx, err := rpcClient.GetTransactionByAppearance(chain, &raw, false, rpcOptions); err != nil { + if tx, err := opts.Conn.GetTransactionByAppearance(chain, &raw, false); err != nil { errorChan <- err return nil } else { @@ -68,7 +70,7 @@ func (opts *ExportOptions) HandleShow(monitorArray []monitor.Monitor) error { } if opts.Accounting { - if statements, err := ledgers.GetStatementsFromAppearance(chain, &raw, rpcOptions); err != nil { + if statements, err := ledgers.GetStatementsFromAppearance(chain, &raw); err != nil { errorChan <- err } else { tx.Statements = &statements diff --git a/src/apps/chifra/internal/export/handle_statements.go b/src/apps/chifra/internal/export/handle_statements.go index 3952fc4bd1..5ac5692cfa 100644 --- a/src/apps/chifra/internal/export/handle_statements.go +++ b/src/apps/chifra/internal/export/handle_statements.go @@ -15,7 +15,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/monitor" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/names" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) @@ -36,14 +35,11 @@ func (opts *ExportOptions) HandleStatements(monitorArray []monitor.Monitor) erro base.BlockRange{First: opts.FirstBlock, Last: opts.LastBlock}, base.RecordRange{First: opts.FirstRecord, Last: opts.GetMax()}, ) - rpcOptions := rpcClient.DefaultRpcOptions(&rpcClient.DefaultRpcOptionsSettings{ - Chain: chain, - }) ctx := context.Background() fetchData := func(modelChan chan types.Modeler[types.RawStatement], errorChan chan error) { for _, mon := range monitorArray { - if statements, err := opts.readStatements(monitorArray, &mon, filter, errorChan, abiCache, rpcOptions); err != nil { + if statements, err := opts.readStatements(monitorArray, &mon, filter, errorChan, abiCache); err != nil { errorChan <- err } else { for _, statement := range statements { @@ -79,7 +75,6 @@ func (opts *ExportOptions) readStatements( filter *monitor.AppearanceFilter, errorChan chan error, abiCache *articulate.AbiCache, - rpcOptions *rpcClient.Options, ) ([]*types.SimpleStatement, error) { if txMap, cnt, err := monitor.ReadAppearancesToMap[types.SimpleTransaction](mon, filter); err != nil { errorChan <- err @@ -87,7 +82,7 @@ func (opts *ExportOptions) readStatements( } else if !opts.NoZero || cnt > 0 { chain := opts.Globals.Chain testMode := opts.Globals.TestMode - if err := opts.readTransactions(mon, txMap, false /* readTraces */, rpcOptions); err != nil { + if err := opts.readTransactions(mon, txMap, false /* readTraces */); err != nil { return nil, err } @@ -118,6 +113,7 @@ func (opts *ExportOptions) readStatements( opts.Traces, &opts.Asset, ) + ledgers.Conn = opts.Conn if opts.Accounting { apps := make([]types.SimpleAppearance, 0, len(txMap)) for _, tx := range txArray { diff --git a/src/apps/chifra/internal/export/handle_traces.go b/src/apps/chifra/internal/export/handle_traces.go index f30fbd9347..816ccf7557 100644 --- a/src/apps/chifra/internal/export/handle_traces.go +++ b/src/apps/chifra/internal/export/handle_traces.go @@ -14,7 +14,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/monitor" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/names" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) @@ -30,14 +29,11 @@ func (opts *ExportOptions) HandleTraces(monitorArray []monitor.Monitor) error { base.BlockRange{First: opts.FirstBlock, Last: opts.LastBlock}, base.RecordRange{First: opts.FirstRecord, Last: opts.GetMax()}, ) - rpcOptions := rpcClient.DefaultRpcOptions(&rpcClient.DefaultRpcOptionsSettings{ - Chain: chain, - }) ctx := context.Background() fetchData := func(modelChan chan types.Modeler[types.RawTrace], errorChan chan error) { for _, mon := range monitorArray { - if items, err := opts.readTraces(monitorArray, &mon, filter, errorChan, abiCache, rpcOptions); err != nil { + if items, err := opts.readTraces(monitorArray, &mon, filter, errorChan, abiCache); err != nil { errorChan <- err continue } else { @@ -73,14 +69,13 @@ func (opts *ExportOptions) readTraces( filter *monitor.AppearanceFilter, errorChan chan error, abiCache *articulate.AbiCache, - rpcOptions *rpcClient.Options, ) ([]*types.SimpleTrace, error) { if txMap, cnt, err := monitor.ReadAppearancesToMap[types.SimpleTransaction](mon, filter); err != nil { errorChan <- err return nil, err } else if !opts.NoZero || cnt > 0 { chain := opts.Globals.Chain - if err := opts.readTransactions(mon, txMap, true /* readTraces */, rpcOptions); err != nil { + if err := opts.readTransactions(mon, txMap, true /* readTraces */); err != nil { return nil, err } diff --git a/src/apps/chifra/internal/export/iterate.go b/src/apps/chifra/internal/export/iterate.go index 7628ceeeea..9e5c61ac48 100644 --- a/src/apps/chifra/internal/export/iterate.go +++ b/src/apps/chifra/internal/export/iterate.go @@ -6,12 +6,11 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/monitor" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) -func (opts *ExportOptions) readTransactions(mon *monitor.Monitor, theMap map[types.SimpleAppearance]*types.SimpleTransaction, readTraces bool, rpcOptions *rpcClient.Options) error { +func (opts *ExportOptions) readTransactions(mon *monitor.Monitor, theMap map[types.SimpleAppearance]*types.SimpleTransaction, readTraces bool) error { chain := opts.Globals.Chain showProgress := !opts.Globals.TestMode var bar = logger.NewBar(mon.Address.Hex(), showProgress, mon.Count()) @@ -23,7 +22,7 @@ func (opts *ExportOptions) readTransactions(mon *monitor.Monitor, theMap map[typ BlockNumber: uint32(app.BlockNumber), TransactionIndex: uint32(app.TransactionIndex), } - if tx, err := rpcClient.GetTransactionByAppearance(chain, &raw, readTraces, rpcOptions); err != nil { + if tx, err := opts.Conn.GetTransactionByAppearance(chain, &raw, readTraces); err != nil { return err } else { matchesFourByte := len(opts.Fourbytes) == 0 // either there is no four bytes... diff --git a/src/apps/chifra/internal/export/options.go b/src/apps/chifra/internal/export/options.go index 8a497dd8c3..1b4142362a 100644 --- a/src/apps/chifra/internal/export/options.go +++ b/src/apps/chifra/internal/export/options.go @@ -52,6 +52,7 @@ type ExportOptions struct { FirstBlock uint64 `json:"firstBlock,omitempty"` // First block to process (inclusive) LastBlock uint64 `json:"lastBlock,omitempty"` // Last block to process (inclusive) Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -92,6 +93,7 @@ func (opts *ExportOptions) testLog() { logger.TestLog(opts.NoZero, "NoZero: ", opts.NoZero) logger.TestLog(opts.FirstBlock != 0, "FirstBlock: ", opts.FirstBlock) logger.TestLog(opts.LastBlock != 0 && opts.LastBlock != utils.NOPOS, "LastBlock: ", opts.LastBlock) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -256,16 +258,22 @@ func exportFinishParseApi(w http.ResponseWriter, r *http.Request) *ExportOptions opts.LastBlock = globals.ToUint64(value[0]) default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "export") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE - opts.Addrs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Addrs) - opts.Emitter, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Emitter) - opts.Asset, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Asset) + opts.Conn.EnableCaches(opts.Globals.Cache, true, opts.CacheTraces) + opts.Addrs, _ = opts.Conn.GetAddressesFromEns(chain, opts.Addrs) + opts.Emitter, _ = opts.Conn.GetAddressesFromEns(chain, opts.Emitter) + opts.Asset, _ = opts.Conn.GetAddressesFromEns(chain, opts.Asset) // EXISTING_CODE return opts @@ -276,7 +284,12 @@ func exportFinishParse(args []string) *ExportOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, true, opts.CacheTraces) dupMap := make(map[string]bool) for _, arg := range args { if !dupMap[arg] { @@ -290,13 +303,14 @@ func exportFinishParse(args []string) *ExportOptions { } dupMap[arg] = true } - opts.Addrs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Addrs) - opts.Emitter, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Emitter) - opts.Asset, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Asset) + opts.Addrs, _ = opts.Conn.GetAddressesFromEns(chain, opts.Addrs) + opts.Emitter, _ = opts.Conn.GetAddressesFromEns(chain, opts.Emitter) + opts.Asset, _ = opts.Conn.GetAddressesFromEns(chain, opts.Asset) // EXISTING_CODE if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/export/output.go b/src/apps/chifra/internal/export/output.go index f735237d18..2ea430f417 100644 --- a/src/apps/chifra/internal/export/output.go +++ b/src/apps/chifra/internal/export/output.go @@ -54,6 +54,7 @@ func (opts *ExportOptions) ExportInternal() (err error, handled bool) { timer := logger.NewTimer() msg := "chifra export" // EXISTING_CODE + chain := opts.Globals.Chain monitorArray := make([]monitor.Monitor, 0, len(opts.Addrs)) if canceled, err := opts.FreshenMonitorsForExport(&monitorArray); err != nil || canceled { return err, true @@ -66,7 +67,7 @@ func (opts *ExportOptions) ExportInternal() (err error, handled bool) { } handled = true - err = opts.Globals.PassItOn("acctExport", opts.Globals.Chain, opts.toCmdLine(), opts.getEnvStr()) + err = opts.Globals.PassItOn("acctExport", chain, opts.toCmdLine(), opts.getEnvStr()) return } diff --git a/src/apps/chifra/internal/export/validate.go b/src/apps/chifra/internal/export/validate.go index 7a6b6b2602..44be64b645 100644 --- a/src/apps/chifra/internal/export/validate.go +++ b/src/apps/chifra/internal/export/validate.go @@ -10,12 +10,12 @@ import ( "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/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) func (opts *ExportOptions) validateExport() error { + chain := opts.Globals.Chain opts.testLog() if opts.BadFlag != nil { @@ -72,7 +72,7 @@ func (opts *ExportOptions) validateExport() error { } if opts.LastBlock != utils.NOPOS { - latest := rpcClient.GetLatestBlockNumber(opts.Globals.Chain) + latest := opts.Conn.GetLatestBlockNumber(chain) if opts.LastBlock > latest { msg := fmt.Sprintf("latest block (%d) must be before the chain's latest block (%d).", opts.LastBlock, latest) return validate.Usage(msg) @@ -149,7 +149,7 @@ func (opts *ExportOptions) validateExport() error { } } - if !rpcClient.IsNodeArchive(opts.Globals.Chain) { + if !opts.Conn.IsNodeArchive(chain) { return validate.Usage("The {0} option requires {1}.", "--accounting", "an archive node") } @@ -172,7 +172,7 @@ func (opts *ExportOptions) validateExport() error { } // Note that this does not return if the index is not initialized - if err := index.IndexIsInitialized(opts.Globals.Chain); err != nil { + if err := index.IndexIsInitialized(chain); err != nil { if opts.Globals.IsApiMode() { return err } else { diff --git a/src/apps/chifra/internal/globals/options.go b/src/apps/chifra/internal/globals/options.go index 1441621e7c..37b6f3f31d 100644 --- a/src/apps/chifra/internal/globals/options.go +++ b/src/apps/chifra/internal/globals/options.go @@ -222,6 +222,7 @@ func GlobalsFinishParseApi(w http.ResponseWriter, r *http.Request) *GlobalOption if len(opts.Chain) == 0 { opts.Chain = config.GetDefaultChain() } + if err := tslib.EstablishTsFile(opts.Chain); err != nil { logger.Error("Could not establish ts file:", err) } diff --git a/src/apps/chifra/internal/globals/validate.go b/src/apps/chifra/internal/globals/validate.go index 4c0c7d8fe7..2a793eaa51 100644 --- a/src/apps/chifra/internal/globals/validate.go +++ b/src/apps/chifra/internal/globals/validate.go @@ -33,7 +33,7 @@ func (opts *GlobalOptions) Validate() error { // TODO: Can we re-enable this? It doesn't work in Sepolia under docker. Returns a really weird message. // tmpPath := filepath.Join(config.GetPathToCache(opts.Chain), "tmp", "checkProvider.txt") // if !file.FileExists(tmpPath) { - // if version, err := rpcClient.GetClientVersion(opts.Chain); err != nil { + // if version, err := rpcOptions.GetClientVersion(opts.Chain); err != nil { // logger.Fatal("Cannot connect with the node software.", version, err) // } else { // file.StringToAsciiFile(tmpPath, version) diff --git a/src/apps/chifra/internal/init/handle_dryrun.go b/src/apps/chifra/internal/init/handle_dryrun.go index 14658b8229..8cdd4d9a6c 100644 --- a/src/apps/chifra/internal/init/handle_dryrun.go +++ b/src/apps/chifra/internal/init/handle_dryrun.go @@ -21,8 +21,8 @@ func (opts *InitOptions) HandleDryRun() error { return err } - if remoteManifest.Chain != opts.Globals.Chain { - msg := fmt.Sprintf("The chain value found in the downloaded manifest (%s) does not match the manifest on the command line (%s).", remoteManifest.Chain, opts.Globals.Chain) + if remoteManifest.Chain != chain { + msg := fmt.Sprintf("The chain value found in the downloaded manifest (%s) does not match the manifest on the command line (%s).", remoteManifest.Chain, chain) return errors.New(msg) } diff --git a/src/apps/chifra/internal/init/handle_init.go b/src/apps/chifra/internal/init/handle_init.go index e6e1f765ea..edfeb6ba32 100644 --- a/src/apps/chifra/internal/init/handle_init.go +++ b/src/apps/chifra/internal/init/handle_init.go @@ -37,8 +37,8 @@ func (opts *InitOptions) HandleInit() error { return err } - if remoteManifest.Chain != opts.Globals.Chain { - msg := fmt.Sprintf("The chain value found in the downloaded manifest (%s) does not match the manifest on the command line (%s).", remoteManifest.Chain, opts.Globals.Chain) + if remoteManifest.Chain != chain { + msg := fmt.Sprintf("The chain value found in the downloaded manifest (%s) does not match the manifest on the command line (%s).", remoteManifest.Chain, chain) return errors.New(msg) } @@ -115,6 +115,8 @@ var nStarted12 int // downloadAndReportProgress Downloads the chunks and reports progress to the progressChannel func (opts *InitOptions) downloadAndReportProgress(chunks []manifest.ChunkRecord, chunkType cache.CacheType, nTotal int) ([]manifest.ChunkRecord, bool) { + chain := opts.Globals.Chain + failed := []manifest.ChunkRecord{} cancelled := false @@ -126,7 +128,7 @@ func (opts *InitOptions) downloadAndReportProgress(chunks []manifest.ChunkRecord poolSize := runtime.NumCPU() * 2 // Start the go routine that downloads the chunks. This sends messages through the progressChannel - go index.DownloadChunks(opts.Globals.Chain, chunks, chunkType, poolSize, progressChannel) + go index.DownloadChunks(chain, chunks, chunkType, poolSize, progressChannel) for event := range progressChannel { chunk, ok := event.Payload.(*manifest.ChunkRecord) diff --git a/src/apps/chifra/internal/init/handle_init_prepare.go b/src/apps/chifra/internal/init/handle_init_prepare.go index 1009e1348b..f4b0166e2d 100644 --- a/src/apps/chifra/internal/init/handle_init_prepare.go +++ b/src/apps/chifra/internal/init/handle_init_prepare.go @@ -105,7 +105,7 @@ func (opts *InitOptions) prepareDownloadList(chain string, man *manifest.Manifes } walker := index.NewCacheWalker( - opts.Globals.Chain, + chain, opts.Globals.TestMode, 10, /* maxTests */ cleanIndex, @@ -130,7 +130,7 @@ func (opts *InitOptions) prepareDownloadList(chain string, man *manifest.Manifes if rng.Last < opts.FirstBlock { continue } - _, indexPath := rng.RangeToFilename(opts.Globals.Chain) + _, indexPath := rng.RangeToFilename(chain) if !opts.All && !file.FileExists(indexPath) { chunk.IndexHash = "" chunk.IndexSize = 0 diff --git a/src/apps/chifra/internal/init/options.go b/src/apps/chifra/internal/init/options.go index 6587584cca..58680d2581 100644 --- a/src/apps/chifra/internal/init/options.go +++ b/src/apps/chifra/internal/init/options.go @@ -14,6 +14,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/globals" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/caps" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) @@ -24,6 +25,7 @@ type InitOptions struct { FirstBlock uint64 `json:"firstBlock,omitempty"` // Do not download any chunks earlier than this block Sleep float64 `json:"sleep,omitempty"` // Seconds to sleep between downloads Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -37,6 +39,7 @@ func (opts *InitOptions) testLog() { logger.TestLog(opts.DryRun, "DryRun: ", opts.DryRun) logger.TestLog(opts.FirstBlock != 0, "FirstBlock: ", opts.FirstBlock) logger.TestLog(opts.Sleep != float64(0.0), "Sleep: ", opts.Sleep) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -64,12 +67,17 @@ func initFinishParseApi(w http.ResponseWriter, r *http.Request) *InitOptions { opts.Sleep = globals.ToFloat64(value[0]) default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "init") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE // EXISTING_CODE @@ -81,6 +89,10 @@ func initFinishParse(args []string) *InitOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE if len(args) > 0 { opts.BadFlag = validate.Usage("Invalid argument ({0}).", args[0]) @@ -89,6 +101,7 @@ func initFinishParse(args []string) *InitOptions { if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/list/handle_freshen.go b/src/apps/chifra/internal/list/handle_freshen.go index 99bbc3ba92..8ccc5c90dc 100644 --- a/src/apps/chifra/internal/list/handle_freshen.go +++ b/src/apps/chifra/internal/list/handle_freshen.go @@ -71,6 +71,8 @@ func unlockForAddress(address string) { } func (opts *ListOptions) HandleFreshenMonitors(monitorArray *[]monitor.Monitor) (bool, error) { + chain := opts.Globals.Chain + // TODO: There are special case addresses for the sender of mining rewards and // TODO: prefund allocations that get ignored here because they are baddresses. // TODO: We could, if we wished, create special cases here to (for example) report @@ -107,7 +109,7 @@ func (opts *ListOptions) HandleFreshenMonitors(monitorArray *[]monitor.Monitor) } if updater.MonitorMap[base.HexToAddress(addr)] == nil { - mon, _ := monitor.NewStagedMonitor(opts.Globals.Chain, addr) + mon, _ := monitor.NewStagedMonitor(chain, addr) mon.ReadMonitorHeader() if uint64(mon.LastScanned) < updater.FirstBlock { updater.FirstBlock = uint64(mon.LastScanned) @@ -118,7 +120,6 @@ func (opts *ListOptions) HandleFreshenMonitors(monitorArray *[]monitor.Monitor) } } - chain := opts.Globals.Chain bloomPath := config.GetPathToIndex(chain) + "blooms/" files, err := os.ReadDir(bloomPath) if err != nil { @@ -188,7 +189,7 @@ func (opts *ListOptions) HandleFreshenMonitors(monitorArray *[]monitor.Monitor) if !opts.Globals.TestMode { // TODO: Note we could actually test this if we had the concept of a FAKE_HEAD block - stagePath := cache.ToStagingPath(config.GetPathToIndex(opts.Globals.Chain) + "staging") + stagePath := cache.ToStagingPath(config.GetPathToIndex(chain) + "staging") stageFn, _ := file.LatestFileInFolder(stagePath) rng := base.RangeFromFilename(stageFn) lines := []string{} diff --git a/src/apps/chifra/internal/list/options.go b/src/apps/chifra/internal/list/options.go index 03cab105a3..fc8b951bd3 100644 --- a/src/apps/chifra/internal/list/options.go +++ b/src/apps/chifra/internal/list/options.go @@ -34,6 +34,7 @@ type ListOptions struct { FirstBlock uint64 `json:"firstBlock,omitempty"` // First block to export (inclusive, ignored when freshening) LastBlock uint64 `json:"lastBlock,omitempty"` // Last block to export (inclusive, ignored when freshening) Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -57,6 +58,7 @@ func (opts *ListOptions) testLog() { logger.TestLog(opts.Reversed, "Reversed: ", opts.Reversed) logger.TestLog(opts.FirstBlock != 0, "FirstBlock: ", opts.FirstBlock) logger.TestLog(opts.LastBlock != 0 && opts.LastBlock != utils.NOPOS, "LastBlock: ", opts.LastBlock) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -103,14 +105,19 @@ func listFinishParseApi(w http.ResponseWriter, r *http.Request) *ListOptions { opts.LastBlock = globals.ToUint64(value[0]) default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "list") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE - opts.Addrs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Addrs) + opts.Addrs, _ = opts.Conn.GetAddressesFromEns(chain, opts.Addrs) // EXISTING_CODE return opts @@ -121,12 +128,17 @@ func listFinishParse(args []string) *ListOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE - opts.Addrs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, args) + opts.Addrs, _ = opts.Conn.GetAddressesFromEns(chain, args) // EXISTING_CODE if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/list/validate.go b/src/apps/chifra/internal/list/validate.go index 9361caef62..8a9a340c34 100644 --- a/src/apps/chifra/internal/list/validate.go +++ b/src/apps/chifra/internal/list/validate.go @@ -9,12 +9,13 @@ 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/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) func (opts *ListOptions) validateList() error { + chain := opts.Globals.Chain + opts.testLog() if opts.BadFlag != nil { @@ -35,7 +36,7 @@ func (opts *ListOptions) validateList() error { } if opts.LastBlock != utils.NOPOS && !opts.Globals.TestMode { - latest := rpcClient.GetLatestBlockNumber(opts.Globals.Chain) + latest := opts.Conn.GetLatestBlockNumber(chain) if opts.LastBlock > latest { msg := fmt.Sprintf("latest block (%d) must be before the chain's latest block (%d).", opts.LastBlock, latest) return validate.Usage(msg) @@ -62,7 +63,7 @@ func (opts *ListOptions) validateList() error { } // Note that this does not return if the index is not initialized - if err := index.IndexIsInitialized(opts.Globals.Chain); err != nil { + if err := index.IndexIsInitialized(chain); err != nil { if opts.Globals.IsApiMode() { return err } else { diff --git a/src/apps/chifra/internal/logs/handle_show.go b/src/apps/chifra/internal/logs/handle_show.go index a38fdc94ad..174c2f175e 100644 --- a/src/apps/chifra/internal/logs/handle_show.go +++ b/src/apps/chifra/internal/logs/handle_show.go @@ -9,7 +9,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/identifiers" "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/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) @@ -19,7 +18,6 @@ func (opts *LogsOptions) HandleShowLogs() error { chain := opts.Globals.Chain testMode := opts.Globals.TestMode nErrors := 0 - var rpcOptions = rpcClient.NoOptions ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawLog], errorChan chan error) { @@ -38,7 +36,7 @@ func (opts *LogsOptions) HandleShowLogs() error { BlockNumber: uint32(app.BlockNumber), TransactionIndex: uint32(app.TransactionIndex), } - if tx, err := rpcClient.GetTransactionByAppearance(chain, a, false /* needsTraces */, rpcOptions); err != nil { + if tx, err := opts.Conn.GetTransactionByAppearance(chain, a, false /* needsTraces */); err != nil { return fmt.Errorf("transaction at %s returned an error: %w", app.String(), err) } else if tx == nil || tx.Receipt == nil { return fmt.Errorf("transaction at %s has no logs", app.String()) diff --git a/src/apps/chifra/internal/logs/options.go b/src/apps/chifra/internal/logs/options.go index a8ac83a35b..e1ad637a4b 100644 --- a/src/apps/chifra/internal/logs/options.go +++ b/src/apps/chifra/internal/logs/options.go @@ -16,6 +16,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/caps" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/identifiers" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) @@ -25,6 +26,7 @@ type LogsOptions struct { TransactionIds []identifiers.Identifier `json:"transactionIds,omitempty"` // Transaction identifiers Articulate bool `json:"articulate,omitempty"` // Articulate the retrieved data if ABIs can be found Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -36,6 +38,7 @@ var defaultLogsOptions = LogsOptions{} func (opts *LogsOptions) testLog() { logger.TestLog(len(opts.Transactions) > 0, "Transactions: ", opts.Transactions) logger.TestLog(opts.Articulate, "Articulate: ", opts.Articulate) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -60,13 +63,19 @@ func logsFinishParseApi(w http.ResponseWriter, r *http.Request) *LogsOptions { opts.Articulate = true default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "logs") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, true, false) // EXISTING_CODE return opts @@ -77,12 +86,18 @@ func logsFinishParse(args []string) *LogsOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, true, false) opts.Transactions = args // EXISTING_CODE if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/logs/validate.go b/src/apps/chifra/internal/logs/validate.go index 3e704d1733..2a5595a6b4 100644 --- a/src/apps/chifra/internal/logs/validate.go +++ b/src/apps/chifra/internal/logs/validate.go @@ -9,6 +9,8 @@ import ( ) func (opts *LogsOptions) validateLogs() error { + chain := opts.Globals.Chain + opts.testLog() if opts.BadFlag != nil { @@ -27,7 +29,7 @@ func (opts *LogsOptions) validateLogs() error { } err := validate.ValidateIdentifiers( - opts.Globals.Chain, + chain, opts.Transactions, validate.ValidTransId, -1, diff --git a/src/apps/chifra/internal/monitors/handle_clean.go b/src/apps/chifra/internal/monitors/handle_clean.go index 18f3e73b72..efe8d4cb55 100644 --- a/src/apps/chifra/internal/monitors/handle_clean.go +++ b/src/apps/chifra/internal/monitors/handle_clean.go @@ -14,8 +14,9 @@ import ( // HandleClean handles the chifra monitors --clean command. func (opts *MonitorsOptions) HandleClean() error { + chain := opts.Globals.Chain testMode := opts.Globals.TestMode - _, monArray := monitor.GetMonitorMap(opts.Globals.Chain) + _, monArray := monitor.GetMonitorMap(chain) ctx := context.Background() fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { diff --git a/src/apps/chifra/internal/monitors/handle_crud.go b/src/apps/chifra/internal/monitors/handle_crud.go index a7db01af39..a266a738be 100644 --- a/src/apps/chifra/internal/monitors/handle_crud.go +++ b/src/apps/chifra/internal/monitors/handle_crud.go @@ -19,8 +19,9 @@ import ( // Deleted | Error | Undelete | Remove | Remove and Decache | // ------------|--------|------------------------------------------------| func (opts *MonitorsOptions) HandleCrudCommands() error { + chain := opts.Globals.Chain for _, addr := range opts.Addrs { - m := monitor.NewMonitor(opts.Globals.Chain, addr, false) + m := monitor.NewMonitor(chain, addr, false) if !file.FileExists(m.Path()) { return validate.Usage("No monitor was found for address " + addr + ".") @@ -45,7 +46,7 @@ func (opts *MonitorsOptions) HandleCrudCommands() error { } for _, addr := range opts.Addrs { - m := monitor.NewMonitor(opts.Globals.Chain, addr, false) + m := monitor.NewMonitor(chain, addr, false) if opts.Undelete { m.ReadMonitorHeader() m.UnDelete() diff --git a/src/apps/chifra/internal/monitors/handle_decache.go b/src/apps/chifra/internal/monitors/handle_decache.go index 44d4c835d0..c18d5e6b62 100644 --- a/src/apps/chifra/internal/monitors/handle_decache.go +++ b/src/apps/chifra/internal/monitors/handle_decache.go @@ -24,12 +24,13 @@ func (opts *MonitorsOptions) HandleDecache() error { return nil } + chain := opts.Globals.Chain for _, addr := range opts.Addrs { if !base.IsValidAddress(addr) { continue } - m := monitor.NewMonitor(opts.Globals.Chain, addr, false) + m := monitor.NewMonitor(chain, addr, false) if !usage.QueryUser(getWarning(addr, m.Count()), "Not decaching") { continue } @@ -63,7 +64,7 @@ func (opts *MonitorsOptions) HandleDecache() error { } // Visits every item in the cache related to this monitor and calls into `processorFunc` - err := m.Decache(opts.Globals.Chain, processorFunc) + err := m.Decache(chain, processorFunc) if err != nil { return err } diff --git a/src/apps/chifra/internal/monitors/handle_list.go b/src/apps/chifra/internal/monitors/handle_list.go index cc92218e9d..df5d6c0349 100644 --- a/src/apps/chifra/internal/monitors/handle_list.go +++ b/src/apps/chifra/internal/monitors/handle_list.go @@ -18,8 +18,8 @@ import ( // HandleList handles the chifra monitors --list command. func (opts *MonitorsOptions) HandleList() error { - testMode := opts.Globals.TestMode chain := opts.Globals.Chain + testMode := opts.Globals.TestMode monitorMap, monArray := monitor.GetMonitorMap(chain) if opts.Globals.Verbose { for i := 0; i < len(monArray); i++ { diff --git a/src/apps/chifra/internal/monitors/options.go b/src/apps/chifra/internal/monitors/options.go index cf4f108fa4..4b5893bf9d 100644 --- a/src/apps/chifra/internal/monitors/options.go +++ b/src/apps/chifra/internal/monitors/options.go @@ -31,6 +31,7 @@ type MonitorsOptions struct { Watch bool `json:"watch,omitempty"` // Continually scan for new blocks and extract data for monitored addresses Sleep float64 `json:"sleep,omitempty"` // Seconds to sleep between monitor passes Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -49,6 +50,7 @@ func (opts *MonitorsOptions) testLog() { logger.TestLog(opts.List, "List: ", opts.List) logger.TestLog(opts.Watch, "Watch: ", opts.Watch) logger.TestLog(opts.Sleep != float64(14), "Sleep: ", opts.Sleep) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -88,14 +90,19 @@ func monitorsFinishParseApi(w http.ResponseWriter, r *http.Request) *MonitorsOpt opts.Sleep = globals.ToFloat64(value[0]) default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "monitors") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE - opts.Addrs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Addrs) + opts.Addrs, _ = opts.Conn.GetAddressesFromEns(chain, opts.Addrs) // EXISTING_CODE return opts @@ -106,12 +113,17 @@ func monitorsFinishParse(args []string) *MonitorsOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE - opts.Addrs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, args) + opts.Addrs, _ = opts.Conn.GetAddressesFromEns(chain, args) // EXISTING_CODE if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/monitors/scrape_monitor.go b/src/apps/chifra/internal/monitors/scrape_monitor.go index 1f68e1c8f4..474107adda 100644 --- a/src/apps/chifra/internal/monitors/scrape_monitor.go +++ b/src/apps/chifra/internal/monitors/scrape_monitor.go @@ -30,7 +30,7 @@ func (opts *MonitorsOptions) RunMonitorScraper(wg *sync.WaitGroup) { chain := opts.Globals.Chain establishExportPaths(chain) - tmpPath := config.GetPathToCache(opts.Globals.Chain) + "tmp/" + tmpPath := config.GetPathToCache(chain) + "tmp/" var s = &MonitorScraper s.ChangeState(true, tmpPath) @@ -92,6 +92,7 @@ func (sp SemiParse) String() string { const addrsPerBatch = 8 func (opts *MonitorsOptions) Refresh(monitors []monitor.Monitor) (bool, error) { + chain := opts.Globals.Chain theCmds, _ := getCommandsFromFile(opts.Globals) batches := batchMonitors(monitors, addrsPerBatch) @@ -133,7 +134,7 @@ func (opts *MonitorsOptions) Refresh(monitors []monitor.Monitor) (bool, error) { cmd = strings.Replace(cmd, " ", " ", -1) o := opts o.Globals.File = "" - o.Globals.PassItOn("acctExport", opts.Globals.Chain, cmd, []string{}) + o.Globals.PassItOn("acctExport", chain, cmd, []string{}) // fmt.Println("Processing:", colors.BrightYellow, outputFn, colors.BrightWhite, exists, countBefore, countAfter, colors.Off) // } else { // fmt.Println("Skipping:", colors.BrightYellow, outputFn, colors.BrightWhite, exists, countBefore, countAfter, colors.Off) diff --git a/src/apps/chifra/internal/monitors/validate.go b/src/apps/chifra/internal/monitors/validate.go index a0c7350b4d..2af2bdaa6d 100644 --- a/src/apps/chifra/internal/monitors/validate.go +++ b/src/apps/chifra/internal/monitors/validate.go @@ -15,6 +15,8 @@ import ( ) func (opts *MonitorsOptions) validateMonitors() error { + chain := opts.Globals.Chain + opts.testLog() if opts.BadFlag != nil { @@ -29,7 +31,7 @@ func (opts *MonitorsOptions) validateMonitors() error { // phonied up just to make sure we have bloom for block zero var expOpts exportPkg.ExportOptions expOpts.Addrs = append(expOpts.Addrs, "0x0000000000000000000000000000000000000001") - expOpts.Globals.Chain = opts.Globals.Chain + expOpts.Globals.Chain = chain err := expOpts.Validate() if err != nil { return validate.Usage(err.Error()) diff --git a/src/apps/chifra/internal/names/handle_autoname.go b/src/apps/chifra/internal/names/handle_autoname.go index dba7f839aa..1bebc2feca 100644 --- a/src/apps/chifra/internal/names/handle_autoname.go +++ b/src/apps/chifra/internal/names/handle_autoname.go @@ -8,11 +8,12 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/names" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) func (opts *NamesOptions) HandleAutoname() error { + chain := opts.Globals.Chain + // For --dry_run, we don't want to write to the real database var overrideDatabase names.Database if opts.DryRun { @@ -24,7 +25,7 @@ func (opts *NamesOptions) HandleAutoname() error { return err } - err = names.WriteRegularNames(opts.Globals.Chain, overrideDatabase) + err = names.WriteRegularNames(chain, overrideDatabase) if err != nil { return err } @@ -55,7 +56,8 @@ func (opts *NamesOptions) HandleAutoname() error { // readContractAndClean will read contract data and call `cleanName` for the given address func (opts *NamesOptions) readContractAndClean() (name *types.SimpleName, err error) { - converted, ok := rpcClient.GetAddressesFromEns(opts.Globals.Chain, []string{opts.Autoname}) + chain := opts.Globals.Chain + converted, ok := opts.Conn.GetAddressesFromEns(chain, []string{opts.Autoname}) term := opts.Autoname if ok { term = converted[0] @@ -68,7 +70,7 @@ func (opts *NamesOptions) readContractAndClean() (name *types.SimpleName, err er Source: "TrueBlocks.io", IsCustom: false, } - if _, err = cleanName(opts.Globals.Chain, name); err != nil { + if _, err = cleanName(chain, name); err != nil { err = fmt.Errorf("autoname %s: %w", &address, err) return } @@ -79,7 +81,7 @@ func (opts *NamesOptions) readContractAndClean() (name *types.SimpleName, err er return } - if _, err = names.LoadNamesMap(opts.Globals.Chain, names.Regular, []string{}); err != nil { + if _, err = names.LoadNamesMap(chain, names.Regular, []string{}); err != nil { return } diff --git a/src/apps/chifra/internal/names/handle_clean.go b/src/apps/chifra/internal/names/handle_clean.go index 0d133b37a9..179986cdf2 100644 --- a/src/apps/chifra/internal/names/handle_clean.go +++ b/src/apps/chifra/internal/names/handle_clean.go @@ -22,13 +22,15 @@ import ( ) func (opts *NamesOptions) HandleClean() error { + chain := opts.Globals.Chain + label := "custom" db := names.DatabaseCustom if opts.Regular { label = "regular" db = names.DatabaseRegular } - sourcePath := names.GetDatabasePath(opts.Globals.Chain, db) + sourcePath := names.GetDatabasePath(chain, db) logger.Info("Processing", label, "names file", "("+sourcePath+")") destinationLabel := sourcePath if opts.DryRun { @@ -57,17 +59,19 @@ func (opts *NamesOptions) HandleClean() error { } func (opts *NamesOptions) cleanNames() (int, error) { + chain := opts.Globals.Chain + parts := names.Custom if opts.Regular { parts = names.Regular } // Load databases - allNames, err := names.LoadNamesMap(opts.Globals.Chain, parts, []string{}) + allNames, err := names.LoadNamesMap(chain, parts, []string{}) if err != nil { return 0, err } - prefundMap, err := preparePrefunds(opts.Globals.Chain) + prefundMap, err := preparePrefunds(chain) if err != nil { return 0, err } @@ -110,7 +114,7 @@ func (opts *NamesOptions) cleanNames() (int, error) { defer cancel() errorChan := make(chan error) go utils.IterateOverMap(ctx, errorChan, allNames, func(address base.Address, name types.SimpleName) error { - modified, err := cleanName(opts.Globals.Chain, &name) + modified, err := cleanName(chain, &name) if err != nil { return wrapErrorWithAddr(&address, err) } @@ -154,10 +158,10 @@ func (opts *NamesOptions) cleanNames() (int, error) { // Write to disk if opts.Regular { - return modifiedCount, names.WriteRegularNames(opts.Globals.Chain, overrideDatabase) + return modifiedCount, names.WriteRegularNames(chain, overrideDatabase) } - return modifiedCount, names.WriteCustomNames(opts.Globals.Chain, overrideDatabase) + return modifiedCount, names.WriteCustomNames(chain, overrideDatabase) } // wrapErrorWithAddr prepends `err` with `address`, so that we can learn which name caused troubles @@ -183,7 +187,8 @@ func preparePrefunds(chain string) (results map[base.Address]bool, err error) { } func cleanName(chain string, name *types.SimpleName) (modified bool, err error) { - if err = rpcClient.IsContractAt(chain, name.Address, nil); err != nil && !errors.Is(err, rpcClient.ErrNotAContract) { + conn := rpcClient.NewConnection(chain, []string{}) + if err = conn.IsContractAt(chain, name.Address, nil); err != nil && !errors.Is(err, rpcClient.ErrNotAContract) { return } diff --git a/src/apps/chifra/internal/names/handle_crud.go b/src/apps/chifra/internal/names/handle_crud.go index ba55012ddb..0b3cc720b8 100644 --- a/src/apps/chifra/internal/names/handle_crud.go +++ b/src/apps/chifra/internal/names/handle_crud.go @@ -11,33 +11,35 @@ import ( ) func (opts *NamesOptions) HandleCrud() (err error) { + chain := opts.Globals.Chain + parts := opts.getType() // TODO: Why do we do this if we don't use the result? - if _, err = names.LoadNamesMap(opts.Globals.Chain, parts, nil); err != nil { + if _, err = names.LoadNamesMap(chain, parts, nil); err != nil { return err } var name *types.SimpleName if opts.Create || opts.Update { - name, err = handleCreate(opts.Globals.Chain, opts.crudData) + name, err = handleCreate(chain, opts.crudData) if err != nil { return } } if opts.Delete { - name, err = handleDelete(opts.Globals.Chain, opts.crudData) + name, err = handleDelete(chain, opts.crudData) if err != nil { return } } if opts.Undelete { - name, err = handleUndelete(opts.Globals.Chain, opts.crudData) + name, err = handleUndelete(chain, opts.crudData) if err != nil { return } } if opts.Remove { - name, err = handleRemove(opts.Globals.Chain, opts.crudData) + name, err = handleRemove(chain, opts.crudData) // Remove doesn't print the removed item return } diff --git a/src/apps/chifra/internal/names/handle_tags.go b/src/apps/chifra/internal/names/handle_tags.go index ad698fd64b..dd9865b971 100644 --- a/src/apps/chifra/internal/names/handle_tags.go +++ b/src/apps/chifra/internal/names/handle_tags.go @@ -11,7 +11,8 @@ import ( ) func (opts *NamesOptions) HandleTags() error { - namesArray, err := names.LoadNamesArray(opts.Globals.Chain, opts.getType(), names.SortByTags, opts.Terms) + chain := opts.Globals.Chain + namesArray, err := names.LoadNamesArray(chain, opts.getType(), names.SortByTags, opts.Terms) if err != nil { return err } diff --git a/src/apps/chifra/internal/names/handle_terms.go b/src/apps/chifra/internal/names/handle_terms.go index 379ef96e7c..655f1ccd09 100644 --- a/src/apps/chifra/internal/names/handle_terms.go +++ b/src/apps/chifra/internal/names/handle_terms.go @@ -15,6 +15,7 @@ import ( ) func (opts *NamesOptions) HandleTerms() error { + chain := opts.Globals.Chain var fetchData func(modelChan chan types.Modeler[types.RawName], errorChan chan error) apiMode := opts.Globals.IsApiMode() @@ -43,7 +44,7 @@ func (opts *NamesOptions) HandleTerms() error { logger.Warn("falling back to file-based search") } - namesArray, err := names.LoadNamesArray(opts.Globals.Chain, opts.getType(), names.SortByAddress, opts.Terms) + namesArray, err := names.LoadNamesArray(chain, opts.getType(), names.SortByAddress, opts.Terms) if err != nil { return err } diff --git a/src/apps/chifra/internal/names/options.go b/src/apps/chifra/internal/names/options.go index 624b316f6a..77ef0923e9 100644 --- a/src/apps/chifra/internal/names/options.go +++ b/src/apps/chifra/internal/names/options.go @@ -40,6 +40,7 @@ type NamesOptions struct { Remove bool `json:"remove,omitempty"` // Remove a previously deleted name Named bool `json:"named,omitempty"` // Please use the --all option instead Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE crudData *CrudData @@ -68,6 +69,7 @@ func (opts *NamesOptions) testLog() { logger.TestLog(opts.Undelete, "Undelete: ", opts.Undelete) logger.TestLog(opts.Remove, "Remove: ", opts.Remove) logger.TestLog(opts.Named, "Named: ", opts.Named) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -124,14 +126,19 @@ func namesFinishParseApi(w http.ResponseWriter, r *http.Request) *NamesOptions { opts.Named = true default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "names") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE - opts.Terms, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Terms) + opts.Terms, _ = opts.Conn.GetAddressesFromEns(chain, opts.Terms) // EXISTING_CODE return opts @@ -142,12 +149,17 @@ func namesFinishParse(args []string) *NamesOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE - opts.Terms, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, args) + opts.Terms, _ = opts.Conn.GetAddressesFromEns(chain, args) // EXISTING_CODE if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/names/output_test.go b/src/apps/chifra/internal/names/output_test.go index 8d4abd2dcb..b10a0ea9bb 100644 --- a/src/apps/chifra/internal/names/output_test.go +++ b/src/apps/chifra/internal/names/output_test.go @@ -19,6 +19,8 @@ import ( "testing" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) func TestNamesOptions_getCrudDataHttp(t *testing.T) { @@ -141,6 +143,8 @@ func TestNamesOptions_getCrudDataEnv(t *testing.T) { } setEnvs(expected) opts = &NamesOptions{} + chain := utils.GetTestChain() + opts.Conn = rpcClient.NewConnection(chain, []string{}) result, err = opts.getCrudDataEnv() if err != nil { t.Fatal(err) @@ -163,6 +167,7 @@ func TestNamesOptions_getCrudDataEnv(t *testing.T) { } setEnvs(expected) opts = &NamesOptions{} + opts.Conn = rpcClient.NewConnection(chain, []string{}) _, err = opts.getCrudDataEnv() if err == nil { t.Fatal("error expected") diff --git a/src/apps/chifra/internal/receipts/handle_show.go b/src/apps/chifra/internal/receipts/handle_show.go index 1ec03e94fe..19cea09d9f 100644 --- a/src/apps/chifra/internal/receipts/handle_show.go +++ b/src/apps/chifra/internal/receipts/handle_show.go @@ -9,7 +9,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/identifiers" "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/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) @@ -19,7 +18,6 @@ func (opts *ReceiptsOptions) HandleShowReceipts() error { chain := opts.Globals.Chain testMode := opts.Globals.TestMode nErrors := 0 - var rpcOptions = rpcClient.NoOptions ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawReceipt], errorChan chan error) { @@ -38,7 +36,7 @@ func (opts *ReceiptsOptions) HandleShowReceipts() error { BlockNumber: uint32(app.BlockNumber), TransactionIndex: uint32(app.TransactionIndex), } - if tx, err := rpcClient.GetTransactionByAppearance(chain, a, false /* needsTraces */, rpcOptions); err != nil { + if tx, err := opts.Conn.GetTransactionByAppearance(chain, a, false /* needsTraces */); err != nil { return fmt.Errorf("transaction at %s returned an error: %w", app.String(), err) } else if tx == nil || tx.Receipt == nil { return fmt.Errorf("transaction at %s has no logs", app.String()) diff --git a/src/apps/chifra/internal/receipts/options.go b/src/apps/chifra/internal/receipts/options.go index 218a72809e..08b0e6643f 100644 --- a/src/apps/chifra/internal/receipts/options.go +++ b/src/apps/chifra/internal/receipts/options.go @@ -16,6 +16,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/caps" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/identifiers" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) @@ -25,6 +26,7 @@ type ReceiptsOptions struct { TransactionIds []identifiers.Identifier `json:"transactionIds,omitempty"` // Transaction identifiers Articulate bool `json:"articulate,omitempty"` // Articulate the retrieved data if ABIs can be found Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -36,6 +38,7 @@ var defaultReceiptsOptions = ReceiptsOptions{} func (opts *ReceiptsOptions) testLog() { logger.TestLog(len(opts.Transactions) > 0, "Transactions: ", opts.Transactions) logger.TestLog(opts.Articulate, "Articulate: ", opts.Articulate) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -60,13 +63,19 @@ func receiptsFinishParseApi(w http.ResponseWriter, r *http.Request) *ReceiptsOpt opts.Articulate = true default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "receipts") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, true, false) // EXISTING_CODE return opts @@ -77,12 +86,18 @@ func receiptsFinishParse(args []string) *ReceiptsOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, true, false) opts.Transactions = args // EXISTING_CODE if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/receipts/validate.go b/src/apps/chifra/internal/receipts/validate.go index 589949483a..bee8a89728 100644 --- a/src/apps/chifra/internal/receipts/validate.go +++ b/src/apps/chifra/internal/receipts/validate.go @@ -9,6 +9,8 @@ import ( ) func (opts *ReceiptsOptions) validateReceipts() error { + chain := opts.Globals.Chain + opts.testLog() if opts.BadFlag != nil { @@ -27,7 +29,7 @@ func (opts *ReceiptsOptions) validateReceipts() error { } err := validate.ValidateIdentifiers( - opts.Globals.Chain, + chain, opts.Transactions, validate.ValidTransId, -1, diff --git a/src/apps/chifra/internal/scrape/handle_blaze_blaze.go b/src/apps/chifra/internal/scrape/handle_blaze_blaze.go index e727a2b64f..f5bafd5670 100644 --- a/src/apps/chifra/internal/scrape/handle_blaze_blaze.go +++ b/src/apps/chifra/internal/scrape/handle_blaze_blaze.go @@ -122,14 +122,17 @@ func (opts *BlazeOptions) BlazeProcessBlocks(meta *rpcClient.MetaData, blockChan blockNumber: base.Blknum(bn), } + chain := opts.Chain + conn := rpcClient.NewConnection(chain, []string{}) + // TODO: BOGUS - This could use rawTraces so as to avoid unnecessary decoding - if sd.traces, err = rpcClient.GetTracesByNumber(opts.Chain, uint64(bn)); err != nil { + if sd.traces, err = conn.GetTracesByNumber(chain, uint64(bn)); err != nil { // TODO: BOGUS - we should send in an errorChannel and send the error down that channel and continue here return err } // TODO: BOGUS - This could use rawTraces so as to avoid unnecessary decoding - if sd.logs, err = rpcClient.GetLogsByNumber(opts.Chain, uint64(bn)); err != nil { + if sd.logs, err = conn.GetLogsByNumber(chain, uint64(bn)); err != nil { // TODO: BOGUS - we should send in an errorChannel and send the error down that channel and continue here return err } @@ -138,7 +141,7 @@ func (opts *BlazeOptions) BlazeProcessBlocks(meta *rpcClient.MetaData, blockChan ts := tslib.TimestampRecord{ Bn: uint32(bn), - Ts: uint32(rpcClient.GetBlockTimestamp(opts.Chain, utils.PointerOf(uint64(bn)))), + Ts: uint32(conn.GetBlockTimestamp(chain, utils.PointerOf(uint64(bn)))), } tsChannel <- ts diff --git a/src/apps/chifra/internal/scrape/handle_prepare.go b/src/apps/chifra/internal/scrape/handle_prepare.go index 4422954563..a9accd78d3 100644 --- a/src/apps/chifra/internal/scrape/handle_prepare.go +++ b/src/apps/chifra/internal/scrape/handle_prepare.go @@ -23,17 +23,19 @@ import ( // true if the processing should continue, false otherwise. Currently, the only thing to do // is write the zero block Index Chunk / Bloom filter pair if it doesn't exist. func (opts *ScrapeOptions) HandlePrepare(progressThen *rpcClient.MetaData, blazeOpts *BlazeOptions) (ok bool, err error) { + chain := opts.Globals.Chain + // We always clean the temporary folders (other than staging) when starting - index.CleanTemporaryFolders(config.GetPathToIndex(opts.Globals.Chain), false) + index.CleanTemporaryFolders(config.GetPathToIndex(chain), false) - bloomPath := config.GetPathToIndex(opts.Globals.Chain) + "blooms/000000000-000000000.bloom" + bloomPath := config.GetPathToIndex(chain) + "blooms/000000000-000000000.bloom" if file.FileExists(bloomPath) { // The file already exists, nothing to do return true, nil } - prefundPath := filepath.Join(config.GetPathToChainConfig(opts.Globals.Chain), "allocs.csv") - prefunds, err := prefunds.LoadPrefunds(opts.Globals.Chain, prefundPath, nil) + prefundPath := filepath.Join(config.GetPathToChainConfig(chain), "allocs.csv") + prefunds, err := prefunds.LoadPrefunds(chain, prefundPath, nil) if err != nil { return false, err } @@ -50,13 +52,13 @@ func (opts *ScrapeOptions) HandlePrepare(progressThen *rpcClient.MetaData, blaze array := []tslib.TimestampRecord{} array = append(array, tslib.TimestampRecord{ Bn: uint32(0), - Ts: uint32(rpcClient.GetBlockTimestamp(opts.Globals.Chain, utils.PointerOf(uint64(0)))), + Ts: uint32(opts.Conn.GetBlockTimestamp(chain, utils.PointerOf(uint64(0)))), }) - tslib.Append(opts.Globals.Chain, array) + tslib.Append(chain, array) logger.Info("Writing block zero allocations for", len(prefunds), "prefunds, nAddresses:", len(appMap)) indexPath := cache.ToIndexPath(bloomPath) - if report, err := index.WriteChunk(opts.Globals.Chain, indexPath, appMap, len(prefunds), opts.Pin, opts.Remote); err != nil { + if report, err := index.WriteChunk(chain, indexPath, appMap, len(prefunds), opts.Pin, opts.Remote); err != nil { return false, err } else if report == nil { logger.Fatal("Should not happen, write chunk returned empty report") diff --git a/src/apps/chifra/internal/scrape/handle_scrape.go b/src/apps/chifra/internal/scrape/handle_scrape.go index 428549270b..f5015a775f 100644 --- a/src/apps/chifra/internal/scrape/handle_scrape.go +++ b/src/apps/chifra/internal/scrape/handle_scrape.go @@ -23,16 +23,17 @@ import ( // TODO: Make sure we're not running acctScrape and/or pause if it's running func (opts *ScrapeOptions) HandleScrape() error { - progress, err := rpcClient.GetMetaData(opts.Globals.Chain, opts.Globals.TestMode) + chain := opts.Globals.Chain + conn := rpcClient.NewConnection(chain, []string{}) + + progress, err := conn.GetMetaData(chain, opts.Globals.TestMode) if err != nil { return err } - chain := opts.Globals.Chain provider, _ := config.GetRpcProvider(chain) - blazeOpts := BlazeOptions{ - Chain: opts.Globals.Chain, + Chain: chain, NChannels: opts.Settings.Channel_count, NProcessed: 0, StartBlock: opts.StartBlock, @@ -50,7 +51,7 @@ func (opts *ScrapeOptions) HandleScrape() error { origBlockCnt := opts.BlockCnt for { - progress, err = rpcClient.GetMetaData(opts.Globals.Chain, opts.Globals.TestMode) + progress, err = conn.GetMetaData(chain, opts.Globals.TestMode) if err != nil { return err } @@ -72,11 +73,10 @@ func (opts *ScrapeOptions) HandleScrape() error { ripeBlock = progress.Latest - opts.Settings.Unripe_dist } - chain := opts.Globals.Chain provider, _ := config.GetRpcProvider(chain) blazeOpts = BlazeOptions{ - Chain: opts.Globals.Chain, + Chain: chain, NChannels: opts.Settings.Channel_count, NProcessed: 0, StartBlock: opts.StartBlock, @@ -92,7 +92,7 @@ func (opts *ScrapeOptions) HandleScrape() error { // Remove whatever's in the unripePath before running each round. We do this // because the chain may have re-organized (which it does frequently). This is // why we have an unripePath. - unripePath := filepath.Join(config.GetPathToIndex(opts.Globals.Chain), "unripe") + unripePath := filepath.Join(config.GetPathToIndex(chain), "unripe") err = os.RemoveAll(unripePath) if err != nil { return err diff --git a/src/apps/chifra/internal/scrape/handle_scrape_blaze.go b/src/apps/chifra/internal/scrape/handle_scrape_blaze.go index 5d3e6a90d0..68c27494e6 100644 --- a/src/apps/chifra/internal/scrape/handle_scrape_blaze.go +++ b/src/apps/chifra/internal/scrape/handle_scrape_blaze.go @@ -22,10 +22,11 @@ import ( // HandleScrapeBlaze is called each time around the forever loop prior to calling into // Blaze to actually scrape the blocks. func (opts *ScrapeOptions) HandleScrapeBlaze(progress *rpcClient.MetaData, blazeOpts *BlazeOptions) error { + chain := opts.Globals.Chain // Do the actual scrape, wait until it finishes, clean up and return on failure if _, err := blazeOpts.HandleBlaze(progress); err != nil { - index.CleanTemporaryFolders(config.GetPathToIndex(opts.Globals.Chain), false) + index.CleanTemporaryFolders(config.GetPathToIndex(chain), false) return err } @@ -33,7 +34,7 @@ func (opts *ScrapeOptions) HandleScrapeBlaze(progress *rpcClient.MetaData, blaze if !blazeOpts.ProcessedMap[bn] { // At least one block was not processed. This would only happen in the event of an // error, so clean up, report the error and return. The loop will repeat. - index.CleanTemporaryFolders(config.GetPathToIndex(opts.Globals.Chain), false) + index.CleanTemporaryFolders(config.GetPathToIndex(chain), false) msg := fmt.Sprintf("A block %d was not processed%s", bn, strings.Repeat(" ", 50)) return errors.New(msg) } @@ -47,6 +48,8 @@ func (opts *ScrapeOptions) HandleScrapeBlaze(progress *rpcClient.MetaData, blaze // TODO: Protect against overwriting files on disc func WriteTimestamps(chain string, tsArray []tslib.TimestampRecord, endPoint uint64) error { + conn := rpcClient.NewConnection(chain, []string{}) + sort.Slice(tsArray, func(i, j int) bool { return tsArray[i].Bn < tsArray[j].Bn }) @@ -75,14 +78,14 @@ func WriteTimestamps(chain string, tsArray []tslib.TimestampRecord, endPoint uin if cnt >= len(tsArray) { ts = tslib.TimestampRecord{ Bn: uint32(bn), - Ts: uint32(rpcClient.GetBlockTimestamp(chain, &bn)), + Ts: uint32(conn.GetBlockTimestamp(chain, &bn)), } } else { ts = tsArray[cnt] if tsArray[cnt].Bn != uint32(bn) { ts = tslib.TimestampRecord{ Bn: uint32(bn), - Ts: uint32(rpcClient.GetBlockTimestamp(chain, &bn)), + Ts: uint32(conn.GetBlockTimestamp(chain, &bn)), } cnt-- // set it back } diff --git a/src/apps/chifra/internal/scrape/handle_scrape_consolidate.go b/src/apps/chifra/internal/scrape/handle_scrape_consolidate.go index 3594b904e1..1a77b44ad4 100644 --- a/src/apps/chifra/internal/scrape/handle_scrape_consolidate.go +++ b/src/apps/chifra/internal/scrape/handle_scrape_consolidate.go @@ -23,14 +23,16 @@ const asciiAppearanceSize = 59 // HandleScrapeConsolidate calls into the block scraper to (a) call Blaze and (b) consolidate if applicable func (opts *ScrapeOptions) HandleScrapeConsolidate(progressThen *rpcClient.MetaData, blazeOpts *BlazeOptions) (bool, error) { + chain := blazeOpts.Chain + // Get a sorted list of files in the ripe folder - ripeFolder := filepath.Join(config.GetPathToIndex(blazeOpts.Chain), "ripe") + ripeFolder := filepath.Join(config.GetPathToIndex(chain), "ripe") ripeFileList, err := os.ReadDir(ripeFolder) if err != nil { return true, err } - stageFolder := filepath.Join(config.GetPathToIndex(blazeOpts.Chain), "staging") + stageFolder := filepath.Join(config.GetPathToIndex(chain), "staging") if len(ripeFileList) == 0 { // On active chains, this most likely never happens, but on some less used or private chains, this is a frequent occurrence. // return a message, but don't do anything about it. @@ -55,9 +57,9 @@ func (opts *ScrapeOptions) HandleScrapeConsolidate(progressThen *rpcClient.MetaD ripeCnt := len(ripeFileList) if uint64(ripeCnt) < (blazeOpts.BlockCount - blazeOpts.UnripeDist) { // Then, if they are not at least sequential, clean up and try again... - allowMissing := scrapeCfg.AllowMissing(blazeOpts.Chain) - if err := isListSequential(blazeOpts.Chain, ripeFileList, allowMissing); err != nil { - index.CleanTemporaryFolders(config.GetPathToCache(blazeOpts.Chain), false) + allowMissing := scrapeCfg.AllowMissing(chain) + if err := isListSequential(chain, ripeFileList, allowMissing); err != nil { + index.CleanTemporaryFolders(config.GetPathToCache(chain), false) return true, err } } @@ -74,7 +76,7 @@ func (opts *ScrapeOptions) HandleScrapeConsolidate(progressThen *rpcClient.MetaD } // Note, this file may be empty or non-existant - tmpPath := filepath.Join(config.GetPathToCache(blazeOpts.Chain) + "tmp") + tmpPath := filepath.Join(config.GetPathToCache(chain) + "tmp") backupFn, err := file.MakeBackup(tmpPath, stageFn) if err != nil { return true, errors.New("Could not create backup file: " + err.Error()) @@ -119,8 +121,8 @@ func (opts *ScrapeOptions) HandleScrapeConsolidate(progressThen *rpcClient.MetaD } } - indexPath := config.GetPathToIndex(blazeOpts.Chain) + "finalized/" + curRange.String() + ".bin" - if report, err := index.WriteChunk(blazeOpts.Chain, indexPath, appMap, len(appearances), opts.Pin, opts.Remote); err != nil { + indexPath := config.GetPathToIndex(chain) + "finalized/" + curRange.String() + ".bin" + if report, err := index.WriteChunk(chain, indexPath, appMap, len(appearances), opts.Pin, opts.Remote); err != nil { return false, err } else if report == nil { logger.Fatal("Should not happen, write chunk returned empty report") @@ -144,10 +146,12 @@ func (opts *ScrapeOptions) HandleScrapeConsolidate(progressThen *rpcClient.MetaD } else { return true, errors.New("Cannot find last block number at lineLast in consolidate: " + lineLast) } - m, _ := rpcClient.GetMetaData(blazeOpts.Chain, opts.Globals.TestMode) + + conn := rpcClient.NewConnection(chain, []string{}) + m, _ := conn.GetMetaData(chain, opts.Globals.TestMode) rng := base.FileRange{First: m.Finalized + 1, Last: Last} f := fmt.Sprintf("%s.txt", rng) - fileName := filepath.Join(config.GetPathToIndex(blazeOpts.Chain), "staging", f) + fileName := filepath.Join(config.GetPathToIndex(chain), "staging", f) err = file.LinesToAsciiFile(fileName, appearances) if err != nil { os.Remove(fileName) // cleans up by replacing the previous stage diff --git a/src/apps/chifra/internal/scrape/options.go b/src/apps/chifra/internal/scrape/options.go index 131127bafb..d085b1a0f6 100644 --- a/src/apps/chifra/internal/scrape/options.go +++ b/src/apps/chifra/internal/scrape/options.go @@ -15,6 +15,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/caps" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config/scrapeCfg" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) @@ -27,6 +28,7 @@ type ScrapeOptions struct { StartBlock uint64 `json:"startBlock,omitempty"` // First block to visit when scraping (snapped back to most recent snap_to_grid mark) Settings scrapeCfg.ScrapeSettings `json:"settings,omitempty"` // Configuration items for the scrape Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -44,6 +46,7 @@ func (opts *ScrapeOptions) testLog() { logger.TestLog(opts.Sleep != float64(14), "Sleep: ", opts.Sleep) logger.TestLog(opts.StartBlock != 0, "StartBlock: ", opts.StartBlock) opts.Settings.TestLog(opts.Globals.Chain, opts.Globals.TestMode) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -91,12 +94,17 @@ func scrapeFinishParseApi(w http.ResponseWriter, r *http.Request) *ScrapeOptions opts.Settings.Allow_missing = true default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "scrape") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE // EXISTING_CODE @@ -108,6 +116,10 @@ func scrapeFinishParse(args []string) *ScrapeOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE if len(args) == 1 && (args[0] == "run" || args[0] == "indexer") { // these options have been deprecated, so do nothing @@ -120,6 +132,7 @@ func scrapeFinishParse(args []string) *ScrapeOptions { if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/scrape/validate.go b/src/apps/chifra/internal/scrape/validate.go index aa759f2900..58fc6960b3 100644 --- a/src/apps/chifra/internal/scrape/validate.go +++ b/src/apps/chifra/internal/scrape/validate.go @@ -11,7 +11,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config/scrapeCfg" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/pinning" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) @@ -20,8 +19,10 @@ import ( // TODO: https://github.com/storj/uplink/blob/v1.7.0/bucket.go#L19 func (opts *ScrapeOptions) validateScrape() error { + chain := opts.Globals.Chain + // First, we need to pick up the settings TODO: Should be auto-generated code somehow - opts.Settings, _ = scrapeCfg.GetSettings(opts.Globals.Chain, "blockScrape.toml", &opts.Settings) + opts.Settings, _ = scrapeCfg.GetSettings(chain, "blockScrape.toml", &opts.Settings) opts.testLog() @@ -38,7 +39,7 @@ func (opts *ScrapeOptions) validateScrape() error { return validate.Usage("Cannot test block scraper") } - meta, err := rpcClient.GetMetaData(opts.Globals.Chain, opts.Globals.TestMode) + meta, err := opts.Conn.GetMetaData(chain, opts.Globals.TestMode) if err != nil { return err } @@ -49,7 +50,7 @@ func (opts *ScrapeOptions) validateScrape() error { if opts.Pin { if opts.Remote { - pinataKey, pinataSecret, estuaryKey := config.GetPinningKeys(opts.Globals.Chain) + pinataKey, pinataSecret, estuaryKey := config.GetPinningKeys(chain) if (pinataKey == "" || pinataSecret == "") && estuaryKey == "" { return validate.Usage("The {0} option requires {1}.", "--pin --remote", "an api key") } @@ -61,7 +62,7 @@ func (opts *ScrapeOptions) validateScrape() error { } // Note this does not return if a migration is needed - index.CheckBackLevelIndex(opts.Globals.Chain) + index.CheckBackLevelIndex(chain) return opts.Globals.Validate() } diff --git a/src/apps/chifra/internal/slurp/handle_show.go b/src/apps/chifra/internal/slurp/handle_show.go index b0e88be271..e14547a0ac 100644 --- a/src/apps/chifra/internal/slurp/handle_show.go +++ b/src/apps/chifra/internal/slurp/handle_show.go @@ -243,6 +243,8 @@ func mustParseInt(input any) (result int64) { } func (opts *SlurpOptions) isInRange(bn uint, errorChan chan error) bool { + chain := opts.Globals.Chain + // Note that validation ensures that there is only a single isInRange if len(opts.BlockIds) == 0 { return true @@ -254,7 +256,7 @@ func (opts *SlurpOptions) isInRange(bn uint, errorChan chan error) bool { return br.Start.Number <= bn && bn <= br.End.Number } - blockNums, err := br.ResolveBlocks(opts.Globals.Chain) + blockNums, err := br.ResolveBlocks(chain) if err != nil { errorChan <- err return false diff --git a/src/apps/chifra/internal/slurp/options.go b/src/apps/chifra/internal/slurp/options.go index bd5ab76c7f..9b6092badd 100644 --- a/src/apps/chifra/internal/slurp/options.go +++ b/src/apps/chifra/internal/slurp/options.go @@ -31,6 +31,7 @@ type SlurpOptions struct { PerPage uint64 `json:"perPage,omitempty"` // The number of records to request on each page Sleep float64 `json:"sleep,omitempty"` // Seconds to sleep between requests Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -48,6 +49,7 @@ func (opts *SlurpOptions) testLog() { logger.TestLog(opts.Appearances, "Appearances: ", opts.Appearances) logger.TestLog(opts.PerPage != 5000, "PerPage: ", opts.PerPage) logger.TestLog(opts.Sleep != float64(.25), "Sleep: ", opts.Sleep) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -88,14 +90,20 @@ func slurpFinishParseApi(w http.ResponseWriter, r *http.Request) *SlurpOptions { opts.Sleep = globals.ToFloat64(value[0]) default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "slurp") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE - opts.Addrs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Addrs) + opts.Conn.EnableCaches(opts.Globals.Cache, true, false) + opts.Addrs, _ = opts.Conn.GetAddressesFromEns(chain, opts.Addrs) hasAll := false for _, t := range opts.Types { if t == "all" { @@ -118,7 +126,12 @@ func slurpFinishParse(args []string) *SlurpOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, true, false) dupMap := make(map[string]bool) for _, arg := range args { if !dupMap[arg] { @@ -130,7 +143,7 @@ func slurpFinishParse(args []string) *SlurpOptions { } dupMap[arg] = true } - opts.Addrs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Addrs) + opts.Addrs, _ = opts.Conn.GetAddressesFromEns(chain, opts.Addrs) hasAll := false for _, t := range opts.Types { if t == "all" { @@ -147,6 +160,7 @@ func slurpFinishParse(args []string) *SlurpOptions { if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/slurp/validate.go b/src/apps/chifra/internal/slurp/validate.go index 944b49deae..eccac39139 100644 --- a/src/apps/chifra/internal/slurp/validate.go +++ b/src/apps/chifra/internal/slurp/validate.go @@ -12,6 +12,8 @@ import ( ) func (opts *SlurpOptions) validateSlurp() error { + chain := opts.Globals.Chain + opts.testLog() if opts.BadFlag != nil { @@ -28,7 +30,7 @@ func (opts *SlurpOptions) validateSlurp() error { return err } - if opts.Globals.Chain != "mainnet" { + if chain != "mainnet" { return validate.Usage("The {0} command is currently available only on the {1} chain.", "slurp", "mainnet") } @@ -43,7 +45,7 @@ func (opts *SlurpOptions) validateSlurp() error { } err = validate.ValidateIdentifiers( - opts.Globals.Chain, + chain, opts.Blocks, validate.ValidBlockIdWithRange, 1, diff --git a/src/apps/chifra/internal/state/options.go b/src/apps/chifra/internal/state/options.go index 981eade316..6a494e0979 100644 --- a/src/apps/chifra/internal/state/options.go +++ b/src/apps/chifra/internal/state/options.go @@ -32,6 +32,7 @@ type StateOptions struct { Call string `json:"call,omitempty"` // Call a smart contract with a solidity syntax, a four-byte and parameters, or encoded call data ProxyFor string `json:"proxyFor,omitempty"` // For the --call option only, redirects calls to this implementation Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -48,6 +49,7 @@ func (opts *StateOptions) testLog() { logger.TestLog(opts.NoZero, "NoZero: ", opts.NoZero) logger.TestLog(len(opts.Call) > 0, "Call: ", opts.Call) logger.TestLog(len(opts.ProxyFor) > 0, "ProxyFor: ", opts.ProxyFor) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -88,20 +90,26 @@ func stateFinishParseApi(w http.ResponseWriter, r *http.Request) *StateOptions { opts.ProxyFor = value[0] default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "state") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, false, false) if opts.Call != "" { // The tests need single quotes unquoted := strings.Trim(opts.Call, "'") opts.Call = unquoted } - opts.Addrs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Addrs) - opts.ProxyFor, _ = rpcClient.GetAddressFromEns(opts.Globals.Chain, opts.ProxyFor) + opts.Addrs, _ = opts.Conn.GetAddressesFromEns(chain, opts.Addrs) + opts.ProxyFor, _ = opts.Conn.GetAddressFromEns(chain, opts.ProxyFor) if len(opts.Blocks) == 0 { if opts.Globals.TestMode { opts.Blocks = []string{"17000000"} @@ -119,7 +127,12 @@ func stateFinishParse(args []string) *StateOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, false, false) dupMap := make(map[string]bool) for _, arg := range args { if !dupMap[arg] { @@ -131,14 +144,14 @@ func stateFinishParse(args []string) *StateOptions { } dupMap[arg] = true } - opts.Addrs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Addrs) - opts.ProxyFor, _ = rpcClient.GetAddressFromEns(opts.Globals.Chain, opts.ProxyFor) + opts.Addrs, _ = opts.Conn.GetAddressesFromEns(chain, opts.Addrs) + opts.ProxyFor, _ = opts.Conn.GetAddressFromEns(chain, opts.ProxyFor) opts.Call = strings.Replace(opts.Call, "|", "!", -1) opts.Call = strings.Replace(opts.Call, " !", "!", -1) opts.Call = strings.Replace(opts.Call, "! ", "!", -1) parts := strings.Split(opts.Call, "!") if len(parts) > 0 { - val, _ := rpcClient.GetAddressFromEns(opts.Globals.Chain, parts[0]) + val, _ := opts.Conn.GetAddressFromEns(chain, parts[0]) opts.Call = strings.Replace(opts.Call, parts[0], val, -1) } if len(opts.Blocks) == 0 { @@ -152,6 +165,7 @@ func stateFinishParse(args []string) *StateOptions { if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/state/validate.go b/src/apps/chifra/internal/state/validate.go index bf50c76ca1..e612d79ecd 100644 --- a/src/apps/chifra/internal/state/validate.go +++ b/src/apps/chifra/internal/state/validate.go @@ -14,6 +14,8 @@ import ( ) func (opts *StateOptions) validateState() error { + chain := opts.Globals.Chain + opts.testLog() if opts.BadFlag != nil { @@ -55,7 +57,7 @@ func (opts *StateOptions) validateState() error { contract = opts.ProxyFor } - err := rpcClient.IsContractAt(opts.Globals.Chain, base.HexToAddress(contract), nil) + err := opts.Conn.IsContractAt(chain, base.HexToAddress(contract), nil) if err != nil { if errors.Is(err, rpcClient.ErrNotAContract) { return validate.Usage("The address for the --call option must be a smart contract.") @@ -82,7 +84,7 @@ func (opts *StateOptions) validateState() error { // Blocks are optional, but if they are present, they must be valid if len(opts.Blocks) > 0 { bounds, err := validate.ValidateIdentifiersWithBounds( - opts.Globals.Chain, + chain, opts.Blocks, validate.ValidBlockIdWithRangeAndDate, 1, @@ -101,9 +103,9 @@ func (opts *StateOptions) validateState() error { return err } - latest := rpcClient.GetLatestBlockNumber(opts.Globals.Chain) + latest := opts.Conn.GetLatestBlockNumber(chain) // TODO: Should be configurable - if bounds.First < (latest-250) && !rpcClient.IsNodeArchive(opts.Globals.Chain) { + if bounds.First < (latest-250) && !opts.Conn.IsNodeArchive(chain) { return validate.Usage("The {0} requires {1}.", "query for historical state", "an archive node") } } diff --git a/src/apps/chifra/internal/status/handle_show_item.go b/src/apps/chifra/internal/status/handle_show_item.go index ceb9e02b16..7b0b421fe5 100644 --- a/src/apps/chifra/internal/status/handle_show_item.go +++ b/src/apps/chifra/internal/status/handle_show_item.go @@ -13,8 +13,8 @@ import ( ) func (opts *StatusOptions) getCacheItem(cT cache.CacheType, path string) (map[string]any, error) { - testMode := opts.Globals.TestMode chain := opts.Globals.Chain + testMode := opts.Globals.TestMode date := "--fileDate--" info, err := os.Stat(path) diff --git a/src/apps/chifra/internal/status/options.go b/src/apps/chifra/internal/status/options.go index bb4fbeaff5..dc878469fd 100644 --- a/src/apps/chifra/internal/status/options.go +++ b/src/apps/chifra/internal/status/options.go @@ -16,6 +16,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/cache" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/caps" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) @@ -25,6 +26,7 @@ type StatusOptions struct { FirstRecord uint64 `json:"firstRecord,omitempty"` // The first record to process MaxRecords uint64 `json:"maxRecords,omitempty"` // The maximum number of records to process Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE ModeTypes []cache.CacheType `json:"-"` @@ -40,6 +42,7 @@ func (opts *StatusOptions) testLog() { logger.TestLog(len(opts.Modes) > 0, "Modes: ", opts.Modes) logger.TestLog(opts.FirstRecord != 0, "FirstRecord: ", opts.FirstRecord) logger.TestLog(opts.MaxRecords != 10000, "MaxRecords: ", opts.MaxRecords) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -68,12 +71,17 @@ func statusFinishParseApi(w http.ResponseWriter, r *http.Request) *StatusOptions opts.MaxRecords = globals.ToUint64(value[0]) default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "status") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE if len(opts.Modes) == 0 && opts.Globals.Verbose { opts.Modes = append(opts.Modes, "some") @@ -89,6 +97,10 @@ func statusFinishParse(args []string) *StatusOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE opts.Modes = append(opts.Modes, args...) if len(opts.Modes) == 0 && opts.Globals.Verbose { @@ -102,6 +114,7 @@ func statusFinishParse(args []string) *StatusOptions { if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/status/types_status.go b/src/apps/chifra/internal/status/types_status.go index 2cc4d1575f..352638012a 100644 --- a/src/apps/chifra/internal/status/types_status.go +++ b/src/apps/chifra/internal/status/types_status.go @@ -158,12 +158,12 @@ func (opts *StatusOptions) GetSimpleStatus() (*simpleStatus, error) { chain := opts.Globals.Chain testMode := opts.Globals.TestMode - meta, err := rpcClient.GetMetaData(chain, false) + meta, err := opts.Conn.GetMetaData(chain, false) if err != nil { return nil, err } - vers, err := rpcClient.GetClientVersion(chain) + vers, err := opts.Conn.GetClientVersion(chain) if err != nil { return nil, err } @@ -180,8 +180,8 @@ func (opts *StatusOptions) GetSimpleStatus() (*simpleStatus, error) { Progress: ToProgress(chain, meta), IsTesting: testMode, IsApi: opts.Globals.IsApiMode(), - IsArchive: rpcClient.IsNodeArchive(chain), - IsTracing: rpcClient.IsNodeTracing(testMode, chain), + IsArchive: opts.Conn.IsNodeArchive(chain), + IsTracing: opts.Conn.IsNodeTracing(chain, testMode), HasEsKey: config.HasEsKeys(chain), HasPinKey: config.HasPinningKeys(chain), Chain: chain, diff --git a/src/apps/chifra/internal/tokens/handle_parts.go b/src/apps/chifra/internal/tokens/handle_parts.go index 522552a90d..4aa83dc238 100644 --- a/src/apps/chifra/internal/tokens/handle_parts.go +++ b/src/apps/chifra/internal/tokens/handle_parts.go @@ -28,7 +28,7 @@ func (opts *TokensOptions) HandleParts() error { for _, address := range opts.Addrs { addr := base.HexToAddress(address) for _, br := range opts.BlockIds { - blockNums, err := br.ResolveBlocks(opts.Globals.Chain) + blockNums, err := br.ResolveBlocks(chain) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { diff --git a/src/apps/chifra/internal/tokens/handle_show.go b/src/apps/chifra/internal/tokens/handle_show.go index c0e7822246..07592baace 100644 --- a/src/apps/chifra/internal/tokens/handle_show.go +++ b/src/apps/chifra/internal/tokens/handle_show.go @@ -28,7 +28,7 @@ func (opts *TokensOptions) HandleShow() error { for _, address := range opts.Addrs[1:] { addr := base.HexToAddress(address) for _, br := range opts.BlockIds { - blockNums, err := br.ResolveBlocks(opts.Globals.Chain) + blockNums, err := br.ResolveBlocks(chain) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { diff --git a/src/apps/chifra/internal/tokens/options.go b/src/apps/chifra/internal/tokens/options.go index cc76f587a0..6266aa652a 100644 --- a/src/apps/chifra/internal/tokens/options.go +++ b/src/apps/chifra/internal/tokens/options.go @@ -31,6 +31,7 @@ type TokensOptions struct { Changes bool `json:"changes,omitempty"` // Only report a balance when it changes from one block to the next NoZero bool `json:"noZero,omitempty"` // Suppress the display of zero balance accounts Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -46,6 +47,7 @@ func (opts *TokensOptions) testLog() { logger.TestLog(opts.ByAcct, "ByAcct: ", opts.ByAcct) logger.TestLog(opts.Changes, "Changes: ", opts.Changes) logger.TestLog(opts.NoZero, "NoZero: ", opts.NoZero) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -84,14 +86,20 @@ func tokensFinishParseApi(w http.ResponseWriter, r *http.Request) *TokensOptions opts.NoZero = true default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "tokens") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE - opts.Addrs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Addrs) + opts.Conn.EnableCaches(opts.Globals.Cache, false, false) + opts.Addrs, _ = opts.Conn.GetAddressesFromEns(chain, opts.Addrs) if len(opts.Blocks) == 0 { if opts.Globals.TestMode { opts.Blocks = []string{"17000000"} @@ -109,7 +117,12 @@ func tokensFinishParse(args []string) *TokensOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, false, false) if len(args) > 0 { dupMap := make(map[string]bool) for index, arg := range args { @@ -126,7 +139,7 @@ func tokensFinishParse(args []string) *TokensOptions { } } } - opts.Addrs, _ = rpcClient.GetAddressesFromEns(opts.Globals.Chain, opts.Addrs) + opts.Addrs, _ = opts.Conn.GetAddressesFromEns(chain, opts.Addrs) if len(opts.Blocks) == 0 { if opts.Globals.TestMode { opts.Blocks = []string{"17000000"} @@ -138,6 +151,7 @@ func tokensFinishParse(args []string) *TokensOptions { if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/tokens/validate.go b/src/apps/chifra/internal/tokens/validate.go index 45644a8d5e..c942a8bd8b 100644 --- a/src/apps/chifra/internal/tokens/validate.go +++ b/src/apps/chifra/internal/tokens/validate.go @@ -14,6 +14,8 @@ import ( ) func (opts *TokensOptions) validateTokens() error { + chain := opts.Globals.Chain + opts.testLog() if opts.BadFlag != nil { @@ -52,7 +54,7 @@ func (opts *TokensOptions) validateTokens() error { // all but the last is assumed to be a token for _, addr := range opts.Addrs[:len(opts.Addrs)-1] { - err := rpcClient.IsContractAt(opts.Globals.Chain, base.HexToAddress(addr), nil) + err := opts.Conn.IsContractAt(chain, base.HexToAddress(addr), nil) if err != nil { if errors.Is(err, rpcClient.ErrNotAContract) { return validate.Usage("The value {0} is not a token contract.", addr) @@ -63,7 +65,7 @@ func (opts *TokensOptions) validateTokens() error { } else { // the first is assumed to be a smart contract, the rest can be either non-existant, another smart contract or an EOA addr := opts.Addrs[0] - err := rpcClient.IsContractAt(opts.Globals.Chain, base.HexToAddress(addr), nil) + err := opts.Conn.IsContractAt(chain, base.HexToAddress(addr), nil) if err != nil { if err != nil { if errors.Is(err, rpcClient.ErrNotAContract) { @@ -83,7 +85,7 @@ func (opts *TokensOptions) validateTokens() error { // Blocks are optional, but if they are present, they must be valid if len(opts.Blocks) > 0 { bounds, err := validate.ValidateIdentifiersWithBounds( - opts.Globals.Chain, + chain, opts.Blocks, validate.ValidBlockIdWithRangeAndDate, 1, @@ -102,9 +104,9 @@ func (opts *TokensOptions) validateTokens() error { return err } - latest := rpcClient.GetLatestBlockNumber(opts.Globals.Chain) + latest := opts.Conn.GetLatestBlockNumber(chain) // TODO: Should be configurable - if bounds.First < (latest-250) && !rpcClient.IsNodeArchive(opts.Globals.Chain) { + if bounds.First < (latest-250) && !opts.Conn.IsNodeArchive(chain) { return validate.Usage("The {0} requires {1}.", "query for historical state", "an archive node") } } diff --git a/src/apps/chifra/internal/traces/handle_counts.go b/src/apps/chifra/internal/traces/handle_counts.go index f799cbdfad..4374f606e2 100644 --- a/src/apps/chifra/internal/traces/handle_counts.go +++ b/src/apps/chifra/internal/traces/handle_counts.go @@ -10,17 +10,18 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/tslib" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/ethereum/go-ethereum" ) func (opts *TracesOptions) HandleCounts() error { + chain := opts.Globals.Chain + ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { for _, ids := range opts.TransactionIds { - txIds, err := ids.ResolveTxs(opts.Globals.Chain) + txIds, err := ids.ResolveTxs(chain) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { @@ -31,7 +32,7 @@ func (opts *TracesOptions) HandleCounts() error { } for _, id := range txIds { - tx, err := rpcClient.GetTransactionByNumberAndID(opts.Globals.Chain, uint64(id.BlockNumber), uint64(id.TransactionIndex)) + tx, err := opts.Conn.GetTransactionByNumberAndID(chain, uint64(id.BlockNumber), uint64(id.TransactionIndex)) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { @@ -42,7 +43,7 @@ func (opts *TracesOptions) HandleCounts() error { } txHash := tx.Hash().Hex() - cnt, err := rpcClient.GetCountTracesInTransaction(opts.Globals.Chain, txHash) + cnt, err := opts.Conn.GetCountTracesInTransaction(chain, txHash) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { @@ -52,7 +53,7 @@ func (opts *TracesOptions) HandleCounts() error { return } - ts, err := tslib.FromBnToTs(opts.Globals.Chain, uint64(id.BlockNumber)) + ts, err := tslib.FromBnToTs(chain, uint64(id.BlockNumber)) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { diff --git a/src/apps/chifra/internal/traces/handle_filter.go b/src/apps/chifra/internal/traces/handle_filter.go index 453ef5528c..c778328325 100644 --- a/src/apps/chifra/internal/traces/handle_filter.go +++ b/src/apps/chifra/internal/traces/handle_filter.go @@ -5,7 +5,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/articulate" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) @@ -16,7 +15,7 @@ func (opts *TracesOptions) HandleFilter() error { ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawTrace], errorChan chan error) { - traces, err := rpcClient.GetTracesByFilter(opts.Globals.Chain, opts.Filter) + traces, err := opts.Conn.GetTracesByFilter(chain, opts.Filter) if err != nil { errorChan <- err cancel() @@ -27,7 +26,7 @@ func (opts *TracesOptions) HandleFilter() error { } for index := range traces { - traces[index].Timestamp = rpcClient.GetBlockTimestamp(opts.Globals.Chain, utils.PointerOf(uint64(traces[index].BlockNumber))) + traces[index].Timestamp = opts.Conn.GetBlockTimestamp(chain, utils.PointerOf(uint64(traces[index].BlockNumber))) if opts.Articulate { if err = abiCache.ArticulateTrace(chain, &traces[index]); err != nil { errorChan <- err // continue even with an error diff --git a/src/apps/chifra/internal/traces/handle_show.go b/src/apps/chifra/internal/traces/handle_show.go index 4c4ed98d1e..56c5473ea8 100644 --- a/src/apps/chifra/internal/traces/handle_show.go +++ b/src/apps/chifra/internal/traces/handle_show.go @@ -10,7 +10,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/articulate" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" "github.com/ethereum/go-ethereum" @@ -18,13 +17,12 @@ import ( func (opts *TracesOptions) HandleShowTraces() error { abiCache := articulate.NewAbiCache() - var rpcOptions = rpcClient.NoOptions chain := opts.Globals.Chain ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawTrace], errorChan chan error) { for _, ids := range opts.TransactionIds { - txIds, err := ids.ResolveTxs(opts.Globals.Chain) + txIds, err := ids.ResolveTxs(chain) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { @@ -36,10 +34,10 @@ func (opts *TracesOptions) HandleShowTraces() error { // Timestamp is not part of the raw trace data so we need to get it separately // TxIds don't span blocks, so we can use the first one outside the loop to find timestamp - ts := rpcClient.GetBlockTimestamp(opts.Globals.Chain, utils.PointerOf(uint64(txIds[0].BlockNumber))) + ts := opts.Conn.GetBlockTimestamp(chain, utils.PointerOf(uint64(txIds[0].BlockNumber))) for _, id := range txIds { // Decide on the concrete type of block.Transactions and set values - traces, err := rpcClient.GetTracesByTransactionID(opts.Globals.Chain, uint64(id.BlockNumber), uint64(id.TransactionIndex), rpcOptions) + traces, err := opts.Conn.GetTracesByTransactionID(chain, uint64(id.BlockNumber), uint64(id.TransactionIndex)) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { diff --git a/src/apps/chifra/internal/traces/options.go b/src/apps/chifra/internal/traces/options.go index 15572f2f78..4fddc1c60c 100644 --- a/src/apps/chifra/internal/traces/options.go +++ b/src/apps/chifra/internal/traces/options.go @@ -16,6 +16,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/caps" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/identifiers" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) @@ -27,6 +28,7 @@ type TracesOptions struct { Filter string `json:"filter,omitempty"` // Call the node's trace_filter routine with bang-separated filter Count bool `json:"count,omitempty"` // Show the number of traces for the transaction only (fast) Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -40,6 +42,7 @@ func (opts *TracesOptions) testLog() { logger.TestLog(opts.Articulate, "Articulate: ", opts.Articulate) logger.TestLog(len(opts.Filter) > 0, "Filter: ", opts.Filter) logger.TestLog(opts.Count, "Count: ", opts.Count) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -68,13 +71,19 @@ func tracesFinishParseApi(w http.ResponseWriter, r *http.Request) *TracesOptions opts.Count = true default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "traces") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, false, true) // EXISTING_CODE return opts @@ -85,12 +94,18 @@ func tracesFinishParse(args []string) *TracesOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, false, true) opts.Transactions = args // EXISTING_CODE if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/traces/validate.go b/src/apps/chifra/internal/traces/validate.go index 73f383c293..e69b76ad62 100644 --- a/src/apps/chifra/internal/traces/validate.go +++ b/src/apps/chifra/internal/traces/validate.go @@ -6,12 +6,13 @@ package tracesPkg import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) func (opts *TracesOptions) validateTraces() error { + chain := opts.Globals.Chain + opts.testLog() if opts.BadFlag != nil { @@ -25,7 +26,7 @@ func (opts *TracesOptions) validateTraces() error { return validate.Usage("Please supply one or more transaction identifiers or filters.") } - if !rpcClient.IsNodeTracing(opts.Globals.TestMode, opts.Globals.Chain) { + if !opts.Conn.IsNodeTracing(chain, opts.Globals.TestMode) { return validate.Usage("Tracing is required for this program to work properly.") } @@ -43,7 +44,7 @@ func (opts *TracesOptions) validateTraces() error { } err := validate.ValidateIdentifiers( - opts.Globals.Chain, + chain, opts.Transactions, validate.ValidTransId, -1, diff --git a/src/apps/chifra/internal/transactions/handle_accountfor.go b/src/apps/chifra/internal/transactions/handle_accountfor.go index 03e78f052b..fec824737d 100644 --- a/src/apps/chifra/internal/transactions/handle_accountfor.go +++ b/src/apps/chifra/internal/transactions/handle_accountfor.go @@ -7,7 +7,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/ledger" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" "github.com/ethereum/go-ethereum" @@ -31,9 +30,7 @@ func (opts *TransactionsOptions) HandleAccounting() (err error) { nil, ) ledgers.SetContextsFromIds(chain, opts.TransactionIds) - rpcOptions := rpcClient.DefaultRpcOptions(&rpcClient.DefaultRpcOptionsSettings{ - Chain: chain, - }) + ledgers.Conn = opts.Conn ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawStatement], errorChan chan error) { @@ -45,7 +42,7 @@ func (opts *TransactionsOptions) HandleAccounting() (err error) { } for _, app := range txIds { - if statements, err := ledgers.GetStatementsFromAppearance(chain, &app, rpcOptions); err != nil { + if statements, err := ledgers.GetStatementsFromAppearance(chain, &app); err != nil { errorChan <- err } else { for _, statement := range statements { diff --git a/src/apps/chifra/internal/transactions/handle_decache.go b/src/apps/chifra/internal/transactions/handle_decache.go index 42e3856506..4218e0e5e5 100644 --- a/src/apps/chifra/internal/transactions/handle_decache.go +++ b/src/apps/chifra/internal/transactions/handle_decache.go @@ -17,14 +17,12 @@ import ( ) func (opts *TransactionsOptions) HandleDecache() error { - rpcOptions := rpcClient.DefaultRpcOptions(&rpcClient.DefaultRpcOptionsSettings{ - Chain: opts.Globals.Chain, - ReadonlyCache: true, - }) + chain := opts.Globals.Chain + opts.Conn = rpcClient.NewReadOnlyConnection(chain) toRemove := make([]cacheNew.Locator, 0) for _, rng := range opts.TransactionIds { - txIds, err := rng.ResolveTxs(opts.Globals.Chain) + txIds, err := rng.ResolveTxs(chain) if err != nil && !errors.Is(err, ethereum.NotFound) { continue } @@ -58,7 +56,7 @@ func (opts *TransactionsOptions) HandleDecache() error { return true } - rpcOptions.Store.Decache(toRemove, processorFunc) + opts.Conn.Store.Decache(toRemove, processorFunc) if itemsSeen == 0 { logger.Info("No items matching the query were found in the cache.", strings.Repeat(" ", 60)) @@ -71,7 +69,7 @@ func (opts *TransactionsOptions) HandleDecache() error { // TODO: Review then remove // pairs := []base.Pair[uint32,uint32]{} // for _, rng := range opts.TransactionIds { - // txIds, err := rng.ResolveTxs(opts.Globals.Chain) + // txIds, err := rng.ResolveTxs(chain) // if err != nil && !errors.Is(err, ethereum.NotFound) { // continue // } @@ -111,7 +109,7 @@ func (opts *TransactionsOptions) HandleDecache() error { // } // caches := []string{"txs", "traces"} - // if cont, err := cache.DecacheItems(opts.Globals.Chain, "", processorFunc, caches, pairs); err != nil || !cont { + // if cont, err := cache.DecacheItems(chain, "", processorFunc, caches, pairs); err != nil || !cont { // return err // } diff --git a/src/apps/chifra/internal/transactions/handle_logs.go b/src/apps/chifra/internal/transactions/handle_logs.go index 3d05c73378..ea580071f7 100644 --- a/src/apps/chifra/internal/transactions/handle_logs.go +++ b/src/apps/chifra/internal/transactions/handle_logs.go @@ -11,18 +11,16 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/ethereum/go-ethereum" ) func (opts *TransactionsOptions) HandleLogs() error { chain := opts.Globals.Chain - ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawLog], errorChan chan error) { for _, ids := range opts.TransactionIds { - txIds, err := ids.ResolveTxs(opts.Globals.Chain) + txIds, err := ids.ResolveTxs(chain) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { @@ -54,7 +52,7 @@ func (opts *TransactionsOptions) HandleLogs() error { errorChan <- errors.New("TESTING_ONLY_filter" + fmt.Sprintf("%+v", logFilter)) } - logs, err := rpcClient.GetLogsByFilter(chain, logFilter) + logs, err := opts.Conn.GetLogsByFilter(chain, logFilter) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { diff --git a/src/apps/chifra/internal/transactions/handle_show.go b/src/apps/chifra/internal/transactions/handle_show.go index 4ba28ca1fe..24b083971c 100644 --- a/src/apps/chifra/internal/transactions/handle_show.go +++ b/src/apps/chifra/internal/transactions/handle_show.go @@ -16,19 +16,21 @@ import ( func (opts *TransactionsOptions) HandleShowTxs() (err error) { abiCache := articulate.NewAbiCache() - rpcOptions := rpcClient.DefaultRpcOptions(&rpcClient.DefaultRpcOptionsSettings{ - Chain: opts.Globals.Chain, - Opts: opts, - }) chain := opts.Globals.Chain testMode := opts.Globals.TestMode nErrors := 0 + settings := rpcClient.DefaultRpcOptionsSettings{ + Chain: chain, + Opts: opts, + } + opts.Conn = settings.DefaultRpcOptions() + // TODO: Why does this have to dirty the caller? // If the cache is writeable, fetch the latest block timestamp so that we never // cache pending blocks - if !rpcOptions.Store.ReadOnly() { - rpcOptions.LatestBlockTimestamp = rpcClient.GetBlockTimestamp(opts.Globals.Chain, nil) + if !opts.Conn.Store.ReadOnly() { + opts.Conn.LatestBlockTimestamp = opts.Conn.GetBlockTimestamp(chain, nil) } ctx, cancel := context.WithCancel(context.Background()) @@ -48,7 +50,7 @@ func (opts *TransactionsOptions) HandleShowTxs() (err error) { BlockNumber: uint32(app.BlockNumber), TransactionIndex: uint32(app.TransactionIndex), } - if tx, err := rpcClient.GetTransactionByAppearance(chain, a, opts.Traces /* needsTraces */, rpcOptions); err != nil { + if tx, err := opts.Conn.GetTransactionByAppearance(chain, a, opts.Traces /* needsTraces */); err != nil { return fmt.Errorf("transaction at %s returned an error: %w", app.String(), err) } else if tx == nil { return fmt.Errorf("transaction at %s has no logs", app.String()) diff --git a/src/apps/chifra/internal/transactions/handle_uniq.go b/src/apps/chifra/internal/transactions/handle_uniq.go index 26501af301..7a9f69c286 100644 --- a/src/apps/chifra/internal/transactions/handle_uniq.go +++ b/src/apps/chifra/internal/transactions/handle_uniq.go @@ -13,16 +13,17 @@ import ( func (opts *TransactionsOptions) HandleUniq() (err error) { chain := opts.Globals.Chain - rpcOptions := rpcClient.DefaultRpcOptions(&rpcClient.DefaultRpcOptionsSettings{ + settings := rpcClient.DefaultRpcOptionsSettings{ Chain: chain, Opts: opts, - }) + } + opts.Conn = settings.DefaultRpcOptions() // TODO: Why does this have to dirty the caller? // If the cache is writeable, fetch the latest block timestamp so that we never // cache pending blocks - if !rpcOptions.Store.ReadOnly() { - rpcOptions.LatestBlockTimestamp = rpcClient.GetBlockTimestamp(opts.Globals.Chain, nil) + if !opts.Conn.Store.ReadOnly() { + opts.Conn.LatestBlockTimestamp = opts.Conn.GetBlockTimestamp(chain, nil) } ctx, cancel := context.WithCancel(context.Background()) @@ -33,7 +34,7 @@ func (opts *TransactionsOptions) HandleUniq() (err error) { } for _, rng := range opts.TransactionIds { - txIds, err := rng.ResolveTxs(opts.Globals.Chain) + txIds, err := rng.ResolveTxs(chain) if err != nil && !errors.Is(err, ethereum.NotFound) { errorChan <- err cancel() @@ -41,13 +42,13 @@ func (opts *TransactionsOptions) HandleUniq() (err error) { for _, app := range txIds { bn := uint64(app.BlockNumber) - ts := rpcClient.GetBlockTimestamp(chain, &bn) + ts := opts.Conn.GetBlockTimestamp(chain, &bn) addrMap := make(index.AddressBooleanMap) - if trans, err := rpcClient.GetTransactionByAppearance(chain, &app, true, rpcOptions); err != nil { + if trans, err := opts.Conn.GetTransactionByAppearance(chain, &app, true); err != nil { errorChan <- err } else { - if err = index.UniqFromTransDetails(chain, procFunc, opts.Flow, trans, ts, addrMap, rpcOptions); err != nil { + if err = index.UniqFromTransDetails(chain, procFunc, opts.Flow, trans, ts, addrMap, opts.Conn); err != nil { errorChan <- err } } diff --git a/src/apps/chifra/internal/transactions/options.go b/src/apps/chifra/internal/transactions/options.go index 6efd1c74d9..432b96ff8a 100644 --- a/src/apps/chifra/internal/transactions/options.go +++ b/src/apps/chifra/internal/transactions/options.go @@ -36,6 +36,7 @@ type TransactionsOptions struct { Decache bool `json:"decache,omitempty"` // Removes a transactions and any traces in the transaction from the cache Source bool `json:"source,omitempty"` // Find the source of the funds sent to the receiver Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -57,6 +58,7 @@ func (opts *TransactionsOptions) testLog() { logger.TestLog(opts.CacheTraces, "CacheTraces: ", opts.CacheTraces) logger.TestLog(opts.Decache, "Decache: ", opts.Decache) logger.TestLog(opts.Source, "Source: ", opts.Source) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -107,14 +109,20 @@ func transactionsFinishParseApi(w http.ResponseWriter, r *http.Request) *Transac opts.Source = true default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "transactions") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE - opts.AccountFor, _ = rpcClient.GetAddressFromEns(opts.Globals.Chain, opts.AccountFor) + opts.Conn.EnableCaches(opts.Globals.Cache, true, opts.CacheTraces) + opts.AccountFor, _ = opts.Conn.GetAddressFromEns(chain, opts.AccountFor) // EXISTING_CODE return opts @@ -125,13 +133,19 @@ func transactionsFinishParse(args []string) *TransactionsOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, true, opts.CacheTraces) opts.Transactions = args - opts.AccountFor, _ = rpcClient.GetAddressFromEns(opts.Globals.Chain, opts.AccountFor) + opts.AccountFor, _ = opts.Conn.GetAddressFromEns(chain, opts.AccountFor) // EXISTING_CODE if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/transactions/validate.go b/src/apps/chifra/internal/transactions/validate.go index f6f3f5596c..855480965c 100644 --- a/src/apps/chifra/internal/transactions/validate.go +++ b/src/apps/chifra/internal/transactions/validate.go @@ -6,11 +6,12 @@ package transactionsPkg import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) func (opts *TransactionsOptions) validateTransactions() error { + chain := opts.Globals.Chain + opts.testLog() if opts.BadFlag != nil { @@ -61,7 +62,7 @@ func (opts *TransactionsOptions) validateTransactions() error { } } - if opts.Traces && !rpcClient.IsNodeTracing(opts.Globals.TestMode, opts.Globals.Chain) { + if opts.Traces && !opts.Conn.IsNodeTracing(chain, opts.Globals.TestMode) { return validate.Usage("Tracing is required for this program to work properly.") } @@ -71,7 +72,7 @@ func (opts *TransactionsOptions) validateTransactions() error { } err := validate.ValidateIdentifiers( - opts.Globals.Chain, + chain, opts.Transactions, validate.ValidTransId, -1, diff --git a/src/apps/chifra/internal/when/handle_blocks.go b/src/apps/chifra/internal/when/handle_blocks.go index 1e3f4c8f5b..290d2fff91 100644 --- a/src/apps/chifra/internal/when/handle_blocks.go +++ b/src/apps/chifra/internal/when/handle_blocks.go @@ -11,17 +11,18 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/identifiers" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/tslib" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" "github.com/ethereum/go-ethereum" ) func (opts *WhenOptions) HandleShowBlocks() error { + chain := opts.Globals.Chain + ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawNamedBlock], errorChan chan error) { for _, br := range opts.BlockIds { - blockNums, err := br.ResolveBlocks(opts.Globals.Chain) + blockNums, err := br.ResolveBlocks(chain) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { @@ -32,7 +33,7 @@ func (opts *WhenOptions) HandleShowBlocks() error { } for _, bn := range blockNums { - block, err := rpcClient.GetBlockHeaderByNumber(opts.Globals.Chain, bn, rpcClient.NoOptions) + block, err := opts.Conn.GetBlockHeaderByNumber(chain, bn) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { @@ -47,7 +48,7 @@ func (opts *WhenOptions) HandleShowBlocks() error { } d, _ := tslib.FromTsToDate(block.Timestamp) - nm, _ := tslib.FromBnToName(opts.Globals.Chain, block.BlockNumber) + nm, _ := tslib.FromBnToName(chain, block.BlockNumber) modelChan <- &types.SimpleNamedBlock{ BlockNumber: block.BlockNumber, Timestamp: block.Timestamp, diff --git a/src/apps/chifra/internal/when/handle_list.go b/src/apps/chifra/internal/when/handle_list.go index a06e2c3024..25050fe486 100644 --- a/src/apps/chifra/internal/when/handle_list.go +++ b/src/apps/chifra/internal/when/handle_list.go @@ -11,9 +11,11 @@ import ( ) func (opts *WhenOptions) HandleList() error { + chain := opts.Globals.Chain + ctx, cancel := context.WithCancel(context.Background()) fetchData := func(modelChan chan types.Modeler[types.RawNamedBlock], errorChan chan error) { - results, err := tslib.GetSpecials(opts.Globals.Chain) + results, err := tslib.GetSpecials(chain) if err != nil { errorChan <- err if errors.Is(err, ethereum.NotFound) { diff --git a/src/apps/chifra/internal/when/handle_ts_check.go b/src/apps/chifra/internal/when/handle_ts_check.go index 132d9a6e08..74005ce50b 100644 --- a/src/apps/chifra/internal/when/handle_ts_check.go +++ b/src/apps/chifra/internal/when/handle_ts_check.go @@ -8,7 +8,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/identifiers" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/progress" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "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" @@ -16,7 +15,9 @@ import ( // HandleTimestampsCheck handles chifra when --timestamps --check func (opts *WhenOptions) HandleTimestampsCheck() error { - cnt, err := tslib.NTimestamps(opts.Globals.Chain) + chain := opts.Globals.Chain + + cnt, err := tslib.NTimestamps(chain) if err != nil { return err } @@ -24,12 +25,12 @@ func (opts *WhenOptions) HandleTimestampsCheck() error { // For display only skip := uint64(500) if opts.Deep { - m, _ := rpcClient.GetMetaData(opts.Globals.Chain, opts.Globals.TestMode) + m, _ := opts.Conn.GetMetaData(chain, opts.Globals.TestMode) skip = m.Latest / 500 } scanBar := progress.NewScanBar(cnt /* wanted */, (cnt / skip) /* freq */, cnt /* max */, (2. / 3.)) - blockNums, err := identifiers.GetBlockNumbers(opts.Globals.Chain, opts.BlockIds) + blockNums, err := identifiers.GetBlockNumbers(chain, opts.BlockIds) if err != nil { return err } @@ -59,8 +60,10 @@ func (opts *WhenOptions) HandleTimestampsCheck() error { } func (opts *WhenOptions) checkOneBlock(scanBar *progress.ScanBar, prev *types.SimpleNamedBlock, bn uint64) error { + chain := opts.Globals.Chain + // The i'th item in the timestamp array on disc - itemOnDisc, err := tslib.FromBn(opts.Globals.Chain, bn) + itemOnDisc, err := tslib.FromBn(chain, bn) if err != nil { return err } @@ -74,7 +77,7 @@ func (opts *WhenOptions) checkOneBlock(scanBar *progress.ScanBar, prev *types.Si expected := types.SimpleBlock[string]{BlockNumber: bn, Timestamp: onDisc.Timestamp} if opts.Deep { // If we're going deep, we need to query the node - expected, _ = rpcClient.GetBlockHeaderByNumber(opts.Globals.Chain, bn, rpcClient.NoOptions) + expected, _ = opts.Conn.GetBlockHeaderByNumber(chain, bn) } if prev.Timestamp != utils.NOPOSI { diff --git a/src/apps/chifra/internal/when/handle_ts_repair.go b/src/apps/chifra/internal/when/handle_ts_repair.go index d8c20a2b7a..79d700d095 100644 --- a/src/apps/chifra/internal/when/handle_ts_repair.go +++ b/src/apps/chifra/internal/when/handle_ts_repair.go @@ -12,7 +12,9 @@ import ( // HandleTimestampsRepair handles chifra when --timestamps --reset to reset a single block's timestamps (call repeatedly if needed) func (opts *WhenOptions) HandleTimestampsRepair() error { - cnt, err := tslib.NTimestamps(opts.Globals.Chain) + chain := opts.Globals.Chain + + cnt, err := tslib.NTimestamps(chain) if err != nil { return err } @@ -20,23 +22,23 @@ func (opts *WhenOptions) HandleTimestampsRepair() error { // skip := uint64(500) // scanBar := progress.NewScanBar(cnt /* wanted */, (cnt / skip) /* freq */, cnt /* max */, (2. / 3.)) - blockNums, err := identifiers.GetBlockNumbers(opts.Globals.Chain, opts.BlockIds) + blockNums, err := identifiers.GetBlockNumbers(chain, opts.BlockIds) if err != nil { return err } for _, bn := range blockNums { if bn < cnt { // ranges may include blocks after last block - if err := tslib.Repair(opts.Globals.Chain, bn); err != nil { + if err := tslib.Repair(chain, bn); err != nil { return err } if bn == 1 { // weird special case because because I don't know how to get Cobra to handle non-zero defaults - if err := tslib.Repair(opts.Globals.Chain, 0); err != nil { + if err := tslib.Repair(chain, 0); err != nil { return err } } - ts, _ := tslib.FromBnToTs(opts.Globals.Chain, bn) + ts, _ := tslib.FromBnToTs(chain, bn) logger.Info("The timestamp at block", bn, "was reset to", ts, "from on chain.") } } diff --git a/src/apps/chifra/internal/when/handle_ts_show.go b/src/apps/chifra/internal/when/handle_ts_show.go index 9a0491c5b7..cf6a993261 100644 --- a/src/apps/chifra/internal/when/handle_ts_show.go +++ b/src/apps/chifra/internal/when/handle_ts_show.go @@ -16,13 +16,15 @@ import ( // HandleTimestampsShow handles chifra when --timestamps func (opts *WhenOptions) HandleTimestampsShow() error { - bnMap, err := identifiers.GetBlockNumberMap(opts.Globals.Chain, opts.BlockIds) + chain := opts.Globals.Chain + + bnMap, err := identifiers.GetBlockNumberMap(chain, opts.BlockIds) if err != nil { return err } var cnt uint64 - cnt, err = tslib.NTimestamps(opts.Globals.Chain) + cnt, err = tslib.NTimestamps(chain) if err != nil { return err } @@ -32,7 +34,7 @@ func (opts *WhenOptions) HandleTimestampsShow() error { fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) { for bn := uint64(0); bn < cnt; bn++ { if len(bnMap) == 0 || bnMap[bn] { - ts, err := tslib.FromBn(opts.Globals.Chain, bn) + ts, err := tslib.FromBn(chain, bn) if err != nil { errorChan <- err } diff --git a/src/apps/chifra/internal/when/handle_ts_truncate.go b/src/apps/chifra/internal/when/handle_ts_truncate.go index 4c2196b734..ef6eff9191 100644 --- a/src/apps/chifra/internal/when/handle_ts_truncate.go +++ b/src/apps/chifra/internal/when/handle_ts_truncate.go @@ -11,7 +11,9 @@ import ( // HandleTimestampsTruncate handles chifra when --timestamps --drop func (opts *WhenOptions) HandleTimestampsTruncate() error { - if err := tslib.Truncate(opts.Globals.Chain, opts.Truncate); err != nil { + chain := opts.Globals.Chain + + if err := tslib.Truncate(chain, opts.Truncate); err != nil { return err } diff --git a/src/apps/chifra/internal/when/handle_ts_update.go b/src/apps/chifra/internal/when/handle_ts_update.go index 3395d3e16a..49a4be407c 100644 --- a/src/apps/chifra/internal/when/handle_ts_update.go +++ b/src/apps/chifra/internal/when/handle_ts_update.go @@ -8,23 +8,24 @@ import ( "fmt" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/tslib" ) // HandleTimestampUpdate update the timestamp file to the latest block func (opts *WhenOptions) HandleTimestampUpdate() error { + chain := opts.Globals.Chain + if opts.Globals.TestMode { logger.Warn("Update option not tested.") return nil } - cnt, err := tslib.NTimestamps(opts.Globals.Chain) + cnt, err := tslib.NTimestamps(chain) if err != nil { return err } - meta, err := rpcClient.GetMetaData(opts.Globals.Chain, false) + meta, err := opts.Conn.GetMetaData(chain, false) if err != nil { return err } @@ -38,20 +39,20 @@ func (opts *WhenOptions) HandleTimestampUpdate() error { logger.Info("Updating timestamps file from", cnt, "to", meta.Latest, fmt.Sprintf("(%d blocks)", (meta.Latest-cnt))) for bn := cnt; bn < meta.Latest; bn++ { - block, _ := rpcClient.GetBlockHeaderByNumber(opts.Globals.Chain, bn, rpcClient.NoOptions) + block, _ := opts.Conn.GetBlockHeaderByNumber(chain, bn) record := tslib.TimestampRecord{Bn: uint32(block.BlockNumber), Ts: uint32(block.Timestamp)} timestamps = append(timestamps, record) logger.Progress(true, "Adding block", bn, "to timestamp array") if bn%1000 == 0 { logger.Info("Writing...", len(timestamps), "timestamps at block", bn) - tslib.Append(opts.Globals.Chain, timestamps) + tslib.Append(chain, timestamps) timestamps = []tslib.TimestampRecord{} } } if len(timestamps) > 0 { logger.Info("Writing...", len(timestamps), "timestamps at block", meta.Latest) - tslib.Append(opts.Globals.Chain, timestamps) + tslib.Append(chain, timestamps) } return nil diff --git a/src/apps/chifra/internal/when/options.go b/src/apps/chifra/internal/when/options.go index 476845bf45..f47538403e 100644 --- a/src/apps/chifra/internal/when/options.go +++ b/src/apps/chifra/internal/when/options.go @@ -16,6 +16,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/caps" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/identifiers" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" ) @@ -33,6 +34,7 @@ type WhenOptions struct { Update bool `json:"update,omitempty"` // With --timestamps only, bring the timestamp database forward to the latest block Deep bool `json:"deep,omitempty"` // With --timestamps --check only, verifies timestamps from on chain (slow) Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options + Conn *rpcClient.Options `json:"conn,omitempty"` // The connection to the RPC server BadFlag error `json:"badFlag,omitempty"` // An error flag if needed // EXISTING_CODE // EXISTING_CODE @@ -53,6 +55,7 @@ func (opts *WhenOptions) testLog() { logger.TestLog(opts.Check, "Check: ", opts.Check) logger.TestLog(opts.Update, "Update: ", opts.Update) logger.TestLog(opts.Deep, "Deep: ", opts.Deep) + opts.Conn.TestLog() opts.Globals.TestLog() } @@ -92,13 +95,19 @@ func whenFinishParseApi(w http.ResponseWriter, r *http.Request) *WhenOptions { opts.Deep = true default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "when") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, false, false) // EXISTING_CODE return opts @@ -109,7 +118,12 @@ func whenFinishParse(args []string) *WhenOptions { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE + opts.Conn.EnableCaches(opts.Globals.Cache, false, false) opts.Blocks = args if opts.Truncate == 0 { opts.Truncate = utils.NOPOS @@ -118,6 +132,7 @@ func whenFinishParse(args []string) *WhenOptions { if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/apps/chifra/internal/when/validate.go b/src/apps/chifra/internal/when/validate.go index 9dd5172844..b03abcb6c4 100644 --- a/src/apps/chifra/internal/when/validate.go +++ b/src/apps/chifra/internal/when/validate.go @@ -12,6 +12,8 @@ import ( ) func (opts *WhenOptions) validateWhen() error { + chain := opts.Globals.Chain + opts.testLog() if opts.BadFlag != nil { @@ -81,7 +83,7 @@ func (opts *WhenOptions) validateWhen() error { } err := validate.ValidateIdentifiers( - opts.Globals.Chain, + chain, opts.Blocks, validate.ValidBlockIdWithRangeAndDate, 1, diff --git a/src/apps/chifra/internal/when/validate_integration_test.go b/src/apps/chifra/internal/when/validate_integration_test.go index 9a64d7365e..9bb2e088bc 100644 --- a/src/apps/chifra/internal/when/validate_integration_test.go +++ b/src/apps/chifra/internal/when/validate_integration_test.go @@ -9,10 +9,15 @@ package whenPkg import ( "testing" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) func Test_Validate(t *testing.T) { var opts = WhenOptions{} + chain := utils.GetTestChain() + opts.Conn = rpcClient.NewConnection(chain, []string{}) opts.Blocks = append(opts.Blocks, "2014-01-01") err := opts.validateWhen() if err == nil { diff --git a/src/apps/chifra/pkg/abi/load_abi.go b/src/apps/chifra/pkg/abi/load_abi.go index 89a40e952a..fd6e5474f9 100644 --- a/src/apps/chifra/pkg/abi/load_abi.go +++ b/src/apps/chifra/pkg/abi/load_abi.go @@ -224,7 +224,8 @@ func LoadAbi(chain string, address base.Address, destination AbiInterfaceMap) (e } // We didn't find the file. Check if the address is a contract - if err := rpcClient.IsContractAt(chain, address, nil); err != nil && !errors.Is(err, rpcClient.ErrNotAContract) { + conn := rpcClient.NewConnection(chain, []string{}) + if err := conn.IsContractAt(chain, address, nil); err != nil && !errors.Is(err, rpcClient.ErrNotAContract) { return err } else if errors.Is(err, rpcClient.ErrNotAContract) { return nil diff --git a/src/apps/chifra/pkg/account/state.go b/src/apps/chifra/pkg/account/state.go index 07b86d9aab..405f7c6428 100644 --- a/src/apps/chifra/pkg/account/state.go +++ b/src/apps/chifra/pkg/account/state.go @@ -109,7 +109,7 @@ func GetState(chain string, fields GetStateField, address base.Address, blockNum // deployedChan := make(chan struct{ block base.Blknum; err error }) // if (mode & GetDeployed) != 0 { // go func () { - // block, err := rpcClient.GetContractDeployBlock(chain, address) + // block, err := rpcOptions.GetContractDeployBlock(chain, address) // deployedChan <- struct{block uint64; err error}{ // block, err, // } @@ -117,8 +117,9 @@ func GetState(chain string, fields GetStateField, address base.Address, blockNum // }() // } + conn := rpcClient.NewConnection(chain, []string{}) if (fields & Deployed) != 0 { - block, err := rpcClient.GetContractDeployBlock(chain, address) + block, err := conn.GetContractDeployBlock(chain, address) if err != nil && !errors.Is(err, rpcClient.ErrNotAContract) { return nil, err } @@ -131,7 +132,7 @@ func GetState(chain string, fields GetStateField, address base.Address, blockNum var proxy base.Address if (fields&Proxy) != 0 || (fields&Type) != 0 { - proxy, err = rpcClient.GetProxyAt(chain, address, blockNumber) + proxy, err = conn.GetProxyAt(chain, address, blockNumber) if err != nil { return } @@ -152,7 +153,8 @@ func GetState(chain string, fields GetStateField, address base.Address, blockNum } func getTypeNonProxy(chain string, address base.Address, blockNumber base.Blknum) string { - isContractErr := rpcClient.IsContractAt(chain, address, &types.SimpleNamedBlock{BlockNumber: blockNumber}) + conn := rpcClient.NewConnection(chain, []string{}) + isContractErr := conn.IsContractAt(chain, address, &types.SimpleNamedBlock{BlockNumber: blockNumber}) if errors.Is(isContractErr, rpcClient.ErrNotAContract) { return "EOA" } diff --git a/src/apps/chifra/pkg/account/state_integration_test.go b/src/apps/chifra/pkg/account/state_integration_test.go index 74733a7b8d..bca7ecff1a 100644 --- a/src/apps/chifra/pkg/account/state_integration_test.go +++ b/src/apps/chifra/pkg/account/state_integration_test.go @@ -17,6 +17,8 @@ import ( ) func TestGetState(t *testing.T) { + chain := utils.GetTestChain() + conn := rpcClient.NewConnection(chain, []string{}) type args struct { chain string @@ -63,7 +65,7 @@ func TestGetState(t *testing.T) { }(), Nonce: 0, Code: func() string { - code, err := rpcClient.GetCodeAt("mainnet", base.HexToAddress("0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359"), uint64(15531843)) + code, err := conn.GetCodeAt("mainnet", base.HexToAddress("0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359"), uint64(15531843)) if err != nil { t.Fatal("error when fetching code for smart contract:", err) } diff --git a/src/apps/chifra/pkg/identifiers/resolve.go b/src/apps/chifra/pkg/identifiers/resolve.go index 263e380673..af90151b92 100644 --- a/src/apps/chifra/pkg/identifiers/resolve.go +++ b/src/apps/chifra/pkg/identifiers/resolve.go @@ -72,6 +72,8 @@ func (id *Identifier) getBounds(chain string) (ret base.BlockRange, err error) { } func snapBnToPeriod(bn uint64, chain, period string) (uint64, error) { + conn := rpcClient.NewConnection(chain, []string{}) + dt, err := tslib.FromBnToDate(chain, bn) if err != nil { return bn, err @@ -107,7 +109,7 @@ func snapBnToPeriod(bn uint64, chain, period string) (uint64, error) { dt = dt.FloorYear() } - firstDate := gostradamus.FromUnixTimestamp(rpcClient.GetBlockTimestamp(chain, utils.PointerOf(uint64(0)))) + firstDate := gostradamus.FromUnixTimestamp(conn.GetBlockTimestamp(chain, utils.PointerOf(uint64(0)))) if dt.Time().Before(firstDate.Time()) { dt = firstDate } @@ -173,9 +175,11 @@ func (id *Identifier) nextBlock(chain string, current uint64) (uint64, error) { } func (p *Point) resolvePoint(chain string) uint64 { + conn := rpcClient.NewConnection(chain, []string{}) + var bn uint64 if p.Hash != "" { - bn, _ = rpcClient.GetBlockNumberByHash(chain, p.Hash) + bn, _ = conn.GetBlockNumberByHash(chain, p.Hash) } else if p.Date != "" { bn, _ = tslib.FromDateToBn(chain, p.Date) } else if p.Special != "" { @@ -184,8 +188,8 @@ func (p *Point) resolvePoint(chain string) uint64 { var err error bn, err = tslib.FromTsToBn(chain, base.Timestamp(p.Number)) if err == tslib.ErrInTheFuture { - latest := rpcClient.GetLatestBlockNumber(chain) - tsFuture := rpcClient.GetBlockTimestamp(chain, &latest) + latest := conn.GetLatestBlockNumber(chain) + tsFuture := conn.GetBlockTimestamp(chain, &latest) secs := uint64(tsFuture - base.Timestamp(p.Number)) blks := (secs / 13) bn = latest + blks @@ -197,11 +201,12 @@ func (p *Point) resolvePoint(chain string) uint64 { } func (id *Identifier) ResolveTxs(chain string) ([]types.RawAppearance, error) { + conn := rpcClient.NewConnection(chain, []string{}) txs := []types.RawAppearance{} if id.StartType == BlockNumber { if id.Modifier.Period == "all" { - cnt, err := rpcClient.GetCountTransactionsInBlock(chain, uint64(id.Start.Number)) + cnt, err := conn.GetCountTransactionsInBlock(chain, uint64(id.Start.Number)) if err != nil { return txs, err } @@ -223,7 +228,7 @@ func (id *Identifier) ResolveTxs(chain string) ([]types.RawAppearance, error) { if id.StartType == BlockHash && id.EndType == TransactionIndex { if id.Modifier.Period == "all" { - cnt, err := rpcClient.GetCountTransactionsInBlock(chain, uint64(id.Start.resolvePoint(chain))) + cnt, err := conn.GetCountTransactionsInBlock(chain, uint64(id.Start.resolvePoint(chain))) if err != nil { return txs, err } @@ -239,7 +244,7 @@ func (id *Identifier) ResolveTxs(chain string) ([]types.RawAppearance, error) { } if id.StartType == TransactionHash { - app, err := rpcClient.GetAppearanceFromHash(chain, id.Start.Hash) + app, err := conn.GetAppearanceFromHash(chain, id.Start.Hash) return append(txs, app), err } diff --git a/src/apps/chifra/pkg/index/uniq_appearances.go b/src/apps/chifra/pkg/index/uniq_appearances.go index 68436c5bc8..e5236152eb 100644 --- a/src/apps/chifra/pkg/index/uniq_appearances.go +++ b/src/apps/chifra/pkg/index/uniq_appearances.go @@ -41,7 +41,7 @@ func UniqFromLogs(chain string, logs []types.SimpleLog, addrMap AddressBooleanMa // UniqFromTraces extracts addresses from traces func UniqFromTraces(chain string, traces []types.SimpleTrace, addrMap AddressBooleanMap) (err error) { - var rpcOptions *rpcClient.Options = rpcClient.NoOptions + conn := rpcClient.NewConnection(chain, []string{}) for _, trace := range traces { trace := trace @@ -130,11 +130,11 @@ func UniqFromTraces(chain string, traces []types.SimpleTrace, addrMap AddressBoo if trace.Result != nil && trace.Result.Address.IsZero() { if trace.Error != "" { // TODO: Why does this interface always accept nil and zero at the end? - receipt, err := rpcClient.GetReceipt(chain, rpcClient.ReceiptQuery{ + receipt, err := conn.GetReceipt(chain, rpcClient.ReceiptQuery{ Bn: uint64(bn), Txid: uint64(txid), NeedsTs: false, - }, rpcOptions) + }) if err != nil { msg := fmt.Sprintf("rpcCall failed at block %d, tx %d hash %s err %s", bn, txid, trace.TransactionHash, err) logger.Warn(colors.Red, msg, colors.Off) diff --git a/src/apps/chifra/pkg/index/uniq_appearances_details.go b/src/apps/chifra/pkg/index/uniq_appearances_details.go index 7aee526bc6..0e8801ec66 100644 --- a/src/apps/chifra/pkg/index/uniq_appearances_details.go +++ b/src/apps/chifra/pkg/index/uniq_appearances_details.go @@ -207,11 +207,11 @@ func UniqFromTracesDetails(chain string, procFunc UniqProcFunc, flow string, tra if trace.Result != nil && trace.Result.Address.IsZero() { if trace.Error != "" { // TODO: Why does this interface always accept nil and zero at the end? - receipt, err := rpcClient.GetReceipt(chain, rpcClient.ReceiptQuery{ + receipt, err := options.GetReceipt(chain, rpcClient.ReceiptQuery{ Bn: uint64(bn), Txid: uint64(txid), NeedsTs: false, - }, options) + }) if err != nil { msg := fmt.Sprintf("rpcCall failed at block %d, tx %d hash %s err %s", bn, txid, trace.TransactionHash, err) logger.Warn(colors.Red, msg, colors.Off) diff --git a/src/apps/chifra/pkg/ledger/ledger.go b/src/apps/chifra/pkg/ledger/ledger.go index 223114ec06..ae955c5200 100644 --- a/src/apps/chifra/pkg/ledger/ledger.go +++ b/src/apps/chifra/pkg/ledger/ledger.go @@ -6,6 +6,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/names" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) @@ -27,6 +28,7 @@ type Ledger struct { UseTraces bool AssetFilter *[]base.Address Tx *types.SimpleTransaction + Conn *rpcClient.Options } // NewLedger returns a new empty Ledger struct diff --git a/src/apps/chifra/pkg/ledger/stmnt_from_app.go b/src/apps/chifra/pkg/ledger/stmnt_from_app.go index 3416e1f0d3..ce45da70a9 100644 --- a/src/apps/chifra/pkg/ledger/stmnt_from_app.go +++ b/src/apps/chifra/pkg/ledger/stmnt_from_app.go @@ -1,14 +1,13 @@ package ledger import ( - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) // GetStatementsFromAppearance visits an appearance and returns a list of (hopefully) reconciled statements. -func (l *Ledger) GetStatementsFromAppearance(chain string, app *types.RawAppearance, rpcOptions *rpcClient.Options) (statements []types.SimpleStatement, err error) { +func (l *Ledger) GetStatementsFromAppearance(chain string, app *types.RawAppearance) (statements []types.SimpleStatement, err error) { var tx *types.SimpleTransaction - if tx, err = rpcClient.GetTransactionByAppearance(chain, app, false, rpcOptions); err != nil { + if tx, err = l.Conn.GetTransactionByAppearance(chain, app, false); err != nil { return []types.SimpleStatement{}, err } else { diff --git a/src/apps/chifra/pkg/ledger/stmnt_from_traces.go b/src/apps/chifra/pkg/ledger/stmnt_from_traces.go index 7fde91598f..e566651a14 100644 --- a/src/apps/chifra/pkg/ledger/stmnt_from_traces.go +++ b/src/apps/chifra/pkg/ledger/stmnt_from_traces.go @@ -4,7 +4,6 @@ import ( "math/big" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) @@ -15,7 +14,7 @@ func (l *Ledger) GetStatementsFromTraces(trans *types.SimpleTransaction, s *type ret := *s ret.ClearInternal() - if traces, err := rpcClient.GetTracesByTransactionHash(chain, trans.Hash.Hex(), trans, nil); err != nil { + if traces, err := l.Conn.GetTracesByTransactionHash(chain, trans.Hash.Hex(), trans); err != nil { logger.Error(err) } else { diff --git a/src/apps/chifra/pkg/ledger/stmnt_from_tx.go b/src/apps/chifra/pkg/ledger/stmnt_from_tx.go index eba680921b..f78275c9fc 100644 --- a/src/apps/chifra/pkg/ledger/stmnt_from_tx.go +++ b/src/apps/chifra/pkg/ledger/stmnt_from_tx.go @@ -5,7 +5,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/rpcClient" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) @@ -20,12 +19,12 @@ func (l *Ledger) GetStatementsFromTransaction(trans *types.SimpleTransaction) (s if l.AssetOfInterest(base.FAKE_ETH_ADDRESS) { // TODO: We ignore errors in the next few lines, but we should not // TODO: performance - This greatly increases the number of times we call into eth_getBalance which is quite slow - prevBal, _ := rpcClient.GetBalanceAt(l.Chain, l.AccountFor, ctx.PrevBlock) + prevBal, _ := l.Conn.GetBalanceAt(l.Chain, l.AccountFor, ctx.PrevBlock) if trans.BlockNumber == 0 { prevBal = new(big.Int) } - begBal, _ := rpcClient.GetBalanceAt(l.Chain, l.AccountFor, ctx.CurBlock-1) - endBal, _ := rpcClient.GetBalanceAt(l.Chain, l.AccountFor, ctx.CurBlock) + begBal, _ := l.Conn.GetBalanceAt(l.Chain, l.AccountFor, ctx.CurBlock-1) + endBal, _ := l.Conn.GetBalanceAt(l.Chain, l.AccountFor, ctx.CurBlock) ret := types.SimpleStatement{ AccountedFor: l.AccountFor, diff --git a/src/apps/chifra/pkg/manifest/download.go b/src/apps/chifra/pkg/manifest/download.go index fcfe72e116..cfdbdf33cd 100644 --- a/src/apps/chifra/pkg/manifest/download.go +++ b/src/apps/chifra/pkg/manifest/download.go @@ -56,7 +56,8 @@ func ReadUnchainedIndex(chain, reason string, publisher base.Address) (string, e if contractCall, err := call.NewContractCall(unchainedChain, unchained.GetUnchainedIndexAddress(), theCall, false); err != nil { return "", err } else { - contractCall.BlockNumber = rpcClient.GetLatestBlockNumber(unchainedChain) + conn := rpcClient.NewConnection(unchainedChain, []string{}) + contractCall.BlockNumber = conn.GetLatestBlockNumber(unchainedChain) if result, err := call.CallContract(unchainedChain, contractCall); err != nil { return "", err } else { diff --git a/src/apps/chifra/pkg/output/helpers/helpers.go b/src/apps/chifra/pkg/output/helpers/helpers.go index 09c4322a12..c7565bcf3e 100644 --- a/src/apps/chifra/pkg/output/helpers/helpers.go +++ b/src/apps/chifra/pkg/output/helpers/helpers.go @@ -106,7 +106,9 @@ func InitJsonWriterApi(cmdName string, w io.Writer, opts *globals.GlobalOptions) jw := output.NewDefaultJsonWriter(w, false) jw.ShouldWriteMeta = true jw.GetMeta = func() (*rpcClient.MetaData, error) { - return rpcClient.GetMetaData(opts.Chain, opts.OutputOptions.TestMode) + chain := opts.Chain + conn := rpcClient.NewConnection(chain, []string{}) + return conn.GetMetaData(opts.Chain, opts.OutputOptions.TestMode) } opts.Writer = jw } diff --git a/src/apps/chifra/pkg/rpcClient/client.go b/src/apps/chifra/pkg/rpcClient/client.go index 230638b313..cc57a99faf 100644 --- a/src/apps/chifra/pkg/rpcClient/client.go +++ b/src/apps/chifra/pkg/rpcClient/client.go @@ -55,7 +55,7 @@ func getClient(chain string) (*ethclient.Client, error) { } // GetLatestBlockNumber returns the block number at the front of the chain (i.e. latest) -func GetLatestBlockNumber(chain string) uint64 { +func (options *Options) GetLatestBlockNumber(chain string) uint64 { if ec, err := getClient(chain); err != nil { logger.Error("Could not connect to RPC client: %w", err) return 0 @@ -73,7 +73,7 @@ func GetLatestBlockNumber(chain string) uint64 { } // GetClientIDs returns both chainId and networkId from the node -func GetClientIDs(chain string) (uint64, uint64, error) { +func (options *Options) GetClientIDs(chain string) (uint64, uint64, error) { if ec, err := getClient(chain); err != nil { return 0, 0, err } else { @@ -96,7 +96,7 @@ func GetClientIDs(chain string) (uint64, uint64, error) { // TODO: C++ code used to cache version info // GetClientVersion returns the version of the client -func GetClientVersion(chain string) (version string, err error) { +func (options *Options) GetClientVersion(chain string) (version string, err error) { method := "web3_clientVersion" params := rpc.Params{} @@ -108,7 +108,7 @@ func GetClientVersion(chain string) (version string, err error) { } // GetTransactionHashFromHashStr returns a transaction's hash if it's a valid transaction, an empty string otherwise -func GetTransactionHashFromHashStr(chain, hash string) (string, error) { +func (options *Options) GetTransactionHashFromHashStr(chain, hash string) (string, error) { if ec, err := getClient(chain); err != nil { return "", err } else { @@ -124,7 +124,7 @@ func GetTransactionHashFromHashStr(chain, hash string) (string, error) { } // GetBlockHashFromHashStr returns a block's hash if it's a valid block -func GetBlockHashFromHashStr(chain, hash string) (string, error) { +func (options *Options) GetBlockHashFromHashStr(chain, hash string) (string, error) { if ec, err := getClient(chain); err != nil { return "", err } else { @@ -140,7 +140,7 @@ func GetBlockHashFromHashStr(chain, hash string) (string, error) { } // GetTransactionHashByHashAndID returns a transaction's hash if it's a valid transaction -func GetTransactionHashByHashAndID(chain, hash string, txId uint64) (string, error) { +func (options *Options) GetTransactionHashByHashAndID(chain, hash string, txId uint64) (string, error) { if ec, err := getClient(chain); err != nil { return "", err } else { @@ -156,7 +156,7 @@ func GetTransactionHashByHashAndID(chain, hash string, txId uint64) (string, err } // GetTransactionByNumberAndID returns an actual transaction -func GetTransactionByNumberAndID(chain string, bn, txId uint64) (ethTypes.Transaction, error) { +func (options *Options) GetTransactionByNumberAndID(chain string, bn, txId uint64) (ethTypes.Transaction, error) { if ec, err := getClient(chain); err != nil { return ethTypes.Transaction{}, err } else { @@ -177,7 +177,7 @@ func GetTransactionByNumberAndID(chain string, bn, txId uint64) (ethTypes.Transa } // GetCountTransactionsInBlock returns the number of transactions in a block -func GetCountTransactionsInBlock(chain string, bn uint64) (uint64, error) { +func (options *Options) GetCountTransactionsInBlock(chain string, bn uint64) (uint64, error) { if ec, err := getClient(chain); err != nil { return 0, err } else { @@ -194,7 +194,7 @@ func GetCountTransactionsInBlock(chain string, bn uint64) (uint64, error) { } // GetBlockNumberByHash returns a block's hash if it's a valid block -func GetBlockNumberByHash(chain, hash string) (base.Blknum, error) { +func (options *Options) GetBlockNumberByHash(chain, hash string) (base.Blknum, error) { if ec, err := getClient(chain); err != nil { return 0, err } else { @@ -210,7 +210,7 @@ func GetBlockNumberByHash(chain, hash string) (base.Blknum, error) { } // GetBlockHashByNumber returns a block's hash if it's a valid block -func GetBlockHashByNumber(chain string, bn uint64) (string, error) { +func (options *Options) GetBlockHashByNumber(chain string, bn uint64) (string, error) { if ec, err := getClient(chain); err != nil { return "", err } else { @@ -226,7 +226,7 @@ func GetBlockHashByNumber(chain string, bn uint64) (string, error) { } // GetBalanceAt returns a balance for an address at a block -func GetBalanceAt(chain string, addr base.Address, bn uint64) (*big.Int, error) { +func (options *Options) GetBalanceAt(chain string, addr base.Address, bn uint64) (*big.Int, error) { if ec, err := getClient(chain); err != nil { var zero big.Int return &zero, err @@ -237,7 +237,7 @@ func GetBalanceAt(chain string, addr base.Address, bn uint64) (*big.Int, error) } // GetCodeAt returns a code (if any) for an address at a block -func GetCodeAt(chain string, addr base.Address, bn uint64) ([]byte, error) { +func (options *Options) GetCodeAt(chain string, addr base.Address, bn uint64) ([]byte, error) { if ec, err := getClient(chain); err != nil { return []byte{}, err } else { diff --git a/src/apps/chifra/pkg/rpcClient/client_integration_test.go b/src/apps/chifra/pkg/rpcClient/client_integration_test.go index baa51c5aa4..3738354233 100644 --- a/src/apps/chifra/pkg/rpcClient/client_integration_test.go +++ b/src/apps/chifra/pkg/rpcClient/client_integration_test.go @@ -15,42 +15,46 @@ import ( func Test_Client(t *testing.T) { chain := utils.GetTestChain() + conn := NewConnection(chain, []string{}) - chainId, networkId, _ := GetClientIDs(chain) + chainId, networkId, _ := conn.GetClientIDs(chain) if chainId != networkId || chainId != 1 { t.Error("provider chain id is 1") } - ts := GetBlockTimestamp(chain, utils.PointerOf(uint64(1))) + ts := conn.GetBlockTimestamp(chain, utils.PointerOf(uint64(1))) blockOneTimestamp := int64(1438269988) if ts != blockOneTimestamp { t.Error("timestamp for block 1 is not correct") } - _, err := GetTransactionHashFromHashStr(chain, "0x730724cb08a6eb17bf6b3296359d261570d343ea7944a17a9d7287d77900db08") + _, err := conn.GetTransactionHashFromHashStr(chain, "0x730724cb08a6eb17bf6b3296359d261570d343ea7944a17a9d7287d77900db08") if err != nil { t.Error("couldn't get known transaction hash from tx hash") } - _, err = GetTransactionHashByHashAndID(chain, "0x0b4c6fb75ded4b90218cf0346b0885e442878f104e1b60bf75d5b6860eeacd53", 0) + _, err = conn.GetTransactionHashByHashAndID(chain, "0x0b4c6fb75ded4b90218cf0346b0885e442878f104e1b60bf75d5b6860eeacd53", 0) if err != nil { t.Error("couldn't get known transaction hash from block hash and tx id") } - _, err = GetBlockHashFromHashStr(chain, "0x0b4c6fb75ded4b90218cf0346b0885e442878f104e1b60bf75d5b6860eeacd53") + _, err = conn.GetBlockHashFromHashStr(chain, "0x0b4c6fb75ded4b90218cf0346b0885e442878f104e1b60bf75d5b6860eeacd53") if err != nil { t.Error("couldn't get known block hash from block hash") } - _, err = GetBlockHashByNumber(chain, 12) + _, err = conn.GetBlockHashByNumber(chain, 12) if err != nil { t.Error("couldn't get known block hash from block number") } } func Test_TxFromNumberAndId(t *testing.T) { + chain := utils.GetTestChain() + conn := NewConnection(chain, []string{}) + txId := uint64(0) - _, err := GetTransactionByNumberAndID("mainnet", uint64(1424623), txId) + _, err := conn.GetTransactionByNumberAndID(chain, uint64(1424623), txId) if err != nil { t.Fatal(err) } diff --git a/src/apps/chifra/pkg/rpcClient/contract.go b/src/apps/chifra/pkg/rpcClient/contract.go index 99f0b8237b..4f41aea88b 100644 --- a/src/apps/chifra/pkg/rpcClient/contract.go +++ b/src/apps/chifra/pkg/rpcClient/contract.go @@ -16,7 +16,7 @@ import ( var ErrNotAContract = errors.New("not a contract") // IsContractAt checks if an account is a contract -func IsContractAt(chain string, address base.Address, block *types.SimpleNamedBlock) error { +func (options *Options) IsContractAt(chain string, address base.Address, block *types.SimpleNamedBlock) error { if ec, err := getClient(chain); err != nil { return err } else { @@ -42,7 +42,7 @@ func IsContractAt(chain string, address base.Address, block *types.SimpleNamedBl var deployedCacheMutex sync.Mutex var deployedCache = make(map[base.Address]base.Blknum) -func GetContractDeployBlock(chain string, address base.Address) (block base.Blknum, err error) { +func (options *Options) GetContractDeployBlock(chain string, address base.Address) (block base.Blknum, err error) { // TODO: Couldn't we wait here to lock until we need it? Doesn't this lock even when we only read the cache? deployedCacheMutex.Lock() defer deployedCacheMutex.Unlock() @@ -52,13 +52,13 @@ func GetContractDeployBlock(chain string, address base.Address) (block base.Blkn return } - latest := GetLatestBlockNumber(chain) - if err = IsContractAt(chain, address, &types.SimpleNamedBlock{BlockNumber: latest}); err != nil { + latest := options.GetLatestBlockNumber(chain) + if err = options.IsContractAt(chain, address, &types.SimpleNamedBlock{BlockNumber: latest}); err != nil { return } found := sort.Search(int(latest)+1, func(blockNumber int) bool { - err := IsContractAt(chain, address, &types.SimpleNamedBlock{BlockNumber: base.Blknum(blockNumber)}) + err := options.IsContractAt(chain, address, &types.SimpleNamedBlock{BlockNumber: base.Blknum(blockNumber)}) return err == nil }) @@ -77,7 +77,7 @@ var locations = []string{ } // GetProxyAt returns the proxy address for a contract if any -func GetProxyAt(chain string, address base.Address, blockNumber base.Blknum) (base.Address, error) { +func (options *Options) GetProxyAt(chain string, address base.Address, blockNumber base.Blknum) (base.Address, error) { if ec, err := getClient(chain); err != nil { return base.Address{}, err } else { @@ -114,7 +114,7 @@ func GetProxyAt(chain string, address base.Address, blockNumber base.Blknum) (ba } proxy = base.BytesToAddress(value) if !proxy.IsZero() && proxy.Hex() != address.Hex() { - err = IsContractAt(chain, proxy, &types.SimpleNamedBlock{BlockNumber: blockNumber}) + err = options.IsContractAt(chain, proxy, &types.SimpleNamedBlock{BlockNumber: blockNumber}) if errors.Is(err, ErrNotAContract) { // Not a proxy return base.Address{}, nil diff --git a/src/apps/chifra/pkg/rpcClient/contract_integration_test.go b/src/apps/chifra/pkg/rpcClient/contract_integration_test.go index 4cee9c9d15..455a7ce1a6 100644 --- a/src/apps/chifra/pkg/rpcClient/contract_integration_test.go +++ b/src/apps/chifra/pkg/rpcClient/contract_integration_test.go @@ -7,13 +7,17 @@ import ( "testing" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) func TestGetContractDeployBlock(t *testing.T) { + chain := utils.GetTestChain() + conn := NewConnection(chain, []string{}) + // Finding the first block unchainedIndex := base.HexToAddress("0x0C316b7042b419d07d343F2f4F5Bd54FF731183d") expected := base.Blknum(14957097) - result, err := GetContractDeployBlock("mainnet", unchainedIndex) + result, err := conn.GetContractDeployBlock("mainnet", unchainedIndex) if err != nil { t.Fatal(err) } @@ -31,7 +35,7 @@ func TestGetContractDeployBlock(t *testing.T) { // Reading from cache shortcut fakeBlock := base.Blknum(13000000) deployedCache[unchainedIndex] = fakeBlock - result, err = GetContractDeployBlock("mainnet", unchainedIndex) + result, err = conn.GetContractDeployBlock("mainnet", unchainedIndex) if err != nil { t.Fatal(err) } @@ -40,7 +44,7 @@ func TestGetContractDeployBlock(t *testing.T) { } // Error when the address is not a contract - _, err = GetContractDeployBlock("mainnet", base.HexToAddress("0x0")) + _, err = conn.GetContractDeployBlock("mainnet", base.HexToAddress("0x0")) if err != ErrNotAContract { t.Fatal("expected ErrNotAContract, but got", err) } @@ -52,7 +56,10 @@ func TestGetProxy(t *testing.T) { // 0x4Fabb145d64652a948d72533023f6E7A623C7C53 // 0x00000000441378008ea67f4284a57932b1c000a5 - proxy, err := GetProxyAt("mainnet", base.HexToAddress("0x4Fabb145d64652a948d72533023f6E7A623C7C53"), base.Blknum(12983248)) + chain := utils.GetTestChain() + conn := NewConnection(chain, []string{}) + + proxy, err := conn.GetProxyAt(chain, base.HexToAddress("0x4Fabb145d64652a948d72533023f6E7A623C7C53"), base.Blknum(12983248)) if err != nil { t.Fatal(err) } diff --git a/src/apps/chifra/pkg/rpcClient/ens.go b/src/apps/chifra/pkg/rpcClient/ens.go index e808850d75..8f27c9a933 100644 --- a/src/apps/chifra/pkg/rpcClient/ens.go +++ b/src/apps/chifra/pkg/rpcClient/ens.go @@ -19,7 +19,7 @@ func lowerIfHex(addr string) string { // GetAddressesFromEns converts an array of strings, if they contains .eth, into addresses. Note, we take // chain parameter, but ignore it choosing to look at mainnet ENS only -func GetAddressesFromEns(chain string, addrs []string) (out []string, found bool) { +func (options *Options) GetAddressesFromEns(chain string, addrs []string) (out []string, found bool) { // Note: we use ENS on mainnet always if ec, err := getClient("mainnet"); err != nil { return @@ -40,7 +40,7 @@ func GetAddressesFromEns(chain string, addrs []string) (out []string, found bool // GetAddressFromEns converts a single string, if it contains .eth, into an address. Note, we take // chain parameter, but ignore it choosing to look at mainnet ENS only -func GetAddressFromEns(chain string, addr string) (string, bool) { +func (options *Options) GetAddressFromEns(chain string, addr string) (string, bool) { if !strings.Contains(addr, ".eth") { return lowerIfHex(addr), false } diff --git a/src/apps/chifra/pkg/rpcClient/get_block.go b/src/apps/chifra/pkg/rpcClient/get_block.go index 17f315cbd1..1f157d7487 100644 --- a/src/apps/chifra/pkg/rpcClient/get_block.go +++ b/src/apps/chifra/pkg/rpcClient/get_block.go @@ -22,7 +22,7 @@ import ( ) // GetBlockBodyByNumber fetches the block with transactions from the RPC. -func GetBlockBodyByNumber(chain string, bn uint64, options *Options) (types.SimpleBlock[types.SimpleTransaction], error) { +func (options *Options) GetBlockBodyByNumber(chain string, bn uint64) (types.SimpleBlock[types.SimpleTransaction], error) { if options.HasStore() { // We only cache blocks with transaction hashes cachedBlock := types.SimpleBlock[string]{BlockNumber: bn} @@ -32,7 +32,7 @@ func GetBlockBodyByNumber(chain string, bn uint64, options *Options) (types.Simp result.Transactions = make([]types.SimpleTransaction, 0, len(cachedBlock.Transactions)) success := true for index := range cachedBlock.Transactions { - tx, err := GetTransactionByBlockAndId(chain, cachedBlock.BlockNumber, uint64(index), options) + tx, err := options.GetTransactionByBlockAndId(chain, cachedBlock.BlockNumber, uint64(index)) if err != nil { success = false break @@ -78,14 +78,14 @@ func GetBlockBodyByNumber(chain string, bn uint64, options *Options) (types.Simp // Get the receipt var receipt types.SimpleReceipt - receipt, err = GetReceipt(chain, ReceiptQuery{ + receipt, err = options.GetReceipt(chain, ReceiptQuery{ Bn: uint64(bn), Txid: uint64(raw.TxIndex()), TxHash: raw.TxHash(), GasPrice: raw.TxGasPrice(), NeedsTs: true, Ts: ts, - }, options) + }) if err != nil { return block, err } @@ -105,7 +105,7 @@ func GetBlockBodyByNumber(chain string, bn uint64, options *Options) (types.Simp } // GetBlockHeaderByNumber fetches the block with only transactions' hashes from the RPC -func GetBlockHeaderByNumber(chain string, bn uint64, options *Options) (block types.SimpleBlock[string], err error) { +func (options *Options) GetBlockHeaderByNumber(chain string, bn uint64) (block types.SimpleBlock[string], err error) { if options.HasStore() { block.BlockNumber = bn if err := options.Store.Read(&block, nil); err == nil { @@ -144,7 +144,9 @@ func GetBlockHeaderByNumber(chain string, bn uint64, options *Options) (block ty // loadBlock fetches block from RPC, but it does not try to fill Transactions field. This is delegated to // more specialized functions and makes loadBlock generic. func loadBlock[Tx string | types.SimpleTransaction](chain string, bn uint64, withTxs bool) (block types.SimpleBlock[Tx], rawBlock *types.RawBlock, err error) { - rawBlock, err = getRawBlock(chain, bn, withTxs) + conn := NewConnection(chain, []string{}) + + rawBlock, err = conn.getRawBlock(chain, bn, withTxs) if err != nil { return } @@ -193,7 +195,7 @@ func loadBlock[Tx string | types.SimpleTransaction](chain string, bn uint64, wit return } -func getRawBlock(chain string, bn uint64, withTxs bool) (*types.RawBlock, error) { +func (options *Options) getRawBlock(chain string, bn uint64, withTxs bool) (*types.RawBlock, error) { method := "eth_getBlockByNumber" params := rpc.Params{fmt.Sprintf("0x%x", bn), withTxs} @@ -202,7 +204,7 @@ func getRawBlock(chain string, bn uint64, withTxs bool) (*types.RawBlock, error) } else { if bn == 0 { // The RPC does not return a timestamp for the zero block, so we make one - block.Timestamp = fmt.Sprintf("0x%x", GetBlockTimestamp(chain, utils.PointerOf(uint64(0)))) + block.Timestamp = fmt.Sprintf("0x%x", options.GetBlockTimestamp(chain, utils.PointerOf(uint64(0)))) } else if utils.MustParseUint(block.Timestamp) == 0 { return &types.RawBlock{}, fmt.Errorf("block at %s returned an error: %w", fmt.Sprintf("%d", bn), ethereum.NotFound) } @@ -212,7 +214,7 @@ func getRawBlock(chain string, bn uint64, withTxs bool) (*types.RawBlock, error) } // GetBlockTimestamp returns the timestamp associated with a given block -func GetBlockTimestamp(chain string, bn *uint64) base.Timestamp { +func (options *Options) GetBlockTimestamp(chain string, bn *uint64) base.Timestamp { if ec, err := getClient(chain); err != nil { logger.Error("Could not connect to RPC client", err) return 0 @@ -234,7 +236,7 @@ func GetBlockTimestamp(chain string, bn *uint64) base.Timestamp { if ts == 0 { // The RPC does not return a timestamp for block zero, so we simulate it with ts from block one less 13 seconds // TODO: Chain specific - return GetBlockTimestamp(chain, utils.PointerOf(uint64(1))) - 13 + return options.GetBlockTimestamp(chain, utils.PointerOf(uint64(1))) - 13 } return ts @@ -242,7 +244,7 @@ func GetBlockTimestamp(chain string, bn *uint64) base.Timestamp { } // GetTransactionHashByNumberAndID returns a transaction's hash if it's a valid transaction -func GetTransactionHashByNumberAndID(chain string, bn, txId uint64) (string, error) { +func (options *Options) GetTransactionHashByNumberAndID(chain string, bn, txId uint64) (string, error) { if ec, err := getClient(chain); err != nil { return "", err } else { @@ -261,4 +263,3 @@ func GetTransactionHashByNumberAndID(chain string, bn, txId uint64) (string, err return tx.Hash().Hex(), nil } } - diff --git a/src/apps/chifra/pkg/rpcClient/get_log.go b/src/apps/chifra/pkg/rpcClient/get_log.go index 4d16cea92a..4ae1f4a779 100644 --- a/src/apps/chifra/pkg/rpcClient/get_log.go +++ b/src/apps/chifra/pkg/rpcClient/get_log.go @@ -10,7 +10,7 @@ import ( "github.com/bykof/gostradamus" ) -func getSimpleLogs(chain string, filter types.SimpleLogFilter) ([]types.SimpleLog, error) { +func (options *Options) getSimpleLogs(chain string, filter types.SimpleLogFilter) ([]types.SimpleLog, error) { p := struct { FromBlock string `json:"fromBlock"` ToBlock string `json:"toBlock"` @@ -40,7 +40,7 @@ func getSimpleLogs(chain string, filter types.SimpleLogFilter) ([]types.SimpleLo for _, rawLog := range rawLogs { bn := utils.MustParseUint(rawLog.BlockNumber) if bn != curBlock { - curTs = GetBlockTimestamp(chain, &bn) + curTs = options.GetBlockTimestamp(chain, &bn) curDate = gostradamus.FromUnixTimestamp(curTs) curBlock = bn } @@ -66,22 +66,22 @@ func getSimpleLogs(chain string, filter types.SimpleLogFilter) ([]types.SimpleLo } // GetLogsByFilter returns the logs given a filter -func GetLogsByFilter(chain string, filter types.SimpleLogFilter) ([]types.SimpleLog, error) { - return getSimpleLogs(chain, filter) +func (options *Options) GetLogsByFilter(chain string, filter types.SimpleLogFilter) ([]types.SimpleLog, error) { + return options.getSimpleLogs(chain, filter) } // GetLogsByNumber returns the logs of a block -func GetLogsByNumber(chain string, bn uint64) ([]types.SimpleLog, error) { +func (options *Options) GetLogsByNumber(chain string, bn uint64) ([]types.SimpleLog, error) { filter := types.SimpleLogFilter{ FromBlock: bn, ToBlock: bn, } - return getSimpleLogs(chain, filter) + return options.getSimpleLogs(chain, filter) } // GetCountLogsInBlock returns the number of logs in a block -func GetCountLogsInBlock(chain string, bn uint64) (uint64, error) { - if logs, err := GetLogsByNumber(chain, bn); err != nil { +func (options *Options) GetCountLogsInBlock(chain string, bn uint64) (uint64, error) { + if logs, err := options.GetLogsByNumber(chain, bn); err != nil { return 0, err } else { return uint64(len(logs)), nil diff --git a/src/apps/chifra/pkg/rpcClient/get_meta.go b/src/apps/chifra/pkg/rpcClient/get_meta.go index f2aee43da5..3f00cb5d25 100644 --- a/src/apps/chifra/pkg/rpcClient/get_meta.go +++ b/src/apps/chifra/pkg/rpcClient/get_meta.go @@ -32,8 +32,8 @@ func (m MetaData) Age(bn uint64) int64 { return int64(m.Latest) - int64(bn) // Allows negative } -func GetMetaData(chain string, testmode bool) (*MetaData, error) { - chainId, networkId, err := GetClientIDs(chain) +func (options *Options) GetMetaData(chain string, testmode bool) (*MetaData, error) { + chainId, networkId, err := options.GetClientIDs(chain) if err != nil { return nil, err } @@ -55,7 +55,7 @@ func GetMetaData(chain string, testmode bool) (*MetaData, error) { meta.Chain = chain meta.ChainId = chainId meta.NetworkId = networkId - meta.Latest = GetLatestBlockNumber(chain) + meta.Latest = options.GetLatestBlockNumber(chain) filenameChan := make(chan cache.CacheFileInfo) diff --git a/src/apps/chifra/pkg/rpcClient/get_meta_integration_test.go b/src/apps/chifra/pkg/rpcClient/get_meta_integration_test.go index 0344c56cae..0cd7001513 100644 --- a/src/apps/chifra/pkg/rpcClient/get_meta_integration_test.go +++ b/src/apps/chifra/pkg/rpcClient/get_meta_integration_test.go @@ -9,8 +9,12 @@ package rpcClient import ( "testing" + + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) func Test_GetMetaData(t *testing.T) { - GetMetaData("mainnet", false) + chain := utils.GetTestChain() + conn := NewConnection(chain, []string{}) + conn.GetMetaData(chain, false) } diff --git a/src/apps/chifra/pkg/rpcClient/get_receipt.go b/src/apps/chifra/pkg/rpcClient/get_receipt.go index bed0f9db73..32b2ebf410 100644 --- a/src/apps/chifra/pkg/rpcClient/get_receipt.go +++ b/src/apps/chifra/pkg/rpcClient/get_receipt.go @@ -26,13 +26,13 @@ type ReceiptQuery struct { // GetReceipt fetches receipt from the RPC. If txGasPrice is provided, it will be used for // receipts in blocks before London -func GetReceipt(chain string, query ReceiptQuery, rpcOptions *Options) (receipt types.SimpleReceipt, err error) { - if rpcOptions.HasStore() { +func (options *Options) GetReceipt(chain string, query ReceiptQuery) (receipt types.SimpleReceipt, err error) { + if options.HasStore() { tx := &types.SimpleTransaction{ BlockNumber: query.Bn, TransactionIndex: query.Txid, } - if err := rpcOptions.Store.Read(tx, nil); err == nil { + if err := options.Store.Read(tx, nil); err == nil { // success if tx.Receipt == nil { return receipt, nil @@ -47,7 +47,7 @@ func GetReceipt(chain string, query ReceiptQuery, rpcOptions *Options) (receipt } if query.NeedsTs && query.Ts == 0 { - query.Ts = GetBlockTimestamp(chain, &query.Bn) + query.Ts = options.GetBlockTimestamp(chain, &query.Bn) } logs := []types.SimpleLog{} @@ -113,7 +113,8 @@ func GetReceipt(chain string, query ReceiptQuery, rpcOptions *Options) (receipt // getRawTransactionReceipt fetches raw transaction given blockNumber and transactionIndex func getRawTransactionReceipt(chain string, bn uint64, txid uint64) (receipt *types.RawReceipt, tx *ethTypes.Transaction, err error) { - if fetched, err := GetTransactionByNumberAndID(chain, bn, txid); err != nil { + conn := NewConnection(chain, []string{}) + if fetched, err := conn.GetTransactionByNumberAndID(chain, bn, txid); err != nil { return nil, nil, err } else { diff --git a/src/apps/chifra/pkg/rpcClient/get_traces.go b/src/apps/chifra/pkg/rpcClient/get_traces.go index 9aeab70d3c..dfb9e03e2b 100644 --- a/src/apps/chifra/pkg/rpcClient/get_traces.go +++ b/src/apps/chifra/pkg/rpcClient/get_traces.go @@ -17,8 +17,8 @@ import ( ) // GetCountTracesInBlock returns the number of traces in a block -func GetCountTracesInBlock(chain string, bn uint64) (uint64, error) { - if traces, err := GetTracesByNumber(chain, bn); err != nil { +func (options *Options) GetCountTracesInBlock(chain string, bn uint64) (uint64, error) { + if traces, err := options.GetTracesByNumber(chain, bn); err != nil { return utils.NOPOS, err } else { return uint64(len(traces)), nil @@ -26,7 +26,7 @@ func GetCountTracesInBlock(chain string, bn uint64) (uint64, error) { } // GetTracesByNumber returns a slice of traces in the given block -func GetTracesByNumber(chain string, bn uint64) ([]types.SimpleTrace, error) { +func (options *Options) GetTracesByNumber(chain string, bn uint64) ([]types.SimpleTrace, error) { method := "trace_block" params := rpc.Params{fmt.Sprintf("0x%x", bn)} @@ -34,7 +34,7 @@ func GetTracesByNumber(chain string, bn uint64) ([]types.SimpleTrace, error) { return []types.SimpleTrace{}, err } else { curApp := types.SimpleAppearance{BlockNumber: uint32(^uint32(0))} - curTs := GetBlockTimestamp(chain, &bn) + curTs := options.GetBlockTimestamp(chain, &bn) var idx uint64 // TODO: This could be loadTrace in the same way loadBlocks works @@ -80,7 +80,7 @@ func GetTracesByNumber(chain string, bn uint64) ([]types.SimpleTrace, error) { BlockNumber: uint32(trace.BlockNumber), TransactionIndex: uint32(trace.TransactionIndex), } - curTs = GetBlockTimestamp(chain, &trace.BlockNumber) + curTs = options.GetBlockTimestamp(chain, &trace.BlockNumber) idx = 0 } trace.TraceIndex = idx @@ -93,30 +93,30 @@ func GetTracesByNumber(chain string, bn uint64) ([]types.SimpleTrace, error) { } // GetTracesByTransactionID returns a slice of traces in a given transaction -func GetTracesByTransactionID(chain string, bn, txid uint64, rpcOptions *Options) ([]types.SimpleTrace, error) { +func (options *Options) GetTracesByTransactionID(chain string, bn, txid uint64) ([]types.SimpleTrace, error) { var ret []types.SimpleTrace - if rpcOptions.HasStore() { + if options.HasStore() { traceGroup := &types.SimpleTraceGroup{ BlockNumber: bn, TransactionIndex: int(txid), } - if err := rpcOptions.Store.Read(traceGroup, nil); err == nil { + if err := options.Store.Read(traceGroup, nil); err == nil { // success return traceGroup.Traces, nil } } - txHash, err := GetTransactionHashByNumberAndID(chain, bn, txid) + txHash, err := options.GetTransactionHashByNumberAndID(chain, bn, txid) if err != nil { return ret, err } - return GetTracesByTransactionHash(chain, txHash, nil, rpcOptions) + return options.GetTracesByTransactionHash(chain, txHash, nil) } // GetCountTracesInTransaction returns the number of traces in a given transaction -func GetCountTracesInTransaction(chain string, txHash string) (uint64, error) { - traces, err := GetTracesByTransactionHash(chain, txHash, nil, NoOptions) +func (options *Options) GetCountTracesInTransaction(chain string, txHash string) (uint64, error) { + traces, err := options.GetTracesByTransactionHash(chain, txHash, nil) if err != nil { return 0, err } @@ -124,7 +124,7 @@ func GetCountTracesInTransaction(chain string, txHash string) (uint64, error) { } // GetTracesByFilter returns a slice of traces in a given transaction's hash -func GetTracesByFilter(chain string, filter string) ([]types.SimpleTrace, error) { +func (options *Options) GetTracesByFilter(chain string, filter string) ([]types.SimpleTrace, error) { method := "trace_filter" var f types.SimpleTraceFilter ff := f.ParseBangString(filter) @@ -135,7 +135,7 @@ func GetTracesByFilter(chain string, filter string) ([]types.SimpleTrace, error) return ret, fmt.Errorf("trace filter %s returned an error: %w", filter, ethereum.NotFound) } else { curApp := types.SimpleAppearance{BlockNumber: uint32(^uint32(0))} - curTs := GetBlockTimestamp(chain, utils.PointerOf(utils.MustParseUint(f.FromBlock))) + curTs := options.GetBlockTimestamp(chain, utils.PointerOf(utils.MustParseUint(f.FromBlock))) var idx uint64 // TODO: This could be loadTrace in the same way loadBlocks works @@ -194,7 +194,7 @@ func GetTracesByFilter(chain string, filter string) ([]types.SimpleTrace, error) BlockNumber: uint32(trace.BlockNumber), TransactionIndex: uint32(trace.TransactionIndex), } - curTs = GetBlockTimestamp(chain, utils.PointerOf(trace.BlockNumber)) + curTs = options.GetBlockTimestamp(chain, utils.PointerOf(trace.BlockNumber)) idx = 0 } trace.TraceIndex = idx @@ -208,11 +208,11 @@ func GetTracesByFilter(chain string, filter string) ([]types.SimpleTrace, error) } // GetTracesByTransactionHash returns a slice of traces in a given transaction's hash -func GetTracesByTransactionHash(chain string, txHash string, transaction *types.SimpleTransaction, rpcOptions *Options) ([]types.SimpleTrace, error) { - if rpcOptions.HasStore() && transaction != nil { +func (options *Options) GetTracesByTransactionHash(chain string, txHash string, transaction *types.SimpleTransaction) ([]types.SimpleTrace, error) { + if options.HasStore() && transaction != nil { traceGroup := types.NewSimpleTraceGroup(transaction) - if err := rpcOptions.Store.Read(traceGroup, nil); err == nil { + if err := options.Store.Read(traceGroup, nil); err == nil { // success return traceGroup.Traces, nil } @@ -296,17 +296,17 @@ func GetTracesByTransactionHash(chain string, txHash string, transaction *types. ret = append(ret, trace) } - if rpcOptions.HasStore() && !rpcOptions.TraceWriteDisabled && transaction != nil { + if options.HasStore() && !options.TraceWriteDisabled && transaction != nil { var writeOptions *cacheNew.WriteOptions - if !rpcOptions.Store.ReadOnly() { + if !options.Store.ReadOnly() { writeOptions = &cacheNew.WriteOptions{ // Check if the block is final - Pending: (&types.SimpleBlock[string]{Timestamp: transaction.Timestamp}).Pending(rpcOptions.LatestBlockTimestamp), + Pending: (&types.SimpleBlock[string]{Timestamp: transaction.Timestamp}).Pending(options.LatestBlockTimestamp), } } traceGroup := types.NewSimpleTraceGroup(transaction) traceGroup.Traces = ret - rpcOptions.Store.Write(traceGroup, writeOptions) + options.Store.Write(traceGroup, writeOptions) } return ret, nil diff --git a/src/apps/chifra/pkg/rpcClient/get_transaction.go b/src/apps/chifra/pkg/rpcClient/get_transaction.go index 24003f491b..db5b6dfd9f 100644 --- a/src/apps/chifra/pkg/rpcClient/get_transaction.go +++ b/src/apps/chifra/pkg/rpcClient/get_transaction.go @@ -39,7 +39,7 @@ func getRawTransaction(chain string, blkHash base.Hash, txHash base.Hash, bn bas } } -func GetAppearanceFromHash(chain string, hash string) (types.RawAppearance, error) { +func (options *Options) GetAppearanceFromHash(chain string, hash string) (types.RawAppearance, error) { var ret types.RawAppearance if rawTx, err := getRawTransaction(chain, notAHash, base.HexToHash(hash), notAnInt, notAnInt); err != nil { return ret, err @@ -50,8 +50,7 @@ func GetAppearanceFromHash(chain string, hash string) (types.RawAppearance, erro } } -func GetPrefundTxByApp(chain string, appearance *types.RawAppearance) (tx *types.SimpleTransaction, err error) { - var rpcOptions = NoOptions +func (options *Options) GetPrefundTxByApp(chain string, appearance *types.RawAppearance) (tx *types.SimpleTransaction, err error) { // TODO: performance - This loads and then drops the file every time it's called. Quite slow. // TODO: performance - in the old C++ we stored these values in a pre fundAddrMap so that given a txid in block zero // TODO: performance - we knew which address was granted allocation at that transaction. @@ -61,7 +60,7 @@ func GetPrefundTxByApp(chain string, appearance *types.RawAppearance) (tx *types } else { var blockHash base.Hash var ts int64 - if block, err := GetBlockHeaderByNumber(chain, uint64(0), rpcOptions); err != nil { + if block, err := options.GetBlockHeaderByNumber(chain, uint64(0)); err != nil { return nil, err } else { blockHash = block.Hash @@ -135,11 +134,11 @@ func getBlockReward(bn uint64) *big.Int { // TODO: This is not cross-chain correct -func GetRewardTxByTypeAndApp(chain string, rt RewardType, appearance *types.RawAppearance) (*types.SimpleTransaction, error) { - if block, err := GetBlockBodyByNumber(chain, uint64(appearance.BlockNumber), &Options{Store: cacheNew.NoCache}); err != nil { +func (options *Options) GetRewardTxByTypeAndApp(chain string, rt RewardType, appearance *types.RawAppearance) (*types.SimpleTransaction, error) { + if block, err := options.GetBlockBodyByNumber(chain, uint64(appearance.BlockNumber)); err != nil { return nil, err } else { - if uncles, err := GetUnclesByNumber(chain, uint64(appearance.BlockNumber)); err != nil { + if uncles, err := options.GetUnclesByNumber(chain, uint64(appearance.BlockNumber)); err != nil { return nil, err } else { var blockReward = big.NewInt(0) @@ -181,7 +180,7 @@ func GetRewardTxByTypeAndApp(chain string, rt RewardType, appearance *types.RawA if block.Miner.Hex() == appearance.Address { sender = base.BlockRewardSender // if it's both, it's the block reward // The uncle miner may also have been the miner of the block - if minerTx, err := GetRewardTxByTypeAndApp(chain, BLOCK_REWARD, appearance); err != nil { + if minerTx, err := options.GetRewardTxByTypeAndApp(chain, BLOCK_REWARD, appearance); err != nil { return nil, err } else { blockReward = &minerTx.Rewards.Block @@ -215,20 +214,20 @@ func GetRewardTxByTypeAndApp(chain string, rt RewardType, appearance *types.RawA } } -func GetTransactionByAppearance(chain string, appearance *types.RawAppearance, fetchTraces bool, rpcOptions *Options) (tx *types.SimpleTransaction, err error) { +func (options *Options) GetTransactionByAppearance(chain string, appearance *types.RawAppearance, fetchTraces bool) (tx *types.SimpleTransaction, err error) { bn := uint64(appearance.BlockNumber) txid := uint64(appearance.TransactionIndex) - if rpcOptions.HasStore() { + if options.HasStore() { tx = &types.SimpleTransaction{ BlockNumber: bn, TransactionIndex: txid, } - if err := rpcOptions.Store.Read(tx, nil); err == nil { + if err := options.Store.Read(tx, nil); err == nil { // success if fetchTraces { - traces, err := GetTracesByTransactionHash(chain, tx.Hash.Hex(), tx, rpcOptions) + traces, err := options.GetTracesByTransactionHash(chain, tx.Hash.Hex(), tx) if err != nil { return nil, err } @@ -240,42 +239,42 @@ func GetTransactionByAppearance(chain string, appearance *types.RawAppearance, f var writeOptions *cacheNew.WriteOptions var blockTs base.Timestamp - if rpcOptions.HasStoreWritable() { - blockTs = GetBlockTimestamp(chain, &bn) + if options.HasStoreWritable() { + blockTs = options.GetBlockTimestamp(chain, &bn) writeOptions = &cacheNew.WriteOptions{ // Check if the block is final - Pending: (&types.SimpleBlock[string]{Timestamp: blockTs}).Pending(rpcOptions.LatestBlockTimestamp), + Pending: (&types.SimpleBlock[string]{Timestamp: blockTs}).Pending(options.LatestBlockTimestamp), } } tx = nil if bn == 0 { - if tx, err = GetPrefundTxByApp(chain, appearance); err != nil { + if tx, err = options.GetPrefundTxByApp(chain, appearance); err != nil { return nil, err } } else if txid == 99999 || txid == 99997 || txid == 99996 { - if tx, err = GetRewardTxByTypeAndApp(chain, BLOCK_REWARD, appearance); err != nil { + if tx, err = options.GetRewardTxByTypeAndApp(chain, BLOCK_REWARD, appearance); err != nil { return nil, err } } else if txid == 99998 { - if tx, err = GetRewardTxByTypeAndApp(chain, UNCLE_REWARD, appearance); err != nil { + if tx, err = options.GetRewardTxByTypeAndApp(chain, UNCLE_REWARD, appearance); err != nil { return nil, err } } if tx != nil { - if rpcOptions.HasStore() && !rpcOptions.TransactionWriteDisabled { - rpcOptions.Store.Write(tx, writeOptions) + if options.HasStore() && !options.TransactionWriteDisabled { + options.Store.Write(tx, writeOptions) } return tx, nil } - blockTs = GetBlockTimestamp(chain, &bn) - receipt, err := GetReceipt(chain, ReceiptQuery{ + blockTs = options.GetBlockTimestamp(chain, &bn) + receipt, err := options.GetReceipt(chain, ReceiptQuery{ Bn: bn, Txid: txid, NeedsTs: true, Ts: blockTs, - }, rpcOptions) + }) if err != nil { return } @@ -287,12 +286,12 @@ func GetTransactionByAppearance(chain string, appearance *types.RawAppearance, f tx = types.NewSimpleTransaction(rawTx, &receipt, blockTs) - if rpcOptions.HasStore() && !rpcOptions.TransactionWriteDisabled { - rpcOptions.Store.Write(tx, writeOptions) + if options.HasStore() && !options.TransactionWriteDisabled { + options.Store.Write(tx, writeOptions) } if fetchTraces { - traces, err := GetTracesByTransactionHash(chain, tx.Hash.Hex(), tx, rpcOptions) + traces, err := options.GetTracesByTransactionHash(chain, tx.Hash.Hex(), tx) if err != nil { return nil, err } @@ -302,14 +301,14 @@ func GetTransactionByAppearance(chain string, appearance *types.RawAppearance, f return } -func GetTransactionByBlockAndId(chain string, bn base.Blknum, txid uint64, rpcOptions *Options) (tx *types.SimpleTransaction, err error) { - if rpcOptions.HasStore() { +func (options *Options) GetTransactionByBlockAndId(chain string, bn base.Blknum, txid uint64) (tx *types.SimpleTransaction, err error) { + if options.HasStore() { tx = &types.SimpleTransaction{ BlockNumber: bn, TransactionIndex: txid, } - if err := rpcOptions.Store.Read(tx, nil); err == nil { + if err := options.Store.Read(tx, nil); err == nil { // success return tx, nil } @@ -319,30 +318,30 @@ func GetTransactionByBlockAndId(chain string, bn base.Blknum, txid uint64, rpcOp if err != nil { return } - blockTs := GetBlockTimestamp(chain, &bn) + blockTs := options.GetBlockTimestamp(chain, &bn) var writeOptions *cacheNew.WriteOptions - if rpcOptions.HasStoreWritable() { + if options.HasStoreWritable() { writeOptions = &cacheNew.WriteOptions{ // Check if the block is final - Pending: (&types.SimpleBlock[string]{Timestamp: blockTs}).Pending(rpcOptions.LatestBlockTimestamp), + Pending: (&types.SimpleBlock[string]{Timestamp: blockTs}).Pending(options.LatestBlockTimestamp), } } - receipt, err := GetReceipt(chain, ReceiptQuery{ + receipt, err := options.GetReceipt(chain, ReceiptQuery{ Bn: bn, Txid: txid, NeedsTs: true, Ts: blockTs, - }, rpcOptions) + }) if err != nil { return } tx = types.NewSimpleTransaction(rawTx, &receipt, blockTs) - if rpcOptions.HasStore() && !rpcOptions.TransactionWriteDisabled { - rpcOptions.Store.Write(tx, writeOptions) + if options.HasStore() && !options.TransactionWriteDisabled { + options.Store.Write(tx, writeOptions) } return diff --git a/src/apps/chifra/pkg/rpcClient/get_uncle.go b/src/apps/chifra/pkg/rpcClient/get_uncle.go index 30f01c1906..6c8c64cafa 100644 --- a/src/apps/chifra/pkg/rpcClient/get_uncle.go +++ b/src/apps/chifra/pkg/rpcClient/get_uncle.go @@ -15,7 +15,7 @@ import ( ) // GetCountUnclesInBlock returns the number of uncles in a block. -func GetCountUnclesInBlock(chain string, bn uint64) (uint64, error) { +func (options *Options) GetCountUnclesInBlock(chain string, bn uint64) (uint64, error) { method := "eth_getUncleCountByBlockNumber" params := rpc.Params{fmt.Sprintf("0x%x", bn)} @@ -27,8 +27,8 @@ func GetCountUnclesInBlock(chain string, bn uint64) (uint64, error) { } // GetUncleHashesByNumber returns the uncle hashes in a block. -func GetUncleHashesByNumber(chain string, bn uint64) ([]base.Hash, error) { - if count, err := GetCountUnclesInBlock(chain, bn); err != nil { +func (options *Options) GetUncleHashesByNumber(chain string, bn uint64) ([]base.Hash, error) { + if count, err := options.GetCountUnclesInBlock(chain, bn); err != nil { return nil, err } else if count > 0 { ret := make([]base.Hash, count) @@ -53,8 +53,8 @@ func GetUncleHashesByNumber(chain string, bn uint64) ([]base.Hash, error) { } // GetUnclesByNumber returns the number of uncles in a block. -func GetUnclesByNumber(chain string, bn uint64) ([]types.SimpleBlock[types.SimpleTransaction], error) { - if count, err := GetCountUnclesInBlock(chain, bn); err != nil { +func (options *Options) GetUnclesByNumber(chain string, bn uint64) ([]types.SimpleBlock[types.SimpleTransaction], error) { + if count, err := options.GetCountUnclesInBlock(chain, bn); err != nil { return nil, err } else if count > 0 { ret := make([]types.SimpleBlock[types.SimpleTransaction], count) diff --git a/src/apps/chifra/pkg/rpcClient/is_archive.go b/src/apps/chifra/pkg/rpcClient/is_archive.go index 3c858b07c1..bf0d131743 100644 --- a/src/apps/chifra/pkg/rpcClient/is_archive.go +++ b/src/apps/chifra/pkg/rpcClient/is_archive.go @@ -8,7 +8,7 @@ import ( ) // IsNodeArchive returns true if the node is an archive node -func IsNodeArchive(chain string) bool { +func (options *Options) IsNodeArchive(chain string) bool { // TODO: from C++ code // const CToml* config = getGlobalConfig("blockScrape"); // if (!config->getConfigBool("requires", "archive", true)) @@ -24,10 +24,11 @@ func IsNodeArchive(chain string) bool { return false } - bal, err := GetBalanceAt(chain, largest.Address, 0) + bal, err := options.GetBalanceAt(chain, largest.Address, 0) if err != nil { return false } + // fmt.Println("Largest:", largest.Balance, "Balance:", *bal, "Cmp:", bal.Cmp(&largest.Balance) == 0) return bal.Cmp(&largest.Balance) == 0 } diff --git a/src/apps/chifra/pkg/rpcClient/is_tracing.go b/src/apps/chifra/pkg/rpcClient/is_tracing.go index 4e57e03834..3c95da464c 100644 --- a/src/apps/chifra/pkg/rpcClient/is_tracing.go +++ b/src/apps/chifra/pkg/rpcClient/is_tracing.go @@ -3,7 +3,7 @@ package rpcClient // TODO: BOGUS This needs to be implemented in a cross-chain, cross-client manner // IsNodeTracing returns true if the node is an archive node. Note currently always returns true. -func IsNodeTracing(testMode bool, chain string) bool { +func (options *Options) IsNodeTracing(chain string, testMode bool) bool { // TODO: We can test this with a unit test if testMode && chain == "non-tracing" { return false diff --git a/src/apps/chifra/pkg/rpcClient/options.go b/src/apps/chifra/pkg/rpcClient/options.go index 265f46c06c..7333716be5 100644 --- a/src/apps/chifra/pkg/rpcClient/options.go +++ b/src/apps/chifra/pkg/rpcClient/options.go @@ -10,15 +10,34 @@ var NoOptions *Options = nil // Options carry additional context to rpcClient calls type Options struct { - // Cache Store to use for read/write. Write can be disabled - // by setting Store to read-only mode - Store *cacheNew.Store - - LatestBlockTimestamp base.Timestamp - // Disable caching transactions - TransactionWriteDisabled bool - // Disable caching traces - TraceWriteDisabled bool + Store *cacheNew.Store // Cache Store to use for read/write. Write can be disabled by setting Store to read-only mode + LatestBlockTimestamp base.Timestamp + TransactionWriteDisabled bool // Disable caching transactions + TraceWriteDisabled bool // Disable caching traces +} + +func (options *Options) TestLog() { + logger.TestLog(!options.TraceWriteDisabled, "TraceWriteDisabled: ", options.TraceWriteDisabled) + logger.TestLog(!options.TransactionWriteDisabled, "TransactionWriteDisabled: ", options.TransactionWriteDisabled) + logger.TestLog(options.LatestBlockTimestamp != 0, "LatestBlockTimestamp", options.LatestBlockTimestamp) +} + +func NewConnection(chain string, caches []string) *Options { + settings := DefaultRpcOptionsSettings{ + Chain: chain, + } + return settings.DefaultRpcOptions() +} + +func NewReadOnlyConnection(chain string) *Options { + settings := DefaultRpcOptionsSettings{ + Chain: chain, + ReadonlyCache: true, + } + return settings.DefaultRpcOptions() +} + +func (options *Options) EnableCaches(on, txs, traces bool) { } // CacheStore returns cache for the given chain. If readonly is true, it returns @@ -53,7 +72,7 @@ type CacheStater interface { CacheState() (bool, bool, bool) } -func DefaultRpcOptions(settings *DefaultRpcOptionsSettings) *Options { +func (settings *DefaultRpcOptionsSettings) DefaultRpcOptions() *Options { readonlyCache := false if settings != nil { readonlyCache = settings.ReadonlyCache @@ -80,18 +99,18 @@ func DefaultRpcOptions(settings *DefaultRpcOptionsSettings) *Options { // HasStore is a shorthand to check if Store is initialized. It will return // false for nil pointer to Options -func (o *Options) HasStore() bool { - if o == nil { +func (options *Options) HasStore() bool { + if options == nil { return false } - return o.Store != nil + return options.Store != nil } -func (o *Options) HasStoreWritable() bool { - if !o.HasStore() { +func (options *Options) HasStoreWritable() bool { + if !options.HasStore() { return false } - return !o.Store.ReadOnly() + return !options.Store.ReadOnly() } diff --git a/src/apps/chifra/pkg/tslib/repair.go b/src/apps/chifra/pkg/tslib/repair.go index b957718100..d5113f06f8 100644 --- a/src/apps/chifra/pkg/tslib/repair.go +++ b/src/apps/chifra/pkg/tslib/repair.go @@ -48,7 +48,8 @@ func Repair(chain string, bn uint64) error { pos := (recordSize * int64(bn)) fp.Seek(pos, io.SeekStart) - block, _ := rpcClient.GetBlockHeaderByNumber(chain, bn, rpcClient.NoOptions) + conn := rpcClient.NewConnection(chain, []string{}) + block, _ := conn.GetBlockHeaderByNumber(chain, bn) record := TimestampRecord{Bn: uint32(block.BlockNumber), Ts: uint32(block.Timestamp)} err = binary.Write(fp, binary.LittleEndian, &record) if err != nil { diff --git a/src/apps/chifra/pkg/tslib/tobn.go b/src/apps/chifra/pkg/tslib/tobn.go index ea29896f90..410d85f682 100644 --- a/src/apps/chifra/pkg/tslib/tobn.go +++ b/src/apps/chifra/pkg/tslib/tobn.go @@ -25,7 +25,8 @@ func FromDateToBn(chain, dateStr string) (uint64, error) { // FromNameToBn returns the chain-specific block number (if found) given the name of a special block. The list of special blocks is per-chain. func FromNameToBn(chain, name string) (uint64, error) { if name == "latest" { - meta, err := rpcClient.GetMetaData(chain, false) + conn := rpcClient.NewConnection(chain, []string{}) + meta, err := conn.GetMetaData(chain, false) if err != nil { return 0, err } diff --git a/src/apps/chifra/pkg/tslib/todate.go b/src/apps/chifra/pkg/tslib/todate.go index 70b0eda748..2cb6256758 100644 --- a/src/apps/chifra/pkg/tslib/todate.go +++ b/src/apps/chifra/pkg/tslib/todate.go @@ -25,8 +25,9 @@ func FromNameToDate(chain, name string) (gostradamus.DateTime, error) { } if name == "latest" { - meta, _ := rpcClient.GetMetaData(chain, false) - ts := rpcClient.GetBlockTimestamp(chain, utils.PointerOf(meta.Latest)) + conn := rpcClient.NewConnection(chain, []string{}) + meta, _ := conn.GetMetaData(chain, false) + ts := conn.GetBlockTimestamp(chain, utils.PointerOf(meta.Latest)) return FromTsToDate(ts) } diff --git a/src/apps/chifra/pkg/validate/blockvalidate_test.go b/src/apps/chifra/pkg/validate/blockvalidate_test.go index ed1d581623..175902d2cf 100644 --- a/src/apps/chifra/pkg/validate/blockvalidate_test.go +++ b/src/apps/chifra/pkg/validate/blockvalidate_test.go @@ -157,11 +157,6 @@ func TestIsDateTimeString(t *testing.T) { t.Error("Fails for exact first block date") } - // TODO: Turn off go testing that requires ts.bin - // if !isBeforeFirstBlock(utils.GetTestChain(), "2015-07-30T15:25:59") { - // t.Error("Passes for too early date (before first block)") - // } - if IsDateTimeString("hello") { t.Error("Passes for invalid date #1") } diff --git a/src/apps/chifra/pkg/version/version_test.go b/src/apps/chifra/pkg/version/version_test.go index ee1731b53c..6c52d9589b 100644 --- a/src/apps/chifra/pkg/version/version_test.go +++ b/src/apps/chifra/pkg/version/version_test.go @@ -45,11 +45,11 @@ func TestNewVersion(t *testing.T) { { name: "library version string", args: args{ - str: "GHC-TrueBlocks//0.72.0-beta", + str: "GHC-TrueBlocks//0.76.0-beta", }, wantVers: Version{ Major: 0, - Minor: 72, + Minor: 76, Build: 0, Aspect: "beta", }, diff --git a/src/dev_tools/makeClass/handle_gocmds.cpp b/src/dev_tools/makeClass/handle_gocmds.cpp index e3fdc13b9a..8fdf80de65 100644 --- a/src/dev_tools/makeClass/handle_gocmds.cpp +++ b/src/dev_tools/makeClass/handle_gocmds.cpp @@ -483,6 +483,7 @@ string_q get_optfields(const CCommandOption& cmd) { } } varWidth = max(string_q("Globals").length(), varWidth); + varWidth = max(string_q("Conn").length(), varWidth); varWidth = max(string_q("BadFlag").length(), varWidth); typeWidth = max(string_q("globals.GlobalOptions").length(), typeWidth); typeWidth = max(string_q("error").length(), typeWidth); @@ -531,6 +532,7 @@ string_q get_optfields(const CCommandOption& cmd) { } ONE(os, "Globals", varWidth, "globals.GlobalOptions", typeWidth, "the global options"); + ONE(os, "Conn", varWidth, "*rpcClient.Options", typeWidth, "the connection to the RPC server"); ONE(os, "BadFlag", varWidth, "error", typeWidth, "an error flag if needed"); return os.str(); diff --git a/src/dev_tools/makeClass/templates/blank_options.go.tmpl b/src/dev_tools/makeClass/templates/blank_options.go.tmpl index 0c075258be..ae82c7de58 100644 --- a/src/dev_tools/makeClass/templates/blank_options.go.tmpl +++ b/src/dev_tools/makeClass/templates/blank_options.go.tmpl @@ -32,7 +32,8 @@ var default[{PROPER}]Options = [{PROPER}]Options{[{GODEFS}]} // testLog is used only during testing to export the options for this test case. func (opts *[{PROPER}]Options) testLog() { -[{TEST_LOGS}] opts.Globals.TestLog() +[{TEST_LOGS}] opts.Conn.TestLog() + opts.Globals.TestLog() } // String implements the Stringer interface @@ -49,12 +50,17 @@ func [{LOWER}]FinishParseApi(w http.ResponseWriter, r *http.Request) *[{PROPER}] switch key { [{REQUEST_OPTS}] default: if !copy.Globals.Caps.HasKey(key) { + opts.Conn = &rpcClient.Options{} opts.BadFlag = validate.Usage("Invalid key ({0}) in {1} route.", key, "[{ROUTE}]") return opts } } } opts.Globals = *globals.GlobalsFinishParseApi(w, r) + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE // EXISTING_CODE @@ -66,11 +72,16 @@ func [{LOWER}]FinishParse(args []string) *[{PROPER}]Options { opts := GetOptions() opts.Globals.FinishParse(args) defFmt := "txt" + chain := opts.Globals.Chain + caches := []string{} + opts.Conn = rpcClient.NewConnection(chain, caches) + // EXISTING_CODE // EXISTING_CODE [{CONFIG_OVERRIDE}] if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" { opts.Globals.Format = defFmt } + return opts } diff --git a/src/examples/allContracts/allContracts.go b/src/examples/allContracts/allContracts.go index 8a1980b5f9..b43d69d759 100644 --- a/src/examples/allContracts/allContracts.go +++ b/src/examples/allContracts/allContracts.go @@ -12,7 +12,9 @@ import ( var bar = logger.NewBar("Visiting", true, int64(17000000)) func main() { - latest := rpcClient.GetLatestBlockNumber("mainnet") + chain := "mainnet" + conn := rpcClient.NewConnection(chain, []string{}) + latest := conn.GetLatestBlockNumber(chain) forEveryTrace(46000, latest, visitTrace) bar.Finish(true) } @@ -25,13 +27,15 @@ func visitTrace(trace *types.SimpleTrace, data *any) error { } func forEveryTrace(from, to base.Blknum, visitor func(*types.SimpleTrace, *any) error) error { + chain := "mainnet" + conn := rpcClient.NewConnection(chain, []string{}) for blknum := from; blknum <= to; blknum++ { - if block, err := rpcClient.GetBlockHeaderByNumber("mainnet", blknum, rpcClient.NoOptions); err != nil { + if block, err := conn.GetBlockHeaderByNumber(chain, blknum); err != nil { return err } else { bar.Tick() for _, txHash := range block.Transactions { - if traces, err := rpcClient.GetTracesByTransactionHash("mainnet", txHash, nil, rpcClient.NoOptions); err != nil { + if traces, err := conn.GetTracesByTransactionHash(chain, txHash, nil); err != nil { return err } else { for _, trace := range traces { diff --git a/src/examples/findFirst/findFirst.go b/src/examples/findFirst/findFirst.go index 2cbf21bfeb..36a96e984b 100644 --- a/src/examples/findFirst/findFirst.go +++ b/src/examples/findFirst/findFirst.go @@ -23,17 +23,19 @@ import ( // forEveryTrace, forEveryLog, etc. // ----------------------------------------------------------------------------------------------- func main() { - slowWay() - fastWay() + chain := "mainnet" + conn := rpcClient.NewConnection(chain, []string{}) + slowWay(conn) + fastWay(conn) } var chain = "mainnet" -func slowWay() { +func slowWay(conn *rpcClient.Options) { start := time.Now() bar := logger.NewBarWithStart("Getting stuff", true, 40000, 60000) for i := 40000; i < 60000; i++ { - if block, err := rpcClient.GetBlockHeaderByNumber(chain, base.Blknum(i), rpcClient.NoOptions); err != nil { + if block, err := conn.GetBlockHeaderByNumber(chain, base.Blknum(i)); err != nil { fmt.Println(err) } else { if len(block.Transactions) > 0 { @@ -49,7 +51,7 @@ func slowWay() { } } -func fastWay() { +func fastWay(conn *rpcClient.Options) { bar := logger.NewBarWithStart("Getting stuff", true, 40000, 60000) var TxIds []identifiers.Identifier @@ -66,7 +68,7 @@ func fastWay() { var firstBlock types.SimpleBlock[string] firstBlock.BlockNumber = utils.NOPOS iterateFunc := func(key identifiers.ResolvedId, value *bool) error { - if theBlock, err := rpcClient.GetBlockHeaderByNumber(chain, base.Blknum(key.BlockNumber), rpcClient.NoOptions); err != nil { + if theBlock, err := conn.GetBlockHeaderByNumber(chain, base.Blknum(key.BlockNumber)); err != nil { return err } else { if len(theBlock.Transactions) > 0 { diff --git a/src/examples/simple/simple.go b/src/examples/simple/simple.go index f25195c849..70f5c18867 100644 --- a/src/examples/simple/simple.go +++ b/src/examples/simple/simple.go @@ -9,7 +9,9 @@ import ( ) func main() { - if block, err := rpcClient.GetBlockHeaderByNumber("mainnet", base.Blknum(3500000), rpcClient.NoOptions); err != nil { + chain := "mainnet" + conn := rpcClient.NewConnection(chain, []string{}) + if block, err := conn.GetBlockHeaderByNumber(chain, base.Blknum(3500000)); err != nil { fmt.Println(err) } else { bytes, _ := json.MarshalIndent(block, "", " ")