Skip to content

Commit

Permalink
feat: Update solana.go to use SonicFeeDataAccountID constant in SendT…
Browse files Browse the repository at this point in the history
…xFeeSettlement and InitializeDataAccount
  • Loading branch information
ZeneDeLuca committed Sep 15, 2024
1 parent 863f605 commit 2c0a377
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion hypergrid-aide/tools/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (s *SolanaClient) GetBlocks(start_slot uint64, limit uint64) ([]SolanaBlock
blocks = append(blocks, SolanaBlock{
Blockhash: resp2.Blockhash.String(),
Slot: block,
BlockTime: resp2.BlockTime.Time().Second(),
BlockTime: int(resp2.BlockTime.Time().Unix()),
Fee: Fee,
})
}
Expand Down
15 changes: 9 additions & 6 deletions tools/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func (d *InitializedParams) BorshEncode() ([]byte, error) {
}

const SonicFeeProgramID = "SonicFeeSet1ement11111111111111111111111111"
const SonicFeeDataAccountID = "SonicFeeSet1ementData1111111111111111111112"
const L1InboxProgramID = "5XJ1wZkTwAw9mc5FbM3eBgAT83TKgtAGzKos9wVxC6my"

func getLocalPrivateKey() (solana.PrivateKey, error) {
Expand Down Expand Up @@ -231,7 +232,7 @@ func sendSonicTx(rpcUrl string, programId string, accounts solana.AccountMetaSli
return &sig, nil
}

func SendTxFeeSettlement(rpcUrl string, data_accounts []string, FromId uint64, EndID uint64, bills map[string]uint64) (*solana.Signature, error) {
func SendTxFeeSettlement(rpcUrl string /*data_accounts []string,*/, FromId uint64, EndID uint64, bills map[string]uint64) (*solana.Signature, error) {
Bills := []SettlementBillParam{}
// convert bills to []SettlementBillParam
for key, value := range bills {
Expand All @@ -255,10 +256,12 @@ func SendTxFeeSettlement(rpcUrl string, data_accounts []string, FromId uint64, E
return nil, err
}

accounts := solana.AccountMetaSlice{}
for _, data_account := range data_accounts {
accounts = append(accounts, solana.NewAccountMeta(solana.MustPublicKeyFromBase58(data_account), true, false))
accounts := solana.AccountMetaSlice{
solana.NewAccountMeta(solana.MustPublicKeyFromBase58(SonicFeeDataAccountID), true, false),
}
// for _, data_account := range data_accounts {
// accounts = append(accounts, solana.NewAccountMeta(solana.MustPublicKeyFromBase58(data_account), true, false))
// }
signer, err := getLocalPrivateKey()
if err != nil {
// panic(err)
Expand All @@ -269,7 +272,7 @@ func SendTxFeeSettlement(rpcUrl string, data_accounts []string, FromId uint64, E
return sendSonicTx(rpcUrl, SonicFeeProgramID, accounts, serializedData, signers)
}

func InitializeDataAccount(rpcUrl string, owner string, data_account string, account_type uint32) (*solana.Signature, error) {
func InitializeDataAccount(rpcUrl string, owner string /*data_account string,*/, account_type uint32) (*solana.Signature, error) {
instructionData := InitializedParams{
Instruction: 0,
Owner: solana.MustPublicKeyFromBase58(owner),
Expand All @@ -284,7 +287,7 @@ func InitializeDataAccount(rpcUrl string, owner string, data_account string, acc
}

accounts := solana.AccountMetaSlice{
solana.NewAccountMeta(solana.MustPublicKeyFromBase58(data_account), true, false),
solana.NewAccountMeta(solana.MustPublicKeyFromBase58(SonicFeeDataAccountID), true, false),
}

signer, err := getLocalPrivateKey()
Expand Down
10 changes: 5 additions & 5 deletions x/hypergridssn/keeper/msg_server_fee_settlement_bill.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ func (k msgServer) CreateFeeSettlementBill(goCtx context.Context, msg *types.Msg
//todo: call sonic grid to settle the fee
// get sonic grid node
sonic_grid_rpc := ""
data_accounts := []string{}
// data_accounts := []string{}
nodes := k.GetAllHypergridNode(goCtx)
for _, node := range nodes {
// get sonic grid node from the list
if node.Role == 2 && sonic_grid_rpc == "" {
sonic_grid_rpc = node.Rpc
}
if node.DataAccount != "" {
data_accounts = append(data_accounts, node.DataAccount)
}
// if node.DataAccount != "" {
// data_accounts = append(data_accounts, node.DataAccount)
// }
}

if sonic_grid_rpc == "" {
return nil, errorsmod.Wrap(sdkerrors.ErrKeyNotFound, "sonic grid rpc not found")
}

sig, err := solana.SendTxFeeSettlement(sonic_grid_rpc, data_accounts, feeSettlementBill.FromId, feeSettlementBill.EndId, bills)
sig, err := solana.SendTxFeeSettlement(sonic_grid_rpc /* data_accounts,*/, feeSettlementBill.FromId, feeSettlementBill.EndId, bills)
if err != nil {
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion x/hypergridssn/keeper/msg_server_grid_block_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func (k msgServer) CreateGridBlockFee(goCtx context.Context, msg *types.MsgCreateGridBlockFee) (*types.MsgCreateGridBlockFeeResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

ids := make([]uint64, len(msg.Items))
ids := make([]uint64, 0, len(msg.Items))
for _, item := range msg.Items {
var gridBlockFee = types.GridBlockFee{
Creator: msg.Creator,
Expand Down

0 comments on commit 2c0a377

Please sign in to comment.