Skip to content

Commit

Permalink
Add contract messages (#69)
Browse files Browse the repository at this point in the history
Add migration and code upload for contracts

---------

Co-authored-by: Aaron Choo <[email protected]>
  • Loading branch information
StrathCole and AaronCQL authored Jun 1, 2024
1 parent 4da00ba commit 4633f94
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
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,
}
};
}
}

0 comments on commit 4633f94

Please sign in to comment.