Skip to content

Commit

Permalink
Add MsgInstantiateContract (#56)
Browse files Browse the repository at this point in the history
Co-authored-by: StrathCole <[email protected]>
  • Loading branch information
przmyst and StrathCole authored Mar 31, 2024
1 parent 5b763f6 commit 8281f63
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export { simulateTx, type SimulateTxParams } from "./apis/simulateTx";
export { RpcClient } from "./clients/RpcClient";
export { type Adapter } from "./models/Adapter";
export { MsgExecuteContract } from "./models/MsgExecuteContract";
export { MsgInstantiateContract } from "./models/MsgInstantiateContract";
export { MsgExecuteContractInjective } from "./models/MsgExecuteContractInjective";
export { MsgIbcTransfer } from "./models/MsgIbcTransfer";
export { MsgOsmosisSinglePoolSwap } from "./models/MsgOsmosisSinglePoolSwap";
Expand Down
41 changes: 41 additions & 0 deletions src/client/models/MsgInstantiateContract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { PlainMessage } from "@bufbuild/protobuf";
import { utf8 } from "cosmes/codec";
import { CosmwasmWasmV1MsgInstantiateContract as ProtoMsgInstantiateContract } from "cosmes/protobufs";

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

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

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

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

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

public toAmino() {
return {
type: "wasm/MsgInstantiateContract",
value: {
sender: this.data.sender,
admin: this.data.admin,
code_id: this.data.codeId,
label: this.data.label,
msg: this.data.msg,
funds: this.data.funds,
}
};
}
}

0 comments on commit 8281f63

Please sign in to comment.