Skip to content

Commit

Permalink
fixing:
Browse files Browse the repository at this point in the history
 (HAL-06) USE OF MAGIC VALUES
 (HAL-09) USAGE OF HARDCODED PATHS
  • Loading branch information
ZeneDeLuca committed Oct 10, 2024
1 parent dd9cf03 commit 3b4a2fc
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 25 deletions.
4 changes: 4 additions & 0 deletions cmd/hypergrid-ssnd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import (

"hypergrid-ssn/app"
"hypergrid-ssn/cmd/hypergrid-ssnd/cmd"
"hypergrid-ssn/tools"
)

func main() {
//read config file
tools.ReadVariablesFromYaml("~/.hypergrid-ssn/config/hypergrid.yaml")

rootCmd := cmd.NewRootCmd()
if err := svrcmd.Execute(rootCmd, "", app.DefaultNodeHome); err != nil {
fmt.Fprintln(rootCmd.OutOrStderr(), err)
Expand Down
59 changes: 53 additions & 6 deletions hypergrid-aide/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"io"
"log"
"os"
"strconv"
Expand All @@ -12,18 +13,61 @@ import (
// Importing the general purpose Cosmos blockchain client
"github.com/ignite/cli/v28/ignite/pkg/cosmosaccount"
"github.com/ignite/cli/v28/ignite/pkg/cosmosclient"
"gopkg.in/yaml.v3"
// Importing the types package of your blog blockchain
)

const SOLANA_RPC_ENDPOINT = "http://localhost:8899" //"https://devnet1.sonic.game" //
const COSMOS_RPC_ENDPOINT = "http://172.31.10.244:26657"
const COSMOS_ADDRESS_PREFIX = "cosmos"
const COSMOS_HOME = ".hypergrid-ssn"
const COSMOS_KEY = "my_key"
const COSMOS_GAS = "100000000"
// Default values for the global variables
var SOLANA_RPC_ENDPOINT = "http://localhost:8899" //"https://devnet1.sonic.game" //
var SOLANA_PRIVATE_KEY = "~/.config/solana/id.json"
var COSMOS_RPC_ENDPOINT = "http://172.31.10.244:26657"
var COSMOS_ADDRESS_PREFIX = "cosmos"
var COSMOS_HOME = ".hypergrid-ssn"
var COSMOS_KEY = "my_key"
var COSMOS_GAS = "100000000"

const AIDE_GET_BLOCKS_COUNT_LIMIT = uint64(200)

// read variables from yaml file
func readVariablesFromYaml(filename string) {
// Open the file
file, err := os.Open(filename)
if err != nil {
log.Fatal(err)
return
}
defer file.Close()

// Read the file
data, err := io.ReadAll(file)
if err != nil {
log.Fatal(err)
return
}

// Unmarshal the YAML
var params map[string]interface{}
err = yaml.Unmarshal(data, &params)
if err != nil {
log.Fatal(err)
return
}

// Print the params
log.Println(params)

// Set the global variables
SOLANA_RPC_ENDPOINT = params["solana_rpc"].(string)
SOLANA_PRIVATE_KEY = params["solana_private_key"].(string)
COSMOS_RPC_ENDPOINT = params["cosmos_rpc"].(string)
COSMOS_ADDRESS_PREFIX = params["cosmos_address_prefix"].(string)
COSMOS_HOME = params["cosmos_home"].(string)
COSMOS_KEY = params["cosmos_key"].(string)
COSMOS_GAS = params["cosmos_gas"].(string)

tools.COSMOS_ADDRESS_PREFIX = COSMOS_ADDRESS_PREFIX
}

func SendGridBlockFees(cosmos tools.CosmosClient, solana tools.SolanaClient, account cosmosaccount.Account, gridId string, limit uint64) {
first_available_slot, err := solana.GetFirstBlock()
if err != nil {
Expand Down Expand Up @@ -117,6 +161,9 @@ func main() {
// os.Exit(1)
}

//read variables from yaml file
readVariablesFromYaml(home + "/.hypergrid-aide.yaml")

command := args[1]
switch command {
case "sync":
Expand Down
2 changes: 1 addition & 1 deletion hypergrid-aide/tools/cosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// Importing the types package of your blog blockchain
)

const COSMOS_ADDRESS_PREFIX = "cosmos"
var COSMOS_ADDRESS_PREFIX = "cosmos"

type CosmosClient struct {
Context context.Context
Expand Down
10 changes: 2 additions & 8 deletions hypergrid-aide/tools/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,9 @@ func (s *SolanaClient) RequestAirdrop(address string, amount uint64) {
spew.Dump(out)
}

func (s *SolanaClient) SendTransaction(programID string) (*solana.Signature, error) {
func (s *SolanaClient) SendTransaction(LocalPrivateKey string, programID string) (*solana.Signature, error) {
// Load the account that you will send funds FROM:
//get home path "~/"
home, err := os.UserHomeDir()
if err != nil {
// panic(err)
return nil, err
}
accountFrom, err := solana.PrivateKeyFromSolanaKeygenFile(home + "/.config/solana/id.json")
accountFrom, err := solana.PrivateKeyFromSolanaKeygenFile(LocalPrivateKey)
if err != nil {
panic(err)
}
Expand Down
50 changes: 40 additions & 10 deletions tools/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/sha256"
"encoding/binary"
"fmt"
"io"
"log"
"os"
"sort"
Expand All @@ -17,6 +18,7 @@ import (
confirm "github.com/gagliardetto/solana-go/rpc/sendAndConfirmTransaction"
"github.com/gagliardetto/solana-go/rpc/ws"
"github.com/near/borsh-go"
"gopkg.in/yaml.v3"
)

func GetAccountInfo(rpcUrl string, address string) (*rpc.GetAccountInfoResult, error) {
Expand Down Expand Up @@ -137,21 +139,49 @@ func (d *InitializedParams) BorshEncode() ([]byte, error) {
return buf.Bytes(), nil
}

const SonicFeeProgramID = "SonicFeeSet1ement11111111111111111111111111"
const L1InboxProgramID = "5XJ1wZkTwAw9mc5FbM3eBgAT83TKgtAGzKos9wVxC6my"
// global variables with default values
var SonicFeeProgramID = "SonicFeeSet1ement11111111111111111111111111"
var L1InboxProgramID = "5XJ1wZkTwAw9mc5FbM3eBgAT83TKgtAGzKos9wVxC6my"
var LocalPrivateKey = "~/.config/solana/id.json"

func getLocalPrivateKey() (solana.PrivateKey, error) {
//get home path "~/"
home, err := os.UserHomeDir()
// read variables from yaml file
func ReadVariablesFromYaml(filename string) {
// Open the file
file, err := os.Open(filename)
if err != nil {
// panic(err)
return nil, err
log.Fatal(err)
return
}
// Load the account that you will send funds FROM:
accountFrom, err := solana.PrivateKeyFromSolanaKeygenFile(home + "/.config/solana/id.json")
defer file.Close()

// Read the file
data, err := io.ReadAll(file)
if err != nil {
log.Fatal(err)
return
}

// Unmarshal the YAML
var params map[string]interface{}
err = yaml.Unmarshal(data, &params)
if err != nil {
log.Fatal(err)
return
}

// Print the params
log.Println(params)

// Set the global variables
SonicFeeProgramID = params["SonicFeeProgramID"].(string)
L1InboxProgramID = params["L1InboxProgramID"].(string)
LocalPrivateKey = params["LocalPrivateKey"].(string)
}

func getLocalPrivateKey() (solana.PrivateKey, error) {
// Load the account that you will send funds FROM:
// accountFrom, err := solana.PrivateKeyFromBase58("5gA6JTpFziXu7py2j63arRUq1H29p6pcPMB74LaNuzcSqULPD6s1SZUS3UMPvFEE9oXmt1kk6ez3C6piTc3bwpJ6")
accountFrom, err := solana.PrivateKeyFromSolanaKeygenFile(LocalPrivateKey)

if err != nil {
// panic(err)
return nil, err
Expand Down

0 comments on commit 3b4a2fc

Please sign in to comment.