From 2c0a37724b585fd30958f7a1e659e5466da3aa5b Mon Sep 17 00:00:00 2001 From: ZeneDeLuca Date: Sun, 15 Sep 2024 02:03:00 +0000 Subject: [PATCH] feat: Update solana.go to use SonicFeeDataAccountID constant in SendTxFeeSettlement and InitializeDataAccount --- hypergrid-aide/tools/solana.go | 2 +- tools/solana.go | 15 +++++++++------ .../keeper/msg_server_fee_settlement_bill.go | 10 +++++----- .../keeper/msg_server_grid_block_fee.go | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/hypergrid-aide/tools/solana.go b/hypergrid-aide/tools/solana.go index 4727878..e2c55ec 100644 --- a/hypergrid-aide/tools/solana.go +++ b/hypergrid-aide/tools/solana.go @@ -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, }) } diff --git a/tools/solana.go b/tools/solana.go index da7aa26..f24e99b 100644 --- a/tools/solana.go +++ b/tools/solana.go @@ -136,6 +136,7 @@ func (d *InitializedParams) BorshEncode() ([]byte, error) { } const SonicFeeProgramID = "SonicFeeSet1ement11111111111111111111111111" +const SonicFeeDataAccountID = "SonicFeeSet1ementData1111111111111111111112" const L1InboxProgramID = "5XJ1wZkTwAw9mc5FbM3eBgAT83TKgtAGzKos9wVxC6my" func getLocalPrivateKey() (solana.PrivateKey, error) { @@ -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 { @@ -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) @@ -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), @@ -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() diff --git a/x/hypergridssn/keeper/msg_server_fee_settlement_bill.go b/x/hypergridssn/keeper/msg_server_fee_settlement_bill.go index e190f9e..95b7f19 100644 --- a/x/hypergridssn/keeper/msg_server_fee_settlement_bill.go +++ b/x/hypergridssn/keeper/msg_server_fee_settlement_bill.go @@ -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()) } diff --git a/x/hypergridssn/keeper/msg_server_grid_block_fee.go b/x/hypergridssn/keeper/msg_server_grid_block_fee.go index 7e6ac8c..933d374 100644 --- a/x/hypergridssn/keeper/msg_server_grid_block_fee.go +++ b/x/hypergridssn/keeper/msg_server_grid_block_fee.go @@ -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,