-
Notifications
You must be signed in to change notification settings - Fork 14
Conversation
* allocating a static Buffer on the heap * adding documentation
Adding `Commit` method to `svm_kv::traits::KVStore` is required in order to proceed.
* native rust (a.k.a `Builder`) * json * wasm
./../build.sh | ||
cp ../../../target/wasm32-unknown-unknown/debug/svm_codec.wasm svm_codec.wasm | ||
|
||
npm test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add npm i
. Otherwise mocha
need to be a global dependency.
|
||
function wasmNewBuffer(instance, object) { | ||
const objectStr = JSON.stringify(object); | ||
const bytes = new TextEncoder('utf-8').encode(objectStr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All tests are failing for me locally with ReferenceError: TextEncoder is not defined
.
Which Nodejs version do you use? it should be specified in package.json
.
Mine:
Moshes-MacBook-Pro:examples moshababo$ node -v
v10.15.3
If this is problematic, maybe you should use the well-supported Buffer
class instead (assuming this code is intended to run in Nodejs and not in a browser).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❯ node -v
v12.6.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add to package.json
/// If the encoding failed, the returned WASM buffer will contain a JSON with the error. | ||
#[no_mangle] | ||
#[cfg(target_arch = "wasm32")] | ||
pub extern "C" fn wasm_deploy_template(buf_ptr: i32) -> i32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here I found it confusing - we're not deploying a template here, but encoding an app template.
So maybe wasm_encode_app_template
instead?
Same for the other types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
./../build.sh | ||
cp ../../../target/wasm32-unknown-unknown/debug/svm_codec.wasm svm_codec.wasm | ||
|
||
npm test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test need to be added to the CI.
crates/svm-codec/src/lib.rs
Outdated
/// Encodes a `deploy-template` binary-transaction using that JSON value. | ||
/// | ||
/// Returns a pointer to a new WASM buffer holding the encoded transaction. | ||
/// If the encoding failed, the returned WASM buffer will contain a JSON with the error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From reading this, it's not clear how the OK/ERROR result type can be detected. So perhaps you should add a brief explanation about that.
Motivation
We're breaking the
svm-app
crate that logically contains:This PR will introduce two new crates:
svm-types
: will contain the most types declared undersvm-app
.svm-codec
: will contain the encoding & decoding of transactions.This crate should also compile to a WASM file and be used by the Spacemesh Wallet
(as part of synthesizing binary transactions to be submitted to the network).
Future PRs:
Depercating
svm-app
crate (usingsvm-codec
instead).Other code of
svm-app
will move to thesvm-runtime
crate.A likely future code change after this PR will be moving the code of the
svm-common
crate to sit undersvm-types