Skip to content

Commit

Permalink
moving storage events (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
dahn510 authored Sep 4, 2024
2 parents 59be453 + 573edbc commit 02299dc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
57 changes: 29 additions & 28 deletions x/storage/keeper/msg_server_post_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@ func (k msgServer) PostFile(goCtx context.Context, msg *types.MsgPostFile) (*typ

res := &types.MsgPostFileResponse{ProviderIps: ips, StartBlock: ctx.BlockHeight()}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
)

b := False // pay once event
if msg.Expires > 0 {
b = True
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeSignContract,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
sdk.NewAttribute(types.AttributeKeyContract, hex.EncodeToString(msg.Merkle)),
sdk.NewAttribute(types.AttributeKeyPayOnce, b),
sdk.NewAttribute(types.AttributeKeyStart, fmt.Sprintf("%d", ctx.BlockHeight())),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeJackalMessage,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

totalSize := msg.FileSize * msg.MaxProofs
if msg.Expires > 0 { // if the file is posted as a one-time payment
kbs := totalSize / 1000
Expand Down Expand Up @@ -112,33 +141,5 @@ func (k msgServer) PostFile(goCtx context.Context, msg *types.MsgPostFile) (*typ

k.SetStoragePaymentInfo(ctx, paymentInfo)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
)

b := False // pay once event
if msg.Expires > 0 {
b = True
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeSignContract,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
sdk.NewAttribute(types.AttributeKeyContract, hex.EncodeToString(msg.Merkle)),
sdk.NewAttribute(types.AttributeKeyPayOnce, b),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeJackalMessage,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

return res, nil
}
1 change: 1 addition & 0 deletions x/storage/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
AttributeKeySigner = "signer" // sign storage deal
AttributeKeyContract = "file"
AttributeKeyPayOnce = "pay_once"
AttributeKeyStart = "start"

EventTypeJackalMessage = "jackal_message"
)

0 comments on commit 02299dc

Please sign in to comment.