From 2f3d1e9e5b6a752e8063604234d49a5bb9fa6c89 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 26 Jul 2024 16:05:33 +0530 Subject: [PATCH] Accommodate changes for string type for participant role --- proto/cerc/onboarding/v1/onboarding.proto | 16 +- proto/cerc/onboarding/v1/tx.proto | 2 +- proto/cerc/registry/v1/query.proto | 15 ++ src/laconic-client.ts | 4 +- src/onboarding.test.ts | 4 +- src/proto/cerc/onboarding/v1/onboarding.ts | 59 +------ src/proto/cerc/onboarding/v1/tx.ts | 18 +-- src/proto/cerc/registry/v1/query.ts | 177 +++++++++++++++++++++ src/types/cerc/onboarding/message.ts | 3 +- 9 files changed, 216 insertions(+), 82 deletions(-) diff --git a/proto/cerc/onboarding/v1/onboarding.proto b/proto/cerc/onboarding/v1/onboarding.proto index 494ab0c..002dc6a 100644 --- a/proto/cerc/onboarding/v1/onboarding.proto +++ b/proto/cerc/onboarding/v1/onboarding.proto @@ -27,7 +27,7 @@ message Participant { "json:\"nitro_address\" yaml:\"nitro_address\"" ]; // participant's role (participant | validator) - Role role = 3 [ (gogoproto.moretags) = "json:\"role\" yaml:\"role\"" ]; + string role = 3 [ (gogoproto.moretags) = "json:\"role\" yaml:\"role\"" ]; // participant's KYC receipt ID string kyc_id = 4 @@ -41,17 +41,3 @@ message EthPayload { string msg = 2 [ (gogoproto.moretags) = "json:\"msg\" yaml:\"msg\"" ]; } - -// Participant Role -enum Role { - option (gogoproto.goproto_enum_prefix) = false; - - // ROLE_UNSPECIFIED indicates unknown role. - ROLE_UNSPECIFIED = 0; - - // ROLE_PARTICIPANT indicates the participant role. - ROLE_PARTICIPANT = 1; - - // ROLE_VALIDATOR indicates user participating as a validator. - ROLE_VALIDATOR = 2; -} diff --git a/proto/cerc/onboarding/v1/tx.proto b/proto/cerc/onboarding/v1/tx.proto index c0e7b6d..6e0eab6 100644 --- a/proto/cerc/onboarding/v1/tx.proto +++ b/proto/cerc/onboarding/v1/tx.proto @@ -28,7 +28,7 @@ message MsgOnboardParticipant { string participant = 1; EthPayload eth_payload = 2 [ (gogoproto.nullable) = false ]; string eth_signature = 3; - Role role = 4; + string role = 4; string kyc_id = 5; } diff --git a/proto/cerc/registry/v1/query.proto b/proto/cerc/registry/v1/query.proto index 3bc1909..1d3052f 100644 --- a/proto/cerc/registry/v1/query.proto +++ b/proto/cerc/registry/v1/query.proto @@ -58,6 +58,11 @@ service Query { returns (QueryGetRegistryModuleBalanceResponse) { option (google.api.http).get = "/cerc/registry/v1/balance"; } + + // Authorities queries all authorities + rpc Authorities(QueryAuthoritiesRequest) returns (QueryAuthoritiesResponse) { + option (google.api.http).get = "/cerc/registry/v1/authorities"; + } } // QueryParamsRequest is request type for registry params @@ -152,6 +157,16 @@ message QueryWhoisResponse { ]; } +// QueryAuthoritiesRequest is request type to get all authorities +message QueryAuthoritiesRequest { string owner = 1; } + +// QueryAuthoritiesResponse is response type for authorities request +message QueryAuthoritiesResponse { + repeated AuthorityEntry authorities = 1 [ (gogoproto.nullable) = false ]; + // pagination defines the pagination in the response. + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + // QueryLookupLrnRequest is request type for LookupLrn message QueryLookupLrnRequest { string lrn = 1; } diff --git a/src/laconic-client.ts b/src/laconic-client.ts index b11e3ba..551393d 100644 --- a/src/laconic-client.ts +++ b/src/laconic-client.ts @@ -22,7 +22,7 @@ import { MsgCommitBidResponse, MsgRevealBidResponse } from './proto/cerc/auction import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto/cerc/bond/v1/tx'; import { MsgOnboardParticipantResponse } from './proto/cerc/onboarding/v1/tx'; import { bankTypes } from './types/cosmos/bank/message'; -import { EthPayload, Role } from './proto/cerc/onboarding/v1/onboarding'; +import { EthPayload } from './proto/cerc/onboarding/v1/onboarding'; const DEFAULT_WRITE_ERROR = 'Unable to write to laconicd.'; @@ -394,7 +394,7 @@ export class LaconicClient extends SigningStargateClient { signer: string, ethPayload: EthPayload, ethSignature: string, - role: Role, + role: string, kycId: string, fee: StdFee | 'auto' | number, memo = '' diff --git a/src/onboarding.test.ts b/src/onboarding.test.ts index d67240c..3c7c80e 100644 --- a/src/onboarding.test.ts +++ b/src/onboarding.test.ts @@ -4,13 +4,13 @@ import { DirectSecp256k1Wallet } from '@cosmjs/proto-signing'; import { Registry, Account } from './index'; import { getConfig } from './testing/helper'; -import { Participant, Role } from './proto/cerc/onboarding/v1/onboarding'; +import { Participant } from './proto/cerc/onboarding/v1/onboarding'; const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig(); jest.setTimeout(90 * 1000); -const DUMMY_ROLE = Role.ROLE_VALIDATOR; +const DUMMY_ROLE = 'validator'; const DUMMY_KYC_ID = 'dummyKycId'; const onboardingEnabledTests = () => { diff --git a/src/proto/cerc/onboarding/v1/onboarding.ts b/src/proto/cerc/onboarding/v1/onboarding.ts index 5afbcae..4c65d15 100644 --- a/src/proto/cerc/onboarding/v1/onboarding.ts +++ b/src/proto/cerc/onboarding/v1/onboarding.ts @@ -4,49 +4,6 @@ import _m0 from "protobufjs/minimal"; export const protobufPackage = "cerc.onboarding.v1"; -/** Participant Role */ -export enum Role { - /** ROLE_UNSPECIFIED - ROLE_UNSPECIFIED indicates unknown role. */ - ROLE_UNSPECIFIED = 0, - /** ROLE_PARTICIPANT - ROLE_PARTICIPANT indicates the participant role. */ - ROLE_PARTICIPANT = 1, - /** ROLE_VALIDATOR - ROLE_VALIDATOR indicates user participating as a validator. */ - ROLE_VALIDATOR = 2, - UNRECOGNIZED = -1, -} - -export function roleFromJSON(object: any): Role { - switch (object) { - case 0: - case "ROLE_UNSPECIFIED": - return Role.ROLE_UNSPECIFIED; - case 1: - case "ROLE_PARTICIPANT": - return Role.ROLE_PARTICIPANT; - case 2: - case "ROLE_VALIDATOR": - return Role.ROLE_VALIDATOR; - case -1: - case "UNRECOGNIZED": - default: - return Role.UNRECOGNIZED; - } -} - -export function roleToJSON(object: Role): string { - switch (object) { - case Role.ROLE_UNSPECIFIED: - return "ROLE_UNSPECIFIED"; - case Role.ROLE_PARTICIPANT: - return "ROLE_PARTICIPANT"; - case Role.ROLE_VALIDATOR: - return "ROLE_VALIDATOR"; - case Role.UNRECOGNIZED: - default: - return "UNRECOGNIZED"; - } -} - /** Params defines the parameters of the onboarding module. */ export interface Params { onboardingEnabled: boolean; @@ -62,7 +19,7 @@ export interface Participant { /** participant's Nitro address */ nitroAddress: string; /** participant's role (participant | validator) */ - role: Role; + role: string; /** participant's KYC receipt ID */ kycId: string; } @@ -129,7 +86,7 @@ export const Params = { }; function createBaseParticipant(): Participant { - return { cosmosAddress: "", nitroAddress: "", role: 0, kycId: "" }; + return { cosmosAddress: "", nitroAddress: "", role: "", kycId: "" }; } export const Participant = { @@ -143,8 +100,8 @@ export const Participant = { if (message.nitroAddress !== "") { writer.uint32(18).string(message.nitroAddress); } - if (message.role !== 0) { - writer.uint32(24).int32(message.role); + if (message.role !== "") { + writer.uint32(26).string(message.role); } if (message.kycId !== "") { writer.uint32(34).string(message.kycId); @@ -166,7 +123,7 @@ export const Participant = { message.nitroAddress = reader.string(); break; case 3: - message.role = reader.int32() as any; + message.role = reader.string(); break; case 4: message.kycId = reader.string(); @@ -187,7 +144,7 @@ export const Participant = { nitroAddress: isSet(object.nitroAddress) ? String(object.nitroAddress) : "", - role: isSet(object.role) ? roleFromJSON(object.role) : 0, + role: isSet(object.role) ? String(object.role) : "", kycId: isSet(object.kycId) ? String(object.kycId) : "", }; }, @@ -198,7 +155,7 @@ export const Participant = { (obj.cosmosAddress = message.cosmosAddress); message.nitroAddress !== undefined && (obj.nitroAddress = message.nitroAddress); - message.role !== undefined && (obj.role = roleToJSON(message.role)); + message.role !== undefined && (obj.role = message.role); message.kycId !== undefined && (obj.kycId = message.kycId); return obj; }, @@ -209,7 +166,7 @@ export const Participant = { const message = createBaseParticipant(); message.cosmosAddress = object.cosmosAddress ?? ""; message.nitroAddress = object.nitroAddress ?? ""; - message.role = object.role ?? 0; + message.role = object.role ?? ""; message.kycId = object.kycId ?? ""; return message; }, diff --git a/src/proto/cerc/onboarding/v1/tx.ts b/src/proto/cerc/onboarding/v1/tx.ts index cb755a6..085a6d5 100644 --- a/src/proto/cerc/onboarding/v1/tx.ts +++ b/src/proto/cerc/onboarding/v1/tx.ts @@ -1,5 +1,5 @@ /* eslint-disable */ -import { EthPayload, Role, roleFromJSON, roleToJSON } from "./onboarding"; +import { EthPayload } from "./onboarding"; import Long from "long"; import _m0 from "protobufjs/minimal"; @@ -11,7 +11,7 @@ export interface MsgOnboardParticipant { participant: string; ethPayload?: EthPayload; ethSignature: string; - role: Role; + role: string; kycId: string; } @@ -26,7 +26,7 @@ function createBaseMsgOnboardParticipant(): MsgOnboardParticipant { participant: "", ethPayload: undefined, ethSignature: "", - role: 0, + role: "", kycId: "", }; } @@ -45,8 +45,8 @@ export const MsgOnboardParticipant = { if (message.ethSignature !== "") { writer.uint32(26).string(message.ethSignature); } - if (message.role !== 0) { - writer.uint32(32).int32(message.role); + if (message.role !== "") { + writer.uint32(34).string(message.role); } if (message.kycId !== "") { writer.uint32(42).string(message.kycId); @@ -74,7 +74,7 @@ export const MsgOnboardParticipant = { message.ethSignature = reader.string(); break; case 4: - message.role = reader.int32() as any; + message.role = reader.string(); break; case 5: message.kycId = reader.string(); @@ -96,7 +96,7 @@ export const MsgOnboardParticipant = { ethSignature: isSet(object.ethSignature) ? String(object.ethSignature) : "", - role: isSet(object.role) ? roleFromJSON(object.role) : 0, + role: isSet(object.role) ? String(object.role) : "", kycId: isSet(object.kycId) ? String(object.kycId) : "", }; }, @@ -111,7 +111,7 @@ export const MsgOnboardParticipant = { : undefined); message.ethSignature !== undefined && (obj.ethSignature = message.ethSignature); - message.role !== undefined && (obj.role = roleToJSON(message.role)); + message.role !== undefined && (obj.role = message.role); message.kycId !== undefined && (obj.kycId = message.kycId); return obj; }, @@ -126,7 +126,7 @@ export const MsgOnboardParticipant = { ? EthPayload.fromPartial(object.ethPayload) : undefined; message.ethSignature = object.ethSignature ?? ""; - message.role = object.role ?? 0; + message.role = object.role ?? ""; message.kycId = object.kycId ?? ""; return message; }, diff --git a/src/proto/cerc/registry/v1/query.ts b/src/proto/cerc/registry/v1/query.ts index 7f00354..f1fa3e9 100644 --- a/src/proto/cerc/registry/v1/query.ts +++ b/src/proto/cerc/registry/v1/query.ts @@ -5,6 +5,7 @@ import { NameAuthority, NameRecord, NameEntry, + AuthorityEntry, } from "./registry"; import { PageRequest, @@ -118,6 +119,18 @@ export interface QueryWhoisResponse { nameAuthority?: NameAuthority; } +/** QueryAuthoritiesRequest is request type to get all authorities */ +export interface QueryAuthoritiesRequest { + owner: string; +} + +/** QueryAuthoritiesResponse is response type for authorities request */ +export interface QueryAuthoritiesResponse { + authorities: AuthorityEntry[]; + /** pagination defines the pagination in the response. */ + pagination?: PageResponse; +} + /** QueryLookupLrnRequest is request type for LookupLrn */ export interface QueryLookupLrnRequest { lrn: string; @@ -1460,6 +1473,151 @@ export const QueryWhoisResponse = { }, }; +function createBaseQueryAuthoritiesRequest(): QueryAuthoritiesRequest { + return { owner: "" }; +} + +export const QueryAuthoritiesRequest = { + encode( + message: QueryAuthoritiesRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.owner !== "") { + writer.uint32(10).string(message.owner); + } + return writer; + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryAuthoritiesRequest { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseQueryAuthoritiesRequest(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.owner = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): QueryAuthoritiesRequest { + return { + owner: isSet(object.owner) ? String(object.owner) : "", + }; + }, + + toJSON(message: QueryAuthoritiesRequest): unknown { + const obj: any = {}; + message.owner !== undefined && (obj.owner = message.owner); + return obj; + }, + + fromPartial, I>>( + object: I + ): QueryAuthoritiesRequest { + const message = createBaseQueryAuthoritiesRequest(); + message.owner = object.owner ?? ""; + return message; + }, +}; + +function createBaseQueryAuthoritiesResponse(): QueryAuthoritiesResponse { + return { authorities: [], pagination: undefined }; +} + +export const QueryAuthoritiesResponse = { + encode( + message: QueryAuthoritiesResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.authorities) { + AuthorityEntry.encode(v!, writer.uint32(10).fork()).ldelim(); + } + if (message.pagination !== undefined) { + PageResponse.encode( + message.pagination, + writer.uint32(18).fork() + ).ldelim(); + } + return writer; + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryAuthoritiesResponse { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseQueryAuthoritiesResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.authorities.push( + AuthorityEntry.decode(reader, reader.uint32()) + ); + break; + case 2: + message.pagination = PageResponse.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): QueryAuthoritiesResponse { + return { + authorities: Array.isArray(object?.authorities) + ? object.authorities.map((e: any) => AuthorityEntry.fromJSON(e)) + : [], + pagination: isSet(object.pagination) + ? PageResponse.fromJSON(object.pagination) + : undefined, + }; + }, + + toJSON(message: QueryAuthoritiesResponse): unknown { + const obj: any = {}; + if (message.authorities) { + obj.authorities = message.authorities.map((e) => + e ? AuthorityEntry.toJSON(e) : undefined + ); + } else { + obj.authorities = []; + } + message.pagination !== undefined && + (obj.pagination = message.pagination + ? PageResponse.toJSON(message.pagination) + : undefined); + return obj; + }, + + fromPartial, I>>( + object: I + ): QueryAuthoritiesResponse { + const message = createBaseQueryAuthoritiesResponse(); + message.authorities = + object.authorities?.map((e) => AuthorityEntry.fromPartial(e)) || []; + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageResponse.fromPartial(object.pagination) + : undefined; + return message; + }, +}; + function createBaseQueryLookupLrnRequest(): QueryLookupLrnRequest { return { lrn: "" }; } @@ -1907,6 +2065,10 @@ export interface Query { GetRegistryModuleBalance( request: QueryGetRegistryModuleBalanceRequest ): Promise; + /** Authorities queries all authorities */ + Authorities( + request: QueryAuthoritiesRequest + ): Promise; } export class QueryClientImpl implements Query { @@ -1922,6 +2084,7 @@ export class QueryClientImpl implements Query { this.LookupLrn = this.LookupLrn.bind(this); this.ResolveLrn = this.ResolveLrn.bind(this); this.GetRegistryModuleBalance = this.GetRegistryModuleBalance.bind(this); + this.Authorities = this.Authorities.bind(this); } Params(request: QueryParamsRequest): Promise { const data = QueryParamsRequest.encode(request).finish(); @@ -2026,6 +2189,20 @@ export class QueryClientImpl implements Query { QueryGetRegistryModuleBalanceResponse.decode(new _m0.Reader(data)) ); } + + Authorities( + request: QueryAuthoritiesRequest + ): Promise { + const data = QueryAuthoritiesRequest.encode(request).finish(); + const promise = this.rpc.request( + "cerc.registry.v1.Query", + "Authorities", + data + ); + return promise.then((data) => + QueryAuthoritiesResponse.decode(new _m0.Reader(data)) + ); + } } interface Rpc { diff --git a/src/types/cerc/onboarding/message.ts b/src/types/cerc/onboarding/message.ts index 369a9b3..872f8b2 100644 --- a/src/types/cerc/onboarding/message.ts +++ b/src/types/cerc/onboarding/message.ts @@ -1,7 +1,6 @@ import { EncodeObject, GeneratedType } from '@cosmjs/proto-signing'; import { MsgOnboardParticipantResponse, MsgOnboardParticipant } from '../../../proto/cerc/onboarding/v1/tx'; -import { Role } from '../../../proto/cerc/onboarding/v1/onboarding'; export const typeUrlMsgOnboardParticipant = '/cerc.onboarding.v1.MsgOnboardParticipant'; export const typeUrlMsgOnboardParticipantResponse = '/cerc.onboarding.v1.MsgOnboardParticipantResponse'; @@ -24,6 +23,6 @@ interface ethPayload { export interface MessageMsgOnboardParticipant { ethPayload: ethPayload ethSignature: string - role: Role + role: string kycId: string }