Merge pull request #1071 from cosmos/reorganize-module-files
Reorganize module files
This commit is contained in:
commit
bb926925e1
@ -1,232 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { fromBase64, fromUtf8, toBase64, toUtf8 } from "@cosmjs/encoding";
|
||||
import { AminoConverter, Coin } from "@cosmjs/stargate";
|
||||
import {
|
||||
MsgClearAdmin,
|
||||
MsgExecuteContract,
|
||||
MsgInstantiateContract,
|
||||
MsgMigrateContract,
|
||||
MsgStoreCode,
|
||||
MsgUpdateAdmin,
|
||||
} from "cosmjs-types/cosmwasm/wasm/v1/tx";
|
||||
import Long from "long";
|
||||
|
||||
// TODO: implement
|
||||
/**
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/types.proto#L36-L41
|
||||
*/
|
||||
type AccessConfig = never;
|
||||
|
||||
/**
|
||||
* The Amino JSON representation of [MsgStoreCode].
|
||||
*
|
||||
* [MsgStoreCode]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L28-L39
|
||||
*/
|
||||
export interface AminoMsgStoreCode {
|
||||
type: "wasm/MsgStoreCode";
|
||||
value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
/** Base64 encoded Wasm */
|
||||
readonly wasm_byte_code: string;
|
||||
readonly instantiate_permission?: AccessConfig;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The Amino JSON representation of [MsgExecuteContract].
|
||||
*
|
||||
* [MsgExecuteContract]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L73-L86
|
||||
*/
|
||||
export interface AminoMsgExecuteContract {
|
||||
type: "wasm/MsgExecuteContract";
|
||||
value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
/** Bech32 account address */
|
||||
readonly contract: string;
|
||||
/** Execute message as JavaScript object */
|
||||
readonly msg: any;
|
||||
readonly funds: readonly Coin[];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The Amino JSON representation of [MsgInstantiateContract].
|
||||
*
|
||||
* [MsgInstantiateContract]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L46-L64
|
||||
*/
|
||||
export interface AminoMsgInstantiateContract {
|
||||
type: "wasm/MsgInstantiateContract";
|
||||
value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
/** ID of the Wasm code that was uploaded before */
|
||||
readonly code_id: string;
|
||||
/** Human-readable label for this contract */
|
||||
readonly label: string;
|
||||
/** Instantiate message as JavaScript object */
|
||||
readonly msg: any;
|
||||
readonly funds: readonly Coin[];
|
||||
/** Bech32-encoded admin address */
|
||||
readonly admin?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The Amino JSON representation of [MsgMigrateContract].
|
||||
*
|
||||
* [MsgMigrateContract]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L94-L104
|
||||
*/
|
||||
export interface AminoMsgMigrateContract {
|
||||
type: "wasm/MsgMigrateContract";
|
||||
value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
/** Bech32 account address */
|
||||
readonly contract: string;
|
||||
/** The new code */
|
||||
readonly code_id: string;
|
||||
/** Migrate message as JavaScript object */
|
||||
readonly msg: any;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The Amino JSON representation of [MsgUpdateAdmin].
|
||||
*
|
||||
* [MsgUpdateAdmin]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L113-L121
|
||||
*/
|
||||
export interface AminoMsgUpdateAdmin {
|
||||
type: "wasm/MsgUpdateAdmin";
|
||||
value: {
|
||||
/** Bech32-encoded sender address. This must be the old admin. */
|
||||
readonly sender: string;
|
||||
/** Bech32-encoded contract address to be updated */
|
||||
readonly contract: string;
|
||||
/** Bech32-encoded address of the new admin */
|
||||
readonly new_admin: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The Amino JSON representation of [MsgClearAdmin].
|
||||
*
|
||||
* [MsgClearAdmin]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L126-L132
|
||||
*/
|
||||
export interface AminoMsgClearAdmin {
|
||||
type: "wasm/MsgClearAdmin";
|
||||
value: {
|
||||
/** Bech32-encoded sender address. This must be the old admin. */
|
||||
readonly sender: string;
|
||||
/** Bech32-encoded contract address to be updated */
|
||||
readonly contract: string;
|
||||
};
|
||||
}
|
||||
|
||||
export const cosmWasmTypes: Record<string, AminoConverter> = {
|
||||
"/cosmwasm.wasm.v1.MsgStoreCode": {
|
||||
aminoType: "wasm/MsgStoreCode",
|
||||
toAmino: ({ sender, wasmByteCode }: MsgStoreCode): AminoMsgStoreCode["value"] => ({
|
||||
sender: sender,
|
||||
wasm_byte_code: toBase64(wasmByteCode),
|
||||
}),
|
||||
fromAmino: ({ sender, wasm_byte_code }: AminoMsgStoreCode["value"]): MsgStoreCode => ({
|
||||
sender: sender,
|
||||
wasmByteCode: fromBase64(wasm_byte_code),
|
||||
instantiatePermission: undefined,
|
||||
}),
|
||||
},
|
||||
"/cosmwasm.wasm.v1.MsgInstantiateContract": {
|
||||
aminoType: "wasm/MsgInstantiateContract",
|
||||
toAmino: ({
|
||||
sender,
|
||||
codeId,
|
||||
label,
|
||||
msg,
|
||||
funds,
|
||||
admin,
|
||||
}: MsgInstantiateContract): AminoMsgInstantiateContract["value"] => ({
|
||||
sender: sender,
|
||||
code_id: codeId.toString(),
|
||||
label: label,
|
||||
msg: JSON.parse(fromUtf8(msg)),
|
||||
funds: funds,
|
||||
admin: admin || undefined,
|
||||
}),
|
||||
fromAmino: ({
|
||||
sender,
|
||||
code_id,
|
||||
label,
|
||||
msg,
|
||||
funds,
|
||||
admin,
|
||||
}: AminoMsgInstantiateContract["value"]): MsgInstantiateContract => ({
|
||||
sender: sender,
|
||||
codeId: Long.fromString(code_id),
|
||||
label: label,
|
||||
msg: toUtf8(JSON.stringify(msg)),
|
||||
funds: [...funds],
|
||||
admin: admin ?? "",
|
||||
}),
|
||||
},
|
||||
"/cosmwasm.wasm.v1.MsgUpdateAdmin": {
|
||||
aminoType: "wasm/MsgUpdateAdmin",
|
||||
toAmino: ({ sender, newAdmin, contract }: MsgUpdateAdmin): AminoMsgUpdateAdmin["value"] => ({
|
||||
sender: sender,
|
||||
new_admin: newAdmin,
|
||||
contract: contract,
|
||||
}),
|
||||
fromAmino: ({ sender, new_admin, contract }: AminoMsgUpdateAdmin["value"]): MsgUpdateAdmin => ({
|
||||
sender: sender,
|
||||
newAdmin: new_admin,
|
||||
contract: contract,
|
||||
}),
|
||||
},
|
||||
"/cosmwasm.wasm.v1.MsgClearAdmin": {
|
||||
aminoType: "wasm/MsgClearAdmin",
|
||||
toAmino: ({ sender, contract }: MsgClearAdmin): AminoMsgClearAdmin["value"] => ({
|
||||
sender: sender,
|
||||
contract: contract,
|
||||
}),
|
||||
fromAmino: ({ sender, contract }: AminoMsgClearAdmin["value"]): MsgClearAdmin => ({
|
||||
sender: sender,
|
||||
contract: contract,
|
||||
}),
|
||||
},
|
||||
"/cosmwasm.wasm.v1.MsgExecuteContract": {
|
||||
aminoType: "wasm/MsgExecuteContract",
|
||||
toAmino: ({ sender, contract, msg, funds }: MsgExecuteContract): AminoMsgExecuteContract["value"] => ({
|
||||
sender: sender,
|
||||
contract: contract,
|
||||
msg: JSON.parse(fromUtf8(msg)),
|
||||
funds: funds,
|
||||
}),
|
||||
fromAmino: ({ sender, contract, msg, funds }: AminoMsgExecuteContract["value"]): MsgExecuteContract => ({
|
||||
sender: sender,
|
||||
contract: contract,
|
||||
msg: toUtf8(JSON.stringify(msg)),
|
||||
funds: [...funds],
|
||||
}),
|
||||
},
|
||||
"/cosmwasm.wasm.v1.MsgMigrateContract": {
|
||||
aminoType: "wasm/MsgMigrateContract",
|
||||
toAmino: ({ sender, contract, codeId, msg }: MsgMigrateContract): AminoMsgMigrateContract["value"] => ({
|
||||
sender: sender,
|
||||
contract: contract,
|
||||
code_id: codeId.toString(),
|
||||
msg: JSON.parse(fromUtf8(msg)),
|
||||
}),
|
||||
fromAmino: ({
|
||||
sender,
|
||||
contract,
|
||||
code_id,
|
||||
msg,
|
||||
}: AminoMsgMigrateContract["value"]): MsgMigrateContract => ({
|
||||
sender: sender,
|
||||
contract: contract,
|
||||
codeId: Long.fromString(code_id),
|
||||
msg: toUtf8(JSON.stringify(msg)),
|
||||
}),
|
||||
},
|
||||
};
|
||||
@ -28,7 +28,7 @@ import { assert, sleep } from "@cosmjs/utils";
|
||||
import { CodeInfoResponse } from "cosmjs-types/cosmwasm/wasm/v1/query";
|
||||
import { ContractCodeHistoryOperationType } from "cosmjs-types/cosmwasm/wasm/v1/types";
|
||||
|
||||
import { JsonObject, setupWasmExtension, WasmExtension } from "./queries";
|
||||
import { JsonObject, setupWasmExtension, WasmExtension } from "./modules";
|
||||
|
||||
export interface Code {
|
||||
readonly id: number;
|
||||
|
||||
@ -1,78 +0,0 @@
|
||||
import { EncodeObject } from "@cosmjs/proto-signing";
|
||||
import {
|
||||
MsgClearAdmin,
|
||||
MsgExecuteContract,
|
||||
MsgInstantiateContract,
|
||||
MsgMigrateContract,
|
||||
MsgStoreCode,
|
||||
MsgUpdateAdmin,
|
||||
} from "cosmjs-types/cosmwasm/wasm/v1/tx";
|
||||
|
||||
export interface MsgStoreCodeEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode";
|
||||
readonly value: Partial<MsgStoreCode>;
|
||||
}
|
||||
|
||||
export function isMsgStoreCodeEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgStoreCodeEncodeObject {
|
||||
return (encodeObject as MsgStoreCodeEncodeObject).typeUrl === "/cosmwasm.wasm.v1.MsgStoreCode";
|
||||
}
|
||||
|
||||
export interface MsgInstantiateContractEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract";
|
||||
readonly value: Partial<MsgInstantiateContract>;
|
||||
}
|
||||
|
||||
export function isMsgInstantiateContractEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgInstantiateContractEncodeObject {
|
||||
return (
|
||||
(encodeObject as MsgInstantiateContractEncodeObject).typeUrl ===
|
||||
"/cosmwasm.wasm.v1.MsgInstantiateContract"
|
||||
);
|
||||
}
|
||||
|
||||
export interface MsgUpdateAdminEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1.MsgUpdateAdmin";
|
||||
readonly value: Partial<MsgUpdateAdmin>;
|
||||
}
|
||||
|
||||
export function isMsgUpdateAdminEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgUpdateAdminEncodeObject {
|
||||
return (encodeObject as MsgUpdateAdminEncodeObject).typeUrl === "/cosmwasm.wasm.v1.MsgUpdateAdmin";
|
||||
}
|
||||
|
||||
export interface MsgClearAdminEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1.MsgClearAdmin";
|
||||
readonly value: Partial<MsgClearAdmin>;
|
||||
}
|
||||
|
||||
export function isMsgClearAdminEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgClearAdminEncodeObject {
|
||||
return (encodeObject as MsgClearAdminEncodeObject).typeUrl === "/cosmwasm.wasm.v1.MsgClearAdmin";
|
||||
}
|
||||
|
||||
export interface MsgMigrateContractEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1.MsgMigrateContract";
|
||||
readonly value: Partial<MsgMigrateContract>;
|
||||
}
|
||||
|
||||
export function isMsgMigrateEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgMigrateContractEncodeObject {
|
||||
return (encodeObject as MsgMigrateContractEncodeObject).typeUrl === "/cosmwasm.wasm.v1.MsgMigrateContract";
|
||||
}
|
||||
|
||||
export interface MsgExecuteContractEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract";
|
||||
readonly value: Partial<MsgExecuteContract>;
|
||||
}
|
||||
|
||||
export function isMsgExecuteEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgExecuteContractEncodeObject {
|
||||
return (encodeObject as MsgExecuteContractEncodeObject).typeUrl === "/cosmwasm.wasm.v1.MsgExecuteContract";
|
||||
}
|
||||
@ -1,21 +1,24 @@
|
||||
export { cosmWasmTypes } from "./aminotypes";
|
||||
export { Code, CodeDetails, Contract, ContractCodeHistoryEntry, CosmWasmClient } from "./cosmwasmclient";
|
||||
export { fromBinary, toBinary } from "./encoding";
|
||||
export {
|
||||
cosmWasmTypes,
|
||||
createWasmAminoConverters,
|
||||
isMsgClearAdminEncodeObject,
|
||||
isMsgExecuteEncodeObject,
|
||||
isMsgInstantiateContractEncodeObject,
|
||||
isMsgMigrateEncodeObject,
|
||||
isMsgStoreCodeEncodeObject,
|
||||
isMsgUpdateAdminEncodeObject,
|
||||
JsonObject,
|
||||
MsgClearAdminEncodeObject,
|
||||
MsgExecuteContractEncodeObject,
|
||||
MsgInstantiateContractEncodeObject,
|
||||
MsgMigrateContractEncodeObject,
|
||||
MsgStoreCodeEncodeObject,
|
||||
MsgUpdateAdminEncodeObject,
|
||||
} from "./encodeobjects";
|
||||
export { fromBinary, toBinary } from "./encoding";
|
||||
export { JsonObject, setupWasmExtension, WasmExtension } from "./queries";
|
||||
setupWasmExtension,
|
||||
WasmExtension,
|
||||
} from "./modules";
|
||||
export {
|
||||
ChangeAdminResult,
|
||||
ExecuteResult,
|
||||
|
||||
26
packages/cosmwasm-stargate/src/modules/index.ts
Normal file
26
packages/cosmwasm-stargate/src/modules/index.ts
Normal file
@ -0,0 +1,26 @@
|
||||
export {
|
||||
AminoMsgClearAdmin,
|
||||
AminoMsgExecuteContract,
|
||||
AminoMsgInstantiateContract,
|
||||
AminoMsgMigrateContract,
|
||||
AminoMsgStoreCode,
|
||||
AminoMsgUpdateAdmin,
|
||||
cosmWasmTypes,
|
||||
createWasmAminoConverters,
|
||||
} from "./wasm/aminomessages";
|
||||
export {
|
||||
isMsgClearAdminEncodeObject,
|
||||
isMsgExecuteEncodeObject,
|
||||
isMsgInstantiateContractEncodeObject,
|
||||
isMsgMigrateEncodeObject,
|
||||
isMsgStoreCodeEncodeObject,
|
||||
isMsgUpdateAdminEncodeObject,
|
||||
MsgClearAdminEncodeObject,
|
||||
MsgExecuteContractEncodeObject,
|
||||
MsgInstantiateContractEncodeObject,
|
||||
MsgMigrateContractEncodeObject,
|
||||
MsgStoreCodeEncodeObject,
|
||||
MsgUpdateAdminEncodeObject,
|
||||
wasmTypes,
|
||||
} from "./wasm/messages";
|
||||
export { JsonObject, setupWasmExtension, WasmExtension } from "./wasm/queries";
|
||||
@ -18,8 +18,8 @@ import {
|
||||
AminoMsgMigrateContract,
|
||||
AminoMsgStoreCode,
|
||||
AminoMsgUpdateAdmin,
|
||||
cosmWasmTypes,
|
||||
} from "./aminotypes";
|
||||
createWasmAminoConverters,
|
||||
} from "./aminomessages";
|
||||
|
||||
describe("AminoTypes", () => {
|
||||
describe("toAmino", () => {
|
||||
@ -29,7 +29,7 @@ describe("AminoTypes", () => {
|
||||
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
|
||||
instantiatePermission: undefined,
|
||||
};
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
|
||||
value: msg,
|
||||
});
|
||||
@ -54,10 +54,12 @@ describe("AminoTypes", () => {
|
||||
funds: coins(1234, "ucosm"),
|
||||
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
};
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
|
||||
value: msg,
|
||||
});
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino(
|
||||
{
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
|
||||
value: msg,
|
||||
},
|
||||
);
|
||||
const expected: AminoMsgInstantiateContract = {
|
||||
type: "wasm/MsgInstantiateContract",
|
||||
value: {
|
||||
@ -82,10 +84,12 @@ describe("AminoTypes", () => {
|
||||
funds: coins(1234, "ucosm"),
|
||||
admin: "",
|
||||
};
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
|
||||
value: msg,
|
||||
});
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino(
|
||||
{
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
|
||||
value: msg,
|
||||
},
|
||||
);
|
||||
const expected: AminoMsgInstantiateContract = {
|
||||
type: "wasm/MsgInstantiateContract",
|
||||
value: {
|
||||
@ -107,7 +111,7 @@ describe("AminoTypes", () => {
|
||||
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
};
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgUpdateAdmin",
|
||||
value: msg,
|
||||
});
|
||||
@ -127,7 +131,7 @@ describe("AminoTypes", () => {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
};
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgClearAdmin",
|
||||
value: msg,
|
||||
});
|
||||
@ -148,7 +152,7 @@ describe("AminoTypes", () => {
|
||||
msg: toUtf8(`{"foo":"bar"}`),
|
||||
funds: coins(1234, "ucosm"),
|
||||
};
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
||||
value: msg,
|
||||
});
|
||||
@ -171,7 +175,7 @@ describe("AminoTypes", () => {
|
||||
codeId: Long.fromString("98765"),
|
||||
msg: toUtf8(`{"foo":"bar"}`),
|
||||
};
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgMigrateContract",
|
||||
value: msg,
|
||||
});
|
||||
@ -197,7 +201,9 @@ describe("AminoTypes", () => {
|
||||
wasm_byte_code: "WUVMTE9XIFNVQk1BUklORQ==",
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
|
||||
aminoMsg,
|
||||
);
|
||||
const expectedValue: MsgStoreCode = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
|
||||
@ -223,7 +229,9 @@ describe("AminoTypes", () => {
|
||||
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
|
||||
aminoMsg,
|
||||
);
|
||||
const expectedValue: MsgInstantiateContract = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
codeId: Long.fromString("12345"),
|
||||
@ -250,7 +258,9 @@ describe("AminoTypes", () => {
|
||||
funds: coins(1234, "ucosm"),
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
|
||||
aminoMsg,
|
||||
);
|
||||
const expectedValue: MsgInstantiateContract = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
codeId: Long.fromString("12345"),
|
||||
@ -275,7 +285,9 @@ describe("AminoTypes", () => {
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
|
||||
aminoMsg,
|
||||
);
|
||||
const expectedValue: MsgUpdateAdmin = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
@ -295,7 +307,9 @@ describe("AminoTypes", () => {
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
|
||||
aminoMsg,
|
||||
);
|
||||
const expectedValue: MsgClearAdmin = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
@ -316,7 +330,9 @@ describe("AminoTypes", () => {
|
||||
funds: coins(1234, "ucosm"),
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
|
||||
aminoMsg,
|
||||
);
|
||||
const expectedValue: MsgExecuteContract = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
@ -339,7 +355,9 @@ describe("AminoTypes", () => {
|
||||
msg: { foo: "bar" },
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
|
||||
aminoMsg,
|
||||
);
|
||||
const expectedValue: MsgMigrateContract = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
242
packages/cosmwasm-stargate/src/modules/wasm/aminomessages.ts
Normal file
242
packages/cosmwasm-stargate/src/modules/wasm/aminomessages.ts
Normal file
@ -0,0 +1,242 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { fromBase64, fromUtf8, toBase64, toUtf8 } from "@cosmjs/encoding";
|
||||
import { AminoConverters, Coin } from "@cosmjs/stargate";
|
||||
import {
|
||||
MsgClearAdmin,
|
||||
MsgExecuteContract,
|
||||
MsgInstantiateContract,
|
||||
MsgMigrateContract,
|
||||
MsgStoreCode,
|
||||
MsgUpdateAdmin,
|
||||
} from "cosmjs-types/cosmwasm/wasm/v1/tx";
|
||||
import Long from "long";
|
||||
|
||||
// TODO: implement
|
||||
/**
|
||||
* @see https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/types.proto#L36-L41
|
||||
*/
|
||||
type AccessConfig = never;
|
||||
|
||||
/**
|
||||
* The Amino JSON representation of [MsgStoreCode].
|
||||
*
|
||||
* [MsgStoreCode]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L28-L39
|
||||
*/
|
||||
export interface AminoMsgStoreCode {
|
||||
type: "wasm/MsgStoreCode";
|
||||
value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
/** Base64 encoded Wasm */
|
||||
readonly wasm_byte_code: string;
|
||||
readonly instantiate_permission?: AccessConfig;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The Amino JSON representation of [MsgExecuteContract].
|
||||
*
|
||||
* [MsgExecuteContract]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L73-L86
|
||||
*/
|
||||
export interface AminoMsgExecuteContract {
|
||||
type: "wasm/MsgExecuteContract";
|
||||
value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
/** Bech32 account address */
|
||||
readonly contract: string;
|
||||
/** Execute message as JavaScript object */
|
||||
readonly msg: any;
|
||||
readonly funds: readonly Coin[];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The Amino JSON representation of [MsgInstantiateContract].
|
||||
*
|
||||
* [MsgInstantiateContract]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L46-L64
|
||||
*/
|
||||
export interface AminoMsgInstantiateContract {
|
||||
type: "wasm/MsgInstantiateContract";
|
||||
value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
/** ID of the Wasm code that was uploaded before */
|
||||
readonly code_id: string;
|
||||
/** Human-readable label for this contract */
|
||||
readonly label: string;
|
||||
/** Instantiate message as JavaScript object */
|
||||
readonly msg: any;
|
||||
readonly funds: readonly Coin[];
|
||||
/** Bech32-encoded admin address */
|
||||
readonly admin?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The Amino JSON representation of [MsgMigrateContract].
|
||||
*
|
||||
* [MsgMigrateContract]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L94-L104
|
||||
*/
|
||||
export interface AminoMsgMigrateContract {
|
||||
type: "wasm/MsgMigrateContract";
|
||||
value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
/** Bech32 account address */
|
||||
readonly contract: string;
|
||||
/** The new code */
|
||||
readonly code_id: string;
|
||||
/** Migrate message as JavaScript object */
|
||||
readonly msg: any;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The Amino JSON representation of [MsgUpdateAdmin].
|
||||
*
|
||||
* [MsgUpdateAdmin]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L113-L121
|
||||
*/
|
||||
export interface AminoMsgUpdateAdmin {
|
||||
type: "wasm/MsgUpdateAdmin";
|
||||
value: {
|
||||
/** Bech32-encoded sender address. This must be the old admin. */
|
||||
readonly sender: string;
|
||||
/** Bech32-encoded contract address to be updated */
|
||||
readonly contract: string;
|
||||
/** Bech32-encoded address of the new admin */
|
||||
readonly new_admin: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The Amino JSON representation of [MsgClearAdmin].
|
||||
*
|
||||
* [MsgClearAdmin]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L126-L132
|
||||
*/
|
||||
export interface AminoMsgClearAdmin {
|
||||
type: "wasm/MsgClearAdmin";
|
||||
value: {
|
||||
/** Bech32-encoded sender address. This must be the old admin. */
|
||||
readonly sender: string;
|
||||
/** Bech32-encoded contract address to be updated */
|
||||
readonly contract: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function createWasmAminoConverters(): AminoConverters {
|
||||
return {
|
||||
"/cosmwasm.wasm.v1.MsgStoreCode": {
|
||||
aminoType: "wasm/MsgStoreCode",
|
||||
toAmino: ({ sender, wasmByteCode }: MsgStoreCode): AminoMsgStoreCode["value"] => ({
|
||||
sender: sender,
|
||||
wasm_byte_code: toBase64(wasmByteCode),
|
||||
}),
|
||||
fromAmino: ({ sender, wasm_byte_code }: AminoMsgStoreCode["value"]): MsgStoreCode => ({
|
||||
sender: sender,
|
||||
wasmByteCode: fromBase64(wasm_byte_code),
|
||||
instantiatePermission: undefined,
|
||||
}),
|
||||
},
|
||||
"/cosmwasm.wasm.v1.MsgInstantiateContract": {
|
||||
aminoType: "wasm/MsgInstantiateContract",
|
||||
toAmino: ({
|
||||
sender,
|
||||
codeId,
|
||||
label,
|
||||
msg,
|
||||
funds,
|
||||
admin,
|
||||
}: MsgInstantiateContract): AminoMsgInstantiateContract["value"] => ({
|
||||
sender: sender,
|
||||
code_id: codeId.toString(),
|
||||
label: label,
|
||||
msg: JSON.parse(fromUtf8(msg)),
|
||||
funds: funds,
|
||||
admin: admin || undefined,
|
||||
}),
|
||||
fromAmino: ({
|
||||
sender,
|
||||
code_id,
|
||||
label,
|
||||
msg,
|
||||
funds,
|
||||
admin,
|
||||
}: AminoMsgInstantiateContract["value"]): MsgInstantiateContract => ({
|
||||
sender: sender,
|
||||
codeId: Long.fromString(code_id),
|
||||
label: label,
|
||||
msg: toUtf8(JSON.stringify(msg)),
|
||||
funds: [...funds],
|
||||
admin: admin ?? "",
|
||||
}),
|
||||
},
|
||||
"/cosmwasm.wasm.v1.MsgUpdateAdmin": {
|
||||
aminoType: "wasm/MsgUpdateAdmin",
|
||||
toAmino: ({ sender, newAdmin, contract }: MsgUpdateAdmin): AminoMsgUpdateAdmin["value"] => ({
|
||||
sender: sender,
|
||||
new_admin: newAdmin,
|
||||
contract: contract,
|
||||
}),
|
||||
fromAmino: ({ sender, new_admin, contract }: AminoMsgUpdateAdmin["value"]): MsgUpdateAdmin => ({
|
||||
sender: sender,
|
||||
newAdmin: new_admin,
|
||||
contract: contract,
|
||||
}),
|
||||
},
|
||||
"/cosmwasm.wasm.v1.MsgClearAdmin": {
|
||||
aminoType: "wasm/MsgClearAdmin",
|
||||
toAmino: ({ sender, contract }: MsgClearAdmin): AminoMsgClearAdmin["value"] => ({
|
||||
sender: sender,
|
||||
contract: contract,
|
||||
}),
|
||||
fromAmino: ({ sender, contract }: AminoMsgClearAdmin["value"]): MsgClearAdmin => ({
|
||||
sender: sender,
|
||||
contract: contract,
|
||||
}),
|
||||
},
|
||||
"/cosmwasm.wasm.v1.MsgExecuteContract": {
|
||||
aminoType: "wasm/MsgExecuteContract",
|
||||
toAmino: ({ sender, contract, msg, funds }: MsgExecuteContract): AminoMsgExecuteContract["value"] => ({
|
||||
sender: sender,
|
||||
contract: contract,
|
||||
msg: JSON.parse(fromUtf8(msg)),
|
||||
funds: funds,
|
||||
}),
|
||||
fromAmino: ({
|
||||
sender,
|
||||
contract,
|
||||
msg,
|
||||
funds,
|
||||
}: AminoMsgExecuteContract["value"]): MsgExecuteContract => ({
|
||||
sender: sender,
|
||||
contract: contract,
|
||||
msg: toUtf8(JSON.stringify(msg)),
|
||||
funds: [...funds],
|
||||
}),
|
||||
},
|
||||
"/cosmwasm.wasm.v1.MsgMigrateContract": {
|
||||
aminoType: "wasm/MsgMigrateContract",
|
||||
toAmino: ({ sender, contract, codeId, msg }: MsgMigrateContract): AminoMsgMigrateContract["value"] => ({
|
||||
sender: sender,
|
||||
contract: contract,
|
||||
code_id: codeId.toString(),
|
||||
msg: JSON.parse(fromUtf8(msg)),
|
||||
}),
|
||||
fromAmino: ({
|
||||
sender,
|
||||
contract,
|
||||
code_id,
|
||||
msg,
|
||||
}: AminoMsgMigrateContract["value"]): MsgMigrateContract => ({
|
||||
sender: sender,
|
||||
contract: contract,
|
||||
codeId: Long.fromString(code_id),
|
||||
msg: toUtf8(JSON.stringify(msg)),
|
||||
}),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** @deprecated use `createWasmAminoConverters()` */
|
||||
export const cosmWasmTypes: AminoConverters = createWasmAminoConverters();
|
||||
76
packages/cosmwasm-stargate/src/modules/wasm/messages.ts
Normal file
76
packages/cosmwasm-stargate/src/modules/wasm/messages.ts
Normal file
@ -0,0 +1,76 @@
|
||||
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing";
|
||||
import {
|
||||
MsgClearAdmin,
|
||||
MsgExecuteContract,
|
||||
MsgInstantiateContract,
|
||||
MsgMigrateContract,
|
||||
MsgStoreCode,
|
||||
MsgUpdateAdmin,
|
||||
} from "cosmjs-types/cosmwasm/wasm/v1/tx";
|
||||
|
||||
export const wasmTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
["/cosmwasm.wasm.v1.MsgClearAdmin", MsgClearAdmin],
|
||||
["/cosmwasm.wasm.v1.MsgExecuteContract", MsgExecuteContract],
|
||||
["/cosmwasm.wasm.v1.MsgMigrateContract", MsgMigrateContract],
|
||||
["/cosmwasm.wasm.v1.MsgStoreCode", MsgStoreCode],
|
||||
["/cosmwasm.wasm.v1.MsgInstantiateContract", MsgInstantiateContract],
|
||||
["/cosmwasm.wasm.v1.MsgUpdateAdmin", MsgUpdateAdmin],
|
||||
];
|
||||
|
||||
export interface MsgStoreCodeEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode";
|
||||
readonly value: Partial<MsgStoreCode>;
|
||||
}
|
||||
|
||||
export function isMsgStoreCodeEncodeObject(object: EncodeObject): object is MsgStoreCodeEncodeObject {
|
||||
return (object as MsgStoreCodeEncodeObject).typeUrl === "/cosmwasm.wasm.v1.MsgStoreCode";
|
||||
}
|
||||
|
||||
export interface MsgInstantiateContractEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract";
|
||||
readonly value: Partial<MsgInstantiateContract>;
|
||||
}
|
||||
|
||||
export function isMsgInstantiateContractEncodeObject(
|
||||
object: EncodeObject,
|
||||
): object is MsgInstantiateContractEncodeObject {
|
||||
return (
|
||||
(object as MsgInstantiateContractEncodeObject).typeUrl === "/cosmwasm.wasm.v1.MsgInstantiateContract"
|
||||
);
|
||||
}
|
||||
|
||||
export interface MsgUpdateAdminEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1.MsgUpdateAdmin";
|
||||
readonly value: Partial<MsgUpdateAdmin>;
|
||||
}
|
||||
|
||||
export function isMsgUpdateAdminEncodeObject(object: EncodeObject): object is MsgUpdateAdminEncodeObject {
|
||||
return (object as MsgUpdateAdminEncodeObject).typeUrl === "/cosmwasm.wasm.v1.MsgUpdateAdmin";
|
||||
}
|
||||
|
||||
export interface MsgClearAdminEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1.MsgClearAdmin";
|
||||
readonly value: Partial<MsgClearAdmin>;
|
||||
}
|
||||
|
||||
export function isMsgClearAdminEncodeObject(object: EncodeObject): object is MsgClearAdminEncodeObject {
|
||||
return (object as MsgClearAdminEncodeObject).typeUrl === "/cosmwasm.wasm.v1.MsgClearAdmin";
|
||||
}
|
||||
|
||||
export interface MsgMigrateContractEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1.MsgMigrateContract";
|
||||
readonly value: Partial<MsgMigrateContract>;
|
||||
}
|
||||
|
||||
export function isMsgMigrateEncodeObject(object: EncodeObject): object is MsgMigrateContractEncodeObject {
|
||||
return (object as MsgMigrateContractEncodeObject).typeUrl === "/cosmwasm.wasm.v1.MsgMigrateContract";
|
||||
}
|
||||
|
||||
export interface MsgExecuteContractEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract";
|
||||
readonly value: Partial<MsgExecuteContract>;
|
||||
}
|
||||
|
||||
export function isMsgExecuteEncodeObject(object: EncodeObject): object is MsgExecuteContractEncodeObject {
|
||||
return (object as MsgExecuteContractEncodeObject).typeUrl === "/cosmwasm.wasm.v1.MsgExecuteContract";
|
||||
}
|
||||
@ -16,12 +16,7 @@ import { MsgExecuteContract, MsgInstantiateContract, MsgStoreCode } from "cosmjs
|
||||
import { ContractCodeHistoryOperationType } from "cosmjs-types/cosmwasm/wasm/v1/types";
|
||||
import Long from "long";
|
||||
|
||||
import {
|
||||
MsgExecuteContractEncodeObject,
|
||||
MsgInstantiateContractEncodeObject,
|
||||
MsgStoreCodeEncodeObject,
|
||||
} from "../encodeobjects";
|
||||
import { SigningCosmWasmClient } from "../signingcosmwasmclient";
|
||||
import { SigningCosmWasmClient } from "../../signingcosmwasmclient";
|
||||
import {
|
||||
alice,
|
||||
bech32AddressMatcher,
|
||||
@ -33,13 +28,15 @@ import {
|
||||
pendingWithoutWasmd,
|
||||
wasmd,
|
||||
wasmdEnabled,
|
||||
} from "../testutils.spec";
|
||||
} from "../../testutils.spec";
|
||||
import {
|
||||
MsgExecuteContractEncodeObject,
|
||||
MsgInstantiateContractEncodeObject,
|
||||
MsgStoreCodeEncodeObject,
|
||||
wasmTypes,
|
||||
} from "./messages";
|
||||
|
||||
const registry = new Registry([
|
||||
["/cosmwasm.wasm.v1.MsgExecuteContract", MsgExecuteContract],
|
||||
["/cosmwasm.wasm.v1.MsgStoreCode", MsgStoreCode],
|
||||
["/cosmwasm.wasm.v1.MsgInstantiateContract", MsgInstantiateContract],
|
||||
]);
|
||||
const registry = new Registry(wasmTypes);
|
||||
|
||||
async function uploadContract(
|
||||
signer: OfflineDirectSigner,
|
||||
@ -1 +0,0 @@
|
||||
export { JsonObject, setupWasmExtension, WasmExtension } from "./wasm";
|
||||
@ -22,7 +22,7 @@ import Long from "long";
|
||||
import pako from "pako";
|
||||
import protobuf from "protobufjs/minimal";
|
||||
|
||||
import { MsgExecuteContractEncodeObject, MsgStoreCodeEncodeObject } from "./encodeobjects";
|
||||
import { MsgExecuteContractEncodeObject, MsgStoreCodeEncodeObject } from "./modules";
|
||||
import { SigningCosmWasmClient } from "./signingcosmwasmclient";
|
||||
import {
|
||||
alice,
|
||||
|
||||
@ -46,16 +46,17 @@ import {
|
||||
import Long from "long";
|
||||
import pako from "pako";
|
||||
|
||||
import { cosmWasmTypes } from "./aminotypes";
|
||||
import { CosmWasmClient } from "./cosmwasmclient";
|
||||
import {
|
||||
createWasmAminoConverters,
|
||||
MsgClearAdminEncodeObject,
|
||||
MsgExecuteContractEncodeObject,
|
||||
MsgInstantiateContractEncodeObject,
|
||||
MsgMigrateContractEncodeObject,
|
||||
MsgStoreCodeEncodeObject,
|
||||
MsgUpdateAdminEncodeObject,
|
||||
} from "./encodeobjects";
|
||||
wasmTypes,
|
||||
} from "./modules";
|
||||
|
||||
export interface UploadResult {
|
||||
/** Size of the original wasm code in bytes */
|
||||
@ -148,14 +149,7 @@ function createDeliverTxResponseErrorMessage(result: DeliverTxResponse): string
|
||||
}
|
||||
|
||||
function createDefaultRegistry(): Registry {
|
||||
const registry = new Registry(defaultStargateTypes);
|
||||
registry.register("/cosmwasm.wasm.v1.MsgClearAdmin", MsgClearAdmin);
|
||||
registry.register("/cosmwasm.wasm.v1.MsgExecuteContract", MsgExecuteContract);
|
||||
registry.register("/cosmwasm.wasm.v1.MsgMigrateContract", MsgMigrateContract);
|
||||
registry.register("/cosmwasm.wasm.v1.MsgStoreCode", MsgStoreCode);
|
||||
registry.register("/cosmwasm.wasm.v1.MsgInstantiateContract", MsgInstantiateContract);
|
||||
registry.register("/cosmwasm.wasm.v1.MsgUpdateAdmin", MsgUpdateAdmin);
|
||||
return registry;
|
||||
return new Registry([...defaultStargateTypes, ...wasmTypes]);
|
||||
}
|
||||
|
||||
export interface SigningCosmWasmClientOptions {
|
||||
@ -211,7 +205,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
const prefix = options.prefix ?? "cosmos";
|
||||
const {
|
||||
registry = createDefaultRegistry(),
|
||||
aminoTypes = new AminoTypes({ prefix, additions: cosmWasmTypes }),
|
||||
aminoTypes = new AminoTypes({ prefix, additions: createWasmAminoConverters() }),
|
||||
} = options;
|
||||
this.registry = registry;
|
||||
this.aminoTypes = aminoTypes;
|
||||
|
||||
@ -22,7 +22,7 @@ import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
|
||||
import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
|
||||
import { AuthInfo, SignDoc, TxBody } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
||||
|
||||
import { setupWasmExtension, WasmExtension } from "./queries";
|
||||
import { setupWasmExtension, WasmExtension } from "./modules";
|
||||
import { SigningCosmWasmClientOptions } from "./signingcosmwasmclient";
|
||||
import hackatom from "./testdata/contract.json";
|
||||
|
||||
|
||||
8
packages/stargate/src/aminoconverters.ts
Normal file
8
packages/stargate/src/aminoconverters.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export interface AminoConverter {
|
||||
readonly aminoType: string;
|
||||
readonly toAmino: (value: any) => any;
|
||||
readonly fromAmino: (value: any) => any;
|
||||
}
|
||||
|
||||
/** A map from protobuf type URL to the AminoConverter implementation if supported on chain */
|
||||
export type AminoConverters = Record<string, AminoConverter | "not_supported_by_chain">;
|
||||
@ -1,390 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoMsg, Coin } from "@cosmjs/amino";
|
||||
|
||||
// auth (no messages) - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/auth/auth.proto
|
||||
|
||||
// bank - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/bank/bank.proto
|
||||
|
||||
/** A high level transaction of the coin module */
|
||||
export interface AminoMsgSend extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgSend";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly from_address: string;
|
||||
/** Bech32 account address */
|
||||
readonly to_address: string;
|
||||
readonly amount: readonly Coin[];
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgSend(msg: AminoMsg): msg is AminoMsgSend {
|
||||
return msg.type === "cosmos-sdk/MsgSend";
|
||||
}
|
||||
|
||||
interface Input {
|
||||
/** Bech32 account address */
|
||||
readonly address: string;
|
||||
readonly coins: readonly Coin[];
|
||||
}
|
||||
|
||||
interface Output {
|
||||
/** Bech32 account address */
|
||||
readonly address: string;
|
||||
readonly coins: readonly Coin[];
|
||||
}
|
||||
|
||||
/** A high level transaction of the coin module */
|
||||
export interface AminoMsgMultiSend extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgMultiSend";
|
||||
readonly value: {
|
||||
readonly inputs: readonly Input[];
|
||||
readonly outputs: readonly Output[];
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgMultiSend(msg: AminoMsg): msg is AminoMsgMultiSend {
|
||||
return msg.type === "cosmos-sdk/MsgMultiSend";
|
||||
}
|
||||
|
||||
// crisis - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/crisis/crisis.proto
|
||||
|
||||
/** Verifies a particular invariance */
|
||||
export interface AminoMsgVerifyInvariant extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgVerifyInvariant";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
readonly invariant_module_name: string;
|
||||
readonly invariant_route: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgVerifyInvariant(msg: AminoMsg): msg is AminoMsgVerifyInvariant {
|
||||
return msg.type === "cosmos-sdk/MsgVerifyInvariant";
|
||||
}
|
||||
|
||||
// distribution - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/distribution/distribution.proto
|
||||
|
||||
/** Changes the withdraw address for a delegator (or validator self-delegation) */
|
||||
export interface AminoMsgSetWithdrawAddress extends AminoMsg {
|
||||
// NOTE: Type string and names diverge here!
|
||||
readonly type: "cosmos-sdk/MsgModifyWithdrawAddress";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly delegator_address: string;
|
||||
/** Bech32 account address */
|
||||
readonly withdraw_address: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgSetWithdrawAddress(msg: AminoMsg): msg is AminoMsgSetWithdrawAddress {
|
||||
// NOTE: Type string and names diverge here!
|
||||
return msg.type === "cosmos-sdk/MsgModifyWithdrawAddress";
|
||||
}
|
||||
|
||||
/** Message for delegation withdraw from a single validator */
|
||||
export interface AminoMsgWithdrawDelegatorReward extends AminoMsg {
|
||||
// NOTE: Type string and names diverge here!
|
||||
readonly type: "cosmos-sdk/MsgWithdrawDelegationReward";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly delegator_address: string;
|
||||
/** Bech32 account address */
|
||||
readonly validator_address: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgWithdrawDelegatorReward(msg: AminoMsg): msg is AminoMsgWithdrawDelegatorReward {
|
||||
// NOTE: Type string and names diverge here!
|
||||
return msg.type === "cosmos-sdk/MsgWithdrawDelegationReward";
|
||||
}
|
||||
|
||||
/** Message for validator withdraw */
|
||||
export interface AminoMsgWithdrawValidatorCommission extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgWithdrawValidatorCommission";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly validator_address: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgWithdrawValidatorCommission(
|
||||
msg: AminoMsg,
|
||||
): msg is AminoMsgWithdrawValidatorCommission {
|
||||
return msg.type === "cosmos-sdk/MsgWithdrawValidatorCommission";
|
||||
}
|
||||
|
||||
/** Allows an account to directly fund the community pool. */
|
||||
export interface AminoMsgFundCommunityPool extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgFundCommunityPool";
|
||||
readonly value: {
|
||||
readonly amount: readonly Coin[];
|
||||
/** Bech32 account address */
|
||||
readonly depositor: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgFundCommunityPool(msg: AminoMsg): msg is AminoMsgFundCommunityPool {
|
||||
return msg.type === "cosmos-sdk/MsgFundCommunityPool";
|
||||
}
|
||||
|
||||
// evidence - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/evidence/evidence.proto
|
||||
|
||||
interface Any {
|
||||
readonly type_url: string;
|
||||
readonly value: Uint8Array;
|
||||
}
|
||||
|
||||
/** Supports submitting arbitrary evidence */
|
||||
export interface AminoMsgSubmitEvidence extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgSubmitEvidence";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly submitter: string;
|
||||
readonly evidence: Any;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgSubmitEvidence(msg: AminoMsg): msg is AminoMsgSubmitEvidence {
|
||||
return msg.type === "cosmos-sdk/MsgSubmitEvidence";
|
||||
}
|
||||
|
||||
// gov - https://github.com/cosmos/cosmos-sdk/blob/efa73c7edb31a7bd65786501da213b294f89267a/proto/cosmos/gov/gov.proto
|
||||
|
||||
/** Supports submitting arbitrary proposal content. */
|
||||
export interface AminoMsgSubmitProposal extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgSubmitProposal";
|
||||
readonly value: {
|
||||
/**
|
||||
* A proposal structure, e.g.
|
||||
*
|
||||
* ```
|
||||
* {
|
||||
* type: 'cosmos-sdk/TextProposal',
|
||||
* value: {
|
||||
* description: 'This proposal proposes to test whether this proposal passes',
|
||||
* title: 'Test Proposal'
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
readonly content: {
|
||||
readonly type: string;
|
||||
readonly value: any;
|
||||
};
|
||||
readonly initial_deposit: readonly Coin[];
|
||||
/** Bech32 account address */
|
||||
readonly proposer: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgSubmitProposal(msg: AminoMsg): msg is AminoMsgSubmitProposal {
|
||||
return msg.type === "cosmos-sdk/MsgSubmitProposal";
|
||||
}
|
||||
|
||||
/** Casts a vote */
|
||||
export interface AminoMsgVote extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgVote";
|
||||
readonly value: {
|
||||
readonly proposal_id: string;
|
||||
/** Bech32 account address */
|
||||
readonly voter: string;
|
||||
/**
|
||||
* VoteOption as integer from 0 to 4 🤷
|
||||
*
|
||||
* @see https://github.com/cosmos/cosmos-sdk/blob/v0.42.9/x/gov/types/gov.pb.go#L38-L49
|
||||
*/
|
||||
readonly option: number;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgVote(msg: AminoMsg): msg is AminoMsgVote {
|
||||
return msg.type === "cosmos-sdk/MsgVote";
|
||||
}
|
||||
|
||||
/** Submits a deposit to an existing proposal */
|
||||
export interface AminoMsgDeposit extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgDeposit";
|
||||
readonly value: {
|
||||
readonly proposal_id: string;
|
||||
/** Bech32 account address */
|
||||
readonly depositor: string;
|
||||
readonly amount: readonly Coin[];
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgDeposit(msg: AminoMsg): msg is AminoMsgDeposit {
|
||||
return msg.type === "cosmos-sdk/MsgDeposit";
|
||||
}
|
||||
|
||||
// mint (no messages) - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/mint/mint.proto
|
||||
|
||||
// params (no messages) - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/params/params.proto
|
||||
|
||||
// slashing - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/slashing/slashing.proto
|
||||
|
||||
/** Unjails a jailed validator */
|
||||
export interface AminoMsgUnjail extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgUnjail";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly validator_addr: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgUnjail(msg: AminoMsg): msg is AminoMsgUnjail {
|
||||
return msg.type === "cosmos-sdk/MsgUnjail";
|
||||
}
|
||||
|
||||
// staking - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/staking/staking.proto
|
||||
|
||||
/** The initial commission rates to be used for creating a validator */
|
||||
interface CommissionRates {
|
||||
readonly rate: string;
|
||||
readonly max_rate: string;
|
||||
readonly max_change_rate: string;
|
||||
}
|
||||
|
||||
/** A validator description. */
|
||||
interface Description {
|
||||
readonly moniker: string;
|
||||
readonly identity: string;
|
||||
readonly website: string;
|
||||
readonly security_contact: string;
|
||||
readonly details: string;
|
||||
}
|
||||
|
||||
/** Creates a new validator. */
|
||||
export interface AminoMsgCreateValidator extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgCreateValidator";
|
||||
readonly value: {
|
||||
readonly description: Description;
|
||||
readonly commission: CommissionRates;
|
||||
readonly min_self_delegation: string;
|
||||
/** Bech32 encoded delegator address */
|
||||
readonly delegator_address: string;
|
||||
/** Bech32 encoded validator address */
|
||||
readonly validator_address: string;
|
||||
/** Bech32 encoded public key */
|
||||
readonly pubkey: string;
|
||||
readonly value: Coin;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgCreateValidator(msg: AminoMsg): msg is AminoMsgCreateValidator {
|
||||
return msg.type === "cosmos-sdk/MsgCreateValidator";
|
||||
}
|
||||
|
||||
/** Edits an existing validator. */
|
||||
export interface AminoMsgEditValidator extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgEditValidator";
|
||||
readonly value: {
|
||||
readonly description: Description;
|
||||
/** Bech32 encoded validator address */
|
||||
readonly validator_address: string;
|
||||
readonly commission_rate: string;
|
||||
readonly min_self_delegation: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgEditValidator(msg: AminoMsg): msg is AminoMsgEditValidator {
|
||||
return msg.type === "cosmos-sdk/MsgEditValidator";
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a delegation from a delegate to a validator.
|
||||
*
|
||||
* @see https://docs.cosmos.network/master/modules/staking/03_messages.html#msgdelegate
|
||||
*/
|
||||
export interface AminoMsgDelegate extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgDelegate";
|
||||
readonly value: {
|
||||
/** Bech32 encoded delegator address */
|
||||
readonly delegator_address: string;
|
||||
/** Bech32 encoded validator address */
|
||||
readonly validator_address: string;
|
||||
readonly amount: Coin;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgDelegate(msg: AminoMsg): msg is AminoMsgDelegate {
|
||||
return msg.type === "cosmos-sdk/MsgDelegate";
|
||||
}
|
||||
|
||||
/** Performs a redelegation from a delegate and source validator to a destination validator */
|
||||
export interface AminoMsgBeginRedelegate extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgBeginRedelegate";
|
||||
readonly value: {
|
||||
/** Bech32 encoded delegator address */
|
||||
readonly delegator_address: string;
|
||||
/** Bech32 encoded source validator address */
|
||||
readonly validator_src_address: string;
|
||||
/** Bech32 encoded destination validator address */
|
||||
readonly validator_dst_address: string;
|
||||
readonly amount: Coin;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgBeginRedelegate(msg: AminoMsg): msg is AminoMsgBeginRedelegate {
|
||||
return msg.type === "cosmos-sdk/MsgBeginRedelegate";
|
||||
}
|
||||
|
||||
/** Performs an undelegation from a delegate and a validator */
|
||||
export interface AminoMsgUndelegate extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgUndelegate";
|
||||
readonly value: {
|
||||
/** Bech32 encoded delegator address */
|
||||
readonly delegator_address: string;
|
||||
/** Bech32 encoded validator address */
|
||||
readonly validator_address: string;
|
||||
readonly amount: Coin;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgUndelegate(msg: AminoMsg): msg is AminoMsgUndelegate {
|
||||
return msg.type === "cosmos-sdk/MsgUndelegate";
|
||||
}
|
||||
|
||||
// upgrade (no messages) - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/upgrade/upgrade.proto
|
||||
|
||||
// ibc
|
||||
|
||||
// https://github.com/cosmos/ibc-go/blob/07b6a97b67d17fd214a83764cbdb2c2c3daef445/modules/core/02-client/types/client.pb.go#L297-L312
|
||||
interface AminoHeight {
|
||||
/** 0 values must be omitted (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/core/02-client/types/client.pb.go#L252). */
|
||||
readonly revision_number?: string;
|
||||
/** 0 values must be omitted (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/core/02-client/types/client.pb.go#L254). */
|
||||
readonly revision_height?: string;
|
||||
}
|
||||
|
||||
// https://github.com/cosmos/ibc-go/blob/07b6a97b67d17fd214a83764cbdb2c2c3daef445/modules/apps/transfer/types/tx.pb.go#L33-L53
|
||||
/** Transfers fungible tokens (i.e Coins) between ICS20 enabled chains */
|
||||
export interface AminoMsgTransfer extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgTransfer";
|
||||
readonly value: {
|
||||
readonly source_port: string;
|
||||
readonly source_channel: string;
|
||||
readonly token?: Coin;
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
/** Bech32 account address */
|
||||
readonly receiver: string;
|
||||
/**
|
||||
* The timeout as a (revision_number, revision_height) pair.
|
||||
*
|
||||
* This fied is is non-optional (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/applications/transfer/types/tx.pb.go#L49).
|
||||
* In order to not set the timeout height, set it to {}.
|
||||
*/
|
||||
readonly timeout_height: AminoHeight;
|
||||
/**
|
||||
* Timeout timestamp in nanoseconds since Unix epoch. The timeout is disabled when set to 0.
|
||||
*
|
||||
* 0 values must be omitted (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/applications/transfer/types/tx.pb.go#L52).
|
||||
*/
|
||||
readonly timeout_timestamp?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgTransfer(msg: AminoMsg): msg is AminoMsgTransfer {
|
||||
return msg.type === "cosmos-sdk/MsgTransfer";
|
||||
}
|
||||
@ -21,6 +21,7 @@ import {
|
||||
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
|
||||
import Long from "long";
|
||||
|
||||
import { AminoTypes } from "./aminotypes";
|
||||
import {
|
||||
AminoMsgBeginRedelegate,
|
||||
AminoMsgCreateValidator,
|
||||
@ -37,8 +38,7 @@ import {
|
||||
AminoMsgVote,
|
||||
AminoMsgWithdrawDelegatorReward,
|
||||
AminoMsgWithdrawValidatorCommission,
|
||||
} from "./aminomsgs";
|
||||
import { AminoTypes } from "./aminotypes";
|
||||
} from "./modules";
|
||||
|
||||
describe("AminoTypes", () => {
|
||||
describe("constructor", () => {
|
||||
|
||||
@ -1,519 +1,27 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoMsg, decodeBech32Pubkey, encodeBech32Pubkey } from "@cosmjs/amino";
|
||||
import { fromBase64, toBase64 } from "@cosmjs/encoding";
|
||||
import { AminoMsg } from "@cosmjs/amino";
|
||||
import { EncodeObject } from "@cosmjs/proto-signing";
|
||||
import { assert, assertDefinedAndNotNull, isNonNullObject } from "@cosmjs/utils";
|
||||
import { MsgMultiSend, MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
|
||||
|
||||
import { AminoConverter, AminoConverters } from "./aminoconverters";
|
||||
import {
|
||||
MsgFundCommunityPool,
|
||||
MsgSetWithdrawAddress,
|
||||
MsgWithdrawDelegatorReward,
|
||||
MsgWithdrawValidatorCommission,
|
||||
} from "cosmjs-types/cosmos/distribution/v1beta1/tx";
|
||||
import { TextProposal, voteOptionFromJSON } from "cosmjs-types/cosmos/gov/v1beta1/gov";
|
||||
import { MsgDeposit, MsgSubmitProposal, MsgVote } from "cosmjs-types/cosmos/gov/v1beta1/tx";
|
||||
import {
|
||||
MsgBeginRedelegate,
|
||||
MsgCreateValidator,
|
||||
MsgDelegate,
|
||||
MsgEditValidator,
|
||||
MsgUndelegate,
|
||||
} from "cosmjs-types/cosmos/staking/v1beta1/tx";
|
||||
import { Any } from "cosmjs-types/google/protobuf/any";
|
||||
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
|
||||
import Long from "long";
|
||||
createAuthzAminoConverters,
|
||||
createBankAminoConverters,
|
||||
createDistributionAminoConverters,
|
||||
createFreegrantAminoConverters,
|
||||
createGovAminoConverters,
|
||||
createIbcAminoConverters,
|
||||
createStakingAminoConverters,
|
||||
} from "./modules";
|
||||
|
||||
import {
|
||||
AminoMsgBeginRedelegate,
|
||||
AminoMsgCreateValidator,
|
||||
AminoMsgDelegate,
|
||||
AminoMsgDeposit,
|
||||
AminoMsgEditValidator,
|
||||
AminoMsgFundCommunityPool,
|
||||
AminoMsgMultiSend,
|
||||
AminoMsgSend,
|
||||
AminoMsgSetWithdrawAddress,
|
||||
AminoMsgSubmitProposal,
|
||||
AminoMsgTransfer,
|
||||
AminoMsgUndelegate,
|
||||
AminoMsgVote,
|
||||
AminoMsgWithdrawDelegatorReward,
|
||||
AminoMsgWithdrawValidatorCommission,
|
||||
} from "./aminomsgs";
|
||||
|
||||
export interface AminoConverter {
|
||||
readonly aminoType: string;
|
||||
readonly toAmino: (value: any) => any;
|
||||
readonly fromAmino: (value: any) => any;
|
||||
}
|
||||
|
||||
function omitDefault<T extends string | number | Long>(input: T): T | undefined {
|
||||
if (typeof input === "string") {
|
||||
return input === "" ? undefined : input;
|
||||
}
|
||||
|
||||
if (typeof input === "number") {
|
||||
return input === 0 ? undefined : input;
|
||||
}
|
||||
|
||||
if (Long.isLong(input)) {
|
||||
return input.isZero() ? undefined : input;
|
||||
}
|
||||
|
||||
throw new Error(`Got unsupported type '${typeof input}'`);
|
||||
}
|
||||
|
||||
function createDefaultTypes(prefix: string): Record<string, AminoConverter | "not_supported_by_chain"> {
|
||||
function createDefaultTypes(prefix: string): AminoConverters {
|
||||
return {
|
||||
// authz
|
||||
"/cosmos.authz.v1beta1.MsgGrant": "not_supported_by_chain",
|
||||
"/cosmos.authz.v1beta1.MsgExec": "not_supported_by_chain",
|
||||
"/cosmos.authz.v1beta1.MsgRevoke": "not_supported_by_chain",
|
||||
|
||||
// bank
|
||||
"/cosmos.bank.v1beta1.MsgSend": {
|
||||
aminoType: "cosmos-sdk/MsgSend",
|
||||
toAmino: ({ fromAddress, toAddress, amount }: MsgSend): AminoMsgSend["value"] => ({
|
||||
from_address: fromAddress,
|
||||
to_address: toAddress,
|
||||
amount: [...amount],
|
||||
}),
|
||||
fromAmino: ({ from_address, to_address, amount }: AminoMsgSend["value"]): MsgSend => ({
|
||||
fromAddress: from_address,
|
||||
toAddress: to_address,
|
||||
amount: [...amount],
|
||||
}),
|
||||
},
|
||||
"/cosmos.bank.v1beta1.MsgMultiSend": {
|
||||
aminoType: "cosmos-sdk/MsgMultiSend",
|
||||
toAmino: ({ inputs, outputs }: MsgMultiSend): AminoMsgMultiSend["value"] => ({
|
||||
inputs: inputs.map((input) => ({
|
||||
address: input.address,
|
||||
coins: [...input.coins],
|
||||
})),
|
||||
outputs: outputs.map((output) => ({
|
||||
address: output.address,
|
||||
coins: [...output.coins],
|
||||
})),
|
||||
}),
|
||||
fromAmino: ({ inputs, outputs }: AminoMsgMultiSend["value"]): MsgMultiSend => ({
|
||||
inputs: inputs.map((input) => ({
|
||||
address: input.address,
|
||||
coins: [...input.coins],
|
||||
})),
|
||||
outputs: outputs.map((output) => ({
|
||||
address: output.address,
|
||||
coins: [...output.coins],
|
||||
})),
|
||||
}),
|
||||
},
|
||||
|
||||
// distribution
|
||||
|
||||
"/cosmos.distribution.v1beta1.MsgFundCommunityPool": {
|
||||
aminoType: "cosmos-sdk/MsgFundCommunityPool",
|
||||
toAmino: ({ amount, depositor }: MsgFundCommunityPool): AminoMsgFundCommunityPool["value"] => ({
|
||||
amount: [...amount],
|
||||
depositor: depositor,
|
||||
}),
|
||||
fromAmino: ({ amount, depositor }: AminoMsgFundCommunityPool["value"]): MsgFundCommunityPool => ({
|
||||
amount: [...amount],
|
||||
depositor: depositor,
|
||||
}),
|
||||
},
|
||||
"/cosmos.distribution.v1beta1.MsgSetWithdrawAddress": {
|
||||
aminoType: "cosmos-sdk/MsgModifyWithdrawAddress",
|
||||
toAmino: ({
|
||||
delegatorAddress,
|
||||
withdrawAddress,
|
||||
}: MsgSetWithdrawAddress): AminoMsgSetWithdrawAddress["value"] => ({
|
||||
delegator_address: delegatorAddress,
|
||||
withdraw_address: withdrawAddress,
|
||||
}),
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
withdraw_address,
|
||||
}: AminoMsgSetWithdrawAddress["value"]): MsgSetWithdrawAddress => ({
|
||||
delegatorAddress: delegator_address,
|
||||
withdrawAddress: withdraw_address,
|
||||
}),
|
||||
},
|
||||
"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward": {
|
||||
aminoType: "cosmos-sdk/MsgWithdrawDelegationReward",
|
||||
toAmino: ({
|
||||
delegatorAddress,
|
||||
validatorAddress,
|
||||
}: MsgWithdrawDelegatorReward): AminoMsgWithdrawDelegatorReward["value"] => ({
|
||||
delegator_address: delegatorAddress,
|
||||
validator_address: validatorAddress,
|
||||
}),
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
}: AminoMsgWithdrawDelegatorReward["value"]): MsgWithdrawDelegatorReward => ({
|
||||
delegatorAddress: delegator_address,
|
||||
validatorAddress: validator_address,
|
||||
}),
|
||||
},
|
||||
"/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission": {
|
||||
aminoType: "cosmos-sdk/MsgWithdrawValidatorCommission",
|
||||
toAmino: ({
|
||||
validatorAddress,
|
||||
}: MsgWithdrawValidatorCommission): AminoMsgWithdrawValidatorCommission["value"] => ({
|
||||
validator_address: validatorAddress,
|
||||
}),
|
||||
fromAmino: ({
|
||||
validator_address,
|
||||
}: AminoMsgWithdrawValidatorCommission["value"]): MsgWithdrawValidatorCommission => ({
|
||||
validatorAddress: validator_address,
|
||||
}),
|
||||
},
|
||||
|
||||
// gov
|
||||
|
||||
"/cosmos.gov.v1beta1.MsgDeposit": {
|
||||
aminoType: "cosmos-sdk/MsgDeposit",
|
||||
toAmino: ({ amount, depositor, proposalId }: MsgDeposit): AminoMsgDeposit["value"] => {
|
||||
return {
|
||||
amount,
|
||||
depositor,
|
||||
proposal_id: proposalId.toString(),
|
||||
};
|
||||
},
|
||||
fromAmino: ({ amount, depositor, proposal_id }: AminoMsgDeposit["value"]): MsgDeposit => {
|
||||
return {
|
||||
amount: Array.from(amount),
|
||||
depositor,
|
||||
proposalId: Long.fromString(proposal_id),
|
||||
};
|
||||
},
|
||||
},
|
||||
"/cosmos.gov.v1beta1.MsgVote": {
|
||||
aminoType: "cosmos-sdk/MsgVote",
|
||||
toAmino: ({ option, proposalId, voter }: MsgVote): AminoMsgVote["value"] => {
|
||||
return {
|
||||
option: option,
|
||||
proposal_id: proposalId.toString(),
|
||||
voter: voter,
|
||||
};
|
||||
},
|
||||
fromAmino: ({ option, proposal_id, voter }: AminoMsgVote["value"]): MsgVote => {
|
||||
return {
|
||||
option: voteOptionFromJSON(option),
|
||||
proposalId: Long.fromString(proposal_id),
|
||||
voter: voter,
|
||||
};
|
||||
},
|
||||
},
|
||||
"/cosmos.gov.v1beta1.MsgSubmitProposal": {
|
||||
aminoType: "cosmos-sdk/MsgSubmitProposal",
|
||||
toAmino: ({
|
||||
initialDeposit,
|
||||
proposer,
|
||||
content,
|
||||
}: MsgSubmitProposal): AminoMsgSubmitProposal["value"] => {
|
||||
assertDefinedAndNotNull(content);
|
||||
let proposal: any;
|
||||
switch (content.typeUrl) {
|
||||
case "/cosmos.gov.v1beta1.TextProposal": {
|
||||
const textProposal = TextProposal.decode(content.value);
|
||||
proposal = {
|
||||
type: "cosmos-sdk/TextProposal",
|
||||
value: {
|
||||
description: textProposal.description,
|
||||
title: textProposal.title,
|
||||
},
|
||||
};
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unsupported proposal type: '${content.typeUrl}'`);
|
||||
}
|
||||
return {
|
||||
initial_deposit: initialDeposit,
|
||||
proposer: proposer,
|
||||
content: proposal,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
initial_deposit,
|
||||
proposer,
|
||||
content,
|
||||
}: AminoMsgSubmitProposal["value"]): MsgSubmitProposal => {
|
||||
let any_content: Any;
|
||||
switch (content.type) {
|
||||
case "cosmos-sdk/TextProposal": {
|
||||
const { value } = content;
|
||||
assert(isNonNullObject(value));
|
||||
const { title, description } = value as any;
|
||||
assert(typeof title === "string");
|
||||
assert(typeof description === "string");
|
||||
any_content = Any.fromPartial({
|
||||
typeUrl: "/cosmos.gov.v1beta1.TextProposal",
|
||||
value: TextProposal.encode(
|
||||
TextProposal.fromPartial({
|
||||
title: title,
|
||||
description: description,
|
||||
}),
|
||||
).finish(),
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unsupported proposal type: '${content.type}'`);
|
||||
}
|
||||
return {
|
||||
initialDeposit: Array.from(initial_deposit),
|
||||
proposer: proposer,
|
||||
content: any_content,
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
// staking
|
||||
|
||||
"/cosmos.staking.v1beta1.MsgBeginRedelegate": {
|
||||
aminoType: "cosmos-sdk/MsgBeginRedelegate",
|
||||
toAmino: ({
|
||||
delegatorAddress,
|
||||
validatorSrcAddress,
|
||||
validatorDstAddress,
|
||||
amount,
|
||||
}: MsgBeginRedelegate): AminoMsgBeginRedelegate["value"] => {
|
||||
assertDefinedAndNotNull(amount, "missing amount");
|
||||
return {
|
||||
delegator_address: delegatorAddress,
|
||||
validator_src_address: validatorSrcAddress,
|
||||
validator_dst_address: validatorDstAddress,
|
||||
amount: amount,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_src_address,
|
||||
validator_dst_address,
|
||||
amount,
|
||||
}: AminoMsgBeginRedelegate["value"]): MsgBeginRedelegate => ({
|
||||
delegatorAddress: delegator_address,
|
||||
validatorSrcAddress: validator_src_address,
|
||||
validatorDstAddress: validator_dst_address,
|
||||
amount: amount,
|
||||
}),
|
||||
},
|
||||
"/cosmos.staking.v1beta1.MsgCreateValidator": {
|
||||
aminoType: "cosmos-sdk/MsgCreateValidator",
|
||||
toAmino: ({
|
||||
description,
|
||||
commission,
|
||||
minSelfDelegation,
|
||||
delegatorAddress,
|
||||
validatorAddress,
|
||||
pubkey,
|
||||
value,
|
||||
}: MsgCreateValidator): AminoMsgCreateValidator["value"] => {
|
||||
assertDefinedAndNotNull(description, "missing description");
|
||||
assertDefinedAndNotNull(commission, "missing commission");
|
||||
assertDefinedAndNotNull(pubkey, "missing pubkey");
|
||||
assertDefinedAndNotNull(value, "missing value");
|
||||
return {
|
||||
description: {
|
||||
moniker: description.moniker,
|
||||
identity: description.identity,
|
||||
website: description.website,
|
||||
security_contact: description.securityContact,
|
||||
details: description.details,
|
||||
},
|
||||
commission: {
|
||||
rate: commission.rate,
|
||||
max_rate: commission.maxRate,
|
||||
max_change_rate: commission.maxChangeRate,
|
||||
},
|
||||
min_self_delegation: minSelfDelegation,
|
||||
delegator_address: delegatorAddress,
|
||||
validator_address: validatorAddress,
|
||||
pubkey: encodeBech32Pubkey(
|
||||
{
|
||||
type: "tendermint/PubKeySecp256k1",
|
||||
value: toBase64(pubkey.value),
|
||||
},
|
||||
prefix,
|
||||
),
|
||||
value: value,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
description,
|
||||
commission,
|
||||
min_self_delegation,
|
||||
delegator_address,
|
||||
validator_address,
|
||||
pubkey,
|
||||
value,
|
||||
}: AminoMsgCreateValidator["value"]): MsgCreateValidator => {
|
||||
const decodedPubkey = decodeBech32Pubkey(pubkey);
|
||||
if (decodedPubkey.type !== "tendermint/PubKeySecp256k1") {
|
||||
throw new Error("Only Secp256k1 public keys are supported");
|
||||
}
|
||||
return {
|
||||
description: {
|
||||
moniker: description.moniker,
|
||||
identity: description.identity,
|
||||
website: description.website,
|
||||
securityContact: description.security_contact,
|
||||
details: description.details,
|
||||
},
|
||||
commission: {
|
||||
rate: commission.rate,
|
||||
maxRate: commission.max_rate,
|
||||
maxChangeRate: commission.max_change_rate,
|
||||
},
|
||||
minSelfDelegation: min_self_delegation,
|
||||
delegatorAddress: delegator_address,
|
||||
validatorAddress: validator_address,
|
||||
pubkey: {
|
||||
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
|
||||
value: fromBase64(decodedPubkey.value),
|
||||
},
|
||||
value: value,
|
||||
};
|
||||
},
|
||||
},
|
||||
"/cosmos.staking.v1beta1.MsgDelegate": {
|
||||
aminoType: "cosmos-sdk/MsgDelegate",
|
||||
toAmino: ({ delegatorAddress, validatorAddress, amount }: MsgDelegate): AminoMsgDelegate["value"] => {
|
||||
assertDefinedAndNotNull(amount, "missing amount");
|
||||
return {
|
||||
delegator_address: delegatorAddress,
|
||||
validator_address: validatorAddress,
|
||||
amount: amount,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
amount,
|
||||
}: AminoMsgDelegate["value"]): MsgDelegate => ({
|
||||
delegatorAddress: delegator_address,
|
||||
validatorAddress: validator_address,
|
||||
amount: amount,
|
||||
}),
|
||||
},
|
||||
"/cosmos.staking.v1beta1.MsgEditValidator": {
|
||||
aminoType: "cosmos-sdk/MsgEditValidator",
|
||||
toAmino: ({
|
||||
description,
|
||||
commissionRate,
|
||||
minSelfDelegation,
|
||||
validatorAddress,
|
||||
}: MsgEditValidator): AminoMsgEditValidator["value"] => {
|
||||
assertDefinedAndNotNull(description, "missing description");
|
||||
return {
|
||||
description: {
|
||||
moniker: description.moniker,
|
||||
identity: description.identity,
|
||||
website: description.website,
|
||||
security_contact: description.securityContact,
|
||||
details: description.details,
|
||||
},
|
||||
commission_rate: commissionRate,
|
||||
min_self_delegation: minSelfDelegation,
|
||||
validator_address: validatorAddress,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
description,
|
||||
commission_rate,
|
||||
min_self_delegation,
|
||||
validator_address,
|
||||
}: AminoMsgEditValidator["value"]): MsgEditValidator => ({
|
||||
description: {
|
||||
moniker: description.moniker,
|
||||
identity: description.identity,
|
||||
website: description.website,
|
||||
securityContact: description.security_contact,
|
||||
details: description.details,
|
||||
},
|
||||
commissionRate: commission_rate,
|
||||
minSelfDelegation: min_self_delegation,
|
||||
validatorAddress: validator_address,
|
||||
}),
|
||||
},
|
||||
"/cosmos.staking.v1beta1.MsgUndelegate": {
|
||||
aminoType: "cosmos-sdk/MsgUndelegate",
|
||||
toAmino: ({
|
||||
delegatorAddress,
|
||||
validatorAddress,
|
||||
amount,
|
||||
}: MsgUndelegate): AminoMsgUndelegate["value"] => {
|
||||
assertDefinedAndNotNull(amount, "missing amount");
|
||||
return {
|
||||
delegator_address: delegatorAddress,
|
||||
validator_address: validatorAddress,
|
||||
amount: amount,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
amount,
|
||||
}: AminoMsgUndelegate["value"]): MsgUndelegate => ({
|
||||
delegatorAddress: delegator_address,
|
||||
validatorAddress: validator_address,
|
||||
amount: amount,
|
||||
}),
|
||||
},
|
||||
|
||||
// ibc
|
||||
|
||||
"/ibc.applications.transfer.v1.MsgTransfer": {
|
||||
aminoType: "cosmos-sdk/MsgTransfer",
|
||||
toAmino: ({
|
||||
sourcePort,
|
||||
sourceChannel,
|
||||
token,
|
||||
sender,
|
||||
receiver,
|
||||
timeoutHeight,
|
||||
timeoutTimestamp,
|
||||
}: MsgTransfer): AminoMsgTransfer["value"] => ({
|
||||
source_port: sourcePort,
|
||||
source_channel: sourceChannel,
|
||||
token: token,
|
||||
sender: sender,
|
||||
receiver: receiver,
|
||||
timeout_height: timeoutHeight
|
||||
? {
|
||||
revision_height: omitDefault(timeoutHeight.revisionHeight)?.toString(),
|
||||
revision_number: omitDefault(timeoutHeight.revisionNumber)?.toString(),
|
||||
}
|
||||
: {},
|
||||
timeout_timestamp: omitDefault(timeoutTimestamp)?.toString(),
|
||||
}),
|
||||
fromAmino: ({
|
||||
source_port,
|
||||
source_channel,
|
||||
token,
|
||||
sender,
|
||||
receiver,
|
||||
timeout_height,
|
||||
timeout_timestamp,
|
||||
}: AminoMsgTransfer["value"]): MsgTransfer => ({
|
||||
sourcePort: source_port,
|
||||
sourceChannel: source_channel,
|
||||
token: token,
|
||||
sender: sender,
|
||||
receiver: receiver,
|
||||
timeoutHeight: timeout_height
|
||||
? {
|
||||
revisionHeight: Long.fromString(timeout_height.revision_height || "0", true),
|
||||
revisionNumber: Long.fromString(timeout_height.revision_number || "0", true),
|
||||
}
|
||||
: undefined,
|
||||
timeoutTimestamp: Long.fromString(timeout_timestamp || "0", true),
|
||||
}),
|
||||
},
|
||||
"/cosmos.feegrant.v1beta1.MsgGrantAllowance": "not_supported_by_chain",
|
||||
"/cosmos.feegrant.v1beta1.MsgRevokeAllowance": "not_supported_by_chain",
|
||||
...createAuthzAminoConverters(),
|
||||
...createBankAminoConverters(),
|
||||
...createDistributionAminoConverters(),
|
||||
...createGovAminoConverters(),
|
||||
...createStakingAminoConverters(prefix),
|
||||
...createIbcAminoConverters(),
|
||||
...createFreegrantAminoConverters(),
|
||||
};
|
||||
}
|
||||
|
||||
@ -522,7 +30,7 @@ export interface AminoTypesOptions {
|
||||
* The Bech32 address prefix of the chain you work with (also called Bech32 human-readable part).
|
||||
*/
|
||||
readonly prefix: string;
|
||||
readonly additions?: Record<string, AminoConverter>;
|
||||
readonly additions?: AminoConverters;
|
||||
}
|
||||
|
||||
function isAminoConverter(
|
||||
|
||||
@ -1,93 +0,0 @@
|
||||
import { EncodeObject } from "@cosmjs/proto-signing";
|
||||
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
|
||||
import { MsgWithdrawDelegatorReward } from "cosmjs-types/cosmos/distribution/v1beta1/tx";
|
||||
import { MsgDeposit, MsgSubmitProposal, MsgVote } from "cosmjs-types/cosmos/gov/v1beta1/tx";
|
||||
import { MsgDelegate, MsgUndelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
|
||||
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
|
||||
|
||||
export interface MsgSendEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmos.bank.v1beta1.MsgSend";
|
||||
readonly value: Partial<MsgSend>;
|
||||
}
|
||||
|
||||
export function isMsgSendEncodeObject(encodeObject: EncodeObject): encodeObject is MsgSendEncodeObject {
|
||||
return (encodeObject as MsgSendEncodeObject).typeUrl === "/cosmos.bank.v1beta1.MsgSend";
|
||||
}
|
||||
|
||||
export interface MsgDelegateEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmos.staking.v1beta1.MsgDelegate";
|
||||
readonly value: Partial<MsgDelegate>;
|
||||
}
|
||||
|
||||
export function isMsgDelegateEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgDelegateEncodeObject {
|
||||
return (encodeObject as MsgDelegateEncodeObject).typeUrl === "/cosmos.staking.v1beta1.MsgDelegate";
|
||||
}
|
||||
|
||||
export interface MsgUndelegateEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate";
|
||||
readonly value: Partial<MsgUndelegate>;
|
||||
}
|
||||
|
||||
export function isMsgUndelegateEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgUndelegateEncodeObject {
|
||||
return (encodeObject as MsgUndelegateEncodeObject).typeUrl === "/cosmos.staking.v1beta1.MsgUndelegate";
|
||||
}
|
||||
|
||||
export interface MsgWithdrawDelegatorRewardEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward";
|
||||
readonly value: Partial<MsgWithdrawDelegatorReward>;
|
||||
}
|
||||
|
||||
export function isMsgWithdrawDelegatorRewardEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgWithdrawDelegatorRewardEncodeObject {
|
||||
return (
|
||||
(encodeObject as MsgWithdrawDelegatorRewardEncodeObject).typeUrl ===
|
||||
"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward"
|
||||
);
|
||||
}
|
||||
|
||||
export interface MsgTransferEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/ibc.applications.transfer.v1.MsgTransfer";
|
||||
readonly value: Partial<MsgTransfer>;
|
||||
}
|
||||
|
||||
export function isMsgTransferEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgTransferEncodeObject {
|
||||
return (encodeObject as MsgTransferEncodeObject).typeUrl === "/ibc.applications.transfer.v1.MsgTransfer";
|
||||
}
|
||||
|
||||
export interface MsgDepositEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmos.gov.v1beta1.MsgDeposit";
|
||||
readonly value: Partial<MsgDeposit>;
|
||||
}
|
||||
|
||||
export function isMsgDepositEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgSubmitProposalEncodeObject {
|
||||
return (encodeObject as MsgDepositEncodeObject).typeUrl === "/cosmos.gov.v1beta1.MsgDeposit";
|
||||
}
|
||||
|
||||
export interface MsgSubmitProposalEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmos.gov.v1beta1.MsgSubmitProposal";
|
||||
readonly value: Partial<MsgSubmitProposal>;
|
||||
}
|
||||
|
||||
export function isMsgSubmitProposalEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgSubmitProposalEncodeObject {
|
||||
return (encodeObject as MsgSubmitProposalEncodeObject).typeUrl === "/cosmos.gov.v1beta1.MsgSubmitProposal";
|
||||
}
|
||||
|
||||
export interface MsgVoteEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmos.gov.v1beta1.MsgVote";
|
||||
readonly value: Partial<MsgVote>;
|
||||
}
|
||||
|
||||
export function isMsgVoteEncodeObject(encodeObject: EncodeObject): encodeObject is MsgVoteEncodeObject {
|
||||
return (encodeObject as MsgVoteEncodeObject).typeUrl === "/cosmos.gov.v1beta1.MsgVote";
|
||||
}
|
||||
@ -1,4 +1,8 @@
|
||||
export { Account, accountFromAny } from "./accounts";
|
||||
export { AminoConverter, AminoConverters } from "./aminoconverters";
|
||||
export { AminoTypes, AminoTypesOptions } from "./aminotypes";
|
||||
export { calculateFee, GasPrice } from "./fee";
|
||||
export * as logs from "./logs";
|
||||
export {
|
||||
AminoMsgBeginRedelegate,
|
||||
AminoMsgCreateValidator,
|
||||
@ -17,6 +21,13 @@ export {
|
||||
AminoMsgVote,
|
||||
AminoMsgWithdrawDelegatorReward,
|
||||
AminoMsgWithdrawValidatorCommission,
|
||||
AuthExtension,
|
||||
BankExtension,
|
||||
DistributionExtension,
|
||||
GovExtension,
|
||||
GovParamsType,
|
||||
GovProposalId,
|
||||
IbcExtension,
|
||||
isAminoMsgBeginRedelegate,
|
||||
isAminoMsgCreateValidator,
|
||||
isAminoMsgDelegate,
|
||||
@ -34,9 +45,6 @@ export {
|
||||
isAminoMsgVote,
|
||||
isAminoMsgWithdrawDelegatorReward,
|
||||
isAminoMsgWithdrawValidatorCommission,
|
||||
} from "./aminomsgs";
|
||||
export { AminoConverter, AminoTypes, AminoTypesOptions } from "./aminotypes";
|
||||
export {
|
||||
isMsgDelegateEncodeObject,
|
||||
isMsgDepositEncodeObject,
|
||||
isMsgSendEncodeObject,
|
||||
@ -45,6 +53,8 @@ export {
|
||||
isMsgUndelegateEncodeObject,
|
||||
isMsgVoteEncodeObject,
|
||||
isMsgWithdrawDelegatorRewardEncodeObject,
|
||||
MintExtension,
|
||||
MintParams,
|
||||
MsgDelegateEncodeObject,
|
||||
MsgDepositEncodeObject,
|
||||
MsgSendEncodeObject,
|
||||
@ -53,25 +63,6 @@ export {
|
||||
MsgUndelegateEncodeObject,
|
||||
MsgVoteEncodeObject,
|
||||
MsgWithdrawDelegatorRewardEncodeObject,
|
||||
} from "./encodeobjects";
|
||||
export { calculateFee, GasPrice } from "./fee";
|
||||
export * as logs from "./logs";
|
||||
export { makeMultisignedTx } from "./multisignature";
|
||||
export {
|
||||
AuthExtension,
|
||||
BankExtension,
|
||||
createPagination,
|
||||
createProtobufRpcClient,
|
||||
decodeCosmosSdkDecFromProto,
|
||||
DistributionExtension,
|
||||
GovExtension,
|
||||
GovParamsType,
|
||||
GovProposalId,
|
||||
IbcExtension,
|
||||
MintExtension,
|
||||
MintParams,
|
||||
ProtobufRpcClient,
|
||||
QueryClient,
|
||||
setupAuthExtension,
|
||||
setupBankExtension,
|
||||
setupDistributionExtension,
|
||||
@ -82,7 +73,15 @@ export {
|
||||
setupTxExtension,
|
||||
StakingExtension,
|
||||
TxExtension,
|
||||
} from "./queries";
|
||||
} from "./modules";
|
||||
export { makeMultisignedTx } from "./multisignature";
|
||||
export {
|
||||
createPagination,
|
||||
createProtobufRpcClient,
|
||||
decodeCosmosSdkDecFromProto,
|
||||
ProtobufRpcClient,
|
||||
QueryClient,
|
||||
} from "./queryclient";
|
||||
export {
|
||||
isSearchByHeightQuery,
|
||||
isSearchBySentFromOrToQuery,
|
||||
|
||||
@ -6,9 +6,9 @@ import { BaseAccount } from "cosmjs-types/cosmos/auth/v1beta1/auth";
|
||||
import { Any } from "cosmjs-types/google/protobuf/any";
|
||||
import Long from "long";
|
||||
|
||||
import { nonExistentAddress, pendingWithoutSimapp, simapp, unused, validator } from "../testutils.spec";
|
||||
import { AuthExtension, setupAuthExtension } from "./auth";
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { QueryClient } from "../../queryclient";
|
||||
import { nonExistentAddress, pendingWithoutSimapp, simapp, unused, validator } from "../../testutils.spec";
|
||||
import { AuthExtension, setupAuthExtension } from "./queries";
|
||||
|
||||
async function makeClientWithAuth(
|
||||
rpcUrl: string,
|
||||
@ -1,8 +1,7 @@
|
||||
import { QueryClientImpl } from "cosmjs-types/cosmos/auth/v1beta1/query";
|
||||
import { Any } from "cosmjs-types/google/protobuf/any";
|
||||
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { createProtobufRpcClient } from "./utils";
|
||||
import { createProtobufRpcClient, QueryClient } from "../../queryclient";
|
||||
|
||||
export interface AuthExtension {
|
||||
readonly auth: {
|
||||
9
packages/stargate/src/modules/authz/aminomessages.ts
Normal file
9
packages/stargate/src/modules/authz/aminomessages.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
|
||||
export function createAuthzAminoConverters(): AminoConverters {
|
||||
return {
|
||||
"/cosmos.authz.v1beta1.MsgGrant": "not_supported_by_chain",
|
||||
"/cosmos.authz.v1beta1.MsgExec": "not_supported_by_chain",
|
||||
"/cosmos.authz.v1beta1.MsgRevoke": "not_supported_by_chain",
|
||||
};
|
||||
}
|
||||
8
packages/stargate/src/modules/authz/messages.ts
Normal file
8
packages/stargate/src/modules/authz/messages.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { GeneratedType } from "@cosmjs/proto-signing";
|
||||
import { MsgExec, MsgGrant, MsgRevoke } from "cosmjs-types/cosmos/authz/v1beta1/tx";
|
||||
|
||||
export const authzTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
["/cosmos.authz.v1beta1.MsgExec", MsgExec],
|
||||
["/cosmos.authz.v1beta1.MsgGrant", MsgGrant],
|
||||
["/cosmos.authz.v1beta1.MsgRevoke", MsgRevoke],
|
||||
];
|
||||
88
packages/stargate/src/modules/bank/aminomessages.ts
Normal file
88
packages/stargate/src/modules/bank/aminomessages.ts
Normal file
@ -0,0 +1,88 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoMsg, Coin } from "@cosmjs/amino";
|
||||
import { MsgMultiSend, MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
|
||||
|
||||
// eslint-disable-next-line import/no-cycle
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
|
||||
/** A high level transaction of the coin module */
|
||||
export interface AminoMsgSend extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgSend";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly from_address: string;
|
||||
/** Bech32 account address */
|
||||
readonly to_address: string;
|
||||
readonly amount: readonly Coin[];
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgSend(msg: AminoMsg): msg is AminoMsgSend {
|
||||
return msg.type === "cosmos-sdk/MsgSend";
|
||||
}
|
||||
|
||||
interface Input {
|
||||
/** Bech32 account address */
|
||||
readonly address: string;
|
||||
readonly coins: readonly Coin[];
|
||||
}
|
||||
|
||||
interface Output {
|
||||
/** Bech32 account address */
|
||||
readonly address: string;
|
||||
readonly coins: readonly Coin[];
|
||||
}
|
||||
|
||||
/** A high level transaction of the coin module */
|
||||
export interface AminoMsgMultiSend extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgMultiSend";
|
||||
readonly value: {
|
||||
readonly inputs: readonly Input[];
|
||||
readonly outputs: readonly Output[];
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgMultiSend(msg: AminoMsg): msg is AminoMsgMultiSend {
|
||||
return msg.type === "cosmos-sdk/MsgMultiSend";
|
||||
}
|
||||
|
||||
export function createBankAminoConverters(): AminoConverters {
|
||||
return {
|
||||
"/cosmos.bank.v1beta1.MsgSend": {
|
||||
aminoType: "cosmos-sdk/MsgSend",
|
||||
toAmino: ({ fromAddress, toAddress, amount }: MsgSend): AminoMsgSend["value"] => ({
|
||||
from_address: fromAddress,
|
||||
to_address: toAddress,
|
||||
amount: [...amount],
|
||||
}),
|
||||
fromAmino: ({ from_address, to_address, amount }: AminoMsgSend["value"]): MsgSend => ({
|
||||
fromAddress: from_address,
|
||||
toAddress: to_address,
|
||||
amount: [...amount],
|
||||
}),
|
||||
},
|
||||
"/cosmos.bank.v1beta1.MsgMultiSend": {
|
||||
aminoType: "cosmos-sdk/MsgMultiSend",
|
||||
toAmino: ({ inputs, outputs }: MsgMultiSend): AminoMsgMultiSend["value"] => ({
|
||||
inputs: inputs.map((input) => ({
|
||||
address: input.address,
|
||||
coins: [...input.coins],
|
||||
})),
|
||||
outputs: outputs.map((output) => ({
|
||||
address: output.address,
|
||||
coins: [...output.coins],
|
||||
})),
|
||||
}),
|
||||
fromAmino: ({ inputs, outputs }: AminoMsgMultiSend["value"]): MsgMultiSend => ({
|
||||
inputs: inputs.map((input) => ({
|
||||
address: input.address,
|
||||
coins: [...input.coins],
|
||||
})),
|
||||
outputs: outputs.map((output) => ({
|
||||
address: output.address,
|
||||
coins: [...output.coins],
|
||||
})),
|
||||
}),
|
||||
},
|
||||
};
|
||||
}
|
||||
16
packages/stargate/src/modules/bank/messages.ts
Normal file
16
packages/stargate/src/modules/bank/messages.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing";
|
||||
import { MsgMultiSend, MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
|
||||
|
||||
export const bankTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
["/cosmos.bank.v1beta1.MsgMultiSend", MsgMultiSend],
|
||||
["/cosmos.bank.v1beta1.MsgSend", MsgSend],
|
||||
];
|
||||
|
||||
export interface MsgSendEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmos.bank.v1beta1.MsgSend";
|
||||
readonly value: Partial<MsgSend>;
|
||||
}
|
||||
|
||||
export function isMsgSendEncodeObject(encodeObject: EncodeObject): encodeObject is MsgSendEncodeObject {
|
||||
return (encodeObject as MsgSendEncodeObject).typeUrl === "/cosmos.bank.v1beta1.MsgSend";
|
||||
}
|
||||
@ -1,14 +1,14 @@
|
||||
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
|
||||
|
||||
import { QueryClient } from "../../queryclient";
|
||||
import {
|
||||
nonExistentAddress,
|
||||
nonNegativeIntegerMatcher,
|
||||
pendingWithoutSimapp,
|
||||
simapp,
|
||||
unused,
|
||||
} from "../testutils.spec";
|
||||
import { BankExtension, setupBankExtension } from "./bank";
|
||||
import { QueryClient } from "./queryclient";
|
||||
} from "../../testutils.spec";
|
||||
import { BankExtension, setupBankExtension } from "./queries";
|
||||
|
||||
async function makeClientWithBank(
|
||||
rpcUrl: string,
|
||||
@ -4,8 +4,7 @@ import { Metadata } from "cosmjs-types/cosmos/bank/v1beta1/bank";
|
||||
import { QueryClientImpl } from "cosmjs-types/cosmos/bank/v1beta1/query";
|
||||
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
|
||||
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { createProtobufRpcClient } from "./utils";
|
||||
import { createProtobufRpcClient, QueryClient } from "../../queryclient";
|
||||
|
||||
export interface BankExtension {
|
||||
readonly bank: {
|
||||
25
packages/stargate/src/modules/crisis/aminomessages.ts
Normal file
25
packages/stargate/src/modules/crisis/aminomessages.ts
Normal file
@ -0,0 +1,25 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoMsg } from "@cosmjs/amino";
|
||||
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
|
||||
// See https://github.com/cosmos/cosmos-sdk/blob/v0.45.1/proto/cosmos/crisis/v1beta1/tx.proto
|
||||
|
||||
/** Verifies a particular invariance */
|
||||
export interface AminoMsgVerifyInvariant extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgVerifyInvariant";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
readonly invariant_module_name: string;
|
||||
readonly invariant_route: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgVerifyInvariant(msg: AminoMsg): msg is AminoMsgVerifyInvariant {
|
||||
return msg.type === "cosmos-sdk/MsgVerifyInvariant";
|
||||
}
|
||||
|
||||
export function createCrysisAminoConverters(): AminoConverters {
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
139
packages/stargate/src/modules/distribution/aminomessages.ts
Normal file
139
packages/stargate/src/modules/distribution/aminomessages.ts
Normal file
@ -0,0 +1,139 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoMsg, Coin } from "@cosmjs/amino";
|
||||
import {
|
||||
MsgFundCommunityPool,
|
||||
MsgSetWithdrawAddress,
|
||||
MsgWithdrawDelegatorReward,
|
||||
MsgWithdrawValidatorCommission,
|
||||
} from "cosmjs-types/cosmos/distribution/v1beta1/tx";
|
||||
|
||||
import { AminoConverter } from "../..";
|
||||
|
||||
/** Changes the withdraw address for a delegator (or validator self-delegation) */
|
||||
export interface AminoMsgSetWithdrawAddress extends AminoMsg {
|
||||
// NOTE: Type string and names diverge here!
|
||||
readonly type: "cosmos-sdk/MsgModifyWithdrawAddress";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly delegator_address: string;
|
||||
/** Bech32 account address */
|
||||
readonly withdraw_address: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgSetWithdrawAddress(msg: AminoMsg): msg is AminoMsgSetWithdrawAddress {
|
||||
// NOTE: Type string and names diverge here!
|
||||
return msg.type === "cosmos-sdk/MsgModifyWithdrawAddress";
|
||||
}
|
||||
|
||||
/** Message for delegation withdraw from a single validator */
|
||||
export interface AminoMsgWithdrawDelegatorReward extends AminoMsg {
|
||||
// NOTE: Type string and names diverge here!
|
||||
readonly type: "cosmos-sdk/MsgWithdrawDelegationReward";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly delegator_address: string;
|
||||
/** Bech32 account address */
|
||||
readonly validator_address: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgWithdrawDelegatorReward(msg: AminoMsg): msg is AminoMsgWithdrawDelegatorReward {
|
||||
// NOTE: Type string and names diverge here!
|
||||
return msg.type === "cosmos-sdk/MsgWithdrawDelegationReward";
|
||||
}
|
||||
|
||||
/** Message for validator withdraw */
|
||||
export interface AminoMsgWithdrawValidatorCommission extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgWithdrawValidatorCommission";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly validator_address: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgWithdrawValidatorCommission(
|
||||
msg: AminoMsg,
|
||||
): msg is AminoMsgWithdrawValidatorCommission {
|
||||
return msg.type === "cosmos-sdk/MsgWithdrawValidatorCommission";
|
||||
}
|
||||
|
||||
/** Allows an account to directly fund the community pool. */
|
||||
export interface AminoMsgFundCommunityPool extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgFundCommunityPool";
|
||||
readonly value: {
|
||||
readonly amount: readonly Coin[];
|
||||
/** Bech32 account address */
|
||||
readonly depositor: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgFundCommunityPool(msg: AminoMsg): msg is AminoMsgFundCommunityPool {
|
||||
return msg.type === "cosmos-sdk/MsgFundCommunityPool";
|
||||
}
|
||||
|
||||
export function createDistributionAminoConverters(): Record<
|
||||
string,
|
||||
AminoConverter | "not_supported_by_chain"
|
||||
> {
|
||||
return {
|
||||
"/cosmos.distribution.v1beta1.MsgFundCommunityPool": {
|
||||
aminoType: "cosmos-sdk/MsgFundCommunityPool",
|
||||
toAmino: ({ amount, depositor }: MsgFundCommunityPool): AminoMsgFundCommunityPool["value"] => ({
|
||||
amount: [...amount],
|
||||
depositor: depositor,
|
||||
}),
|
||||
fromAmino: ({ amount, depositor }: AminoMsgFundCommunityPool["value"]): MsgFundCommunityPool => ({
|
||||
amount: [...amount],
|
||||
depositor: depositor,
|
||||
}),
|
||||
},
|
||||
"/cosmos.distribution.v1beta1.MsgSetWithdrawAddress": {
|
||||
aminoType: "cosmos-sdk/MsgModifyWithdrawAddress",
|
||||
toAmino: ({
|
||||
delegatorAddress,
|
||||
withdrawAddress,
|
||||
}: MsgSetWithdrawAddress): AminoMsgSetWithdrawAddress["value"] => ({
|
||||
delegator_address: delegatorAddress,
|
||||
withdraw_address: withdrawAddress,
|
||||
}),
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
withdraw_address,
|
||||
}: AminoMsgSetWithdrawAddress["value"]): MsgSetWithdrawAddress => ({
|
||||
delegatorAddress: delegator_address,
|
||||
withdrawAddress: withdraw_address,
|
||||
}),
|
||||
},
|
||||
"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward": {
|
||||
aminoType: "cosmos-sdk/MsgWithdrawDelegationReward",
|
||||
toAmino: ({
|
||||
delegatorAddress,
|
||||
validatorAddress,
|
||||
}: MsgWithdrawDelegatorReward): AminoMsgWithdrawDelegatorReward["value"] => ({
|
||||
delegator_address: delegatorAddress,
|
||||
validator_address: validatorAddress,
|
||||
}),
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
}: AminoMsgWithdrawDelegatorReward["value"]): MsgWithdrawDelegatorReward => ({
|
||||
delegatorAddress: delegator_address,
|
||||
validatorAddress: validator_address,
|
||||
}),
|
||||
},
|
||||
"/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission": {
|
||||
aminoType: "cosmos-sdk/MsgWithdrawValidatorCommission",
|
||||
toAmino: ({
|
||||
validatorAddress,
|
||||
}: MsgWithdrawValidatorCommission): AminoMsgWithdrawValidatorCommission["value"] => ({
|
||||
validator_address: validatorAddress,
|
||||
}),
|
||||
fromAmino: ({
|
||||
validator_address,
|
||||
}: AminoMsgWithdrawValidatorCommission["value"]): MsgWithdrawValidatorCommission => ({
|
||||
validatorAddress: validator_address,
|
||||
}),
|
||||
},
|
||||
};
|
||||
}
|
||||
28
packages/stargate/src/modules/distribution/messages.ts
Normal file
28
packages/stargate/src/modules/distribution/messages.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing";
|
||||
import {
|
||||
MsgFundCommunityPool,
|
||||
MsgSetWithdrawAddress,
|
||||
MsgWithdrawDelegatorReward,
|
||||
MsgWithdrawValidatorCommission,
|
||||
} from "cosmjs-types/cosmos/distribution/v1beta1/tx";
|
||||
|
||||
export const distributionTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
["/cosmos.distribution.v1beta1.MsgFundCommunityPool", MsgFundCommunityPool],
|
||||
["/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", MsgSetWithdrawAddress],
|
||||
["/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", MsgWithdrawDelegatorReward],
|
||||
["/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission", MsgWithdrawValidatorCommission],
|
||||
];
|
||||
|
||||
export interface MsgWithdrawDelegatorRewardEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward";
|
||||
readonly value: Partial<MsgWithdrawDelegatorReward>;
|
||||
}
|
||||
|
||||
export function isMsgWithdrawDelegatorRewardEncodeObject(
|
||||
object: EncodeObject,
|
||||
): object is MsgWithdrawDelegatorRewardEncodeObject {
|
||||
return (
|
||||
(object as MsgWithdrawDelegatorRewardEncodeObject).typeUrl ===
|
||||
"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward"
|
||||
);
|
||||
}
|
||||
@ -4,9 +4,9 @@ import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
|
||||
import { sleep } from "@cosmjs/utils";
|
||||
import { MsgDelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
|
||||
|
||||
import { MsgDelegateEncodeObject } from "../encodeobjects";
|
||||
import { SigningStargateClient } from "../signingstargateclient";
|
||||
import { assertIsDeliverTxSuccess } from "../stargateclient";
|
||||
import { QueryClient } from "../../queryclient";
|
||||
import { SigningStargateClient } from "../../signingstargateclient";
|
||||
import { assertIsDeliverTxSuccess } from "../../stargateclient";
|
||||
import {
|
||||
defaultSigningClientOptions,
|
||||
faucet,
|
||||
@ -14,9 +14,9 @@ import {
|
||||
simapp,
|
||||
simappEnabled,
|
||||
validator,
|
||||
} from "../testutils.spec";
|
||||
import { DistributionExtension, setupDistributionExtension } from "./distribution";
|
||||
import { QueryClient } from "./queryclient";
|
||||
} from "../../testutils.spec";
|
||||
import { MsgDelegateEncodeObject } from "../";
|
||||
import { DistributionExtension, setupDistributionExtension } from "./queries";
|
||||
|
||||
async function makeClientWithDistribution(
|
||||
rpcUrl: string,
|
||||
@ -13,8 +13,7 @@ import {
|
||||
} from "cosmjs-types/cosmos/distribution/v1beta1/query";
|
||||
import Long from "long";
|
||||
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { createPagination, createProtobufRpcClient } from "./utils";
|
||||
import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient";
|
||||
|
||||
export interface DistributionExtension {
|
||||
readonly distribution: {
|
||||
29
packages/stargate/src/modules/evidence/aminomessages.ts
Normal file
29
packages/stargate/src/modules/evidence/aminomessages.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoMsg } from "@cosmjs/amino";
|
||||
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
|
||||
// See https://github.com/cosmos/cosmos-sdk/blob/v0.45.1/proto/cosmos/evidence/v1beta1/tx.proto
|
||||
|
||||
interface Any {
|
||||
readonly type_url: string;
|
||||
readonly value: Uint8Array;
|
||||
}
|
||||
|
||||
/** Supports submitting arbitrary evidence */
|
||||
export interface AminoMsgSubmitEvidence extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgSubmitEvidence";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly submitter: string;
|
||||
readonly evidence: Any;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgSubmitEvidence(msg: AminoMsg): msg is AminoMsgSubmitEvidence {
|
||||
return msg.type === "cosmos-sdk/MsgSubmitEvidence";
|
||||
}
|
||||
|
||||
export function createEvidenceAminoConverters(): AminoConverters {
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
8
packages/stargate/src/modules/feegrant/aminomessages.ts
Normal file
8
packages/stargate/src/modules/feegrant/aminomessages.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
|
||||
export function createFreegrantAminoConverters(): AminoConverters {
|
||||
return {
|
||||
"/cosmos.feegrant.v1beta1.MsgGrantAllowance": "not_supported_by_chain",
|
||||
"/cosmos.feegrant.v1beta1.MsgRevokeAllowance": "not_supported_by_chain",
|
||||
};
|
||||
}
|
||||
7
packages/stargate/src/modules/feegrant/messages.ts
Normal file
7
packages/stargate/src/modules/feegrant/messages.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { GeneratedType } from "@cosmjs/proto-signing";
|
||||
import { MsgGrantAllowance, MsgRevokeAllowance } from "cosmjs-types/cosmos/feegrant/v1beta1/tx";
|
||||
|
||||
export const feegrantTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
["/cosmos.feegrant.v1beta1.MsgGrantAllowance", MsgGrantAllowance],
|
||||
["/cosmos.feegrant.v1beta1.MsgRevokeAllowance", MsgRevokeAllowance],
|
||||
];
|
||||
178
packages/stargate/src/modules/gov/aminomessages.ts
Normal file
178
packages/stargate/src/modules/gov/aminomessages.ts
Normal file
@ -0,0 +1,178 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoMsg, Coin } from "@cosmjs/amino";
|
||||
import { assert, assertDefinedAndNotNull, isNonNullObject } from "@cosmjs/utils";
|
||||
import { TextProposal, voteOptionFromJSON } from "cosmjs-types/cosmos/gov/v1beta1/gov";
|
||||
import { MsgDeposit, MsgSubmitProposal, MsgVote } from "cosmjs-types/cosmos/gov/v1beta1/tx";
|
||||
import { Any } from "cosmjs-types/google/protobuf/any";
|
||||
import Long from "long";
|
||||
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
|
||||
/** Supports submitting arbitrary proposal content. */
|
||||
export interface AminoMsgSubmitProposal extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgSubmitProposal";
|
||||
readonly value: {
|
||||
/**
|
||||
* A proposal structure, e.g.
|
||||
*
|
||||
* ```
|
||||
* {
|
||||
* type: 'cosmos-sdk/TextProposal',
|
||||
* value: {
|
||||
* description: 'This proposal proposes to test whether this proposal passes',
|
||||
* title: 'Test Proposal'
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
readonly content: {
|
||||
readonly type: string;
|
||||
readonly value: any;
|
||||
};
|
||||
readonly initial_deposit: readonly Coin[];
|
||||
/** Bech32 account address */
|
||||
readonly proposer: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgSubmitProposal(msg: AminoMsg): msg is AminoMsgSubmitProposal {
|
||||
return msg.type === "cosmos-sdk/MsgSubmitProposal";
|
||||
}
|
||||
|
||||
/** Casts a vote */
|
||||
export interface AminoMsgVote extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgVote";
|
||||
readonly value: {
|
||||
readonly proposal_id: string;
|
||||
/** Bech32 account address */
|
||||
readonly voter: string;
|
||||
/**
|
||||
* VoteOption as integer from 0 to 4 🤷
|
||||
*
|
||||
* @see https://github.com/cosmos/cosmos-sdk/blob/v0.42.9/x/gov/types/gov.pb.go#L38-L49
|
||||
*/
|
||||
readonly option: number;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgVote(msg: AminoMsg): msg is AminoMsgVote {
|
||||
return msg.type === "cosmos-sdk/MsgVote";
|
||||
}
|
||||
|
||||
/** Submits a deposit to an existing proposal */
|
||||
export interface AminoMsgDeposit extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgDeposit";
|
||||
readonly value: {
|
||||
readonly proposal_id: string;
|
||||
/** Bech32 account address */
|
||||
readonly depositor: string;
|
||||
readonly amount: readonly Coin[];
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgDeposit(msg: AminoMsg): msg is AminoMsgDeposit {
|
||||
return msg.type === "cosmos-sdk/MsgDeposit";
|
||||
}
|
||||
|
||||
export function createGovAminoConverters(): AminoConverters {
|
||||
return {
|
||||
"/cosmos.gov.v1beta1.MsgDeposit": {
|
||||
aminoType: "cosmos-sdk/MsgDeposit",
|
||||
toAmino: ({ amount, depositor, proposalId }: MsgDeposit): AminoMsgDeposit["value"] => {
|
||||
return {
|
||||
amount,
|
||||
depositor,
|
||||
proposal_id: proposalId.toString(),
|
||||
};
|
||||
},
|
||||
fromAmino: ({ amount, depositor, proposal_id }: AminoMsgDeposit["value"]): MsgDeposit => {
|
||||
return {
|
||||
amount: Array.from(amount),
|
||||
depositor,
|
||||
proposalId: Long.fromString(proposal_id),
|
||||
};
|
||||
},
|
||||
},
|
||||
"/cosmos.gov.v1beta1.MsgVote": {
|
||||
aminoType: "cosmos-sdk/MsgVote",
|
||||
toAmino: ({ option, proposalId, voter }: MsgVote): AminoMsgVote["value"] => {
|
||||
return {
|
||||
option: option,
|
||||
proposal_id: proposalId.toString(),
|
||||
voter: voter,
|
||||
};
|
||||
},
|
||||
fromAmino: ({ option, proposal_id, voter }: AminoMsgVote["value"]): MsgVote => {
|
||||
return {
|
||||
option: voteOptionFromJSON(option),
|
||||
proposalId: Long.fromString(proposal_id),
|
||||
voter: voter,
|
||||
};
|
||||
},
|
||||
},
|
||||
"/cosmos.gov.v1beta1.MsgSubmitProposal": {
|
||||
aminoType: "cosmos-sdk/MsgSubmitProposal",
|
||||
toAmino: ({
|
||||
initialDeposit,
|
||||
proposer,
|
||||
content,
|
||||
}: MsgSubmitProposal): AminoMsgSubmitProposal["value"] => {
|
||||
assertDefinedAndNotNull(content);
|
||||
let proposal: any;
|
||||
switch (content.typeUrl) {
|
||||
case "/cosmos.gov.v1beta1.TextProposal": {
|
||||
const textProposal = TextProposal.decode(content.value);
|
||||
proposal = {
|
||||
type: "cosmos-sdk/TextProposal",
|
||||
value: {
|
||||
description: textProposal.description,
|
||||
title: textProposal.title,
|
||||
},
|
||||
};
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unsupported proposal type: '${content.typeUrl}'`);
|
||||
}
|
||||
return {
|
||||
initial_deposit: initialDeposit,
|
||||
proposer: proposer,
|
||||
content: proposal,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
initial_deposit,
|
||||
proposer,
|
||||
content,
|
||||
}: AminoMsgSubmitProposal["value"]): MsgSubmitProposal => {
|
||||
let any_content: Any;
|
||||
switch (content.type) {
|
||||
case "cosmos-sdk/TextProposal": {
|
||||
const { value } = content;
|
||||
assert(isNonNullObject(value));
|
||||
const { title, description } = value as any;
|
||||
assert(typeof title === "string");
|
||||
assert(typeof description === "string");
|
||||
any_content = Any.fromPartial({
|
||||
typeUrl: "/cosmos.gov.v1beta1.TextProposal",
|
||||
value: TextProposal.encode(
|
||||
TextProposal.fromPartial({
|
||||
title: title,
|
||||
description: description,
|
||||
}),
|
||||
).finish(),
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unsupported proposal type: '${content.type}'`);
|
||||
}
|
||||
return {
|
||||
initialDeposit: Array.from(initial_deposit),
|
||||
proposer: proposer,
|
||||
content: any_content,
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
37
packages/stargate/src/modules/gov/messages.ts
Normal file
37
packages/stargate/src/modules/gov/messages.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing";
|
||||
import { MsgDeposit, MsgSubmitProposal, MsgVote } from "cosmjs-types/cosmos/gov/v1beta1/tx";
|
||||
|
||||
export const govTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
["/cosmos.gov.v1beta1.MsgDeposit", MsgDeposit],
|
||||
["/cosmos.gov.v1beta1.MsgSubmitProposal", MsgSubmitProposal],
|
||||
["/cosmos.gov.v1beta1.MsgVote", MsgVote],
|
||||
];
|
||||
|
||||
export interface MsgDepositEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmos.gov.v1beta1.MsgDeposit";
|
||||
readonly value: Partial<MsgDeposit>;
|
||||
}
|
||||
|
||||
export function isMsgDepositEncodeObject(object: EncodeObject): object is MsgSubmitProposalEncodeObject {
|
||||
return (object as MsgDepositEncodeObject).typeUrl === "/cosmos.gov.v1beta1.MsgDeposit";
|
||||
}
|
||||
|
||||
export interface MsgSubmitProposalEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmos.gov.v1beta1.MsgSubmitProposal";
|
||||
readonly value: Partial<MsgSubmitProposal>;
|
||||
}
|
||||
|
||||
export function isMsgSubmitProposalEncodeObject(
|
||||
object: EncodeObject,
|
||||
): object is MsgSubmitProposalEncodeObject {
|
||||
return (object as MsgSubmitProposalEncodeObject).typeUrl === "/cosmos.gov.v1beta1.MsgSubmitProposal";
|
||||
}
|
||||
|
||||
export interface MsgVoteEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmos.gov.v1beta1.MsgVote";
|
||||
readonly value: Partial<MsgVote>;
|
||||
}
|
||||
|
||||
export function isMsgVoteEncodeObject(object: EncodeObject): object is MsgVoteEncodeObject {
|
||||
return (object as MsgVoteEncodeObject).typeUrl === "/cosmos.gov.v1beta1.MsgVote";
|
||||
}
|
||||
@ -13,13 +13,9 @@ import {
|
||||
import { Any } from "cosmjs-types/google/protobuf/any";
|
||||
import Long from "long";
|
||||
|
||||
import {
|
||||
MsgDelegateEncodeObject,
|
||||
MsgSubmitProposalEncodeObject,
|
||||
MsgVoteEncodeObject,
|
||||
} from "../encodeobjects";
|
||||
import { SigningStargateClient } from "../signingstargateclient";
|
||||
import { assertIsDeliverTxSuccess } from "../stargateclient";
|
||||
import { longify, QueryClient } from "../../queryclient";
|
||||
import { SigningStargateClient } from "../../signingstargateclient";
|
||||
import { assertIsDeliverTxSuccess } from "../../stargateclient";
|
||||
import {
|
||||
defaultSigningClientOptions,
|
||||
faucet,
|
||||
@ -29,10 +25,9 @@ import {
|
||||
simapp42Enabled,
|
||||
simappEnabled,
|
||||
validator,
|
||||
} from "../testutils.spec";
|
||||
import { GovExtension, setupGovExtension } from "./gov";
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { longify } from "./utils";
|
||||
} from "../../testutils.spec";
|
||||
import { MsgDelegateEncodeObject, MsgSubmitProposalEncodeObject, MsgVoteEncodeObject } from "../";
|
||||
import { GovExtension, setupGovExtension } from "./queries";
|
||||
|
||||
async function makeClientWithGov(rpcUrl: string): Promise<[QueryClient & GovExtension, Tendermint34Client]> {
|
||||
const tmClient = await Tendermint34Client.connect(rpcUrl);
|
||||
@ -13,8 +13,7 @@ import {
|
||||
} from "cosmjs-types/cosmos/gov/v1beta1/query";
|
||||
import Long from "long";
|
||||
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { createPagination, createProtobufRpcClient, longify } from "./utils";
|
||||
import { createPagination, createProtobufRpcClient, longify, QueryClient } from "../../queryclient";
|
||||
|
||||
export type GovParamsType = "deposit" | "tallying" | "voting";
|
||||
|
||||
114
packages/stargate/src/modules/ibc/aminomessages.ts
Normal file
114
packages/stargate/src/modules/ibc/aminomessages.ts
Normal file
@ -0,0 +1,114 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoMsg, Coin } from "@cosmjs/amino";
|
||||
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
|
||||
import Long from "long";
|
||||
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
|
||||
// https://github.com/cosmos/ibc-go/blob/07b6a97b67d17fd214a83764cbdb2c2c3daef445/modules/core/02-client/types/client.pb.go#L297-L312
|
||||
interface AminoHeight {
|
||||
/** 0 values must be omitted (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/core/02-client/types/client.pb.go#L252). */
|
||||
readonly revision_number?: string;
|
||||
/** 0 values must be omitted (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/core/02-client/types/client.pb.go#L254). */
|
||||
readonly revision_height?: string;
|
||||
}
|
||||
|
||||
// https://github.com/cosmos/ibc-go/blob/07b6a97b67d17fd214a83764cbdb2c2c3daef445/modules/apps/transfer/types/tx.pb.go#L33-L53
|
||||
/** Transfers fungible tokens (i.e Coins) between ICS20 enabled chains */
|
||||
export interface AminoMsgTransfer extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgTransfer";
|
||||
readonly value: {
|
||||
readonly source_port: string;
|
||||
readonly source_channel: string;
|
||||
readonly token?: Coin;
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
/** Bech32 account address */
|
||||
readonly receiver: string;
|
||||
/**
|
||||
* The timeout as a (revision_number, revision_height) pair.
|
||||
*
|
||||
* This fied is is non-optional (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/applications/transfer/types/tx.pb.go#L49).
|
||||
* In order to not set the timeout height, set it to {}.
|
||||
*/
|
||||
readonly timeout_height: AminoHeight;
|
||||
/**
|
||||
* Timeout timestamp in nanoseconds since Unix epoch. The timeout is disabled when set to 0.
|
||||
*
|
||||
* 0 values must be omitted (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/applications/transfer/types/tx.pb.go#L52).
|
||||
*/
|
||||
readonly timeout_timestamp?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgTransfer(msg: AminoMsg): msg is AminoMsgTransfer {
|
||||
return msg.type === "cosmos-sdk/MsgTransfer";
|
||||
}
|
||||
|
||||
function omitDefault<T extends string | number | Long>(input: T): T | undefined {
|
||||
if (typeof input === "string") {
|
||||
return input === "" ? undefined : input;
|
||||
}
|
||||
|
||||
if (typeof input === "number") {
|
||||
return input === 0 ? undefined : input;
|
||||
}
|
||||
|
||||
if (Long.isLong(input)) {
|
||||
return input.isZero() ? undefined : input;
|
||||
}
|
||||
|
||||
throw new Error(`Got unsupported type '${typeof input}'`);
|
||||
}
|
||||
|
||||
export function createIbcAminoConverters(): AminoConverters {
|
||||
return {
|
||||
"/ibc.applications.transfer.v1.MsgTransfer": {
|
||||
aminoType: "cosmos-sdk/MsgTransfer",
|
||||
toAmino: ({
|
||||
sourcePort,
|
||||
sourceChannel,
|
||||
token,
|
||||
sender,
|
||||
receiver,
|
||||
timeoutHeight,
|
||||
timeoutTimestamp,
|
||||
}: MsgTransfer): AminoMsgTransfer["value"] => ({
|
||||
source_port: sourcePort,
|
||||
source_channel: sourceChannel,
|
||||
token: token,
|
||||
sender: sender,
|
||||
receiver: receiver,
|
||||
timeout_height: timeoutHeight
|
||||
? {
|
||||
revision_height: omitDefault(timeoutHeight.revisionHeight)?.toString(),
|
||||
revision_number: omitDefault(timeoutHeight.revisionNumber)?.toString(),
|
||||
}
|
||||
: {},
|
||||
timeout_timestamp: omitDefault(timeoutTimestamp)?.toString(),
|
||||
}),
|
||||
fromAmino: ({
|
||||
source_port,
|
||||
source_channel,
|
||||
token,
|
||||
sender,
|
||||
receiver,
|
||||
timeout_height,
|
||||
timeout_timestamp,
|
||||
}: AminoMsgTransfer["value"]): MsgTransfer => ({
|
||||
sourcePort: source_port,
|
||||
sourceChannel: source_channel,
|
||||
token: token,
|
||||
sender: sender,
|
||||
receiver: receiver,
|
||||
timeoutHeight: timeout_height
|
||||
? {
|
||||
revisionHeight: Long.fromString(timeout_height.revision_height || "0", true),
|
||||
revisionNumber: Long.fromString(timeout_height.revision_number || "0", true),
|
||||
}
|
||||
: undefined,
|
||||
timeoutTimestamp: Long.fromString(timeout_timestamp || "0", true),
|
||||
}),
|
||||
},
|
||||
};
|
||||
}
|
||||
57
packages/stargate/src/modules/ibc/messages.ts
Normal file
57
packages/stargate/src/modules/ibc/messages.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing";
|
||||
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
|
||||
import {
|
||||
MsgAcknowledgement,
|
||||
MsgChannelCloseConfirm,
|
||||
MsgChannelCloseInit,
|
||||
MsgChannelOpenAck,
|
||||
MsgChannelOpenConfirm,
|
||||
MsgChannelOpenInit,
|
||||
MsgChannelOpenTry,
|
||||
MsgRecvPacket,
|
||||
MsgTimeout,
|
||||
MsgTimeoutOnClose,
|
||||
} from "cosmjs-types/ibc/core/channel/v1/tx";
|
||||
import {
|
||||
MsgCreateClient,
|
||||
MsgSubmitMisbehaviour,
|
||||
MsgUpdateClient,
|
||||
MsgUpgradeClient,
|
||||
} from "cosmjs-types/ibc/core/client/v1/tx";
|
||||
import {
|
||||
MsgConnectionOpenAck,
|
||||
MsgConnectionOpenConfirm,
|
||||
MsgConnectionOpenInit,
|
||||
MsgConnectionOpenTry,
|
||||
} from "cosmjs-types/ibc/core/connection/v1/tx";
|
||||
|
||||
export const ibcTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
["/ibc.applications.transfer.v1.MsgTransfer", MsgTransfer],
|
||||
["/ibc.core.channel.v1.MsgAcknowledgement", MsgAcknowledgement],
|
||||
["/ibc.core.channel.v1.MsgChannelCloseConfirm", MsgChannelCloseConfirm],
|
||||
["/ibc.core.channel.v1.MsgChannelCloseInit", MsgChannelCloseInit],
|
||||
["/ibc.core.channel.v1.MsgChannelOpenAck", MsgChannelOpenAck],
|
||||
["/ibc.core.channel.v1.MsgChannelOpenConfirm", MsgChannelOpenConfirm],
|
||||
["/ibc.core.channel.v1.MsgChannelOpenInit", MsgChannelOpenInit],
|
||||
["/ibc.core.channel.v1.MsgChannelOpenTry", MsgChannelOpenTry],
|
||||
["/ibc.core.channel.v1.MsgRecvPacket", MsgRecvPacket],
|
||||
["/ibc.core.channel.v1.MsgTimeout", MsgTimeout],
|
||||
["/ibc.core.channel.v1.MsgTimeoutOnClose", MsgTimeoutOnClose],
|
||||
["/ibc.core.client.v1.MsgCreateClient", MsgCreateClient],
|
||||
["/ibc.core.client.v1.MsgSubmitMisbehaviour", MsgSubmitMisbehaviour],
|
||||
["/ibc.core.client.v1.MsgUpdateClient", MsgUpdateClient],
|
||||
["/ibc.core.client.v1.MsgUpgradeClient", MsgUpgradeClient],
|
||||
["/ibc.core.connection.v1.MsgConnectionOpenAck", MsgConnectionOpenAck],
|
||||
["/ibc.core.connection.v1.MsgConnectionOpenConfirm", MsgConnectionOpenConfirm],
|
||||
["/ibc.core.connection.v1.MsgConnectionOpenInit", MsgConnectionOpenInit],
|
||||
["/ibc.core.connection.v1.MsgConnectionOpenTry", MsgConnectionOpenTry],
|
||||
];
|
||||
|
||||
export interface MsgTransferEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/ibc.applications.transfer.v1.MsgTransfer";
|
||||
readonly value: Partial<MsgTransfer>;
|
||||
}
|
||||
|
||||
export function isMsgTransferEncodeObject(object: EncodeObject): object is MsgTransferEncodeObject {
|
||||
return (object as MsgTransferEncodeObject).typeUrl === "/ibc.applications.transfer.v1.MsgTransfer";
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
|
||||
import Long from "long";
|
||||
|
||||
import { pendingWithoutSimapp42, simapp } from "../testutils.spec";
|
||||
import { IbcExtension, setupIbcExtension } from "./ibc";
|
||||
import { QueryClient } from "../../queryclient";
|
||||
import { pendingWithoutSimapp42, simapp } from "../../testutils.spec";
|
||||
import * as ibcTest from "./ibctestdata.spec";
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { IbcExtension, setupIbcExtension } from "./queries";
|
||||
|
||||
async function makeClientWithIbc(rpcUrl: string): Promise<[QueryClient & IbcExtension, Tendermint34Client]> {
|
||||
const tmClient = await Tendermint34Client.connect(rpcUrl);
|
||||
@ -50,8 +50,7 @@ import {
|
||||
} from "cosmjs-types/ibc/lightclients/tendermint/v1/tendermint";
|
||||
import Long from "long";
|
||||
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { createPagination, createProtobufRpcClient } from "./utils";
|
||||
import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient";
|
||||
|
||||
function decodeTendermintClientStateAny(clientState: Any | undefined): TendermintClientState {
|
||||
if (clientState?.typeUrl !== "/ibc.lightclients.tendermint.v1.ClientState") {
|
||||
88
packages/stargate/src/modules/index.ts
Normal file
88
packages/stargate/src/modules/index.ts
Normal file
@ -0,0 +1,88 @@
|
||||
export { AuthExtension, setupAuthExtension } from "./auth/queries";
|
||||
export { createAuthzAminoConverters } from "./authz/aminomessages";
|
||||
export { authzTypes } from "./authz/messages";
|
||||
export {
|
||||
AminoMsgMultiSend,
|
||||
AminoMsgSend,
|
||||
createBankAminoConverters,
|
||||
isAminoMsgMultiSend,
|
||||
isAminoMsgSend,
|
||||
} from "./bank/aminomessages";
|
||||
export { bankTypes, isMsgSendEncodeObject, MsgSendEncodeObject } from "./bank/messages";
|
||||
export { BankExtension, setupBankExtension } from "./bank/queries";
|
||||
export {
|
||||
AminoMsgVerifyInvariant,
|
||||
createCrysisAminoConverters,
|
||||
isAminoMsgVerifyInvariant,
|
||||
} from "./crisis/aminomessages";
|
||||
export {
|
||||
AminoMsgFundCommunityPool,
|
||||
AminoMsgSetWithdrawAddress,
|
||||
AminoMsgWithdrawDelegatorReward,
|
||||
AminoMsgWithdrawValidatorCommission,
|
||||
createDistributionAminoConverters,
|
||||
isAminoMsgFundCommunityPool,
|
||||
isAminoMsgSetWithdrawAddress,
|
||||
isAminoMsgWithdrawDelegatorReward,
|
||||
isAminoMsgWithdrawValidatorCommission,
|
||||
} from "./distribution/aminomessages";
|
||||
export {
|
||||
distributionTypes,
|
||||
isMsgWithdrawDelegatorRewardEncodeObject,
|
||||
MsgWithdrawDelegatorRewardEncodeObject,
|
||||
} from "./distribution/messages";
|
||||
export { DistributionExtension, setupDistributionExtension } from "./distribution/queries";
|
||||
export {
|
||||
AminoMsgSubmitEvidence,
|
||||
createEvidenceAminoConverters,
|
||||
isAminoMsgSubmitEvidence,
|
||||
} from "./evidence/aminomessages";
|
||||
export { createFreegrantAminoConverters } from "./feegrant/aminomessages";
|
||||
export { feegrantTypes } from "./feegrant/messages";
|
||||
export {
|
||||
AminoMsgDeposit,
|
||||
AminoMsgSubmitProposal,
|
||||
AminoMsgVote,
|
||||
createGovAminoConverters,
|
||||
isAminoMsgDeposit,
|
||||
isAminoMsgSubmitProposal,
|
||||
isAminoMsgVote,
|
||||
} from "./gov/aminomessages";
|
||||
export {
|
||||
govTypes,
|
||||
isMsgDepositEncodeObject,
|
||||
isMsgSubmitProposalEncodeObject,
|
||||
isMsgVoteEncodeObject,
|
||||
MsgDepositEncodeObject,
|
||||
MsgSubmitProposalEncodeObject,
|
||||
MsgVoteEncodeObject,
|
||||
} from "./gov/messages";
|
||||
export { GovExtension, GovParamsType, GovProposalId, setupGovExtension } from "./gov/queries";
|
||||
export { AminoMsgTransfer, createIbcAminoConverters, isAminoMsgTransfer } from "./ibc/aminomessages";
|
||||
export { ibcTypes, isMsgTransferEncodeObject, MsgTransferEncodeObject } from "./ibc/messages";
|
||||
export { IbcExtension, setupIbcExtension } from "./ibc/queries";
|
||||
export { MintExtension, MintParams, setupMintExtension } from "./mint/queries";
|
||||
export { AminoMsgUnjail, createSlashingAminoConverters, isAminoMsgUnjail } from "./slashing/aminomessages";
|
||||
export { setupSlashingExtension, SlashingExtension } from "./slashing/queries";
|
||||
export {
|
||||
AminoMsgBeginRedelegate,
|
||||
AminoMsgCreateValidator,
|
||||
AminoMsgDelegate,
|
||||
AminoMsgEditValidator,
|
||||
AminoMsgUndelegate,
|
||||
createStakingAminoConverters,
|
||||
isAminoMsgBeginRedelegate,
|
||||
isAminoMsgCreateValidator,
|
||||
isAminoMsgDelegate,
|
||||
isAminoMsgEditValidator,
|
||||
isAminoMsgUndelegate,
|
||||
} from "./staking/aminomessages";
|
||||
export {
|
||||
isMsgDelegateEncodeObject,
|
||||
isMsgUndelegateEncodeObject,
|
||||
MsgDelegateEncodeObject,
|
||||
MsgUndelegateEncodeObject,
|
||||
stakingTypes,
|
||||
} from "./staking/messages";
|
||||
export { setupStakingExtension, StakingExtension } from "./staking/queries";
|
||||
export { setupTxExtension, TxExtension } from "./tx/queries";
|
||||
@ -1,8 +1,8 @@
|
||||
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
|
||||
|
||||
import { QueryClient } from "../";
|
||||
import { pendingWithoutSimapp, simapp } from "../testutils.spec";
|
||||
import { MintExtension, setupMintExtension } from "./mint";
|
||||
import { QueryClient } from "../../queryclient";
|
||||
import { pendingWithoutSimapp, simapp } from "../../testutils.spec";
|
||||
import { MintExtension, setupMintExtension } from "./queries";
|
||||
|
||||
async function makeClientWithMint(
|
||||
rpcUrl: string,
|
||||
@ -3,9 +3,7 @@ import { assert } from "@cosmjs/utils";
|
||||
import { Params } from "cosmjs-types/cosmos/mint/v1beta1/mint";
|
||||
import { QueryClientImpl } from "cosmjs-types/cosmos/mint/v1beta1/query";
|
||||
|
||||
import { createProtobufRpcClient } from "../";
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { decodeCosmosSdkDecFromProto } from "./utils";
|
||||
import { createProtobufRpcClient, decodeCosmosSdkDecFromProto, QueryClient } from "../../queryclient";
|
||||
|
||||
/**
|
||||
* Like Params from "cosmjs-types/cosmos/mint/v1beta1/mint"
|
||||
23
packages/stargate/src/modules/slashing/aminomessages.ts
Normal file
23
packages/stargate/src/modules/slashing/aminomessages.ts
Normal file
@ -0,0 +1,23 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoMsg } from "@cosmjs/amino";
|
||||
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
|
||||
// See https://github.com/cosmos/cosmos-sdk/blob/v0.45.1/proto/cosmos/slashing/v1beta1/tx.proto
|
||||
|
||||
/** Unjails a jailed validator */
|
||||
export interface AminoMsgUnjail extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgUnjail";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly validator_addr: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgUnjail(msg: AminoMsg): msg is AminoMsgUnjail {
|
||||
return msg.type === "cosmos-sdk/MsgUnjail";
|
||||
}
|
||||
|
||||
export function createSlashingAminoConverters(): AminoConverters {
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
|
||||
|
||||
import { pendingWithoutSimapp, simapp } from "../testutils.spec";
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { setupSlashingExtension, SlashingExtension } from "./slashing";
|
||||
import { QueryClient } from "../../queryclient";
|
||||
import { pendingWithoutSimapp, simapp } from "../../testutils.spec";
|
||||
import { setupSlashingExtension, SlashingExtension } from "./queries";
|
||||
|
||||
async function makeClientWithSlashing(
|
||||
rpcUrl: string,
|
||||
@ -6,8 +6,7 @@ import {
|
||||
} from "cosmjs-types/cosmos/slashing/v1beta1/query";
|
||||
import { QueryClientImpl } from "cosmjs-types/cosmos/slashing/v1beta1/query";
|
||||
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { createPagination, createProtobufRpcClient } from "./utils";
|
||||
import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient";
|
||||
|
||||
export interface SlashingExtension {
|
||||
readonly slashing: {
|
||||
317
packages/stargate/src/modules/staking/aminomessages.ts
Normal file
317
packages/stargate/src/modules/staking/aminomessages.ts
Normal file
@ -0,0 +1,317 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoMsg, Coin, decodeBech32Pubkey, encodeBech32Pubkey } from "@cosmjs/amino";
|
||||
import { fromBase64, toBase64 } from "@cosmjs/encoding";
|
||||
import { assertDefinedAndNotNull } from "@cosmjs/utils";
|
||||
import {
|
||||
MsgBeginRedelegate,
|
||||
MsgCreateValidator,
|
||||
MsgDelegate,
|
||||
MsgEditValidator,
|
||||
MsgUndelegate,
|
||||
} from "cosmjs-types/cosmos/staking/v1beta1/tx";
|
||||
|
||||
import { AminoConverter } from "../..";
|
||||
|
||||
/** The initial commission rates to be used for creating a validator */
|
||||
interface CommissionRates {
|
||||
readonly rate: string;
|
||||
readonly max_rate: string;
|
||||
readonly max_change_rate: string;
|
||||
}
|
||||
|
||||
/** A validator description. */
|
||||
interface Description {
|
||||
readonly moniker: string;
|
||||
readonly identity: string;
|
||||
readonly website: string;
|
||||
readonly security_contact: string;
|
||||
readonly details: string;
|
||||
}
|
||||
|
||||
/** Creates a new validator. */
|
||||
export interface AminoMsgCreateValidator extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgCreateValidator";
|
||||
readonly value: {
|
||||
readonly description: Description;
|
||||
readonly commission: CommissionRates;
|
||||
readonly min_self_delegation: string;
|
||||
/** Bech32 encoded delegator address */
|
||||
readonly delegator_address: string;
|
||||
/** Bech32 encoded validator address */
|
||||
readonly validator_address: string;
|
||||
/** Bech32 encoded public key */
|
||||
readonly pubkey: string;
|
||||
readonly value: Coin;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgCreateValidator(msg: AminoMsg): msg is AminoMsgCreateValidator {
|
||||
return msg.type === "cosmos-sdk/MsgCreateValidator";
|
||||
}
|
||||
|
||||
/** Edits an existing validator. */
|
||||
export interface AminoMsgEditValidator extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgEditValidator";
|
||||
readonly value: {
|
||||
readonly description: Description;
|
||||
/** Bech32 encoded validator address */
|
||||
readonly validator_address: string;
|
||||
readonly commission_rate: string;
|
||||
readonly min_self_delegation: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgEditValidator(msg: AminoMsg): msg is AminoMsgEditValidator {
|
||||
return msg.type === "cosmos-sdk/MsgEditValidator";
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a delegation from a delegate to a validator.
|
||||
*
|
||||
* @see https://docs.cosmos.network/master/modules/staking/03_messages.html#msgdelegate
|
||||
*/
|
||||
export interface AminoMsgDelegate extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgDelegate";
|
||||
readonly value: {
|
||||
/** Bech32 encoded delegator address */
|
||||
readonly delegator_address: string;
|
||||
/** Bech32 encoded validator address */
|
||||
readonly validator_address: string;
|
||||
readonly amount: Coin;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgDelegate(msg: AminoMsg): msg is AminoMsgDelegate {
|
||||
return msg.type === "cosmos-sdk/MsgDelegate";
|
||||
}
|
||||
|
||||
/** Performs a redelegation from a delegate and source validator to a destination validator */
|
||||
export interface AminoMsgBeginRedelegate extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgBeginRedelegate";
|
||||
readonly value: {
|
||||
/** Bech32 encoded delegator address */
|
||||
readonly delegator_address: string;
|
||||
/** Bech32 encoded source validator address */
|
||||
readonly validator_src_address: string;
|
||||
/** Bech32 encoded destination validator address */
|
||||
readonly validator_dst_address: string;
|
||||
readonly amount: Coin;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgBeginRedelegate(msg: AminoMsg): msg is AminoMsgBeginRedelegate {
|
||||
return msg.type === "cosmos-sdk/MsgBeginRedelegate";
|
||||
}
|
||||
|
||||
/** Performs an undelegation from a delegate and a validator */
|
||||
export interface AminoMsgUndelegate extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgUndelegate";
|
||||
readonly value: {
|
||||
/** Bech32 encoded delegator address */
|
||||
readonly delegator_address: string;
|
||||
/** Bech32 encoded validator address */
|
||||
readonly validator_address: string;
|
||||
readonly amount: Coin;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgUndelegate(msg: AminoMsg): msg is AminoMsgUndelegate {
|
||||
return msg.type === "cosmos-sdk/MsgUndelegate";
|
||||
}
|
||||
|
||||
export function createStakingAminoConverters(
|
||||
prefix: string,
|
||||
): Record<string, AminoConverter | "not_supported_by_chain"> {
|
||||
return {
|
||||
"/cosmos.staking.v1beta1.MsgBeginRedelegate": {
|
||||
aminoType: "cosmos-sdk/MsgBeginRedelegate",
|
||||
toAmino: ({
|
||||
delegatorAddress,
|
||||
validatorSrcAddress,
|
||||
validatorDstAddress,
|
||||
amount,
|
||||
}: MsgBeginRedelegate): AminoMsgBeginRedelegate["value"] => {
|
||||
assertDefinedAndNotNull(amount, "missing amount");
|
||||
return {
|
||||
delegator_address: delegatorAddress,
|
||||
validator_src_address: validatorSrcAddress,
|
||||
validator_dst_address: validatorDstAddress,
|
||||
amount: amount,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_src_address,
|
||||
validator_dst_address,
|
||||
amount,
|
||||
}: AminoMsgBeginRedelegate["value"]): MsgBeginRedelegate => ({
|
||||
delegatorAddress: delegator_address,
|
||||
validatorSrcAddress: validator_src_address,
|
||||
validatorDstAddress: validator_dst_address,
|
||||
amount: amount,
|
||||
}),
|
||||
},
|
||||
"/cosmos.staking.v1beta1.MsgCreateValidator": {
|
||||
aminoType: "cosmos-sdk/MsgCreateValidator",
|
||||
toAmino: ({
|
||||
description,
|
||||
commission,
|
||||
minSelfDelegation,
|
||||
delegatorAddress,
|
||||
validatorAddress,
|
||||
pubkey,
|
||||
value,
|
||||
}: MsgCreateValidator): AminoMsgCreateValidator["value"] => {
|
||||
assertDefinedAndNotNull(description, "missing description");
|
||||
assertDefinedAndNotNull(commission, "missing commission");
|
||||
assertDefinedAndNotNull(pubkey, "missing pubkey");
|
||||
assertDefinedAndNotNull(value, "missing value");
|
||||
return {
|
||||
description: {
|
||||
moniker: description.moniker,
|
||||
identity: description.identity,
|
||||
website: description.website,
|
||||
security_contact: description.securityContact,
|
||||
details: description.details,
|
||||
},
|
||||
commission: {
|
||||
rate: commission.rate,
|
||||
max_rate: commission.maxRate,
|
||||
max_change_rate: commission.maxChangeRate,
|
||||
},
|
||||
min_self_delegation: minSelfDelegation,
|
||||
delegator_address: delegatorAddress,
|
||||
validator_address: validatorAddress,
|
||||
pubkey: encodeBech32Pubkey(
|
||||
{
|
||||
type: "tendermint/PubKeySecp256k1",
|
||||
value: toBase64(pubkey.value),
|
||||
},
|
||||
prefix,
|
||||
),
|
||||
value: value,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
description,
|
||||
commission,
|
||||
min_self_delegation,
|
||||
delegator_address,
|
||||
validator_address,
|
||||
pubkey,
|
||||
value,
|
||||
}: AminoMsgCreateValidator["value"]): MsgCreateValidator => {
|
||||
const decodedPubkey = decodeBech32Pubkey(pubkey);
|
||||
if (decodedPubkey.type !== "tendermint/PubKeySecp256k1") {
|
||||
throw new Error("Only Secp256k1 public keys are supported");
|
||||
}
|
||||
return {
|
||||
description: {
|
||||
moniker: description.moniker,
|
||||
identity: description.identity,
|
||||
website: description.website,
|
||||
securityContact: description.security_contact,
|
||||
details: description.details,
|
||||
},
|
||||
commission: {
|
||||
rate: commission.rate,
|
||||
maxRate: commission.max_rate,
|
||||
maxChangeRate: commission.max_change_rate,
|
||||
},
|
||||
minSelfDelegation: min_self_delegation,
|
||||
delegatorAddress: delegator_address,
|
||||
validatorAddress: validator_address,
|
||||
pubkey: {
|
||||
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
|
||||
value: fromBase64(decodedPubkey.value),
|
||||
},
|
||||
value: value,
|
||||
};
|
||||
},
|
||||
},
|
||||
"/cosmos.staking.v1beta1.MsgDelegate": {
|
||||
aminoType: "cosmos-sdk/MsgDelegate",
|
||||
toAmino: ({ delegatorAddress, validatorAddress, amount }: MsgDelegate): AminoMsgDelegate["value"] => {
|
||||
assertDefinedAndNotNull(amount, "missing amount");
|
||||
return {
|
||||
delegator_address: delegatorAddress,
|
||||
validator_address: validatorAddress,
|
||||
amount: amount,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
amount,
|
||||
}: AminoMsgDelegate["value"]): MsgDelegate => ({
|
||||
delegatorAddress: delegator_address,
|
||||
validatorAddress: validator_address,
|
||||
amount: amount,
|
||||
}),
|
||||
},
|
||||
"/cosmos.staking.v1beta1.MsgEditValidator": {
|
||||
aminoType: "cosmos-sdk/MsgEditValidator",
|
||||
toAmino: ({
|
||||
description,
|
||||
commissionRate,
|
||||
minSelfDelegation,
|
||||
validatorAddress,
|
||||
}: MsgEditValidator): AminoMsgEditValidator["value"] => {
|
||||
assertDefinedAndNotNull(description, "missing description");
|
||||
return {
|
||||
description: {
|
||||
moniker: description.moniker,
|
||||
identity: description.identity,
|
||||
website: description.website,
|
||||
security_contact: description.securityContact,
|
||||
details: description.details,
|
||||
},
|
||||
commission_rate: commissionRate,
|
||||
min_self_delegation: minSelfDelegation,
|
||||
validator_address: validatorAddress,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
description,
|
||||
commission_rate,
|
||||
min_self_delegation,
|
||||
validator_address,
|
||||
}: AminoMsgEditValidator["value"]): MsgEditValidator => ({
|
||||
description: {
|
||||
moniker: description.moniker,
|
||||
identity: description.identity,
|
||||
website: description.website,
|
||||
securityContact: description.security_contact,
|
||||
details: description.details,
|
||||
},
|
||||
commissionRate: commission_rate,
|
||||
minSelfDelegation: min_self_delegation,
|
||||
validatorAddress: validator_address,
|
||||
}),
|
||||
},
|
||||
"/cosmos.staking.v1beta1.MsgUndelegate": {
|
||||
aminoType: "cosmos-sdk/MsgUndelegate",
|
||||
toAmino: ({
|
||||
delegatorAddress,
|
||||
validatorAddress,
|
||||
amount,
|
||||
}: MsgUndelegate): AminoMsgUndelegate["value"] => {
|
||||
assertDefinedAndNotNull(amount, "missing amount");
|
||||
return {
|
||||
delegator_address: delegatorAddress,
|
||||
validator_address: validatorAddress,
|
||||
amount: amount,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
amount,
|
||||
}: AminoMsgUndelegate["value"]): MsgUndelegate => ({
|
||||
delegatorAddress: delegator_address,
|
||||
validatorAddress: validator_address,
|
||||
amount: amount,
|
||||
}),
|
||||
},
|
||||
};
|
||||
}
|
||||
34
packages/stargate/src/modules/staking/messages.ts
Normal file
34
packages/stargate/src/modules/staking/messages.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing";
|
||||
import {
|
||||
MsgBeginRedelegate,
|
||||
MsgCreateValidator,
|
||||
MsgDelegate,
|
||||
MsgEditValidator,
|
||||
MsgUndelegate,
|
||||
} from "cosmjs-types/cosmos/staking/v1beta1/tx";
|
||||
|
||||
export const stakingTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
["/cosmos.staking.v1beta1.MsgBeginRedelegate", MsgBeginRedelegate],
|
||||
["/cosmos.staking.v1beta1.MsgCreateValidator", MsgCreateValidator],
|
||||
["/cosmos.staking.v1beta1.MsgDelegate", MsgDelegate],
|
||||
["/cosmos.staking.v1beta1.MsgEditValidator", MsgEditValidator],
|
||||
["/cosmos.staking.v1beta1.MsgUndelegate", MsgUndelegate],
|
||||
];
|
||||
|
||||
export interface MsgDelegateEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmos.staking.v1beta1.MsgDelegate";
|
||||
readonly value: Partial<MsgDelegate>;
|
||||
}
|
||||
|
||||
export function isMsgDelegateEncodeObject(object: EncodeObject): object is MsgDelegateEncodeObject {
|
||||
return (object as MsgDelegateEncodeObject).typeUrl === "/cosmos.staking.v1beta1.MsgDelegate";
|
||||
}
|
||||
|
||||
export interface MsgUndelegateEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate";
|
||||
readonly value: Partial<MsgUndelegate>;
|
||||
}
|
||||
|
||||
export function isMsgUndelegateEncodeObject(object: EncodeObject): object is MsgUndelegateEncodeObject {
|
||||
return (object as MsgUndelegateEncodeObject).typeUrl === "/cosmos.staking.v1beta1.MsgUndelegate";
|
||||
}
|
||||
@ -4,9 +4,9 @@ import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
|
||||
import { sleep } from "@cosmjs/utils";
|
||||
import { MsgDelegate, MsgUndelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
|
||||
|
||||
import { MsgDelegateEncodeObject, MsgUndelegateEncodeObject } from "../encodeobjects";
|
||||
import { SigningStargateClient } from "../signingstargateclient";
|
||||
import { assertIsDeliverTxSuccess } from "../stargateclient";
|
||||
import { QueryClient } from "../../queryclient";
|
||||
import { SigningStargateClient } from "../../signingstargateclient";
|
||||
import { assertIsDeliverTxSuccess } from "../../stargateclient";
|
||||
import {
|
||||
defaultSigningClientOptions,
|
||||
faucet,
|
||||
@ -14,9 +14,9 @@ import {
|
||||
simapp,
|
||||
simappEnabled,
|
||||
validator,
|
||||
} from "../testutils.spec";
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { setupStakingExtension, StakingExtension } from "./staking";
|
||||
} from "../../testutils.spec";
|
||||
import { MsgDelegateEncodeObject, MsgUndelegateEncodeObject } from "./messages";
|
||||
import { setupStakingExtension, StakingExtension } from "./queries";
|
||||
|
||||
async function makeClientWithStaking(
|
||||
rpcUrl: string,
|
||||
@ -19,8 +19,7 @@ import {
|
||||
import { BondStatus } from "cosmjs-types/cosmos/staking/v1beta1/staking";
|
||||
import Long from "long";
|
||||
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { createPagination, createProtobufRpcClient } from "./utils";
|
||||
import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient";
|
||||
|
||||
export type BondStatusString = Exclude<keyof typeof BondStatus, "BOND_STATUS_UNSPECIFIED">;
|
||||
|
||||
@ -4,8 +4,9 @@ import { assertDefined, sleep } from "@cosmjs/utils";
|
||||
import { MsgDelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
|
||||
import Long from "long";
|
||||
|
||||
import { defaultRegistryTypes, SigningStargateClient } from "../signingstargateclient";
|
||||
import { assertIsDeliverTxSuccess, StargateClient } from "../stargateclient";
|
||||
import { longify, QueryClient } from "../../queryclient";
|
||||
import { defaultRegistryTypes, SigningStargateClient } from "../../signingstargateclient";
|
||||
import { assertIsDeliverTxSuccess, StargateClient } from "../../stargateclient";
|
||||
import {
|
||||
defaultSigningClientOptions,
|
||||
faucet,
|
||||
@ -14,10 +15,8 @@ import {
|
||||
simapp,
|
||||
simappEnabled,
|
||||
validator,
|
||||
} from "../testutils.spec";
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { setupTxExtension, TxExtension } from "./tx";
|
||||
import { longify } from "./utils";
|
||||
} from "../../testutils.spec";
|
||||
import { setupTxExtension, TxExtension } from "./queries";
|
||||
|
||||
async function makeClientWithTx(rpcUrl: string): Promise<[QueryClient & TxExtension, Tendermint34Client]> {
|
||||
const tmClient = await Tendermint34Client.connect(rpcUrl);
|
||||
@ -12,8 +12,7 @@ import { AuthInfo, Fee, Tx, TxBody } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
||||
import { Any } from "cosmjs-types/google/protobuf/any";
|
||||
import Long from "long";
|
||||
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { createProtobufRpcClient } from "./utils";
|
||||
import { createProtobufRpcClient, QueryClient } from "../../queryclient";
|
||||
|
||||
export interface TxExtension {
|
||||
readonly tx: {
|
||||
@ -10,7 +10,7 @@ import { assert } from "@cosmjs/utils";
|
||||
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
|
||||
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
||||
|
||||
import { MsgSendEncodeObject } from "./encodeobjects";
|
||||
import { MsgSendEncodeObject } from "./modules";
|
||||
import { makeCompactBitArray, makeMultisignedTx } from "./multisignature";
|
||||
import { SignerData, SigningStargateClient } from "./signingstargateclient";
|
||||
import { assertIsDeliverTxSuccess, StargateClient } from "./stargateclient";
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
// Base symbols
|
||||
|
||||
export { QueryClient } from "./queryclient";
|
||||
|
||||
// Extensions
|
||||
|
||||
export { AuthExtension, setupAuthExtension } from "./auth";
|
||||
export { BankExtension, setupBankExtension } from "./bank";
|
||||
export { DistributionExtension, setupDistributionExtension } from "./distribution";
|
||||
export { GovExtension, GovParamsType, GovProposalId, setupGovExtension } from "./gov";
|
||||
export { IbcExtension, setupIbcExtension } from "./ibc";
|
||||
export { MintExtension, MintParams, setupMintExtension } from "./mint";
|
||||
export { setupSlashingExtension, SlashingExtension } from "./slashing";
|
||||
export { setupStakingExtension, StakingExtension } from "./staking";
|
||||
export { setupTxExtension, TxExtension } from "./tx";
|
||||
export {
|
||||
createPagination,
|
||||
createProtobufRpcClient,
|
||||
decodeCosmosSdkDecFromProto,
|
||||
ProtobufRpcClient,
|
||||
} from "./utils";
|
||||
8
packages/stargate/src/queryclient/index.ts
Normal file
8
packages/stargate/src/queryclient/index.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export { QueryClient } from "./queryclient";
|
||||
export {
|
||||
createPagination,
|
||||
createProtobufRpcClient,
|
||||
decodeCosmosSdkDecFromProto,
|
||||
longify,
|
||||
ProtobufRpcClient,
|
||||
} from "./utils";
|
||||
@ -9,9 +9,8 @@ import { AuthInfo, TxBody, TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
||||
import Long from "long";
|
||||
import protobuf from "protobufjs/minimal";
|
||||
|
||||
import { AminoMsgDelegate } from "./aminomsgs";
|
||||
import { AminoTypes } from "./aminotypes";
|
||||
import { MsgDelegateEncodeObject, MsgSendEncodeObject } from "./encodeobjects";
|
||||
import { AminoMsgDelegate, MsgDelegateEncodeObject, MsgSendEncodeObject } from "./modules";
|
||||
import { PrivateSigningStargateClient, SigningStargateClient } from "./signingstargateclient";
|
||||
import { assertIsDeliverTxFailure, assertIsDeliverTxSuccess, isDeliverTxFailure } from "./stargateclient";
|
||||
import {
|
||||
|
||||
@ -14,105 +14,42 @@ import {
|
||||
} from "@cosmjs/proto-signing";
|
||||
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
|
||||
import { assert, assertDefined } from "@cosmjs/utils";
|
||||
import { MsgExec, MsgGrant, MsgRevoke } from "cosmjs-types/cosmos/authz/v1beta1/tx";
|
||||
import { MsgMultiSend, MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
|
||||
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
|
||||
import {
|
||||
MsgFundCommunityPool,
|
||||
MsgSetWithdrawAddress,
|
||||
MsgWithdrawDelegatorReward,
|
||||
MsgWithdrawValidatorCommission,
|
||||
} from "cosmjs-types/cosmos/distribution/v1beta1/tx";
|
||||
import { MsgGrantAllowance, MsgRevokeAllowance } from "cosmjs-types/cosmos/feegrant/v1beta1/tx";
|
||||
import { MsgDeposit, MsgSubmitProposal, MsgVote } from "cosmjs-types/cosmos/gov/v1beta1/tx";
|
||||
import {
|
||||
MsgBeginRedelegate,
|
||||
MsgCreateValidator,
|
||||
MsgDelegate,
|
||||
MsgEditValidator,
|
||||
MsgUndelegate,
|
||||
} from "cosmjs-types/cosmos/staking/v1beta1/tx";
|
||||
import { MsgWithdrawDelegatorReward } from "cosmjs-types/cosmos/distribution/v1beta1/tx";
|
||||
import { MsgDelegate, MsgUndelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
|
||||
import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
|
||||
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
||||
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
|
||||
import {
|
||||
MsgAcknowledgement,
|
||||
MsgChannelCloseConfirm,
|
||||
MsgChannelCloseInit,
|
||||
MsgChannelOpenAck,
|
||||
MsgChannelOpenConfirm,
|
||||
MsgChannelOpenInit,
|
||||
MsgChannelOpenTry,
|
||||
MsgRecvPacket,
|
||||
MsgTimeout,
|
||||
MsgTimeoutOnClose,
|
||||
} from "cosmjs-types/ibc/core/channel/v1/tx";
|
||||
import { Height } from "cosmjs-types/ibc/core/client/v1/client";
|
||||
import {
|
||||
MsgCreateClient,
|
||||
MsgSubmitMisbehaviour,
|
||||
MsgUpdateClient,
|
||||
MsgUpgradeClient,
|
||||
} from "cosmjs-types/ibc/core/client/v1/tx";
|
||||
import {
|
||||
MsgConnectionOpenAck,
|
||||
MsgConnectionOpenConfirm,
|
||||
MsgConnectionOpenInit,
|
||||
MsgConnectionOpenTry,
|
||||
} from "cosmjs-types/ibc/core/connection/v1/tx";
|
||||
import Long from "long";
|
||||
|
||||
import { AminoTypes } from "./aminotypes";
|
||||
import { calculateFee, GasPrice } from "./fee";
|
||||
import {
|
||||
authzTypes,
|
||||
bankTypes,
|
||||
distributionTypes,
|
||||
feegrantTypes,
|
||||
govTypes,
|
||||
ibcTypes,
|
||||
MsgDelegateEncodeObject,
|
||||
MsgSendEncodeObject,
|
||||
MsgTransferEncodeObject,
|
||||
MsgUndelegateEncodeObject,
|
||||
MsgWithdrawDelegatorRewardEncodeObject,
|
||||
} from "./encodeobjects";
|
||||
import { calculateFee, GasPrice } from "./fee";
|
||||
stakingTypes,
|
||||
} from "./modules";
|
||||
import { DeliverTxResponse, StargateClient } from "./stargateclient";
|
||||
|
||||
export const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
["/cosmos.authz.v1beta1.MsgExec", MsgExec],
|
||||
["/cosmos.authz.v1beta1.MsgGrant", MsgGrant],
|
||||
["/cosmos.authz.v1beta1.MsgRevoke", MsgRevoke],
|
||||
["/cosmos.bank.v1beta1.MsgMultiSend", MsgMultiSend],
|
||||
["/cosmos.bank.v1beta1.MsgSend", MsgSend],
|
||||
["/cosmos.base.v1beta1.Coin", Coin],
|
||||
["/cosmos.distribution.v1beta1.MsgFundCommunityPool", MsgFundCommunityPool],
|
||||
["/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", MsgSetWithdrawAddress],
|
||||
["/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", MsgWithdrawDelegatorReward],
|
||||
["/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission", MsgWithdrawValidatorCommission],
|
||||
["/cosmos.feegrant.v1beta1.MsgGrantAllowance", MsgGrantAllowance],
|
||||
["/cosmos.feegrant.v1beta1.MsgRevokeAllowance", MsgRevokeAllowance],
|
||||
["/cosmos.gov.v1beta1.MsgDeposit", MsgDeposit],
|
||||
["/cosmos.gov.v1beta1.MsgSubmitProposal", MsgSubmitProposal],
|
||||
["/cosmos.gov.v1beta1.MsgVote", MsgVote],
|
||||
["/cosmos.staking.v1beta1.MsgBeginRedelegate", MsgBeginRedelegate],
|
||||
["/cosmos.staking.v1beta1.MsgCreateValidator", MsgCreateValidator],
|
||||
["/cosmos.staking.v1beta1.MsgDelegate", MsgDelegate],
|
||||
["/cosmos.staking.v1beta1.MsgEditValidator", MsgEditValidator],
|
||||
["/cosmos.staking.v1beta1.MsgUndelegate", MsgUndelegate],
|
||||
["/ibc.applications.transfer.v1.MsgTransfer", MsgTransfer],
|
||||
["/ibc.core.channel.v1.MsgAcknowledgement", MsgAcknowledgement],
|
||||
["/ibc.core.channel.v1.MsgChannelCloseConfirm", MsgChannelCloseConfirm],
|
||||
["/ibc.core.channel.v1.MsgChannelCloseInit", MsgChannelCloseInit],
|
||||
["/ibc.core.channel.v1.MsgChannelOpenAck", MsgChannelOpenAck],
|
||||
["/ibc.core.channel.v1.MsgChannelOpenConfirm", MsgChannelOpenConfirm],
|
||||
["/ibc.core.channel.v1.MsgChannelOpenInit", MsgChannelOpenInit],
|
||||
["/ibc.core.channel.v1.MsgChannelOpenTry", MsgChannelOpenTry],
|
||||
["/ibc.core.channel.v1.MsgRecvPacket", MsgRecvPacket],
|
||||
["/ibc.core.channel.v1.MsgTimeout", MsgTimeout],
|
||||
["/ibc.core.channel.v1.MsgTimeoutOnClose", MsgTimeoutOnClose],
|
||||
["/ibc.core.client.v1.MsgCreateClient", MsgCreateClient],
|
||||
["/ibc.core.client.v1.MsgSubmitMisbehaviour", MsgSubmitMisbehaviour],
|
||||
["/ibc.core.client.v1.MsgUpdateClient", MsgUpdateClient],
|
||||
["/ibc.core.client.v1.MsgUpgradeClient", MsgUpgradeClient],
|
||||
["/ibc.core.connection.v1.MsgConnectionOpenAck", MsgConnectionOpenAck],
|
||||
["/ibc.core.connection.v1.MsgConnectionOpenConfirm", MsgConnectionOpenConfirm],
|
||||
["/ibc.core.connection.v1.MsgConnectionOpenInit", MsgConnectionOpenInit],
|
||||
["/ibc.core.connection.v1.MsgConnectionOpenTry", MsgConnectionOpenTry],
|
||||
...authzTypes,
|
||||
...bankTypes,
|
||||
...distributionTypes,
|
||||
...feegrantTypes,
|
||||
...govTypes,
|
||||
...stakingTypes,
|
||||
...ibcTypes,
|
||||
];
|
||||
|
||||
function createDefaultRegistry(): Registry {
|
||||
|
||||
@ -13,7 +13,7 @@ import { assert, sleep } from "@cosmjs/utils";
|
||||
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
|
||||
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
||||
|
||||
import { isMsgSendEncodeObject } from "./encodeobjects";
|
||||
import { isMsgSendEncodeObject } from "./modules";
|
||||
import { DeliverTxResponse, isDeliverTxFailure, isDeliverTxSuccess, StargateClient } from "./stargateclient";
|
||||
import {
|
||||
defaultSigningClientOptions,
|
||||
|
||||
@ -10,14 +10,14 @@ import { Account, accountFromAny } from "./accounts";
|
||||
import {
|
||||
AuthExtension,
|
||||
BankExtension,
|
||||
QueryClient,
|
||||
setupAuthExtension,
|
||||
setupBankExtension,
|
||||
setupStakingExtension,
|
||||
setupTxExtension,
|
||||
StakingExtension,
|
||||
TxExtension,
|
||||
} from "./queries";
|
||||
} from "./modules";
|
||||
import { QueryClient } from "./queryclient";
|
||||
import {
|
||||
isSearchByHeightQuery,
|
||||
isSearchBySentFromOrToQuery,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user