Skip to content

Commit

Permalink
[gear-api] Fix encode payload in programState.readUsingWasm method (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit authored Sep 25, 2023
1 parent 6fcf25b commit dfb1e0b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 8 additions & 0 deletions api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.33.6

_09/25/2023_

### Changes
https://github.com/gear-tech/gear-js/pull/1410
- Fix payload encoding in state.readUsingWasm method.

## 0.33.5

_09/18/2023_
Expand Down
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gear-js/api",
"version": "0.33.5",
"version": "0.33.6",
"description": "A JavaScript library that provides functionality to connect GEAR Component APIs.",
"main": "cjs/index.js",
"module": "index.js",
Expand Down
7 changes: 2 additions & 5 deletions api/src/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ export class GearProgramState extends GearProgramStorage {
programMeta: ProgramMetadata,
): Promise<Codec> {
const fnTypes = stateMeta?.functions[params.fn_name];
const stateType =
programMeta.version === MetadataVersion.V2Rust ? (programMeta.types.state as HumanTypesRepr).input : undefined;

const argument =
fnTypes?.input !== undefined && fnTypes?.input !== null
? Array.from(stateMeta.createType(fnTypes.input, params.argument).toU8a())
: null;

const payload = isNaN(stateType)
? []
: Array.from(programMeta.createType((programMeta.types.state as HumanTypesRepr).input, params.payload).toU8a());
const payload =
programMeta.version === MetadataVersion.V2Rust ? encodePayload(params.payload, programMeta, 'state') : [];

const code =
typeof params.wasm === 'string' ? params.wasm : CreateType.create<Bytes>('Bytes', Array.from(params.wasm));
Expand Down

0 comments on commit dfb1e0b

Please sign in to comment.