lwk_node 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -102,4 +102,59 @@ Rename the package to `lwk_node` so that we can publish it to npm.
102
102
 
103
103
  ```shell
104
104
  sed -i 's/"lwk_wasm"/"lwk_node"/g' pkg_node/package.json
105
- ```
105
+ ```
106
+
107
+ ### Test node js examples
108
+
109
+ Requirement:
110
+
111
+ * having built node pkg like shown in previous paragraph
112
+ * having node and npm installed
113
+
114
+ ```shell
115
+ cd lwk_wasm/tests/node
116
+ npm install
117
+ node network.js
118
+ ```
119
+
120
+ ## Javascript code conventions
121
+
122
+ ### String
123
+
124
+ For object that have a string representation we implement `std::fmt::Display` and we expose them like that
125
+
126
+ ```rust
127
+ #[wasm_bindgen(js_name = toString)]
128
+ pub fn to_string_js(&self) -> String {
129
+ self.to_string()
130
+ }
131
+ ```
132
+
133
+ ### JSON
134
+
135
+ For objects that have a json representation, like the balance we provide a `toJSON()` method that must work when the caller use for example `JSON.stringify(object)`
136
+ Unfortunately `JSON.stringify` cannot serialize big integers by default, thus we use string representation for `BigInt`.
137
+
138
+ ### Entries
139
+
140
+ Since JSON doesn't support `BigInt` some object expose also the js standard `entries()` method so that the following code is possible
141
+
142
+ ```js
143
+ const balance = wallet.balance();
144
+
145
+ // 1. Create a Map
146
+ const balanceMap = new Map(balance.entries());
147
+
148
+ // 2. Iterate directly in a for...of loop
149
+ for (const [currency, amount] of balance.entries()) {
150
+ console.log(`${currency}: ${amount}`);
151
+ }
152
+
153
+ // 3. Convert to a plain object
154
+ const balanceObject = Object.fromEntries(balance.entries());
155
+ ```
156
+
157
+ ## Documentation
158
+
159
+ Documentation of this crate should not use link to rust types such as [`Transaction`] because they are not usable in end-user javascript packages.
160
+ Many types are wrappers of types in lwk crates, in this cases we mostly duplicate the original documentation with context adjustment.