Skip to content

Commit

Permalink
Merge pull request #3 from NetSepio/rushikesh-solona-wallet-address
Browse files Browse the repository at this point in the history
solona wallet address
  • Loading branch information
Rushikeshnimkar authored Jun 3, 2024
2 parents fa4139e + 46009de commit 89964a0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 11 deletions.
50 changes: 50 additions & 0 deletions core/solonawallet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package core

import (
"bytes"
"crypto/sha256"
"fmt"
"os"

"github.com/mr-tron/base58"
"github.com/tyler-smith/go-bip39"
"golang.org/x/crypto/ed25519"
)

var WalletAddressSolana string

// GenerateWalletAddress generates a wallet address from the mnemonic set in the environment
func GenerateWalletAddresssolana() {
// Read mnemonic from environment variable
mnemonic := os.Getenv("MNEMONIC_sol")
if mnemonic == "" {
fmt.Println("MNEMONIC environment variable is not set")
return
}

// Validate the mnemonic
if !bip39.IsMnemonicValid(mnemonic) {
fmt.Println("Invalid mnemonic")
return
}
fmt.Printf("Mnemonic: %s\n", mnemonic)

// Derive a seed from the mnemonic
seed := bip39.NewSeed(mnemonic, "")

// Generate a keypair
publicKey, _, err := ed25519.GenerateKey(bytes.NewReader(seed))
if err != nil {
fmt.Println(err)
return
}

// Generate wallet address
hash := sha256.Sum256(publicKey)
WalletAddresssol := base58.Encode(hash[:20])
fmt.Printf("Wallet Address: %s\n", WalletAddresssol)

// Assign the wallet address to the variable (consider error handling)
WalletAddressSolana = WalletAddresssol
fmt.Printf("The final wallet address: %s\n", WalletAddressSolana)
}
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ func main() {
err := core.UpdateServerConfigWg()
util.CheckError("Error while creating WireGuard config file: ", err)
// Call the function to generate the wallet address and store it in the global variable
core.GenerateWalletAddress()
core.GenerateWalletAddress(),
core.GenerateWalletAddresssol(),

go p2p.Init()
//running updater
Expand Down
22 changes: 12 additions & 10 deletions util/pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type NodeStatus struct {
StartTimeStamp int64 `json:"startTimeStamp"`
Name string `json:"name"`
WalletAddress string `json:"walletAddress"`
WalletAddresssol string `json:"walletAddressSol"`
}

func CreateNodeStatus(address string, id string, startTimeStamp int64, name string) *NodeStatus {
Expand All @@ -27,16 +28,17 @@ func CreateNodeStatus(address string, id string, startTimeStamp int64, name stri
logrus.Error("failed to fetch network speed: ", err.Error())
}
nodeStatus := &NodeStatus{
HttpPort: os.Getenv("HTTP_PORT"),
Domain: os.Getenv("DOMAIN"),
Address: address,
Region: os.Getenv("REGION"),
Id: id,
DownloadSpeed: speedtestResult.DownloadSpeed,
UploadSpeed: speedtestResult.UploadSpeed,
StartTimeStamp: startTimeStamp,
Name: name,
WalletAddress: core.WalletAddressSui,
HttpPort: os.Getenv("HTTP_PORT"),
Domain: os.Getenv("DOMAIN"),
Address: address,
Region: os.Getenv("REGION"),
Id: id,
DownloadSpeed: speedtestResult.DownloadSpeed,
UploadSpeed: speedtestResult.UploadSpeed,
StartTimeStamp: startTimeStamp,
Name: name,
WalletAddress: core.WalletAddressSui,
WalletAddresssol: core.WalletAddressSolana,
}
return nodeStatus
}

0 comments on commit 89964a0

Please sign in to comment.