diff --git a/tools/solana.go b/tools/solana.go index 4efe822..7322cd2 100644 --- a/tools/solana.go +++ b/tools/solana.go @@ -3,7 +3,6 @@ package tools import ( "bytes" "context" - "crypto/sha256" "encoding/binary" "encoding/json" "fmt" @@ -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{} @@ -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{ diff --git a/tools/solana_test.go b/tools/solana_test.go index 9264552..efd3e64 100644 --- a/tools/solana_test.go +++ b/tools/solana_test.go @@ -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 diff --git a/x/hypergridssn/keeper/msg_server_solana_account.go b/x/hypergridssn/keeper/msg_server_solana_account.go index 19fd9dd..96bada3 100644 --- a/x/hypergridssn/keeper/msg_server_solana_account.go +++ b/x/hypergridssn/keeper/msg_server_solana_account.go @@ -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()) } @@ -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()) }