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

(HAL-01) INDETERMINISTIC SOLANA ACCOUNT INFORMATION RETRIEVAL #45

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
28 changes: 14 additions & 14 deletions tools/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tools
import (
"bytes"
"context"
"crypto/sha256"
"encoding/binary"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -63,6 +62,7 @@ func ReadVariablesFromYaml(filename string) {
SonicStateOracleURL = params["SonicStateOracleURL"].(string)
}

// Get account info from oracle
func GetAccountFromOracle(rpcUrl string, address string, version string) (*rpc.GetAccountInfoResult, error) {
// call http client to get account info from oracle
client := &http.Client{}
Expand Down Expand Up @@ -365,21 +365,21 @@ func InitializeDataAccount(rpcUrl string, owner string, data_account string, acc
return sendSonicTx(rpcUrl, SonicFeeProgramID, accounts, serializedData, signers)
}

type InboxProgrmParams struct {
Instruction [8]byte
Slot uint64
Hash string
}
// type InboxProgrmParams struct {
// Instruction [8]byte
// Slot uint64
// Hash string
// }

func hashInstructionMethod(method string) [8]byte {
hasher := sha256.New()
hasher.Write([]byte(fmt.Sprintf("global:%s", method)))
result := hasher.Sum(nil)
// func hashInstructionMethod(method string) [8]byte {
// hasher := sha256.New()
// hasher.Write([]byte(fmt.Sprintf("global:%s", method)))
// result := hasher.Sum(nil)

var hash [8]byte
copy(hash[:], result[:8])
return hash
}
// var hash [8]byte
// copy(hash[:], result[:8])
// return hash
// }

// func SendTxInbox(rpcUrl string, slot uint64, hash string) (*solana.Signature, *solana.PublicKey, error) {
// instructionData := InboxProgrmParams{
Expand Down
21 changes: 7 additions & 14 deletions tools/solana_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,18 @@ import (
)

func TestSendTxFeeSettlement(t *testing.T) {
// FromId := uint64(1)
// EndID := uint64(100)
// bills := map[string]uint64{
// "EyYFxQ2FRcSkR8rdvefEDNy69KWHi2xTzbuVKxuBVueS": 100,
// "AzVnQCpY2rqQmxJz6PQzxWj9HHQQc5qFuL89wvov6cL4": 101,
// }

// sig, err := SendTxFeeSettlement("http://localhost:8899", []string{"AzVnQCpY2rqQmxJz6PQzxWj9HHQQc5qFuL89wvov6cL4"}, FromId, EndID, bills)
// if err != nil {
// panic(err)
// }
// spew.Dump(sig)
FromId := uint64(1)
EndID := uint64(100)
bills := map[string]uint64{
"EyYFxQ2FRcSkR8rdvefEDNy69KWHi2xTzbuVKxuBVueS": 100,
"AzVnQCpY2rqQmxJz6PQzxWj9HHQQc5qFuL89wvov6cL4": 101,
}

sig, key, err := SendTxInbox("https://api.devnet.solana.com", 53893, "2YmCa9RBVN9CZjAcN3o431UhTEU8BwmaiGoCnbeK1Sgr")
sig, err := SendTxFeeSettlement("http://localhost:8899", []string{"AzVnQCpY2rqQmxJz6PQzxWj9HHQQc5qFuL89wvov6cL4"}, FromId, EndID, bills)
if err != nil {
panic(err)
}
spew.Dump(sig)
spew.Dump(key)

// Bills := []SettlementBillParam{}
// // convert bills to []SettlementBillParam
Expand Down
10 changes: 6 additions & 4 deletions x/hypergridssn/keeper/msg_server_solana_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ func (k msgServer) CreateSolanaAccount(goCtx context.Context, msg *types.MsgCrea
}

// get account info from solana
// resp, err := solana.GetAccountInfo(node.Rpc, msg.Address)
resp, err := solana.GetAccountFromOracle(node.Rpc, msg.Address, msg.Version)
resp, err := solana.GetAccountInfo(node.Rpc, msg.Address)
//TODO: get account info from oracle
//resp, err := solana.GetAccountFromOracle(node.Rpc, msg.Address, msg.Version)
if err != nil {
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, err.Error())
}
Expand Down Expand Up @@ -87,8 +88,9 @@ func (k msgServer) UpdateSolanaAccount(goCtx context.Context, msg *types.MsgUpda
}

// get account info from solana
// resp, err := solana.GetAccountInfo(node.Rpc, msg.Address)
resp, err := solana.GetAccountFromOracle(node.Rpc, msg.Address, msg.Version)
resp, err := solana.GetAccountInfo(node.Rpc, msg.Address)
//TODO: get account info from oracle
// resp, err := solana.GetAccountFromOracle(node.Rpc, msg.Address, msg.Version)
if err != nil {
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, err.Error())
}
Expand Down
Loading