Skip to content

Commit 412062b

Browse files
Calculate fee in Kbs
1 parent 440274a commit 412062b

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

supernode/services/cascade/adaptors/lumera.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ type LumeraClient interface {
1818

1919
// Action Module
2020
GetAction(ctx context.Context, actionID string) (*actiontypes.QueryGetActionResponse, error)
21-
GetActionParams(ctx context.Context) (*actiontypes.QueryParamsResponse, error)
2221
FinalizeAction(ctx context.Context, actionID string, rqids []string) (*action_msg.FinalizeActionResult, error)
23-
22+
GetActionFee(ctx context.Context, dataSize string) (*actiontypes.QueryGetActionFeeResponse, error)
2423
// Auth
2524
Verify(ctx context.Context, creator string, file []byte, sigBytes []byte) error
2625
}
@@ -40,8 +39,8 @@ func (c *Client) GetAction(ctx context.Context, actionID string) (*actiontypes.Q
4039
return c.lc.Action().GetAction(ctx, actionID)
4140
}
4241

43-
func (c *Client) GetActionParams(ctx context.Context) (*actiontypes.QueryParamsResponse, error) {
44-
return c.lc.Action().GetParams(ctx)
42+
func (c *Client) GetActionFee(ctx context.Context, dataSize string) (*actiontypes.QueryGetActionFeeResponse, error) {
43+
return c.lc.Action().GetActionFee(ctx, dataSize)
4544
}
4645

4746
func (c *Client) FinalizeAction(ctx context.Context, actionID string, rqids []string) (*action_msg.FinalizeActionResult, error) {

supernode/services/cascade/helper.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/base64"
66
"fmt"
7+
"strconv"
78
"strings"
89

910
"cosmossdk.io/math"
@@ -201,21 +202,21 @@ func verifyIDs(ticketMetadata, metadata codec.Layout) error {
201202
// verifyActionFee checks if the action fee is sufficient for the given data size
202203
// It fetches action parameters, calculates the required fee, and compares it with the action price
203204
func (task *CascadeRegistrationTask) verifyActionFee(ctx context.Context, action *actiontypes.Action, dataSize int, fields logtrace.Fields) error {
204-
// Fetch action parameters
205-
params, err := task.lumeraClient.GetActionParams(ctx)
205+
206+
dataSizeInKBs := dataSize / 1024
207+
fee, err := task.lumeraClient.GetActionFee(ctx, strconv.Itoa(dataSizeInKBs))
206208
if err != nil {
207-
return task.wrapErr(ctx, "failed to get action parameters", err, fields)
209+
return task.wrapErr(ctx, "failed to get action fee", err, fields)
208210
}
209211

210-
// Get base fee and fee per byte
211-
baseFee := params.Params.BaseActionFee
212-
feePerByte := params.Params.FeePerByte.Amount
212+
// Parse fee amount from string to int64
213+
amount, err := strconv.ParseInt(fee.Amount, 10, 64)
214+
if err != nil {
215+
return task.wrapErr(ctx, "failed to parse fee amount", err, fields)
216+
}
213217

214218
// Calculate per-byte fee based on data size
215-
perByteFee := sdk.NewCoin(baseFee.Denom, feePerByte.Mul(math.NewInt(int64(dataSize))))
216-
217-
// Calculate total fee
218-
requiredFee := baseFee.Add(perByteFee)
219+
requiredFee := sdk.NewCoin("ulume", math.NewInt(amount))
219220

220221
// Log the calculated fee
221222
logtrace.Info(ctx, "calculated required fee", logtrace.Fields{

0 commit comments

Comments
 (0)