forked from gagliardetto/solana-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shuffle around the commands on `slnc`. Better decoding, better reading of data. Simplified API
- Loading branch information
Showing
21 changed files
with
474 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var serumGetCmd = &cobra.Command{ | ||
Use: "get", | ||
Short: "Get Serum objects", | ||
} | ||
|
||
func init() { | ||
serumCmd.AddCommand(serumGetCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var serumListCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List Serum objects", | ||
} | ||
|
||
func init() { | ||
serumCmd.AddCommand(serumListCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/dfuse-io/solana-go" | ||
"github.com/dfuse-io/solana-go/token" | ||
"github.com/ryanuber/columnize" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var splGetMintCmd = &cobra.Command{ | ||
Use: "get-mint {mint_addr}", | ||
Short: "Retrieves mint information", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := cmd.Context() | ||
|
||
mintAddr, err := solana.PublicKeyFromBase58(args[0]) | ||
if err != nil { | ||
return fmt.Errorf("decoding mint addr: %w", err) | ||
} | ||
|
||
client := getClient() | ||
|
||
acct, err := client.GetAccountInfo(ctx, mintAddr) | ||
if err != nil { | ||
return fmt.Errorf("couldn't get account data: %w", err) | ||
} | ||
|
||
mint, err := token.DecodeMint(acct.Value.Data) | ||
if err != nil { | ||
return fmt.Errorf("unable to retrieve int information: %w", err) | ||
} | ||
|
||
if !mint.IsInitialized { | ||
fmt.Println("Uninitialized mint. Data length", len(acct.Value.Data)) | ||
return nil | ||
} | ||
|
||
var out []string | ||
|
||
out = append(out, fmt.Sprintf("Data length | %d", len(acct.Value.Data))) | ||
|
||
if mint.MintAuthorityOption != 0 { | ||
out = append(out, fmt.Sprintf("Mint Authority | %s", mint.MintAuthority)) | ||
} else { | ||
out = append(out, "No mint authority") | ||
} | ||
|
||
out = append(out, fmt.Sprintf("Supply | %d", mint.Supply)) | ||
out = append(out, fmt.Sprintf("Decimals | %d", mint.Decimals)) | ||
|
||
if mint.FreezeAuthorityOption != 0 { | ||
out = append(out, fmt.Sprintf("Freeze Authority | %s", mint.FreezeAuthority)) | ||
} else { | ||
out = append(out, "No freeze authority") | ||
} | ||
|
||
fmt.Println(columnize.Format(out, nil)) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
splCmd.AddCommand(splGetMintCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/dfuse-io/solana-go/token" | ||
"github.com/ryanuber/columnize" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var splListMintsCmd = &cobra.Command{ | ||
Use: "list-mints", | ||
Short: "Lists mints", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
// TODO: implement a different network argument, | ||
// later. Ultimately, get on chain. We have a database here! | ||
|
||
mints, err := token.KnownMints("mainnet") | ||
if err != nil { | ||
return fmt.Errorf("listing mints: %w", err) | ||
} | ||
out := []string{"Symbol | Mint address | Token name"} | ||
|
||
for _, m := range mints { | ||
out = append(out, fmt.Sprintf("%s | %s | %s", m.TokenSymbol, m.MintAddress, m.TokenName)) | ||
} | ||
|
||
fmt.Println(columnize.Format(out, nil)) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
splCmd.AddCommand(splListMintsCmd) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.