Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contract messages #69

Merged
merged 2 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export { RpcClient } from "./clients/RpcClient";
export { type Adapter } from "./models/Adapter";
export { MsgExecuteContract } from "./models/MsgExecuteContract";
export { MsgInstantiateContract } from "./models/MsgInstantiateContract";
export { MsgStoreCode } from "./models/MsgStoreCode";
export { MsgMigrateContract } from "./models/MsgMigrateContract";
export { MsgExecuteContractInjective } from "./models/MsgExecuteContractInjective";
export { MsgIbcTransfer } from "./models/MsgIbcTransfer";
export { MsgOsmosisSinglePoolSwap } from "./models/MsgOsmosisSinglePoolSwap";
Expand Down
39 changes: 39 additions & 0 deletions src/client/models/MsgMigrateContract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { PlainMessage } from "@bufbuild/protobuf";
import { utf8 } from "cosmes/codec";
import { CosmwasmWasmV1MsgMigrateContract as ProtoMsgMigrateContract } from "cosmes/protobufs";

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

type Data<T> = Prettify<
DeepPrettify<Omit<PlainMessage<ProtoMsgMigrateContract>, "msg">> & {
msg: T;
}
>;

export class MsgMigrateContract<T> implements Adapter {
private readonly data: Data<T>;

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

public toProto() {
return new ProtoMsgMigrateContract({
...this.data,
msg: utf8.decode(JSON.stringify(this.data.msg)),
});
}

public toAmino() {
return {
type: "wasm/MsgMigrateContract",
value: {
sender: this.data.sender,
code_id: this.data.codeId,
contract: this.data.contract,
msg: this.data.msg,
}
};
}
}
33 changes: 33 additions & 0 deletions src/client/models/MsgStoreCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { PlainMessage } from "@bufbuild/protobuf";
import { base64 } from "cosmes/codec";
import { CosmwasmWasmV1MsgStoreCode as ProtoMsgStoreCode } from "cosmes/protobufs";

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

type Data = DeepPrettify<PlainMessage<ProtoMsgStoreCode>>;

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

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

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

public toAmino() {
return {
type: "wasm/MsgStoreCode",
value: {
sender: this.data.sender,
wasm_byte_code: base64.encode(this.data.wasmByteCode),
instantiate_permission: this.data.instantiatePermission,
}
};
}
}
Loading