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

fixing: (HAL-06) USE OF MAGIC VALUES , (HAL-09) USAGE OF HARDCODED PATHS #43

Merged
merged 1 commit into from
Oct 10, 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
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
Loading