Skip to content

Commit bf76c29

Browse files
committed
optimize tss signing event
1 parent b6229b6 commit bf76c29

2 files changed

Lines changed: 20 additions & 42 deletions

File tree

x/tss/keeper/signing.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package keeper
22

33
import (
4+
"fmt"
5+
"strings"
6+
47
storetypes "cosmossdk.io/store/types"
58
sdk "github.com/cosmos/cosmos-sdk/types"
69

@@ -108,7 +111,15 @@ func (k Keeper) InitiateSigningRequest(ctx sdk.Context, module string, scopedId
108111
ctx.EventManager().EmitEvent(
109112
sdk.NewEvent(
110113
types.EventTypeInitiateSigning,
111-
types.GetSigningRequestEventAttributes(req.Id, module, scopedId, ty, intent, pubKey, sigHashes, options)...),
114+
sdk.NewAttribute(types.AttributeKeyId, fmt.Sprintf("%d", req.Id)),
115+
sdk.NewAttribute(types.AttributeKeyModule, module),
116+
sdk.NewAttribute(types.AttributeKeyScopedId, scopedId),
117+
sdk.NewAttribute(types.AttributeKeyType, fmt.Sprintf("%d", ty)),
118+
sdk.NewAttribute(types.AttributeKeyIntent, fmt.Sprintf("%d", intent)),
119+
sdk.NewAttribute(types.AttributeKeyPubKey, pubKey),
120+
sdk.NewAttribute(types.AttributeKeySigHashes, strings.Join(sigHashes, types.AttributeValueSeparator)),
121+
sdk.NewAttribute(types.AttributeKeyOption, types.GetSigningOption(ty, options)),
122+
),
112123
)
113124

114125
return req

x/tss/types/events.go

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
package types
22

3-
import (
4-
fmt "fmt"
5-
"strings"
6-
7-
sdk "github.com/cosmos/cosmos-sdk/types"
8-
)
9-
103
// TSS module event types
114
const (
125
EventTypeInitiateDKG = "initiate_dkg"
@@ -29,52 +22,26 @@ const (
2922

3023
AttributeKeyParticipant = "participant"
3124

32-
AttributeKeyPubKey = "pub_key"
33-
AttributeKeySigHashes = "sig_hashes"
34-
AttributeKeyNonce = "nonce"
35-
AttributeKeyAdaptorPoint = "adaptor_point"
25+
AttributeKeyPubKey = "pub_key"
26+
AttributeKeySigHashes = "sig_hashes"
27+
AttributeKeyOption = "option"
3628
)
3729

3830
const (
3931
AttributeValueSeparator = ","
4032
)
4133

42-
// GetSigningRequestEventAttributes gets the event attributes for the signing request
43-
func GetSigningRequestEventAttributes(id uint64, module string, scopedId string, ty SigningType, intent int32, pubKey string, sigHashes []string, options *SigningOptions) []sdk.Attribute {
44-
attributes := []sdk.Attribute{}
45-
46-
attributes = append(attributes, sdk.NewAttribute(AttributeKeyId, fmt.Sprintf("%d", id)))
47-
attributes = append(attributes, sdk.NewAttribute(AttributeKeyModule, module))
48-
attributes = append(attributes, sdk.NewAttribute(AttributeKeyScopedId, scopedId))
49-
attributes = append(attributes, sdk.NewAttribute(AttributeKeyType, fmt.Sprintf("%d", ty)))
50-
attributes = append(attributes, sdk.NewAttribute(AttributeKeyIntent, fmt.Sprintf("%d", intent)))
51-
attributes = append(attributes, sdk.NewAttribute(AttributeKeyPubKey, pubKey))
52-
attributes = append(attributes, sdk.NewAttribute(AttributeKeySigHashes, strings.Join(sigHashes, AttributeValueSeparator)))
53-
54-
if options != nil {
55-
attributes = append(attributes, GetSigningOptionAttribute(ty, options))
56-
}
57-
58-
return attributes
59-
}
60-
61-
// GetSigningOptionAttribute gets the event attribute for the signing option
34+
// GetSigningOption gets the signing option according to the given signing type and options
6235
// Assume that the options match the signing type
63-
func GetSigningOptionAttribute(signingType SigningType, options *SigningOptions) sdk.Attribute {
36+
func GetSigningOption(signingType SigningType, options *SigningOptions) string {
6437
switch signingType {
6538
case SigningType_SIGNING_TYPE_SCHNORR_WITH_COMMITMENT:
66-
return sdk.Attribute{
67-
Key: AttributeKeyNonce,
68-
Value: options.Nonce,
69-
}
39+
return options.Nonce
7040

7141
case SigningType_SIGNING_TYPE_SCHNORR_ADAPTOR:
72-
return sdk.Attribute{
73-
Key: AttributeKeyAdaptorPoint,
74-
Value: options.AdaptorPoint,
75-
}
42+
return options.AdaptorPoint
7643

7744
default:
78-
return sdk.Attribute{}
45+
return ""
7946
}
8047
}

0 commit comments

Comments
 (0)