Skip to content

Commit 8281f63

Browse files
przmystStrathCole
andauthored
Add MsgInstantiateContract (#56)
Co-authored-by: StrathCole <[email protected]>
1 parent 5b763f6 commit 8281f63

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/client/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export { simulateTx, type SimulateTxParams } from "./apis/simulateTx";
3131
export { RpcClient } from "./clients/RpcClient";
3232
export { type Adapter } from "./models/Adapter";
3333
export { MsgExecuteContract } from "./models/MsgExecuteContract";
34+
export { MsgInstantiateContract } from "./models/MsgInstantiateContract";
3435
export { MsgExecuteContractInjective } from "./models/MsgExecuteContractInjective";
3536
export { MsgIbcTransfer } from "./models/MsgIbcTransfer";
3637
export { MsgOsmosisSinglePoolSwap } from "./models/MsgOsmosisSinglePoolSwap";
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { PlainMessage } from "@bufbuild/protobuf";
2+
import { utf8 } from "cosmes/codec";
3+
import { CosmwasmWasmV1MsgInstantiateContract as ProtoMsgInstantiateContract } 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<ProtoMsgInstantiateContract>, "msg">> & {
10+
msg: T;
11+
}
12+
>;
13+
14+
export class MsgInstantiateContract<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 ProtoMsgInstantiateContract({
23+
...this.data,
24+
msg: utf8.decode(JSON.stringify(this.data.msg)),
25+
});
26+
}
27+
28+
public toAmino() {
29+
return {
30+
type: "wasm/MsgInstantiateContract",
31+
value: {
32+
sender: this.data.sender,
33+
admin: this.data.admin,
34+
code_id: this.data.codeId,
35+
label: this.data.label,
36+
msg: this.data.msg,
37+
funds: this.data.funds,
38+
}
39+
};
40+
}
41+
}

0 commit comments

Comments
 (0)