Skip to content

Commit

Permalink
adding tx for requesting keyshare via tx
Browse files Browse the repository at this point in the history
  • Loading branch information
ap0calypse644 committed Jan 19, 2024
1 parent a4d6ba1 commit 41d2486
Show file tree
Hide file tree
Showing 6 changed files with 986 additions and 54 deletions.
76 changes: 76 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35260,6 +35260,49 @@ paths:
type: string
tags:
- Query
/fairyring/keyshare/commitments:
get:
operationId: FairyringKeyshareCommitments
responses:
'200':
description: A successful response.
schema:
type: object
properties:
activeCommitments:
type: object
properties:
commitments:
type: array
items:
type: string
queuedCommitments:
type: object
properties:
commitments:
type: array
items:
type: string
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
tags:
- Query
/fairyring/keyshare/general_key_share:
get:
operationId: FairyringKeyshareGeneralKeyShareAll
Expand Down Expand Up @@ -72179,6 +72222,13 @@ definitions:
type: boolean
authorizedBy:
type: string
fairyring.keyshare.Commitments:
type: object
properties:
commitments:
type: array
items:
type: string
fairyring.keyshare.GeneralKeyShare:
type: object
properties:
Expand Down Expand Up @@ -72245,11 +72295,20 @@ definitions:
type: object
fairyring.keyshare.MsgDeleteAuthorizedAddressResponse:
type: object
fairyring.keyshare.MsgGetAggrKeyshareResponse:
type: object
fairyring.keyshare.MsgRegisterValidatorResponse:
type: object
properties:
creator:
type: string
fairyring.keyshare.MsgRequestAggrKeyshareResponse:
type: object
properties:
identity:
type: string
pubkey:
type: string
fairyring.keyshare.MsgSendKeyshareResponse:
type: object
properties:
Expand Down Expand Up @@ -72517,6 +72576,23 @@ definitions:
repeated Bar results = 1;
PageResponse page = 2;
}
fairyring.keyshare.QueryCommitmentsResponse:
type: object
properties:
activeCommitments:
type: object
properties:
commitments:
type: array
items:
type: string
queuedCommitments:
type: object
properties:
commitments:
type: array
items:
type: string
fairyring.keyshare.QueryGetAggregatedKeyShareResponse:
type: object
properties:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.1
github.com/FairBlock/DistributedIBE v0.0.0-20230528025616-f58fb2b93eaf
github.com/armon/go-metrics v0.4.1
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-sdk v0.47.3
Expand Down Expand Up @@ -47,7 +48,6 @@ require (
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aws/aws-sdk-go v1.44.203 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
Expand Down
18 changes: 18 additions & 0 deletions proto/fairyring/keyshare/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ service Msg {
rpc UpdateAuthorizedAddress (MsgUpdateAuthorizedAddress) returns (MsgUpdateAuthorizedAddressResponse);
rpc DeleteAuthorizedAddress (MsgDeleteAuthorizedAddress) returns (MsgDeleteAuthorizedAddressResponse);
rpc CreateGeneralKeyShare (MsgCreateGeneralKeyShare ) returns (MsgCreateGeneralKeyShareResponse );
rpc RequestAggrKeyshare (MsgRequestAggrKeyshare ) returns (MsgRequestAggrKeyshareResponse );
rpc GetAggrKeyshare (MsgGetAggrKeyshare ) returns (MsgGetAggrKeyshareResponse );
}

message MsgRegisterValidator {
string creator = 1;
}
Expand Down Expand Up @@ -96,3 +99,18 @@ message MsgCreateGeneralKeyShareResponse {
bool success = 7;
string errorMessage = 8;
}

message MsgRequestAggrKeyshare {
string reqId = 1;
}

message MsgRequestAggrKeyshareResponse {
string identity = 1;
string pubkey = 2;
}

message MsgGetAggrKeyshare {
string identity = 1;
}

message MsgGetAggrKeyshareResponse {}
31 changes: 31 additions & 0 deletions x/keyshare/keeper/msg_server_get_aggr_keyshare.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package keeper

import (
"context"
"fairyring/x/keyshare/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

func (k msgServer) GetAggrKeyshare(goCtx context.Context, msg *types.MsgGetAggrKeyshare) (*types.MsgGetAggrKeyshareResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
var rsp types.MsgGetAggrKeyshareResponse

keyshareReq, found := k.GetKeyShareRequest(ctx, msg.Identity)
if !found {
return &rsp, types.ErrRequestNotFound
}

if keyshareReq.AggrKeyshare == "" {

k.Logger(ctx).Info("Got OnRecvGetAggrKeysharePacket")

ctx.EventManager().EmitEvent(
sdk.NewEvent(types.StartSendGeneralKeyShareEventType,
sdk.NewAttribute(types.StartSendGeneralKeyShareEventIdentity, msg.Identity),
),
)
}

return &rsp, nil
}
48 changes: 48 additions & 0 deletions x/keyshare/keeper/msg_server_request_aggr_keyshare.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package keeper

import (
"context"
"errors"
"fairyring/x/keyshare/types"
"strconv"

sdk "github.com/cosmos/cosmos-sdk/types"
)

func (k msgServer) RequestAggrKeyshare(goCtx context.Context, msg *types.MsgRequestAggrKeyshare) (*types.MsgRequestAggrKeyshareResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

var rsp types.MsgRequestAggrKeyshareResponse

reqCountString := k.GetRequestCount(ctx)
reqCount, _ := strconv.ParseUint(reqCountString, 10, 64)
reqCount = reqCount + 1

id := types.IdentityFromRequestCount(reqCount)
activePubKey, found := k.GetActivePubKey(ctx)
if !found {
return &rsp, errors.New("no active pubkey")
}

var keyshareRequest = types.KeyShareRequest{
Identity: id,
Pubkey: activePubKey.PublicKey,
AggrKeyshare: "",
ProposalId: msg.ReqId,
}

k.SetKeyShareRequest(ctx, keyshareRequest)

k.SetRequestCount(ctx, reqCount)

rsp.Identity = id
rsp.Pubkey = activePubKey.PublicKey

ctx.EventManager().EmitEvent(
sdk.NewEvent(types.StartSendGeneralKeyShareEventType,
sdk.NewAttribute(types.StartSendGeneralKeyShareEventIdentity, id),
),
)

return &rsp, nil
}
Loading

0 comments on commit 41d2486

Please sign in to comment.