Skip to content

Commit

Permalink
feat: add ibc protobufs and MsgIbcTransfer model (#7)
Browse files Browse the repository at this point in the history
* feat: ibc protobuf and MsgTransfer model

* chore: generate protobufs

* refactor: rename to MsgIbcTransfer

* fix: toAmino conversion

* fix: amino big ints

* fix: convert names to pascal case

---------

Co-authored-by: Aaron Choo <choozy.aaron@gmail.com>
  • Loading branch information
ryoid and AaronCQL authored Aug 18, 2023
1 parent 03e7684 commit 4a79d9d
Show file tree
Hide file tree
Showing 85 changed files with 16,824 additions and 106 deletions.
10 changes: 7 additions & 3 deletions scripts/gen-protobufs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ const REPOS = [
paths: ["proto"],
},
{
repo: "osmosis-labs/osmosis",
repo: "osmosis-labs/osmosis#main",
paths: ["proto"],
},
{
repo: "cosmos/ibc-go#main",
paths: ["proto"],
},
];
Expand Down Expand Up @@ -91,8 +95,8 @@ function generateIndexExports(dir) {
.replace(PROTOBUFS_DIR + "/", "")
.split("/")
.map((name) =>
// convert name to PascalCase
name.split("-").map(capitalize).join("")
// convert all names to PascalCase
name.split(/[-_]/).map(capitalize).join("")
)
.join("");
for (const file of files) {
Expand Down
46 changes: 46 additions & 0 deletions src/client/models/MsgIbcTransfer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { PlainMessage } from "@bufbuild/protobuf";
import { IbcApplicationsTransferV1MsgTransfer as ProtoMsgIbcTransfer } from "cosmes/protobufs";

import { DeepPrettify } from "../../typeutils/prettify";
import { Adapter } from "./Adapter";

type Data = DeepPrettify<PlainMessage<ProtoMsgIbcTransfer>>;

export class MsgIbcTransfer implements Adapter {
private readonly data: Data;

constructor(data: Data) {
this.data = data;
}

public toProto() {
return new ProtoMsgIbcTransfer(this.data);
}

public toAmino() {
return {
type: "cosmos-sdk/MsgTransfer",
value: {
source_port: this.data.sourcePort,
source_channel: this.data.sourceChannel,
token: this.data.token,
sender: this.data.sender,
receiver: this.data.receiver,
/**
* Protobuf type is optional, but Amino type is non-optional.
*
* @see https://github.com/cosmos/cosmjs/blob/358260bff71c9d3e7ad6644fcf64dc00325cdfb9/packages/stargate/src/modules/ibc/aminomessages.ts#L16-L42
*/
timeout_height: this.data.timeoutHeight
? {
revision_number:
this.data.timeoutHeight.revisionNumber.toString(),
revision_height:
this.data.timeoutHeight.revisionHeight.toString(),
}
: {},
timeout_timestamp: this.data.timeoutTimestamp.toString(),
},
};
}
}
134 changes: 134 additions & 0 deletions src/protobufs/capability/v1/capability_pb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// @generated by protoc-gen-es v1.2.0 with parameter "target=ts"
// @generated from file capability/v1/capability.proto (package capability.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
import { Message, proto3, protoInt64 } from "@bufbuild/protobuf";

/**
* Capability defines an implementation of an object capability. The index
* provided to a Capability must be globally unique.
*
* @generated from message capability.v1.Capability
*/
export class Capability extends Message<Capability> {
/**
* @generated from field: uint64 index = 1;
*/
index = protoInt64.zero;

constructor(data?: PartialMessage<Capability>) {
super();
proto3.util.initPartial(data, this);
}

static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "capability.v1.Capability";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "index", kind: "scalar", T: 4 /* ScalarType.UINT64 */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Capability {
return new Capability().fromBinary(bytes, options);
}

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): Capability {
return new Capability().fromJson(jsonValue, options);
}

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): Capability {
return new Capability().fromJsonString(jsonString, options);
}

static equals(a: Capability | PlainMessage<Capability> | undefined, b: Capability | PlainMessage<Capability> | undefined): boolean {
return proto3.util.equals(Capability, a, b);
}
}

/**
* Owner defines a single capability owner. An owner is defined by the name of
* capability and the module name.
*
* @generated from message capability.v1.Owner
*/
export class Owner extends Message<Owner> {
/**
* @generated from field: string module = 1;
*/
module = "";

/**
* @generated from field: string name = 2;
*/
name = "";

constructor(data?: PartialMessage<Owner>) {
super();
proto3.util.initPartial(data, this);
}

static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "capability.v1.Owner";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "module", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Owner {
return new Owner().fromBinary(bytes, options);
}

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): Owner {
return new Owner().fromJson(jsonValue, options);
}

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): Owner {
return new Owner().fromJsonString(jsonString, options);
}

static equals(a: Owner | PlainMessage<Owner> | undefined, b: Owner | PlainMessage<Owner> | undefined): boolean {
return proto3.util.equals(Owner, a, b);
}
}

/**
* CapabilityOwners defines a set of owners of a single Capability. The set of
* owners must be unique.
*
* @generated from message capability.v1.CapabilityOwners
*/
export class CapabilityOwners extends Message<CapabilityOwners> {
/**
* @generated from field: repeated capability.v1.Owner owners = 1;
*/
owners: Owner[] = [];

constructor(data?: PartialMessage<CapabilityOwners>) {
super();
proto3.util.initPartial(data, this);
}

static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "capability.v1.CapabilityOwners";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "owners", kind: "message", T: Owner, repeated: true },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): CapabilityOwners {
return new CapabilityOwners().fromBinary(bytes, options);
}

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): CapabilityOwners {
return new CapabilityOwners().fromJson(jsonValue, options);
}

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): CapabilityOwners {
return new CapabilityOwners().fromJsonString(jsonString, options);
}

static equals(a: CapabilityOwners | PlainMessage<CapabilityOwners> | undefined, b: CapabilityOwners | PlainMessage<CapabilityOwners> | undefined): boolean {
return proto3.util.equals(CapabilityOwners, a, b);
}
}

108 changes: 108 additions & 0 deletions src/protobufs/capability/v1/genesis_pb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// @generated by protoc-gen-es v1.2.0 with parameter "target=ts"
// @generated from file capability/v1/genesis.proto (package capability.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
import { Message, proto3, protoInt64 } from "@bufbuild/protobuf";
import { CapabilityOwners } from "./capability_pb.js";

/**
* GenesisOwners defines the capability owners with their corresponding index.
*
* @generated from message capability.v1.GenesisOwners
*/
export class GenesisOwners extends Message<GenesisOwners> {
/**
* index is the index of the capability owner.
*
* @generated from field: uint64 index = 1;
*/
index = protoInt64.zero;

/**
* index_owners are the owners at the given index.
*
* @generated from field: capability.v1.CapabilityOwners index_owners = 2;
*/
indexOwners?: CapabilityOwners;

constructor(data?: PartialMessage<GenesisOwners>) {
super();
proto3.util.initPartial(data, this);
}

static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "capability.v1.GenesisOwners";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "index", kind: "scalar", T: 4 /* ScalarType.UINT64 */ },
{ no: 2, name: "index_owners", kind: "message", T: CapabilityOwners },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): GenesisOwners {
return new GenesisOwners().fromBinary(bytes, options);
}

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): GenesisOwners {
return new GenesisOwners().fromJson(jsonValue, options);
}

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): GenesisOwners {
return new GenesisOwners().fromJsonString(jsonString, options);
}

static equals(a: GenesisOwners | PlainMessage<GenesisOwners> | undefined, b: GenesisOwners | PlainMessage<GenesisOwners> | undefined): boolean {
return proto3.util.equals(GenesisOwners, a, b);
}
}

/**
* GenesisState defines the capability module's genesis state.
*
* @generated from message capability.v1.GenesisState
*/
export class GenesisState extends Message<GenesisState> {
/**
* index is the capability global index.
*
* @generated from field: uint64 index = 1;
*/
index = protoInt64.zero;

/**
* owners represents a map from index to owners of the capability index
* index key is string to allow amino marshalling.
*
* @generated from field: repeated capability.v1.GenesisOwners owners = 2;
*/
owners: GenesisOwners[] = [];

constructor(data?: PartialMessage<GenesisState>) {
super();
proto3.util.initPartial(data, this);
}

static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "capability.v1.GenesisState";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "index", kind: "scalar", T: 4 /* ScalarType.UINT64 */ },
{ no: 2, name: "owners", kind: "message", T: GenesisOwners, repeated: true },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): GenesisState {
return new GenesisState().fromBinary(bytes, options);
}

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): GenesisState {
return new GenesisState().fromJson(jsonValue, options);
}

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): GenesisState {
return new GenesisState().fromJsonString(jsonString, options);
}

static equals(a: GenesisState | PlainMessage<GenesisState> | undefined, b: GenesisState | PlainMessage<GenesisState> | undefined): boolean {
return proto3.util.equals(GenesisState, a, b);
}
}

10 changes: 10 additions & 0 deletions src/protobufs/cosmos/autocli/v1/options_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ export class ServiceCommandDescriptor extends Message<ServiceCommandDescriptor>
*/
subCommands: { [key: string]: ServiceCommandDescriptor } = {};

/**
* enhance_custom_commands specifies whether to skip the service when generating commands, if a custom command already exists,
* or enhance the existing command. If set to true, the custom command will be enhanced with the services from gRPC.
* otherwise when a custom command exists, no commands will be generated for the service.
*
* @generated from field: bool enhance_custom_command = 4;
*/
enhanceCustomCommand = false;

constructor(data?: PartialMessage<ServiceCommandDescriptor>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -99,6 +108,7 @@ export class ServiceCommandDescriptor extends Message<ServiceCommandDescriptor>
{ no: 1, name: "service", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "rpc_command_options", kind: "message", T: RpcCommandOptions, repeated: true },
{ no: 3, name: "sub_commands", kind: "map", K: 9 /* ScalarType.STRING */, V: {kind: "message", T: ServiceCommandDescriptor} },
{ no: 4, name: "enhance_custom_command", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ServiceCommandDescriptor {
Expand Down
14 changes: 13 additions & 1 deletion src/protobufs/cosmos/bank/v1beta1/query_cosmes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable */
// @ts-nocheck

import { QueryAllBalancesRequest, QueryAllBalancesResponse, QueryBalanceRequest, QueryBalanceResponse, QueryDenomMetadataRequest, QueryDenomMetadataResponse, QueryDenomOwnersRequest, QueryDenomOwnersResponse, QueryDenomsMetadataRequest, QueryDenomsMetadataResponse, QueryParamsRequest, QueryParamsResponse, QuerySendEnabledRequest, QuerySendEnabledResponse, QuerySpendableBalanceByDenomRequest, QuerySpendableBalanceByDenomResponse, QuerySpendableBalancesRequest, QuerySpendableBalancesResponse, QuerySupplyOfRequest, QuerySupplyOfResponse, QueryTotalSupplyRequest, QueryTotalSupplyResponse } from "./query_pb.js";
import { QueryAllBalancesRequest, QueryAllBalancesResponse, QueryBalanceRequest, QueryBalanceResponse, QueryDenomMetadataByQueryStringRequest, QueryDenomMetadataByQueryStringResponse, QueryDenomMetadataRequest, QueryDenomMetadataResponse, QueryDenomOwnersRequest, QueryDenomOwnersResponse, QueryDenomsMetadataRequest, QueryDenomsMetadataResponse, QueryParamsRequest, QueryParamsResponse, QuerySendEnabledRequest, QuerySendEnabledResponse, QuerySpendableBalanceByDenomRequest, QuerySpendableBalanceByDenomResponse, QuerySpendableBalancesRequest, QuerySpendableBalancesResponse, QuerySupplyOfRequest, QuerySupplyOfResponse, QueryTotalSupplyRequest, QueryTotalSupplyResponse } from "./query_pb.js";

const TYPE_NAME = "cosmos.bank.v1beta1.Query";

Expand Down Expand Up @@ -124,6 +124,18 @@ export const QueryDenomMetadataService = {
Response: QueryDenomMetadataResponse,
} as const;

/**
* DenomsMetadata queries the client metadata of a given coin denomination.
*
* @generated from rpc cosmos.bank.v1beta1.Query.DenomMetadataByQueryString
*/
export const QueryDenomMetadataByQueryStringService = {
typeName: TYPE_NAME,
method: "DenomMetadataByQueryString",
Request: QueryDenomMetadataByQueryStringRequest,
Response: QueryDenomMetadataByQueryStringResponse,
} as const;

/**
* DenomsMetadata queries the client metadata for all registered coin
* denominations.
Expand Down
Loading

0 comments on commit 4a79d9d

Please sign in to comment.