diff --git a/scripts/proto-gen.sh b/scripts/proto-gen.sh index d0f4d5c..4c5d11c 100755 --- a/scripts/proto-gen.sh +++ b/scripts/proto-gen.sh @@ -16,4 +16,5 @@ protoc \ --ts_proto_out=$DEST_TS \ --proto_path=$I \ --ts_proto_opt="esModuleInterop=true,forceLong=long,useOptionals=messages" \ - $(find $REPO_ROOT/proto/cerc -iname "*.proto") + $(find $REPO_ROOT/proto/cerc $REPO_ROOT/proto/cosmos/bank -type f -iname "*.proto" +) diff --git a/src/index.ts b/src/index.ts index ed11e61..935d3ba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -39,6 +39,7 @@ import { import { LaconicClient } from './laconic-client'; import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto2/cerc/bond/v1/tx'; import { Coin } from './proto2/cosmos/base/v1beta1/coin'; +import { MsgSendResponse } from './proto2/cosmos/bank/v1beta1/tx'; export const DEFAULT_CHAIN_ID = 'laconic_9000-1'; @@ -190,8 +191,7 @@ export class Registry { ], fee); - // TODO: Register type /cosmos.bank.v1beta1.MsgSendResponse for decoding response - return response; + return laconicClient.parseResponse(response); } /** diff --git a/src/laconic-client.ts b/src/laconic-client.ts index 385f6e1..eac0398 100644 --- a/src/laconic-client.ts +++ b/src/laconic-client.ts @@ -20,6 +20,7 @@ import { Util } from './util'; import { NAMESERVICE_ERRORS } from './messages/registry'; import { MsgCommitBidResponse, MsgRevealBidResponse } from './proto2/cerc/auction/v1/tx'; import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto2/cerc/bond/v1/tx'; +import { bankTypes } from './types/cosmos/bank/message'; const DEFAULT_WRITE_ERROR = 'Unable to write to laconicd.'; @@ -27,7 +28,8 @@ export const laconicDefaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> ...defaultRegistryTypes, ...bondTypes, ...registryTypes, - ...auctionTypes + ...auctionTypes, + ...bankTypes ]; function createDefaultRegistry (): Registry { diff --git a/src/naming.test.ts b/src/naming.test.ts index 71ce007..7df301d 100644 --- a/src/naming.test.ts +++ b/src/naming.test.ts @@ -289,7 +289,6 @@ const namingTests = () => { await expect(registry.deleteName({ lrn: `lrn://${otherAuthorityName}/app/test` }, privateKey, fee)).rejects.toThrow('Access denied.'); }); - // TODO: Check later for empty records test('Lookup non existing name', async () => { const records = await registry.lookupNames(['lrn://not-reserved/app/test']); expect(records).toBeDefined(); diff --git a/src/proto2/cosmos/bank/v1beta1/bank.ts b/src/proto2/cosmos/bank/v1beta1/bank.ts new file mode 100644 index 0000000..b27452d --- /dev/null +++ b/src/proto2/cosmos/bank/v1beta1/bank.ts @@ -0,0 +1,690 @@ +/* eslint-disable */ +import Long from "long"; +import { Coin } from "../../base/v1beta1/coin"; +import _m0 from "protobufjs/minimal"; + +export const protobufPackage = "cosmos.bank.v1beta1"; + +/** Params defines the parameters for the bank module. */ +export interface Params { + /** + * Deprecated: Use of SendEnabled in params is deprecated. + * For genesis, use the newly added send_enabled field in the genesis object. + * Storage, lookup, and manipulation of this information is now in the keeper. + * + * As of cosmos-sdk 0.47, this only exists for backwards compatibility of genesis files. + * + * @deprecated + */ + sendEnabled: SendEnabled[]; + defaultSendEnabled: boolean; +} + +/** + * SendEnabled maps coin denom to a send_enabled status (whether a denom is + * sendable). + */ +export interface SendEnabled { + denom: string; + enabled: boolean; +} + +/** Input models transaction input. */ +export interface Input { + address: string; + coins: Coin[]; +} + +/** Output models transaction outputs. */ +export interface Output { + address: string; + coins: Coin[]; +} + +/** + * Supply represents a struct that passively keeps track of the total supply + * amounts in the network. + * This message is deprecated now that supply is indexed by denom. + * + * @deprecated + */ +export interface Supply { + total: Coin[]; +} + +/** + * DenomUnit represents a struct that describes a given + * denomination unit of the basic token. + */ +export interface DenomUnit { + /** denom represents the string name of the given denom unit (e.g uatom). */ + denom: string; + /** + * exponent represents power of 10 exponent that one must + * raise the base_denom to in order to equal the given DenomUnit's denom + * 1 denom = 10^exponent base_denom + * (e.g. with a base_denom of uatom, one can create a DenomUnit of 'atom' with + * exponent = 6, thus: 1 atom = 10^6 uatom). + */ + exponent: number; + /** aliases is a list of string aliases for the given denom */ + aliases: string[]; +} + +/** + * Metadata represents a struct that describes + * a basic token. + */ +export interface Metadata { + description: string; + /** denom_units represents the list of DenomUnit's for a given coin */ + denomUnits: DenomUnit[]; + /** base represents the base denom (should be the DenomUnit with exponent = 0). */ + base: string; + /** + * display indicates the suggested denom that should be + * displayed in clients. + */ + display: string; + /** + * name defines the name of the token (eg: Cosmos Atom) + * + * Since: cosmos-sdk 0.43 + */ + name: string; + /** + * symbol is the token symbol usually shown on exchanges (eg: ATOM). This can + * be the same as the display. + * + * Since: cosmos-sdk 0.43 + */ + symbol: string; + /** + * URI to a document (on or off-chain) that contains additional information. Optional. + * + * Since: cosmos-sdk 0.46 + */ + uri: string; + /** + * URIHash is a sha256 hash of a document pointed by URI. It's used to verify that + * the document didn't change. Optional. + * + * Since: cosmos-sdk 0.46 + */ + uriHash: string; +} + +function createBaseParams(): Params { + return { sendEnabled: [], defaultSendEnabled: false }; +} + +export const Params = { + encode( + message: Params, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.sendEnabled) { + SendEnabled.encode(v!, writer.uint32(10).fork()).ldelim(); + } + if (message.defaultSendEnabled === true) { + writer.uint32(16).bool(message.defaultSendEnabled); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Params { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseParams(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.sendEnabled.push(SendEnabled.decode(reader, reader.uint32())); + break; + case 2: + message.defaultSendEnabled = reader.bool(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Params { + return { + sendEnabled: Array.isArray(object?.sendEnabled) + ? object.sendEnabled.map((e: any) => SendEnabled.fromJSON(e)) + : [], + defaultSendEnabled: isSet(object.defaultSendEnabled) + ? Boolean(object.defaultSendEnabled) + : false, + }; + }, + + toJSON(message: Params): unknown { + const obj: any = {}; + if (message.sendEnabled) { + obj.sendEnabled = message.sendEnabled.map((e) => + e ? SendEnabled.toJSON(e) : undefined + ); + } else { + obj.sendEnabled = []; + } + message.defaultSendEnabled !== undefined && + (obj.defaultSendEnabled = message.defaultSendEnabled); + return obj; + }, + + fromPartial, I>>(object: I): Params { + const message = createBaseParams(); + message.sendEnabled = + object.sendEnabled?.map((e) => SendEnabled.fromPartial(e)) || []; + message.defaultSendEnabled = object.defaultSendEnabled ?? false; + return message; + }, +}; + +function createBaseSendEnabled(): SendEnabled { + return { denom: "", enabled: false }; +} + +export const SendEnabled = { + encode( + message: SendEnabled, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.denom !== "") { + writer.uint32(10).string(message.denom); + } + if (message.enabled === true) { + writer.uint32(16).bool(message.enabled); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): SendEnabled { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseSendEnabled(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.denom = reader.string(); + break; + case 2: + message.enabled = reader.bool(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): SendEnabled { + return { + denom: isSet(object.denom) ? String(object.denom) : "", + enabled: isSet(object.enabled) ? Boolean(object.enabled) : false, + }; + }, + + toJSON(message: SendEnabled): unknown { + const obj: any = {}; + message.denom !== undefined && (obj.denom = message.denom); + message.enabled !== undefined && (obj.enabled = message.enabled); + return obj; + }, + + fromPartial, I>>( + object: I + ): SendEnabled { + const message = createBaseSendEnabled(); + message.denom = object.denom ?? ""; + message.enabled = object.enabled ?? false; + return message; + }, +}; + +function createBaseInput(): Input { + return { address: "", coins: [] }; +} + +export const Input = { + encode(message: Input, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.address !== "") { + writer.uint32(10).string(message.address); + } + for (const v of message.coins) { + Coin.encode(v!, writer.uint32(18).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Input { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseInput(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.address = reader.string(); + break; + case 2: + message.coins.push(Coin.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Input { + return { + address: isSet(object.address) ? String(object.address) : "", + coins: Array.isArray(object?.coins) + ? object.coins.map((e: any) => Coin.fromJSON(e)) + : [], + }; + }, + + toJSON(message: Input): unknown { + const obj: any = {}; + message.address !== undefined && (obj.address = message.address); + if (message.coins) { + obj.coins = message.coins.map((e) => (e ? Coin.toJSON(e) : undefined)); + } else { + obj.coins = []; + } + return obj; + }, + + fromPartial, I>>(object: I): Input { + const message = createBaseInput(); + message.address = object.address ?? ""; + message.coins = object.coins?.map((e) => Coin.fromPartial(e)) || []; + return message; + }, +}; + +function createBaseOutput(): Output { + return { address: "", coins: [] }; +} + +export const Output = { + encode( + message: Output, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.address !== "") { + writer.uint32(10).string(message.address); + } + for (const v of message.coins) { + Coin.encode(v!, writer.uint32(18).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Output { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseOutput(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.address = reader.string(); + break; + case 2: + message.coins.push(Coin.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Output { + return { + address: isSet(object.address) ? String(object.address) : "", + coins: Array.isArray(object?.coins) + ? object.coins.map((e: any) => Coin.fromJSON(e)) + : [], + }; + }, + + toJSON(message: Output): unknown { + const obj: any = {}; + message.address !== undefined && (obj.address = message.address); + if (message.coins) { + obj.coins = message.coins.map((e) => (e ? Coin.toJSON(e) : undefined)); + } else { + obj.coins = []; + } + return obj; + }, + + fromPartial, I>>(object: I): Output { + const message = createBaseOutput(); + message.address = object.address ?? ""; + message.coins = object.coins?.map((e) => Coin.fromPartial(e)) || []; + return message; + }, +}; + +function createBaseSupply(): Supply { + return { total: [] }; +} + +export const Supply = { + encode( + message: Supply, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.total) { + Coin.encode(v!, writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Supply { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseSupply(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.total.push(Coin.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Supply { + return { + total: Array.isArray(object?.total) + ? object.total.map((e: any) => Coin.fromJSON(e)) + : [], + }; + }, + + toJSON(message: Supply): unknown { + const obj: any = {}; + if (message.total) { + obj.total = message.total.map((e) => (e ? Coin.toJSON(e) : undefined)); + } else { + obj.total = []; + } + return obj; + }, + + fromPartial, I>>(object: I): Supply { + const message = createBaseSupply(); + message.total = object.total?.map((e) => Coin.fromPartial(e)) || []; + return message; + }, +}; + +function createBaseDenomUnit(): DenomUnit { + return { denom: "", exponent: 0, aliases: [] }; +} + +export const DenomUnit = { + encode( + message: DenomUnit, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.denom !== "") { + writer.uint32(10).string(message.denom); + } + if (message.exponent !== 0) { + writer.uint32(16).uint32(message.exponent); + } + for (const v of message.aliases) { + writer.uint32(26).string(v!); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): DenomUnit { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseDenomUnit(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.denom = reader.string(); + break; + case 2: + message.exponent = reader.uint32(); + break; + case 3: + message.aliases.push(reader.string()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): DenomUnit { + return { + denom: isSet(object.denom) ? String(object.denom) : "", + exponent: isSet(object.exponent) ? Number(object.exponent) : 0, + aliases: Array.isArray(object?.aliases) + ? object.aliases.map((e: any) => String(e)) + : [], + }; + }, + + toJSON(message: DenomUnit): unknown { + const obj: any = {}; + message.denom !== undefined && (obj.denom = message.denom); + message.exponent !== undefined && + (obj.exponent = Math.round(message.exponent)); + if (message.aliases) { + obj.aliases = message.aliases.map((e) => e); + } else { + obj.aliases = []; + } + return obj; + }, + + fromPartial, I>>( + object: I + ): DenomUnit { + const message = createBaseDenomUnit(); + message.denom = object.denom ?? ""; + message.exponent = object.exponent ?? 0; + message.aliases = object.aliases?.map((e) => e) || []; + return message; + }, +}; + +function createBaseMetadata(): Metadata { + return { + description: "", + denomUnits: [], + base: "", + display: "", + name: "", + symbol: "", + uri: "", + uriHash: "", + }; +} + +export const Metadata = { + encode( + message: Metadata, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.description !== "") { + writer.uint32(10).string(message.description); + } + for (const v of message.denomUnits) { + DenomUnit.encode(v!, writer.uint32(18).fork()).ldelim(); + } + if (message.base !== "") { + writer.uint32(26).string(message.base); + } + if (message.display !== "") { + writer.uint32(34).string(message.display); + } + if (message.name !== "") { + writer.uint32(42).string(message.name); + } + if (message.symbol !== "") { + writer.uint32(50).string(message.symbol); + } + if (message.uri !== "") { + writer.uint32(58).string(message.uri); + } + if (message.uriHash !== "") { + writer.uint32(66).string(message.uriHash); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Metadata { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMetadata(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.description = reader.string(); + break; + case 2: + message.denomUnits.push(DenomUnit.decode(reader, reader.uint32())); + break; + case 3: + message.base = reader.string(); + break; + case 4: + message.display = reader.string(); + break; + case 5: + message.name = reader.string(); + break; + case 6: + message.symbol = reader.string(); + break; + case 7: + message.uri = reader.string(); + break; + case 8: + message.uriHash = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Metadata { + return { + description: isSet(object.description) ? String(object.description) : "", + denomUnits: Array.isArray(object?.denomUnits) + ? object.denomUnits.map((e: any) => DenomUnit.fromJSON(e)) + : [], + base: isSet(object.base) ? String(object.base) : "", + display: isSet(object.display) ? String(object.display) : "", + name: isSet(object.name) ? String(object.name) : "", + symbol: isSet(object.symbol) ? String(object.symbol) : "", + uri: isSet(object.uri) ? String(object.uri) : "", + uriHash: isSet(object.uriHash) ? String(object.uriHash) : "", + }; + }, + + toJSON(message: Metadata): unknown { + const obj: any = {}; + message.description !== undefined && + (obj.description = message.description); + if (message.denomUnits) { + obj.denomUnits = message.denomUnits.map((e) => + e ? DenomUnit.toJSON(e) : undefined + ); + } else { + obj.denomUnits = []; + } + message.base !== undefined && (obj.base = message.base); + message.display !== undefined && (obj.display = message.display); + message.name !== undefined && (obj.name = message.name); + message.symbol !== undefined && (obj.symbol = message.symbol); + message.uri !== undefined && (obj.uri = message.uri); + message.uriHash !== undefined && (obj.uriHash = message.uriHash); + return obj; + }, + + fromPartial, I>>(object: I): Metadata { + const message = createBaseMetadata(); + message.description = object.description ?? ""; + message.denomUnits = + object.denomUnits?.map((e) => DenomUnit.fromPartial(e)) || []; + message.base = object.base ?? ""; + message.display = object.display ?? ""; + message.name = object.name ?? ""; + message.symbol = object.symbol ?? ""; + message.uri = object.uri ?? ""; + message.uriHash = object.uriHash ?? ""; + return message; + }, +}; + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined; + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never; + }; + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any; + _m0.configure(); +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/proto2/cosmos/bank/v1beta1/tx.ts b/src/proto2/cosmos/bank/v1beta1/tx.ts new file mode 100644 index 0000000..3619bb2 --- /dev/null +++ b/src/proto2/cosmos/bank/v1beta1/tx.ts @@ -0,0 +1,702 @@ +/* eslint-disable */ +import { Params, Input, Output, SendEnabled } from "./bank"; +import Long from "long"; +import { Coin } from "../../base/v1beta1/coin"; +import _m0 from "protobufjs/minimal"; + +export const protobufPackage = "cosmos.bank.v1beta1"; + +/** MsgSend represents a message to send coins from one account to another. */ +export interface MsgSend { + fromAddress: string; + toAddress: string; + amount: Coin[]; +} + +/** MsgSendResponse defines the Msg/Send response type. */ +export interface MsgSendResponse {} + +/** MsgMultiSend represents an arbitrary multi-in, multi-out send message. */ +export interface MsgMultiSend { + /** + * Inputs, despite being `repeated`, only allows one sender input. This is + * checked in MsgMultiSend's ValidateBasic. + */ + inputs: Input[]; + outputs: Output[]; +} + +/** MsgMultiSendResponse defines the Msg/MultiSend response type. */ +export interface MsgMultiSendResponse {} + +/** + * MsgUpdateParams is the Msg/UpdateParams request type. + * + * Since: cosmos-sdk 0.47 + */ +export interface MsgUpdateParams { + /** authority is the address that controls the module (defaults to x/gov unless overwritten). */ + authority: string; + /** + * params defines the x/bank parameters to update. + * + * NOTE: All parameters must be supplied. + */ + params?: Params; +} + +/** + * MsgUpdateParamsResponse defines the response structure for executing a + * MsgUpdateParams message. + * + * Since: cosmos-sdk 0.47 + */ +export interface MsgUpdateParamsResponse {} + +/** + * MsgSetSendEnabled is the Msg/SetSendEnabled request type. + * + * Only entries to add/update/delete need to be included. + * Existing SendEnabled entries that are not included in this + * message are left unchanged. + * + * Since: cosmos-sdk 0.47 + */ +export interface MsgSetSendEnabled { + /** authority is the address that controls the module. */ + authority: string; + /** send_enabled is the list of entries to add or update. */ + sendEnabled: SendEnabled[]; + /** + * use_default_for is a list of denoms that should use the params.default_send_enabled value. + * Denoms listed here will have their SendEnabled entries deleted. + * If a denom is included that doesn't have a SendEnabled entry, + * it will be ignored. + */ + useDefaultFor: string[]; +} + +/** + * MsgSetSendEnabledResponse defines the Msg/SetSendEnabled response type. + * + * Since: cosmos-sdk 0.47 + */ +export interface MsgSetSendEnabledResponse {} + +function createBaseMsgSend(): MsgSend { + return { fromAddress: "", toAddress: "", amount: [] }; +} + +export const MsgSend = { + encode( + message: MsgSend, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.fromAddress !== "") { + writer.uint32(10).string(message.fromAddress); + } + if (message.toAddress !== "") { + writer.uint32(18).string(message.toAddress); + } + for (const v of message.amount) { + Coin.encode(v!, writer.uint32(26).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgSend { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgSend(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.fromAddress = reader.string(); + break; + case 2: + message.toAddress = reader.string(); + break; + case 3: + message.amount.push(Coin.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgSend { + return { + fromAddress: isSet(object.fromAddress) ? String(object.fromAddress) : "", + toAddress: isSet(object.toAddress) ? String(object.toAddress) : "", + amount: Array.isArray(object?.amount) + ? object.amount.map((e: any) => Coin.fromJSON(e)) + : [], + }; + }, + + toJSON(message: MsgSend): unknown { + const obj: any = {}; + message.fromAddress !== undefined && + (obj.fromAddress = message.fromAddress); + message.toAddress !== undefined && (obj.toAddress = message.toAddress); + if (message.amount) { + obj.amount = message.amount.map((e) => (e ? Coin.toJSON(e) : undefined)); + } else { + obj.amount = []; + } + return obj; + }, + + fromPartial, I>>(object: I): MsgSend { + const message = createBaseMsgSend(); + message.fromAddress = object.fromAddress ?? ""; + message.toAddress = object.toAddress ?? ""; + message.amount = object.amount?.map((e) => Coin.fromPartial(e)) || []; + return message; + }, +}; + +function createBaseMsgSendResponse(): MsgSendResponse { + return {}; +} + +export const MsgSendResponse = { + encode( + _: MsgSendResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgSendResponse { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgSendResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgSendResponse { + return {}; + }, + + toJSON(_: MsgSendResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial, I>>( + _: I + ): MsgSendResponse { + const message = createBaseMsgSendResponse(); + return message; + }, +}; + +function createBaseMsgMultiSend(): MsgMultiSend { + return { inputs: [], outputs: [] }; +} + +export const MsgMultiSend = { + encode( + message: MsgMultiSend, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.inputs) { + Input.encode(v!, writer.uint32(10).fork()).ldelim(); + } + for (const v of message.outputs) { + Output.encode(v!, writer.uint32(18).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgMultiSend { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgMultiSend(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.inputs.push(Input.decode(reader, reader.uint32())); + break; + case 2: + message.outputs.push(Output.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgMultiSend { + return { + inputs: Array.isArray(object?.inputs) + ? object.inputs.map((e: any) => Input.fromJSON(e)) + : [], + outputs: Array.isArray(object?.outputs) + ? object.outputs.map((e: any) => Output.fromJSON(e)) + : [], + }; + }, + + toJSON(message: MsgMultiSend): unknown { + const obj: any = {}; + if (message.inputs) { + obj.inputs = message.inputs.map((e) => (e ? Input.toJSON(e) : undefined)); + } else { + obj.inputs = []; + } + if (message.outputs) { + obj.outputs = message.outputs.map((e) => + e ? Output.toJSON(e) : undefined + ); + } else { + obj.outputs = []; + } + return obj; + }, + + fromPartial, I>>( + object: I + ): MsgMultiSend { + const message = createBaseMsgMultiSend(); + message.inputs = object.inputs?.map((e) => Input.fromPartial(e)) || []; + message.outputs = object.outputs?.map((e) => Output.fromPartial(e)) || []; + return message; + }, +}; + +function createBaseMsgMultiSendResponse(): MsgMultiSendResponse { + return {}; +} + +export const MsgMultiSendResponse = { + encode( + _: MsgMultiSendResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer; + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgMultiSendResponse { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgMultiSendResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgMultiSendResponse { + return {}; + }, + + toJSON(_: MsgMultiSendResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial, I>>( + _: I + ): MsgMultiSendResponse { + const message = createBaseMsgMultiSendResponse(); + return message; + }, +}; + +function createBaseMsgUpdateParams(): MsgUpdateParams { + return { authority: "", params: undefined }; +} + +export const MsgUpdateParams = { + encode( + message: MsgUpdateParams, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.authority !== "") { + writer.uint32(10).string(message.authority); + } + if (message.params !== undefined) { + Params.encode(message.params, writer.uint32(18).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpdateParams { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgUpdateParams(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.authority = reader.string(); + break; + case 2: + message.params = Params.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgUpdateParams { + return { + authority: isSet(object.authority) ? String(object.authority) : "", + params: isSet(object.params) ? Params.fromJSON(object.params) : undefined, + }; + }, + + toJSON(message: MsgUpdateParams): unknown { + const obj: any = {}; + message.authority !== undefined && (obj.authority = message.authority); + message.params !== undefined && + (obj.params = message.params ? Params.toJSON(message.params) : undefined); + return obj; + }, + + fromPartial, I>>( + object: I + ): MsgUpdateParams { + const message = createBaseMsgUpdateParams(); + message.authority = object.authority ?? ""; + message.params = + object.params !== undefined && object.params !== null + ? Params.fromPartial(object.params) + : undefined; + return message; + }, +}; + +function createBaseMsgUpdateParamsResponse(): MsgUpdateParamsResponse { + return {}; +} + +export const MsgUpdateParamsResponse = { + encode( + _: MsgUpdateParamsResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer; + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgUpdateParamsResponse { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgUpdateParamsResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgUpdateParamsResponse { + return {}; + }, + + toJSON(_: MsgUpdateParamsResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial, I>>( + _: I + ): MsgUpdateParamsResponse { + const message = createBaseMsgUpdateParamsResponse(); + return message; + }, +}; + +function createBaseMsgSetSendEnabled(): MsgSetSendEnabled { + return { authority: "", sendEnabled: [], useDefaultFor: [] }; +} + +export const MsgSetSendEnabled = { + encode( + message: MsgSetSendEnabled, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.authority !== "") { + writer.uint32(10).string(message.authority); + } + for (const v of message.sendEnabled) { + SendEnabled.encode(v!, writer.uint32(18).fork()).ldelim(); + } + for (const v of message.useDefaultFor) { + writer.uint32(26).string(v!); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgSetSendEnabled { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgSetSendEnabled(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.authority = reader.string(); + break; + case 2: + message.sendEnabled.push(SendEnabled.decode(reader, reader.uint32())); + break; + case 3: + message.useDefaultFor.push(reader.string()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgSetSendEnabled { + return { + authority: isSet(object.authority) ? String(object.authority) : "", + sendEnabled: Array.isArray(object?.sendEnabled) + ? object.sendEnabled.map((e: any) => SendEnabled.fromJSON(e)) + : [], + useDefaultFor: Array.isArray(object?.useDefaultFor) + ? object.useDefaultFor.map((e: any) => String(e)) + : [], + }; + }, + + toJSON(message: MsgSetSendEnabled): unknown { + const obj: any = {}; + message.authority !== undefined && (obj.authority = message.authority); + if (message.sendEnabled) { + obj.sendEnabled = message.sendEnabled.map((e) => + e ? SendEnabled.toJSON(e) : undefined + ); + } else { + obj.sendEnabled = []; + } + if (message.useDefaultFor) { + obj.useDefaultFor = message.useDefaultFor.map((e) => e); + } else { + obj.useDefaultFor = []; + } + return obj; + }, + + fromPartial, I>>( + object: I + ): MsgSetSendEnabled { + const message = createBaseMsgSetSendEnabled(); + message.authority = object.authority ?? ""; + message.sendEnabled = + object.sendEnabled?.map((e) => SendEnabled.fromPartial(e)) || []; + message.useDefaultFor = object.useDefaultFor?.map((e) => e) || []; + return message; + }, +}; + +function createBaseMsgSetSendEnabledResponse(): MsgSetSendEnabledResponse { + return {}; +} + +export const MsgSetSendEnabledResponse = { + encode( + _: MsgSetSendEnabledResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer; + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgSetSendEnabledResponse { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgSetSendEnabledResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgSetSendEnabledResponse { + return {}; + }, + + toJSON(_: MsgSetSendEnabledResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial, I>>( + _: I + ): MsgSetSendEnabledResponse { + const message = createBaseMsgSetSendEnabledResponse(); + return message; + }, +}; + +/** Msg defines the bank Msg service. */ +export interface Msg { + /** Send defines a method for sending coins from one account to another account. */ + Send(request: MsgSend): Promise; + /** MultiSend defines a method for sending coins from some accounts to other accounts. */ + MultiSend(request: MsgMultiSend): Promise; + /** + * UpdateParams defines a governance operation for updating the x/bank module parameters. + * The authority is defined in the keeper. + * + * Since: cosmos-sdk 0.47 + */ + UpdateParams(request: MsgUpdateParams): Promise; + /** + * SetSendEnabled is a governance operation for setting the SendEnabled flag + * on any number of Denoms. Only the entries to add or update should be + * included. Entries that already exist in the store, but that aren't + * included in this message, will be left unchanged. + * + * Since: cosmos-sdk 0.47 + */ + SetSendEnabled( + request: MsgSetSendEnabled + ): Promise; +} + +export class MsgClientImpl implements Msg { + private readonly rpc: Rpc; + constructor(rpc: Rpc) { + this.rpc = rpc; + this.Send = this.Send.bind(this); + this.MultiSend = this.MultiSend.bind(this); + this.UpdateParams = this.UpdateParams.bind(this); + this.SetSendEnabled = this.SetSendEnabled.bind(this); + } + Send(request: MsgSend): Promise { + const data = MsgSend.encode(request).finish(); + const promise = this.rpc.request("cosmos.bank.v1beta1.Msg", "Send", data); + return promise.then((data) => MsgSendResponse.decode(new _m0.Reader(data))); + } + + MultiSend(request: MsgMultiSend): Promise { + const data = MsgMultiSend.encode(request).finish(); + const promise = this.rpc.request( + "cosmos.bank.v1beta1.Msg", + "MultiSend", + data + ); + return promise.then((data) => + MsgMultiSendResponse.decode(new _m0.Reader(data)) + ); + } + + UpdateParams(request: MsgUpdateParams): Promise { + const data = MsgUpdateParams.encode(request).finish(); + const promise = this.rpc.request( + "cosmos.bank.v1beta1.Msg", + "UpdateParams", + data + ); + return promise.then((data) => + MsgUpdateParamsResponse.decode(new _m0.Reader(data)) + ); + } + + SetSendEnabled( + request: MsgSetSendEnabled + ): Promise { + const data = MsgSetSendEnabled.encode(request).finish(); + const promise = this.rpc.request( + "cosmos.bank.v1beta1.Msg", + "SetSendEnabled", + data + ); + return promise.then((data) => + MsgSetSendEnabledResponse.decode(new _m0.Reader(data)) + ); + } +} + +interface Rpc { + request( + service: string, + method: string, + data: Uint8Array + ): Promise; +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined; + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never; + }; + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any; + _m0.configure(); +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/sdk.test.ts b/src/sdk.test.ts index 5d7ee3e..a69edaf 100644 --- a/src/sdk.test.ts +++ b/src/sdk.test.ts @@ -36,8 +36,7 @@ describe('Querying', () => { expect(registry.chainID).toBe(chainId); }); - // TODO: Unskip - xtest('Get status.', async () => { + test('Get status.', async () => { const status = await registry.getStatus(); expect(status).toBeDefined(); expect(status.version).toBeDefined(); diff --git a/src/types/cosmos/bank/message.ts b/src/types/cosmos/bank/message.ts new file mode 100644 index 0000000..f470d6f --- /dev/null +++ b/src/types/cosmos/bank/message.ts @@ -0,0 +1,11 @@ +import { GeneratedType } from '@cosmjs/proto-signing'; + +import { + MsgSendResponse +} from '../../../proto2/cosmos/bank/v1beta1/tx'; + +export const typeUrlMsgSendResponse = '/cosmos.bank.v1beta1.MsgSendResponse'; + +export const bankTypes: ReadonlyArray<[string, GeneratedType]> = [ + [typeUrlMsgSendResponse, MsgSendResponse] +];