From 10eeff73ee2e4e23973c3bf407eeb941e3cbfaff Mon Sep 17 00:00:00 2001 From: Eduard Voiculescu Date: Mon, 19 Aug 2024 12:27:00 -0400 Subject: [PATCH] adding default value of project name to all codegens --- ethfull/convo.go | 1 + evm-minimal/convo.go | 1 + evm-minimal/templates/README.md.gotmpl | 6 +-- injective-events/convo.go | 1 + injective-minimal/chain_configs.go | 42 +++++++++++++++++++++ injective-minimal/convo.go | 5 +-- injective-minimal/convo_test.go | 2 +- injective-minimal/generate.go | 2 +- injective-minimal/logging.go | 2 +- injective-minimal/state.go | 7 +++- injective-minimal/types.go | 14 ------- sol-minimal/convo.go | 3 +- sol-minimal/templates/README.md.gotmpl | 6 +-- starknet-minimal/convo.go | 1 + starknet-minimal/templates/README.md.gotmpl | 6 +-- starknet-sql/convo.go | 1 + vara-minimal/convo.go | 1 + vara-minimal/templates/README.md.gotmpl | 6 +-- 18 files changed, 68 insertions(+), 39 deletions(-) create mode 100644 injective-minimal/chain_configs.go delete mode 100644 injective-minimal/types.go diff --git a/ethfull/convo.go b/ethfull/convo.go index 78bbde1..968689b 100644 --- a/ethfull/convo.go +++ b/ethfull/convo.go @@ -319,6 +319,7 @@ func (c *Convo) Update(msg loop.Msg) loop.Cmd { return c.action(codegen.InputProjectName{}). TextInput(codegen.InputProjectNameTextInput(), "Submit"). Description(codegen.InputProjectNameDescription()). + DefaultValue("my_project"). Validation(codegen.InputProjectNameRegex(), codegen.InputProjectNameValidation()). Cmd() diff --git a/evm-minimal/convo.go b/evm-minimal/convo.go index 9dc671d..0a7d808 100644 --- a/evm-minimal/convo.go +++ b/evm-minimal/convo.go @@ -117,6 +117,7 @@ func (c *Convo) Update(msg loop.Msg) loop.Cmd { return c.action(codegen.InputProjectName{}). TextInput(codegen.InputProjectNameTextInput(), "Submit"). Description(codegen.InputProjectNameDescription()). + DefaultValue("my_project"). Validation(codegen.InputProjectNameRegex(), codegen.InputProjectNameValidation()). Cmd() diff --git a/evm-minimal/templates/README.md.gotmpl b/evm-minimal/templates/README.md.gotmpl index 6f0dab2..0b9753b 100644 --- a/evm-minimal/templates/README.md.gotmpl +++ b/evm-minimal/templates/README.md.gotmpl @@ -11,13 +11,11 @@ substreams build To run your Substreams you will need to [authenticate](https://substreams.streamingfast.io/documentation/consume/authentication) yourself. ```bash -export API_KEY="your_api_key" -export SUBSTREAMS_API_TOKEN=$(curl https://auth.thegraph.market/v1/auth/issue -s --data-binary '{"api_key":"'$API_KEY'"}' | jq -r .token) +substreams auth ``` ## Run your Substreams ```bash -substreams run ./substreams.yaml map_my_data -t +1000 -substreams gui ./substreams.yaml map_my_data -t +1000 +substreams gui ./substreams.yaml ``` \ No newline at end of file diff --git a/injective-events/convo.go b/injective-events/convo.go index d9f2866..aa4c2b6 100644 --- a/injective-events/convo.go +++ b/injective-events/convo.go @@ -202,6 +202,7 @@ func (c *InjectiveConvo) Update(msg loop.Msg) loop.Cmd { return c.action(codegen.InputProjectName{}). TextInput(codegen.InputProjectNameTextInput(), "Submit"). Description(codegen.InputProjectNameDescription()). + DefaultValue("my_project"). Validation(codegen.InputProjectNameRegex(), codegen.InputProjectNameValidation()). Cmd() diff --git a/injective-minimal/chain_configs.go b/injective-minimal/chain_configs.go new file mode 100644 index 0000000..5c7688b --- /dev/null +++ b/injective-minimal/chain_configs.go @@ -0,0 +1,42 @@ +package injectiveminimal + +import "sort" + +type ChainConfig struct { + ID string // Public + DisplayName string // Public + ExplorerLink string + FirehoseEndpoint string + Network string + + initialBlockCache map[string]uint64 +} + +var ChainConfigs []*ChainConfig + +var ChainConfigByID = map[string]*ChainConfig{ + "injective-mainnet": { + DisplayName: "Injective Mainnet", + ExplorerLink: "https://explorer.injective.network/", + FirehoseEndpoint: "mainnet.injective.streamingfast.io:443", + Network: "injective-mainnet", + initialBlockCache: make(map[string]uint64), + }, + "injective-testnet": { + DisplayName: "Injective Testnet", + ExplorerLink: "https://testnet.explorer.injective.network/", + FirehoseEndpoint: "testnet.injective.streamingfast.io:443", + Network: "injective-testnet", + initialBlockCache: make(map[string]uint64), + }, +} + +func init() { + for k, v := range ChainConfigByID { + v.ID = k + ChainConfigs = append(ChainConfigs, v) + } + sort.Slice(ChainConfigs, func(i, j int) bool { + return ChainConfigs[i].DisplayName < ChainConfigs[j].DisplayName + }) +} diff --git a/injective-minimal/convo.go b/injective-minimal/convo.go index bbef0e6..59ff812 100644 --- a/injective-minimal/convo.go +++ b/injective-minimal/convo.go @@ -1,4 +1,4 @@ -package ethfull +package injectiveminimal import ( "encoding/json" @@ -47,8 +47,6 @@ func cmd(msg any) loop.Cmd { } } -// This function does NOT mutate anything. Only reads. - func (c *Convo) validate() error { if _, err := json.Marshal(c.state); err != nil { return fmt.Errorf("validating state format: %w", err) @@ -102,6 +100,7 @@ func (c *Convo) Update(msg loop.Msg) loop.Cmd { return c.action(codegen.InputProjectName{}). TextInput(codegen.InputProjectNameTextInput(), "Submit"). Description(codegen.InputProjectNameDescription()). + DefaultValue("my_project"). Validation(codegen.InputProjectNameRegex(), codegen.InputProjectNameValidation()). Cmd() diff --git a/injective-minimal/convo_test.go b/injective-minimal/convo_test.go index 97ababc..04668f5 100644 --- a/injective-minimal/convo_test.go +++ b/injective-minimal/convo_test.go @@ -1,4 +1,4 @@ -package ethfull +package injectiveminimal import ( "testing" diff --git a/injective-minimal/generate.go b/injective-minimal/generate.go index 6864ef9..4c7b26d 100644 --- a/injective-minimal/generate.go +++ b/injective-minimal/generate.go @@ -1,4 +1,4 @@ -package ethfull +package injectiveminimal import ( "bytes" diff --git a/injective-minimal/logging.go b/injective-minimal/logging.go index 56260d4..ffe7479 100644 --- a/injective-minimal/logging.go +++ b/injective-minimal/logging.go @@ -1,4 +1,4 @@ -package ethfull +package injectiveminimal import ( "github.com/streamingfast/logging" diff --git a/injective-minimal/state.go b/injective-minimal/state.go index da09992..553c8c5 100644 --- a/injective-minimal/state.go +++ b/injective-minimal/state.go @@ -1,4 +1,4 @@ -package ethfull +package injectiveminimal import ( "strings" @@ -30,3 +30,8 @@ type Project struct { func (p *Project) ModuleName() string { return strings.ReplaceAll(p.Name, "-", "_") } func (p *Project) KebabName() string { return strings.ReplaceAll(p.Name, "_", "-") } + +func (p *Project) ChainConfig() *ChainConfig { return ChainConfigByID[p.ChainName] } +func (p *Project) ChainEndpoint() string { return ChainConfigByID[p.ChainName].FirehoseEndpoint } +func (p *Project) ChainNetwork() string { return ChainConfigByID[p.ChainName].Network } +func (p *Project) IsValidChainName(input string) bool { return ChainConfigByID[input] != nil } diff --git a/injective-minimal/types.go b/injective-minimal/types.go deleted file mode 100644 index 0dac527..0000000 --- a/injective-minimal/types.go +++ /dev/null @@ -1,14 +0,0 @@ -package ethfull - -import ( - pbconvo "github.com/streamingfast/substreams-codegen/pb/sf/codegen/conversation/v1" -) - -type MsgStart struct{ pbconvo.UserInput_Start } - -type AskProjectName struct{} -type InputProjectName struct{ pbconvo.UserInput_TextInput } - -type AskChainName struct{} -type MsgInvalidChainName struct{} -type InputChainName struct{ pbconvo.UserInput_Selection } diff --git a/sol-minimal/convo.go b/sol-minimal/convo.go index 79b9100..3c5b105 100644 --- a/sol-minimal/convo.go +++ b/sol-minimal/convo.go @@ -47,8 +47,6 @@ func cmd(msg any) loop.Cmd { } } -// This function does NOT mutate anything. Only reads. - func (c *Convo) validate() error { if _, err := json.Marshal(c.state); err != nil { return fmt.Errorf("validating state format: %w", err) @@ -103,6 +101,7 @@ func (c *Convo) Update(msg loop.Msg) loop.Cmd { return c.action(codegen.InputProjectName{}). TextInput(codegen.InputProjectNameTextInput(), "Submit"). Description(codegen.InputProjectNameDescription()). + DefaultValue("my_project"). Validation(codegen.InputProjectNameRegex(), codegen.InputProjectNameValidation()). Cmd() diff --git a/sol-minimal/templates/README.md.gotmpl b/sol-minimal/templates/README.md.gotmpl index 1f547f1..de543a7 100644 --- a/sol-minimal/templates/README.md.gotmpl +++ b/sol-minimal/templates/README.md.gotmpl @@ -11,13 +11,11 @@ substreams build To run your Substreams you will need to [authenticate](https://substreams.streamingfast.io/documentation/consume/authentication) yourself. ```bash -export API_KEY="your_api_key" -export SUBSTREAMS_API_TOKEN=$(curl https://auth.thegraph.market/v1/auth/issue -s --data-binary '{"api_key":"'$API_KEY'"}' | jq -r .token) +substreams auth ``` ## Run your Substreams ```bash -substreams run ./substreams.yaml map_my_data -t +1000 -substreams gui ./substreams.yaml map_my_data -t +1000 +substreams gui ./substreams.yaml ``` \ No newline at end of file diff --git a/starknet-minimal/convo.go b/starknet-minimal/convo.go index 5ec0df5..1ae5002 100644 --- a/starknet-minimal/convo.go +++ b/starknet-minimal/convo.go @@ -109,6 +109,7 @@ func (c *Convo) Update(msg loop.Msg) loop.Cmd { return c.action(codegen.InputProjectName{}). TextInput(codegen.InputProjectNameTextInput(), "Submit"). Description(codegen.InputProjectNameDescription()). + DefaultValue("my_project"). Validation(codegen.InputProjectNameRegex(), codegen.InputProjectNameValidation()). Cmd() diff --git a/starknet-minimal/templates/README.md.gotmpl b/starknet-minimal/templates/README.md.gotmpl index a01839f..78d1d07 100644 --- a/starknet-minimal/templates/README.md.gotmpl +++ b/starknet-minimal/templates/README.md.gotmpl @@ -11,13 +11,11 @@ substreams build To run your Substreams you will need to [authenticate](https://substreams.streamingfast.io/documentation/consume/authentication) yourself. ```bash -export API_KEY="your_api_key" -export SUBSTREAMS_API_TOKEN=$(curl https://auth.thegraph.market/v1/auth/issue -s --data-binary '{"api_key":"'$API_KEY'"}' | jq -r .token) +substreams auth ``` ## Run your Substreams ```bash -substreams run ./substreams.yaml map_my_data -t +1000 -substreams gui ./substreams.yaml map_my_data -t +1000 +substreams gui ./substreams.yaml ``` \ No newline at end of file diff --git a/starknet-sql/convo.go b/starknet-sql/convo.go index a49d20f..efc2b6b 100644 --- a/starknet-sql/convo.go +++ b/starknet-sql/convo.go @@ -135,6 +135,7 @@ func (c *Convo) Update(msg loop.Msg) loop.Cmd { return c.action(codegen.InputProjectName{}). TextInput(codegen.InputProjectNameTextInput(), "Submit"). Description(codegen.InputProjectNameDescription()). + DefaultValue("my_project"). Validation(codegen.InputProjectNameRegex(), codegen.InputProjectNameValidation()). Cmd() diff --git a/vara-minimal/convo.go b/vara-minimal/convo.go index f958e4c..a4a3478 100644 --- a/vara-minimal/convo.go +++ b/vara-minimal/convo.go @@ -109,6 +109,7 @@ func (c *Convo) Update(msg loop.Msg) loop.Cmd { return c.action(codegen.InputProjectName{}). TextInput(codegen.InputProjectNameTextInput(), "Submit"). Description(codegen.InputProjectNameDescription()). + DefaultValue("my_project"). Validation(codegen.InputProjectNameRegex(), codegen.InputProjectNameValidation()). Cmd() diff --git a/vara-minimal/templates/README.md.gotmpl b/vara-minimal/templates/README.md.gotmpl index af03922..c80276d 100644 --- a/vara-minimal/templates/README.md.gotmpl +++ b/vara-minimal/templates/README.md.gotmpl @@ -11,13 +11,11 @@ substreams build To run your Substreams you will need to [authenticate](https://substreams.streamingfast.io/documentation/consume/authentication) yourself. ```bash -export API_KEY="your_api_key" -export SUBSTREAMS_API_TOKEN=$(curl https://auth.thegraph.market/v1/auth/issue -s --data-binary '{"api_key":"'$API_KEY'"}' | jq -r .token) +substreams auth ``` ## Run your Substreams ```bash -substreams run ./substreams.yaml map_my_data -t +1000 -substreams gui ./substreams.yaml map_my_data -t +1000 +substreams gui ./substreams.yaml ``` \ No newline at end of file