Skip to content

Commit 4633f94

Browse files
StrathColeAaronCQL
andauthored
Add contract messages (#69)
Add migration and code upload for contracts --------- Co-authored-by: Aaron Choo <[email protected]>
1 parent 4da00ba commit 4633f94

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

src/client/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export { RpcClient } from "./clients/RpcClient";
3232
export { type Adapter } from "./models/Adapter";
3333
export { MsgExecuteContract } from "./models/MsgExecuteContract";
3434
export { MsgInstantiateContract } from "./models/MsgInstantiateContract";
35+
export { MsgStoreCode } from "./models/MsgStoreCode";
36+
export { MsgMigrateContract } from "./models/MsgMigrateContract";
3537
export { MsgExecuteContractInjective } from "./models/MsgExecuteContractInjective";
3638
export { MsgIbcTransfer } from "./models/MsgIbcTransfer";
3739
export { MsgOsmosisSinglePoolSwap } from "./models/MsgOsmosisSinglePoolSwap";
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { PlainMessage } from "@bufbuild/protobuf";
2+
import { utf8 } from "cosmes/codec";
3+
import { CosmwasmWasmV1MsgMigrateContract as ProtoMsgMigrateContract } from "cosmes/protobufs";
4+
5+
import { DeepPrettify, Prettify } from "../../typeutils/prettify";
6+
import { Adapter } from "./Adapter";
7+
8+
type Data<T> = Prettify<
9+
DeepPrettify<Omit<PlainMessage<ProtoMsgMigrateContract>, "msg">> & {
10+
msg: T;
11+
}
12+
>;
13+
14+
export class MsgMigrateContract<T> implements Adapter {
15+
private readonly data: Data<T>;
16+
17+
constructor(data: Data<T>) {
18+
this.data = data;
19+
}
20+
21+
public toProto() {
22+
return new ProtoMsgMigrateContract({
23+
...this.data,
24+
msg: utf8.decode(JSON.stringify(this.data.msg)),
25+
});
26+
}
27+
28+
public toAmino() {
29+
return {
30+
type: "wasm/MsgMigrateContract",
31+
value: {
32+
sender: this.data.sender,
33+
code_id: this.data.codeId,
34+
contract: this.data.contract,
35+
msg: this.data.msg,
36+
}
37+
};
38+
}
39+
}

src/client/models/MsgStoreCode.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { PlainMessage } from "@bufbuild/protobuf";
2+
import { base64 } from "cosmes/codec";
3+
import { CosmwasmWasmV1MsgStoreCode as ProtoMsgStoreCode } from "cosmes/protobufs";
4+
5+
import { DeepPrettify } from "../../typeutils/prettify";
6+
import { Adapter } from "./Adapter";
7+
8+
type Data = DeepPrettify<PlainMessage<ProtoMsgStoreCode>>;
9+
10+
export class MsgStoreCode implements Adapter {
11+
private readonly data: Data;
12+
13+
constructor(data: Data) {
14+
this.data = data;
15+
}
16+
17+
public toProto() {
18+
return new ProtoMsgStoreCode({
19+
...this.data,
20+
});
21+
}
22+
23+
public toAmino() {
24+
return {
25+
type: "wasm/MsgStoreCode",
26+
value: {
27+
sender: this.data.sender,
28+
wasm_byte_code: base64.encode(this.data.wasmByteCode),
29+
instantiate_permission: this.data.instantiatePermission,
30+
}
31+
};
32+
}
33+
}

0 commit comments

Comments
 (0)