-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration and code upload for contracts --------- Co-authored-by: Aaron Choo <[email protected]>
- Loading branch information
1 parent
4da00ba
commit 4633f94
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
}; | ||
} | ||
} |