Skip to content

Commit

Permalink
New text decoder
Browse files Browse the repository at this point in the history
New decode use into get transactions
  • Loading branch information
billettc committed Nov 20, 2020
1 parent eb1b380 commit 5fa02f1
Show file tree
Hide file tree
Showing 17 changed files with 735 additions and 354 deletions.
23 changes: 15 additions & 8 deletions cmd/slnc/cmd/get_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ package cmd
import (
"context"
"fmt"
"os"

"github.com/dfuse-io/solana-go/text"

"github.com/dfuse-io/solana-go"
"github.com/dfuse-io/solana-go/rpc"
Expand All @@ -38,7 +41,7 @@ var getTransactionsCmd = &cobra.Command{
errorCheck("public key", err)

csList, err := client.GetConfirmedSignaturesForAddress2(ctx, pubKey, &rpc.GetConfirmedSignaturesForAddress2Opts{
Limit: 10,
Limit: 100,
Before: "",
Until: "",
})
Expand All @@ -47,17 +50,20 @@ var getTransactionsCmd = &cobra.Command{

for _, cs := range csList {
fmt.Println("-----------------------------------------------------------------------------------------------")
fmt.Println("Transaction: ", cs.Signature)
fmt.Println("Slot: ", cs.Slot)
fmt.Println("Memo: ", cs.Memo)
text.EncoderColorCyan.Print("Transaction: ")
fmt.Println(cs.Signature)

text.EncoderColorGreen.Print("Slot: ")
fmt.Println(cs.Slot)
text.EncoderColorGreen.Print("Memo: ")
fmt.Println(cs.Memo)

ct, err := client.GetConfirmedTransaction(ctx, cs.Signature)
errorCheck("confirm transaction", err)
if ct.Meta.Err != nil {
fmt.Println("ERROR:", ct.Meta.Err)
// for k, _ := range ct.Meta.Err
}
fmt.Println("account count:", len(ct.Transaction.Message.AccountKeys))

fmt.Print("\nInstructions:\n-------------\n\n")
for _, i := range ct.Transaction.Message.Instructions {
Expand All @@ -80,10 +86,11 @@ var getTransactionsCmd = &cobra.Command{
continue
}

decoded, err := decoder(ct.Transaction.Message.AccountKeys, &i)
fmt.Printf("%s\n\n", decoded)
decoded, err := decoder(ct.Transaction.AccountMetaList(), &i)
err = text.NewEncoder(os.Stdout).Encode(decoded, nil)
errorCheck("textEncoding", err)
}
fmt.Print("End of transaction\n\n")
text.EncoderColorCyan.Print("\n\nEnd of transaction\n\n")
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/GeertJohan/go.rice v1.0.0
github.com/dfuse-io/binary v0.0.0-20201117201711-8656308cf309
github.com/dfuse-io/logging v0.0.0-20201110202154-26697de88c79
github.com/fatih/color v1.7.0
github.com/google/go-cmp v0.4.1 // indirect
github.com/gorilla/rpc v1.2.0
github.com/gorilla/websocket v1.4.2
Expand All @@ -25,5 +26,4 @@ require (
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/tools v0.0.0-20200601175630-2caf76543d99 // indirect
google.golang.org/api v0.15.0
gotest.tools v2.2.0+incompatible
)
28 changes: 25 additions & 3 deletions go.sum

Large diffs are not rendered by default.

52 changes: 0 additions & 52 deletions instructions.go

This file was deleted.

2 changes: 1 addition & 1 deletion interface.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package solana

type AccountSettable interface {
SetAccounts(accounts []PublicKey, instructionActIdx []uint8) error
SetAccounts(accounts []*AccountMeta, instructionActIdx []uint8) error
}
4 changes: 2 additions & 2 deletions registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
)

type InstructionDecoder func([]PublicKey, *CompiledInstruction) (interface{}, error)
type InstructionDecoder func([]*AccountMeta, *CompiledInstruction) (interface{}, error)

var InstructionDecoderRegistry = map[string]InstructionDecoder{}

Expand All @@ -16,7 +16,7 @@ func RegisterInstructionDecoder(programID PublicKey, decoder InstructionDecoder)
InstructionDecoderRegistry[p] = decoder
}

func DecodeInstruction(programID PublicKey, accounts []PublicKey, inst *CompiledInstruction) (interface{}, error) {
func DecodeInstruction(programID PublicKey, accounts []*AccountMeta, inst *CompiledInstruction) (interface{}, error) {
p := programID.String()

decoder, found := InstructionDecoderRegistry[p]
Expand Down
4 changes: 2 additions & 2 deletions rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func TestClient_GetAccountInfo(t *testing.T) {

func TestClient_GetConfirmedSignaturesForAddress2(t *testing.T) {
c := NewClient("http://api.mainnet-beta.solana.com:80/rpc")
account := solana.MustPublicKeyFromBase58("CG1XSWuXo2rw2SuHTRc54nihKvLKh4wMYi7oF3487LYt")
accInfo, err := c.GetConfirmedSignaturesForAddress2(context.Background(), account, nil)
account := solana.MustPublicKeyFromBase58("H7ATJQGhwG8Uf8sUntUognFpsKixPy2buFnXkvyNbGUb")
accInfo, err := c.GetConfirmedSignaturesForAddress2(context.Background(), account, &GetConfirmedSignaturesForAddress2Opts{Limit: 1})
require.NoError(t, err)

d, err := json.MarshalIndent(accInfo, "", " ")
Expand Down
2 changes: 1 addition & 1 deletion rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ type KeyedAccount struct {

type GetConfirmedSignaturesForAddress2Opts struct {
Limit uint64 `json:"limit,omitempty"`
Before string `json:"limit,omitempty"`
Before string `json:"before,omitempty"`
Until string `json:"until,omitempty"`
}

Expand Down
Loading

0 comments on commit 5fa02f1

Please sign in to comment.