Skip to content

Commit

Permalink
emit error event
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Jun 25, 2024
1 parent a4b095a commit 2134f84
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
49 changes: 49 additions & 0 deletions app/ibc-hooks/ack.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"

ibchooks "github.com/initia-labs/initia/x/ibc-hooks"
"github.com/initia-labs/initia/x/ibc-hooks/types"
nfttransfertypes "github.com/initia-labs/initia/x/ibc/nft-transfer/types"
)

Expand All @@ -30,6 +31,12 @@ func (h WasmHooks) onAckIcs20Packet(
return nil
} else if err != nil {
h.wasmKeeper.Logger(ctx).Error("failed to parse memo", "error", err)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,

Check failure on line 35 in app/ibc-hooks/ack.go

View workflow job for this annotation

GitHub Actions / Run test and upload codecov

undefined: types.EventTypeHookFailed
sdk.NewAttribute(types.AttributeKeyReason, "failed to parse memo"),

Check failure on line 36 in app/ibc-hooks/ack.go

View workflow job for this annotation

GitHub Actions / Run test and upload codecov

undefined: types.AttributeKeyReason
sdk.NewAttribute(types.AttributeKeyError, err.Error()),

Check failure on line 37 in app/ibc-hooks/ack.go

View workflow job for this annotation

GitHub Actions / Run test and upload codecov

undefined: types.AttributeKeyError
))

return nil
}

Expand All @@ -40,9 +47,21 @@ func (h WasmHooks) onAckIcs20Packet(
callback := hookData.AsyncCallback
if allowed, err := h.checkACL(im, cacheCtx, callback); err != nil {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,

Check failure on line 51 in app/ibc-hooks/ack.go

View workflow job for this annotation

GitHub Actions / Run test and upload codecov

undefined: types.EventTypeHookFailed
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),

Check failure on line 52 in app/ibc-hooks/ack.go

View workflow job for this annotation

GitHub Actions / Run test and upload codecov

undefined: types.AttributeKeyReason
sdk.NewAttribute(types.AttributeKeyError, err.Error()),

Check failure on line 53 in app/ibc-hooks/ack.go

View workflow job for this annotation

GitHub Actions / Run test and upload codecov

undefined: types.AttributeKeyError
))

return nil
} else if !allowed {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,

Check failure on line 60 in app/ibc-hooks/ack.go

View workflow job for this annotation

GitHub Actions / Run test and upload codecov

undefined: types.EventTypeHookFailed
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),

Check failure on line 61 in app/ibc-hooks/ack.go

View workflow job for this annotation

GitHub Actions / Run test and upload codecov

undefined: types.AttributeKeyReason
sdk.NewAttribute(types.AttributeKeyError, "not allowed"),

Check failure on line 62 in app/ibc-hooks/ack.go

View workflow job for this annotation

GitHub Actions / Run test and upload codecov

undefined: types.AttributeKeyError
))

return nil
}

Expand All @@ -69,6 +88,12 @@ func (h WasmHooks) onAckIcs20Packet(
packet.SourceChannel, packet.Sequence, ackAsJson, success))
_, err = h.wasmKeeper.Sudo(cacheCtx, contractAddr, sudoMsg)
if err != nil {
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,

Check failure on line 92 in app/ibc-hooks/ack.go

View workflow job for this annotation

GitHub Actions / Run test and upload codecov

undefined: types.EventTypeHookFailed
sdk.NewAttribute(types.AttributeKeyReason, "failed to execute callback"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

return errorsmod.Wrap(err, "Ack callback error")
}

Expand All @@ -94,6 +119,12 @@ func (h WasmHooks) onAckIcs721Packet(
if !isWasmRouted || hookData.AsyncCallback == "" {
return nil
} else if err != nil {
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to parse memo"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

h.wasmKeeper.Logger(ctx).Error("failed to parse memo", "error", err)
return nil
}
Expand All @@ -105,9 +136,21 @@ func (h WasmHooks) onAckIcs721Packet(
callback := hookData.AsyncCallback
if allowed, err := h.checkACL(im, cacheCtx, callback); err != nil {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

return nil
} else if !allowed {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
sdk.NewAttribute(types.AttributeKeyError, "not allowed"),
))

return nil
}

Expand All @@ -134,6 +177,12 @@ func (h WasmHooks) onAckIcs721Packet(
packet.SourceChannel, packet.Sequence, ackAsJson, success))
_, err = h.wasmKeeper.Sudo(cacheCtx, contractAddr, sudoMsg)
if err != nil {
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to execute callback"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

h.wasmKeeper.Logger(cacheCtx).Error("failed to execute callback", "error", err)
return nil
}
Expand Down
36 changes: 36 additions & 0 deletions app/ibc-hooks/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,21 @@ func (h WasmHooks) onTimeoutIcs20Packet(
callback := hookData.AsyncCallback
if allowed, err := h.checkACL(im, cacheCtx, callback); err != nil {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

return nil
} else if !allowed {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
sdk.NewAttribute(types.AttributeKeyError, "not allowed"),
))

return nil
}

Expand All @@ -55,6 +67,12 @@ func (h WasmHooks) onTimeoutIcs20Packet(
_, err = h.wasmKeeper.Sudo(cacheCtx, contractAddr, sudoMsg)
if err != nil {
h.wasmKeeper.Logger(cacheCtx).Error("failed to execute callback", "error", err)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to execute callback"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

return nil
}

Expand Down Expand Up @@ -90,9 +108,21 @@ func (h WasmHooks) onTimeoutIcs721Packet(
callback := hookData.AsyncCallback
if allowed, err := h.checkACL(im, cacheCtx, callback); err != nil {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

return nil
} else if !allowed {
h.wasmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to check ACL"),
sdk.NewAttribute(types.AttributeKeyError, "not allowed"),
))

return nil
}

Expand All @@ -108,6 +138,12 @@ func (h WasmHooks) onTimeoutIcs721Packet(
_, err = h.wasmKeeper.Sudo(cacheCtx, contractAddr, sudoMsg)
if err != nil {
h.wasmKeeper.Logger(cacheCtx).Error("failed to execute callback", "error", err)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeHookFailed,
sdk.NewAttribute(types.AttributeKeyReason, "failed to execute callback"),
sdk.NewAttribute(types.AttributeKeyError, err.Error()),
))

return nil
}

Expand Down

0 comments on commit 2134f84

Please sign in to comment.