-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable sign in amino wasm, wasmplus store message with access type (#77)
* feat: enable wasm, wasmplus store amino with access type * chore: delete unused things * chore: change port * feat: change codes after bump up wasm * fix: error when omit empty * chore: add changelog * chore: bumpup lbmjs-types and change tests * test: re generate template
- Loading branch information
Showing
47 changed files
with
573 additions
and
106 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
.yarn/cache/lbmjs-types-npm-0.47.0-alpha1-10660dd9cd-4717059664.zip
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
.yarn/cache/lbmjs-types-npm-1.0.0-rc2-e80fe73a1e-3ac7d105e9.zip
Git LFS file not shown
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
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
112 changes: 112 additions & 0 deletions
112
packages/finschia/src/modules/wasm/aminomessages.spec.ts
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,112 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
import { fromBase64 } from "@cosmjs/encoding"; | ||
import { AminoTypes } from "@cosmjs/stargate"; | ||
import { MsgStoreCode } from "lbmjs-types/cosmwasm/wasm/v1/tx"; | ||
import { AccessType } from "lbmjs-types/cosmwasm/wasm/v1/types"; | ||
|
||
import { AminoMsgStoreCode, createWasmAminoConverters } from "./aminomessages"; | ||
|
||
describe("AminoTypes", () => { | ||
describe("toAmino", () => { | ||
it("works for MsgStoreCode", () => { | ||
const msg: MsgStoreCode = { | ||
sender: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="), | ||
instantiatePermission: undefined, | ||
}; | ||
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({ | ||
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode", | ||
value: msg, | ||
}); | ||
const expected: AminoMsgStoreCode = { | ||
type: "wasm/MsgStoreCode", | ||
value: { | ||
sender: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
wasm_byte_code: "WUVMTE9XIFNVQk1BUklORQ==", | ||
instantiate_permission: undefined, | ||
}, | ||
}; | ||
expect(aminoMsg).toEqual(expected); | ||
}); | ||
|
||
it("works for MsgStoreCode with access type", () => { | ||
const msg: MsgStoreCode = { | ||
sender: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="), | ||
instantiatePermission: { | ||
permission: AccessType.ACCESS_TYPE_ONLY_ADDRESS, | ||
address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
addresses: [], | ||
}, | ||
}; | ||
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({ | ||
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode", | ||
value: msg, | ||
}); | ||
const expected: AminoMsgStoreCode = { | ||
type: "wasm/MsgStoreCode", | ||
value: { | ||
sender: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
wasm_byte_code: "WUVMTE9XIFNVQk1BUklORQ==", | ||
instantiate_permission: { | ||
permission: "OnlyAddress", | ||
address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
addresses: undefined, | ||
}, | ||
}, | ||
}; | ||
expect(aminoMsg).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe("fromAmino", () => { | ||
it("works for MsgStoreCode", () => { | ||
const aminoMsg: AminoMsgStoreCode = { | ||
type: "wasm/MsgStoreCode", | ||
value: { | ||
sender: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
wasm_byte_code: "WUVMTE9XIFNVQk1BUklORQ==", | ||
}, | ||
}; | ||
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg); | ||
const expectedValue: MsgStoreCode = { | ||
sender: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="), | ||
instantiatePermission: undefined, | ||
}; | ||
expect(msg).toEqual({ | ||
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode", | ||
value: expectedValue, | ||
}); | ||
}); | ||
|
||
it("works for MsgStoreCode with access type", () => { | ||
const aminoMsg: AminoMsgStoreCode = { | ||
type: "wasm/MsgStoreCode", | ||
value: { | ||
sender: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
wasm_byte_code: "WUVMTE9XIFNVQk1BUklORQ==", | ||
instantiate_permission: { | ||
permission: "OnlyAddress", | ||
address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
addresses: undefined, | ||
}, | ||
}, | ||
}; | ||
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg); | ||
const expectedValue: MsgStoreCode = { | ||
sender: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="), | ||
instantiatePermission: { | ||
permission: AccessType.ACCESS_TYPE_ONLY_ADDRESS, | ||
address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
addresses: [], | ||
}, | ||
}; | ||
expect(msg).toEqual({ | ||
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode", | ||
value: expectedValue, | ||
}); | ||
}); | ||
}); | ||
}); |
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,117 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
import { createWasmAminoConverters as createAminoConverters } from "@cosmjs/cosmwasm-stargate"; | ||
import { fromBase64, toBase64 } from "@cosmjs/encoding"; | ||
import { AminoConverters } from "@cosmjs/stargate"; | ||
import { MsgStoreCode } from "lbmjs-types/cosmwasm/wasm/v1/tx"; | ||
import { AccessType } from "lbmjs-types/cosmwasm/wasm/v1/types"; | ||
|
||
export function accessTypeFromString(str: string): AccessType { | ||
switch (str) { | ||
case "Unspecified": | ||
return AccessType.ACCESS_TYPE_UNSPECIFIED; | ||
case "Nobody": | ||
return AccessType.ACCESS_TYPE_NOBODY; | ||
case "OnlyAddress": | ||
return AccessType.ACCESS_TYPE_ONLY_ADDRESS; | ||
case "Everybody": | ||
return AccessType.ACCESS_TYPE_EVERYBODY; | ||
case "AnyOfAddresses": | ||
return AccessType.ACCESS_TYPE_ANY_OF_ADDRESSES; | ||
default: | ||
return AccessType.UNRECOGNIZED; | ||
} | ||
} | ||
|
||
export function accessTypeToString(object: any): string { | ||
switch (object) { | ||
case AccessType.ACCESS_TYPE_UNSPECIFIED: | ||
return "Unspecified"; | ||
case AccessType.ACCESS_TYPE_NOBODY: | ||
return "Nobody"; | ||
case AccessType.ACCESS_TYPE_ONLY_ADDRESS: | ||
return "OnlyAddress"; | ||
case AccessType.ACCESS_TYPE_EVERYBODY: | ||
return "Everybody"; | ||
case AccessType.ACCESS_TYPE_ANY_OF_ADDRESSES: | ||
return "AnyOfAddresses"; | ||
case AccessType.UNRECOGNIZED: | ||
default: | ||
return "UNRECOGNIZED"; | ||
} | ||
} | ||
|
||
/** | ||
* @see https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/types.proto#L36-L41 | ||
*/ | ||
export interface AccessConfig { | ||
/** | ||
* Permission should be one kind of string 'Nobody', 'OnlyAddress', 'Everybody', 'Unspecified' | ||
* @see https://github.com/CosmWasm/wasmd/blob/v0.28.0/x/wasm/types/params.go#L54 | ||
*/ | ||
readonly permission: string; | ||
/** | ||
* Address | ||
* Deprecated: replaced by addresses | ||
*/ | ||
readonly address?: string; | ||
readonly addresses?: string[]; | ||
} | ||
|
||
/** | ||
* The Amino JSON representation of [MsgStoreCode]. | ||
* | ||
* [MsgStoreCode]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L28-L39 | ||
*/ | ||
export interface AminoMsgStoreCode { | ||
type: "wasm/MsgStoreCode"; | ||
value: { | ||
/** Bech32 account address */ | ||
readonly sender: string; | ||
/** Base64 encoded Wasm */ | ||
readonly wasm_byte_code: string; | ||
readonly instantiate_permission?: AccessConfig; | ||
}; | ||
} | ||
|
||
export function createWasmAminoConverters(): AminoConverters { | ||
return { | ||
...createAminoConverters(), | ||
"/cosmwasm.wasm.v1.MsgStoreCode": { | ||
aminoType: "wasm/MsgStoreCode", | ||
toAmino: ({ | ||
sender, | ||
wasmByteCode, | ||
instantiatePermission, | ||
}: MsgStoreCode): AminoMsgStoreCode["value"] => ({ | ||
sender: sender, | ||
wasm_byte_code: toBase64(wasmByteCode), | ||
instantiate_permission: instantiatePermission | ||
? { | ||
permission: accessTypeToString(instantiatePermission.permission), | ||
address: instantiatePermission.address || undefined, | ||
addresses: | ||
instantiatePermission.addresses.length !== 0 ? instantiatePermission.addresses : undefined, | ||
} | ||
: undefined, | ||
}), | ||
fromAmino: ({ | ||
sender, | ||
wasm_byte_code, | ||
instantiate_permission, | ||
}: AminoMsgStoreCode["value"]): MsgStoreCode => ({ | ||
sender: sender, | ||
wasmByteCode: fromBase64(wasm_byte_code), | ||
instantiatePermission: instantiate_permission | ||
? { | ||
permission: accessTypeFromString(instantiate_permission.permission), | ||
address: instantiate_permission.address ?? "", | ||
addresses: instantiate_permission.addresses ?? [], | ||
} | ||
: undefined, | ||
}), | ||
}, | ||
}; | ||
} | ||
|
||
/** @deprecated use `createWasmAminoConverters()` */ | ||
export const cosmWasmTypes: AminoConverters = createWasmAminoConverters(); |
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
Oops, something went wrong.