Skip to content

Commit

Permalink
Merge pull request #110 from Fairblock/feat/emit-memo-and-underlying-…
Browse files Browse the repository at this point in the history
…events

Add emit memo and underlying tx events
  • Loading branch information
p0p3yee authored Feb 21, 2024
2 parents 7c481f3 + c531403 commit 02af070
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 21 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,25 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Prepare Release Variables
id: vars
uses: ignite/cli/actions/release/[email protected]

- name: Delete the "latest" Release
uses: dev-drprasad/[email protected]
if: ${{ steps.vars.outputs.is_release_type_latest == 'true' }}
with:
tag_name: ${{ steps.vars.outputs.tag_name }}
delete_release: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish the Release
uses: softprops/action-gh-release@v1
if: ${{ steps.vars.outputs.should_release == 'true' }}
with:
tag_name: ${{ steps.vars.outputs.tag_name }}
prerelease: true
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38 changes: 34 additions & 4 deletions x/pep/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package pep
import (
"bytes"
"context"
cosmosmath "cosmossdk.io/math"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/telemetry"

cosmosmath "cosmossdk.io/math"

enc "github.com/FairBlock/DistributedIBE/encryption"

"math"
Expand All @@ -31,7 +30,6 @@ import (
"github.com/Fairblock/fairyring/x/pep/client/cli"
"github.com/Fairblock/fairyring/x/pep/keeper"
"github.com/Fairblock/fairyring/x/pep/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -235,6 +233,17 @@ func (am AppModule) processFailedEncryptedTx(ctx sdk.Context, tx types.Encrypted
am.handleGasConsumption(ctx, creatorAddr, cosmosmath.NewIntFromUint64(actualGasConsumed), tx.ChargedGas)
}

type UnderlyingTxEvent struct {
Type string `json:"type"`
Attributes []EventAttribute `json:"attributes"`
}

type EventAttribute struct {
Key string `json:"key"`
Value string `json:"value"`
Index bool `json:"index"`
}

// BeginBlock contains the logic that is automatically triggered at the beginning of each block
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
strLastExecutedHeight := am.keeper.GetLastExecutedHeight(ctx)
Expand Down Expand Up @@ -536,12 +545,31 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
}

handler := am.msgServiceRouter.Handler(txMsgs[0])
_, err = handler(ctx, txMsgs[0])
handlerResult, err := handler(ctx, txMsgs[0])
if err != nil {
am.processFailedEncryptedTx(ctx, eachTx, fmt.Sprintf("error when handling tx message: %s", err.Error()), startConsumedGas)
continue
}

underlyingTxEvents := make([]UnderlyingTxEvent, 0)

for _, e := range handlerResult.Events {
eventAttributes := make([]EventAttribute, 0)
for _, ea := range e.Attributes {
eventAttributes = append(eventAttributes, EventAttribute{
Key: ea.Key,
Value: ea.Value,
Index: ea.Index,
})
}
underlyingTxEvents = append(underlyingTxEvents, UnderlyingTxEvent{
Type: e.Type,
Attributes: eventAttributes,
})
}

eventStrArrJson, _ := json.Marshal(underlyingTxEvents)

am.keeper.Logger(ctx).Info("! Encrypted Tx Decrypted & Decoded & Executed successfully !")

ctx.EventManager().EmitEvent(
Expand All @@ -550,6 +578,8 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
sdk.NewAttribute(types.EncryptedTxExecutedEventHeight, strconv.FormatUint(eachTx.TargetHeight, 10)),
sdk.NewAttribute(types.EncryptedTxExecutedEventData, eachTx.Data),
sdk.NewAttribute(types.EncryptedTxExecutedEventIndex, strconv.FormatUint(eachTx.Index, 10)),
sdk.NewAttribute(types.EncryptedTxExecutedEventMemo, wrappedTx.GetTx().GetMemo()),
sdk.NewAttribute(types.EncryptedTxExecutedEventUnderlyingEvents, string(eventStrArrJson)),
),
)

Expand Down
34 changes: 18 additions & 16 deletions x/pep/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,28 @@ var (

const (
SubmittedEncryptedTxEventType = "new-encrypted-tx-submitted"
SubmittedEncryptedTxEventCreator = "new-encrypted-tx-creator"
SubmittedEncryptedTxEventTargetHeight = "new-encrypted-tx-target-height"
SubmittedEncryptedTxEventIndex = "new-encrypted-tx-index"
SubmittedEncryptedTxEventData = "new-encrypted-tx-data"
SubmittedEncryptedTxEventCreator = "creator"
SubmittedEncryptedTxEventTargetHeight = "target-height"
SubmittedEncryptedTxEventIndex = "index"
SubmittedEncryptedTxEventData = "data"
)

const (
EncryptedTxExecutedEventType = "executed-encrypted-tx"
EncryptedTxExecutedEventCreator = "executed-encrypted-tx-creator"
EncryptedTxExecutedEventHeight = "executed-encrypted-tx-target-height"
EncryptedTxExecutedEventIndex = "executed-encrypted-tx-index"
EncryptedTxExecutedEventData = "executed-encrypted-tx-data"
EncryptedTxExecutedEventType = "executed-encrypted-tx"
EncryptedTxExecutedEventCreator = "creator"
EncryptedTxExecutedEventHeight = "target-height"
EncryptedTxExecutedEventIndex = "index"
EncryptedTxExecutedEventData = "data"
EncryptedTxExecutedEventMemo = "memo"
EncryptedTxExecutedEventUnderlyingEvents = "events"
)

const (
EncryptedTxRevertedEventType = "reverted-encrypted-tx"
EncryptedTxRevertedEventCreator = "reverted-encrypted-tx-creator"
EncryptedTxRevertedEventHeight = "reverted-encrypted-tx-target-height"
EncryptedTxRevertedEventIndex = "reverted-encrypted-tx-index"
EncryptedTxRevertedEventReason = "reverted-encrypted-tx-reason"
EncryptedTxRevertedEventCreator = "creator"
EncryptedTxRevertedEventHeight = "height"
EncryptedTxRevertedEventIndex = "index"
EncryptedTxRevertedEventReason = "reason"
)

const (
Expand All @@ -63,9 +65,9 @@ const (

const (
KeyShareVerificationType = "keyshare-verification"
KeyShareVerificationCreator = "keyshare-verification-creator"
KeyShareVerificationHeight = "keyshare-verification-height"
KeyShareVerificationReason = "keyshare-verification-reason"
KeyShareVerificationCreator = "creator"
KeyShareVerificationHeight = "height"
KeyShareVerificationReason = "reason"
)

const (
Expand Down

0 comments on commit 02af070

Please sign in to comment.