From e28e1476825b90c4bad2e0c01144e2cedc9d8007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enol=20=C3=81lvarez?= Date: Thu, 12 Sep 2024 17:06:50 +0200 Subject: [PATCH] Update sol-transactions to Solana Common v0.3.0 Fixes conditionally select module --- sol-transactions/convo.go | 18 ++++++++++-------- sol-transactions/state.go | 17 ++++++++++------- .../templates/substreams.yaml.gotmpl | 14 +++++++++----- sol-transactions/types.go | 4 ++-- tests/sol-transactions/generator.json | 2 +- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/sol-transactions/convo.go b/sol-transactions/convo.go index 99f4545..b340aa9 100644 --- a/sol-transactions/convo.go +++ b/sol-transactions/convo.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "strconv" + "strings" codegen "github.com/streamingfast/substreams-codegen" "github.com/streamingfast/substreams-codegen/loop" @@ -41,8 +42,8 @@ func (c *Convo) NextStep() loop.Cmd { return cmd(codegen.AskInitialStartBlockType{}) } - if p.ProgramId == "" { - return cmd(AskProgramId{}) + if p.Filter == "" { + return cmd(AskFilter{}) } return cmd(codegen.RunGenerate{}) @@ -87,14 +88,15 @@ func (c *Convo) Update(msg loop.Msg) loop.Cmd { c.State.InitialBlockSet = true return c.NextStep() - case AskProgramId: - return c.Action(InputProgramId{}). - TextInput(fmt.Sprintf("Filter the transactions based on one or several Program IDs.\nSupported operators are: logical or '||', logical and '&&' and parenthesis: '()'. \nExample: to only consume TRANSACTIONS containing Token or ComputeBudget instructions: 'program:TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA || program:ComputeBudget111111111111111111111111111111'."), "Submit"). - DefaultValue("program:TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"). + case AskFilter: + return c.Action(InputFilter{}). + TextInput(fmt.Sprintf("Filter the transaction by Program IDs and/or accounts.\nSupported operators are: logical or '||', logical and '&&' and parenthesis: '()'. \n\nEXAMPLE: to only consume TRANSACTIONS containing:\n - ComputeBudget instructions\n OR\n - Token Instructions where the account '3MQw72oGrizUDEcD9gZYMgqo1pc364y5GnnJHcGpvurK' is included\n'program:ComputeBudget111111111111111111111111111111 || (program:TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA && account:3MQw72oGrizUDEcD9gZYMgqo1pc364y5GnnJHcGpvurK)'\n"), "Submit"). + DefaultValue("program:ComputeBudget111111111111111111111111111111 || (program:TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA && account:3MQw72oGrizUDEcD9gZYMgqo1pc364y5GnnJHcGpvurK)"). Cmd() - case InputProgramId: - c.State.ProgramId = msg.Value + case InputFilter: + c.State.Filter = msg.Value + c.State.FilterContainsAccount = strings.Contains(c.State.Filter, "account:") return c.NextStep() case codegen.RunGenerate: diff --git a/sol-transactions/state.go b/sol-transactions/state.go index 6dd6789..2764224 100644 --- a/sol-transactions/state.go +++ b/sol-transactions/state.go @@ -5,13 +5,16 @@ import ( ) type Project struct { - Name string `json:"name"` - ChainName string `json:"chainName"` - Compile bool `json:"compile,omitempty"` // optional field to write in state and automatically compile with no confirmation. - Download bool `json:"download,omitempty"` - InitialBlock uint64 `json:"initialBlock,omitempty"` - InitialBlockSet bool `json:"initialBlockSet,omitempty"` - ProgramId string `json:"programId,omitempty"` + Name string `json:"name"` + ChainName string `json:"chainName"` + Compile bool `json:"compile,omitempty"` // optional field to write in state and automatically compile with no confirmation. + Download bool `json:"download,omitempty"` + InitialBlock uint64 `json:"initialBlock,omitempty"` + InitialBlockSet bool `json:"initialBlockSet,omitempty"` + Filter string `json:"filter,omitempty"` + FilterContainsAccount bool `json:"filterContainsAccount,omitempty"` + + generatedCodeCompleted bool } func (p *Project) ModuleName() string { return strings.ReplaceAll(p.Name, "-", "_") } diff --git a/sol-transactions/templates/substreams.yaml.gotmpl b/sol-transactions/templates/substreams.yaml.gotmpl index 433a68c..f34b6c8 100644 --- a/sol-transactions/templates/substreams.yaml.gotmpl +++ b/sol-transactions/templates/substreams.yaml.gotmpl @@ -4,14 +4,18 @@ package: version: v0.1.0 imports: - solana: https://spkg.io/streamingfast/solana-common-v0.2.0.spkg + solana: https://spkg.io/streamingfast/solana-common-v0.3.0.spkg modules: - - name: map_filtered_transactions - use: solana:filtered_transactions_without_votes - initialBlock: {{ .InitialBlock }} + - name: map_filtered_transactions +{{- if .FilterContainsAccount }} + use: solana:transactions_by_programid_and_account_without_votes +{{- else }} + use: solana:transactions_by_programid_without_votes +{{- end }} + initialBlock: {{ .InitialBlock }} network: solana-mainnet-beta params: - map_filtered_transactions: {{ .ProgramId }} + map_filtered_transactions: {{ .Filter }} diff --git a/sol-transactions/types.go b/sol-transactions/types.go index 2a979cc..c04a94c 100644 --- a/sol-transactions/types.go +++ b/sol-transactions/types.go @@ -2,6 +2,6 @@ package soltransactions import pbconvo "github.com/streamingfast/substreams-codegen/pb/sf/codegen/conversation/v1" -type AskProgramId struct{} -type InputProgramId struct{ pbconvo.UserInput_TextInput } +type AskFilter struct{} +type InputFilter struct{ pbconvo.UserInput_TextInput } type ShowInstructions struct{} \ No newline at end of file diff --git a/tests/sol-transactions/generator.json b/tests/sol-transactions/generator.json index 54da6f5..74905ed 100644 --- a/tests/sol-transactions/generator.json +++ b/tests/sol-transactions/generator.json @@ -4,6 +4,6 @@ "name": "my_project", "chainName": "", "initialBlockSet": true, - "programId": "program:TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + "filter": "program:TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" } } \ No newline at end of file