Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sol-transactions to use the latest foundational module #5

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions sol-transactions/convo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"strconv"
"strings"

codegen "github.com/streamingfast/substreams-codegen"
"github.com/streamingfast/substreams-codegen/loop"
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 10 additions & 7 deletions sol-transactions/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "-", "_") }
Expand Down
14 changes: 9 additions & 5 deletions sol-transactions/templates/substreams.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
4 changes: 2 additions & 2 deletions sol-transactions/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
2 changes: 1 addition & 1 deletion tests/sol-transactions/generator.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"name": "my_project",
"chainName": "",
"initialBlockSet": true,
"programId": "program:TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
"filter": "program:TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
}
}
Loading