Skip to content

Commit

Permalink
feat: Add more pigeon status update fields (#1051)
Browse files Browse the repository at this point in the history
* feat: Add more pigeon status update fields

* chore: remove deprecated creator field usage

* fix: val address parsing

* fix: get creator from metadata
  • Loading branch information
byte-bandit authored Dec 5, 2023
1 parent 16d7896 commit fa06d2f
Show file tree
Hide file tree
Showing 3 changed files with 345 additions and 33 deletions.
5 changes: 5 additions & 0 deletions proto/palomachain/paloma/paloma/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ message MsgAddStatusUpdate {
LEVEL_INFO = 1;
LEVEL_ERROR = 2;
}
message KeyValuePair {
string key = 1;
string value = 2;
}
string creator = 1 [deprecated = true];
string status = 2;
Level level = 3;
palomachain.paloma.valset.MsgMetadata metadata = 4 [(gogoproto.nullable) = false];
repeated KeyValuePair args = 5 [(gogoproto.nullable) = false];
}

message EmptyResponse {}
Expand Down
24 changes: 19 additions & 5 deletions x/paloma/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package keeper

import (
"context"
"fmt"
"os"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/palomachain/paloma/util/liblog"
"github.com/palomachain/paloma/x/paloma/types"
)

Expand All @@ -31,24 +33,36 @@ func (k msgServer) AddStatusUpdate(goCtx context.Context, msg *types.MsgAddStatu
return &types.EmptyResponse{}, nil
}

creator, _ := sdk.AccAddressFromBech32(msg.Creator)
creator, err := sdk.AccAddressFromBech32(msg.GetMetadata().GetCreator())
if err != nil {
err = fmt.Errorf("failed to parse creator address: %w", err)
liblog.FromSDKLogger(k.Logger(ctx)).WithError(err).WithFields("component", "pigeon-status-update").Error("Failed to parse creator from message")
return nil, err
}
valAddr := sdk.ValAddress(creator.Bytes())
status := msg.GetStatus()

var logFn func(string, ...interface{})
switch msg.Level {
case types.MsgAddStatusUpdate_LEVEL_DEBUG:
logFn = k.Logger(ctx).Debug
logFn = liblog.FromSDKLogger(k.Logger(ctx)).Debug
case types.MsgAddStatusUpdate_LEVEL_INFO:
logFn = k.Logger(ctx).Info
logFn = liblog.FromSDKLogger(k.Logger(ctx)).Info
case types.MsgAddStatusUpdate_LEVEL_ERROR:
logFn = k.Logger(ctx).Error
logFn = liblog.FromSDKLogger(k.Logger(ctx)).Error
}

args := make([]interface{}, 0, len(msg.GetArgs())*2+6) // len: (k+v) + 6 for static appends
for _, v := range msg.GetArgs() {
args = append(args, fmt.Sprintf("msg.args.%s", v.GetKey()), v.GetValue())
}

logFn(status,
args = append(args,
"component", "pigeon-status-update",
"status", status,
"sender", valAddr)

logFn(status, args...)

return &types.EmptyResponse{}, nil
}
Loading

0 comments on commit fa06d2f

Please sign in to comment.