Skip to content

Commit

Permalink
fix(api): add gr_env_vars stub (#1487)
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit authored Feb 15, 2024
1 parent f6f83ae commit 1a3af0f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 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.36.6

_02/15/2024_

### Changes
https://github.com/gear-tech/gear-js/pull/1487
- Add add `gr_env_vars` stub

## 0.36.5

_02/12/2024_
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.36.5",
"version": "0.36.6",
"description": "A JavaScript library that provides functionality to connect GEAR Component APIs.",
"main": "cjs/index.js",
"module": "index.js",
Expand Down
31 changes: 16 additions & 15 deletions api/src/wasm/importObj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default (
},
free: () => {},
free_range: () => {},
gr_env_vars: () => {},
gr_block_height: () => block_height,
gr_block_timestamp: () => timestamp,
gr_create_program_wgas: () => {},
Expand All @@ -50,16 +51,17 @@ export default (
new TypeRegistry().createType('String', new Uint8Array(memory.buffer.slice(error, error + len))).toHuman(),
);
},
gr_exit: () => {},
gr_gas_available: () => {},
gr_leave: () => {},
gr_message_id: () => {},
gr_oom_panic: () => {},
gr_origin: () => {},
gr_panic: () => {},
gr_pay_program_rent: () => {},
gr_status_code: () => {},
gr_panic: () => {},
gr_oom_panic: () => {},
gr_reply_code: () => {},
gr_signal_code: () => {},
gr_exit: () => {},
gr_gas_available: () => {},
gr_leave: () => {},
gr_message_id: () => {},
gr_program_id: () => {},
gr_random: () => {},
gr_read: (at: number, len: number, buffer: number) => {
Expand All @@ -69,10 +71,13 @@ export default (
gr_reply_commit_wgas: () => {},
gr_reply_commit: () => {},
gr_reply_push: () => {},
gr_reply_push_input: () => {},
gr_reply_to: () => {},
gr_signal_from: () => {},
gr_reply_input_wgas: () => {},
gr_reply_wgas: () => {},
gr_reply: replyFn,
gr_reply_input: () => {},
gr_reservation_reply_commit: () => {},
gr_reservation_reply: () => {},
gr_reservation_send_commit: () => {},
Expand All @@ -82,8 +87,11 @@ export default (
gr_send_commit: () => {},
gr_send_init: () => {},
gr_send_push: () => {},
gr_send_push_input: () => {},
gr_send_input_wgas: () => {},
gr_send_wgas: () => {},
gr_send: () => {},
gr_send_input: () => {},
gr_size: (size_ptr: number) => {
assert.notStrictEqual(inputValue, undefined, 'Input value not found');
const len = new TypeRegistry().createType('u32', inputValue.byteLength).toU8a();
Expand All @@ -92,20 +100,13 @@ export default (
}
},
gr_source: () => {},
gr_status_code: () => {},
gr_system_reserve_gas: () => {},
gr_unreserve_gas: () => {},
gr_value_available: () => {},
gr_value: () => {},
gr_wait: () => {},
gr_wait_up_to: () => {},
gr_wait_for: () => {},
gr_wait_up_to: () => {},
gr_wait: () => {},
gr_wake: () => {},
gr_reply_push_input: () => {},
gr_reply_input_wgas: () => {},
gr_reply_input: () => {},
gr_send_push_input: () => {},
gr_send_input_wgas: () => {},
gr_send_input: () => {},
},
});
20 changes: 11 additions & 9 deletions api/src/wasm/reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ export function getGrReply(wasm: HexString | Buffer | ArrayBuffer | Uint8Array,
importObj(memory, false, undefined, undefined, undefined, (payload: number, len: number) =>
resolve(new Uint8Array(memory.buffer.slice(payload, payload + len))),
),
).then(({ instance: { exports } }) => {
if (!(fn in exports)) {
reject(`${fn} function not found in exports`);
} else if (typeof exports[fn] !== 'function') {
reject(`${fn} is not a function`);
} else {
(exports[fn] as () => void)();
}
});
)
.then(({ instance: { exports } }) => {
if (!(fn in exports)) {
reject(`${fn} function not found in exports`);
} else if (typeof exports[fn] !== 'function') {
reject(`${fn} is not a function`);
} else {
(exports[fn] as () => void)();
}
})
.catch((error) => reject(error));
});
}

0 comments on commit 1a3af0f

Please sign in to comment.