Skip to content

Commit 38f7885

Browse files
committed
data-drivers: fix format
1 parent d7f50be commit 38f7885

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

data-drivers/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ interaction with contracts from both Rust and JavaScript contexts.
1111
Each folder inside `data-drivers/` is a local package with its own README
1212
and focus area:
1313

14-
- `data-driver/`: Utilities to encode & decode arguments.
15-
- `stake-contract/`: Library to encode/decode contract inputs/outputs for the stake contract.
14+
- `data-driver/`: Utilities to encode & decode arguments.
15+
- `stake-contract/`: Library to encode/decode contract inputs/outputs for the stake contract.
1616
- `transfer-contract/`: Library to encode/decode contract inputs/outputs for the transfer contract.
1717

1818
For details on each, see their local README files.

data-drivers/data-driver/README.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
# Data Drivers Overview
42

53
In this module, we provide data drivers whose task is to ease communication with Dusk smart contracts
@@ -9,7 +7,7 @@ JavaScript arguments into a form which is understood by Dusk smart contracts,
97
and also converting Dusk smart contracts outputs into a form which is understood
108
by JavaScript.
119

12-
Data drivers do not call Dusk smart contracts. A particular data driver is aware of methods of the corresponding
10+
Data drivers do not call Dusk smart contracts. A particular data driver is aware of methods of the corresponding
1311
Dusk smart contract, yet it does not call them.
1412

1513
Each data driver has its assigned Dusk smart contract, yet it is important to
@@ -19,12 +17,12 @@ and of their arguments and outputs.
1917
# Module data-driver
2018

2119
Module data-driver contains core code to be used by all drivers. It can be thought of as a framework to
22-
be used by concrete drivers, which are written for particular contracts.
23-
Module data-driver makes it easy for the authors of concrete drivers to create a driver.
20+
be used by concrete drivers, which are written for particular contracts.
21+
Module data-driver makes it easy for the authors of concrete drivers to create a driver.
2422
The authors need just to implement one trait, the complexity is delegated to module data-driver.
2523

26-
Module data-driver provides functionality which make it easy to call drivers from both Rust and JavaScript.
27-
In order to achieve that it does not use wasm-bindgen, but rather provides a set methods which are easy to call
24+
Module data-driver provides functionality which make it easy to call drivers from both Rust and JavaScript.
25+
In order to achieve that it does not use wasm-bindgen, but rather provides a set methods which are easy to call
2826
from modules written in both languages. The methods are declared with no argument mangling, making them callable
2927
from within any language which supports "C"-like calling conventions.
3028

@@ -68,6 +66,7 @@ following parameters:
6866
out_ptr: *mut u8,
6967
out_buf_size: usize,
7068
```
69+
7170
In order to pass method name, caller must allocate a buffer, copy the name to it, and pass
7271
a pointer to the buffer and its length. Similarly, with input data and with output data.
7372
To allocate a buffer, caller needs to use `alloc` method which will return a buffer offset
@@ -88,6 +87,7 @@ There are four methods in this group, so lets consider each one of them in turn:
8887
### encode_input_fn
8988

9089
Parameters:
90+
9191
```
9292
fn_name_ptr: *mut u8,
9393
fn_name_size: usize,
@@ -99,16 +99,17 @@ Parameters:
9999

100100
This method accepts method name and a buffer containing arguments in JSON form.
101101
On return, it fills out the output buffer with output length (first 4 bytes, as a big-endian 32-bit number),
102-
and then it fills out the subsequent bytes of the buffer with rkyv serialization ready to be used when
102+
and then it fills out the subsequent bytes of the buffer with rkyv serialization ready to be used when
103103
making a call to a given smart contract method.
104104
Caller needs to read first 4 bytes of the output buffer first to know the returned data length.
105105
Say, first 4 bytes contained number N. The caller then needs to read the remaining N bytes of rkyv
106-
serialization returned. Assuming that the method name passed to `encode_input_fn` was M,
106+
serialization returned. Assuming that the method name passed to `encode_input_fn` was M,
107107
the caller can pass the obtained data to smart contract method M as its arguments.
108108

109109
### decode_input_fn
110110

111111
Parameters:
112+
112113
```
113114
fn_name_ptr: *mut u8,
114115
fn_name_size: usize,
@@ -124,6 +125,7 @@ rkyv serialization string into JSON. Other calling details are the same as in `e
124125
### decode_output_fn
125126

126127
Parameters:
128+
127129
```
128130
fn_name_ptr: *mut u8,
129131
fn_name_size: usize,
@@ -139,6 +141,7 @@ rather than input. Other calling details are the same as in `encode_input_fn` an
139141
### decode_event
140142

141143
Parameters:
144+
142145
```
143146
event_name_ptr: *mut u8,
144147
event_name_size: usize,
@@ -152,6 +155,7 @@ This method converts event from rkyv-serialized form into JSON. Unlike other arg
152155
this method accepts event name rather than method name.
153156

154157
All the above methods make it possible to:
158+
155159
- convert JSON arguments to rkyv bytes ready to be used in smart contract method calls
156160
- convert rkyv bytes returned by smart contract method calls into JSON
157161
- convert events emitted by smart contract into JSON
@@ -167,15 +171,15 @@ Method get_last_error() allows obtaining detailed error description when ErrorCo
167171
Method get_schema() should return JSON schema describing all contract calls. This feature is not used yet
168172
and in current implementation an empty string is returned.
169173

170-
Method get_version() returns versions of the driver. Currently, versioning is up to the discretion of
174+
Method get_version() returns versions of the driver. Currently, versioning is up to the discretion of
171175
driver's author.
172176

173177
## Trait ConvertibleContract - to be used by drivers' creators
174178

175179
Fortunately, the above functions with their rather complex parameters are to be used only internally, by this module
176-
(i.e. module data-driver) and by the infrastructure. Regular smart contract authors are dealing
177-
only with a much simplified trait named `ConvertibleContract`. The trait is a Rust concept and
178-
its methods are to be implemented in Rust, yet thanks to
180+
(i.e. module data-driver) and by the infrastructure. Regular smart contract authors are dealing
181+
only with a much simplified trait named `ConvertibleContract`. The trait is a Rust concept and
182+
its methods are to be implemented in Rust, yet thanks to
179183
the architecture enabled by the module data-driver, the driver which implements `ConvertibleContract` and uses
180184
module data-driver will provide arguments and return values translations to both JavaScript and Rust users.
181185

@@ -191,7 +195,7 @@ Smart contract author needs to implement the following methods of trait `Convert
191195
```
192196

193197
As you can see, thanks to the fact that the trait is a Rust concept and confined within the the realm
194-
of a single language, the parameters are much simplified. Module data-driver provides a set of
198+
of a single language, the parameters are much simplified. Module data-driver provides a set of
195199
conversion methods which make implementing the trait ConvertibleContract easy.
196200
To such helper functions, provided by module data-driver, belong:
197201

@@ -200,7 +204,7 @@ To such helper functions, provided by module data-driver, belong:
200204
rkyv_to_json
201205
from_rkyv
202206
json_to_rkyv_u64
203-
rkyv_to_json_u64
207+
rkyv_to_json_u64
204208
json_to_rkyv_pair_u64
205209
rkyv_to_json_pair_u64
206210
```
@@ -291,6 +295,7 @@ In such case, example JSON value could be as follows:
291295
`tCR9c1pQU1jC5QgmRi3JRb2g1Rhtrc6AxT24VQPtMY3wrsuRrnMBMP6wSoKWXH2opKTeCm5aniEG2HH8ATcUHzeWe6814e8qdECGvLLZvhaRKsi7MJgLAA33PiWZ4b6ptNt`
292296

293297
### Single object/structural argument
298+
294299
In case of a single object argument of a function, a Rust struct, an example JSON representation could be as follows:
295300

296301
```
@@ -320,24 +325,29 @@ pub struct Stake {
320325
signature: DoubleSignature,
321326
}
322327
```
328+
323329
where StakeKeys is:
330+
324331
```
325332
pub struct StakeKeys {
326333
pub account: BlsPublicKey,
327334
pub owner: StakeFundOwner,
328335
```
336+
329337
and DoubleSignature is:
338+
330339
```
331340
pub struct DoubleSignature {
332341
pub account: BlsSignature,
333342
pub owner: BlsSignature,
334343
}
335344
```
345+
336346
As you can see, JSON representation does not include object name, only its named members.
337347

338348
### Multiple primitive arguments
339349

340-
In case of multiple primitive elements, say, a function which, for example, accepts two arguments,
350+
In case of multiple primitive elements, say, a function which, for example, accepts two arguments,
341351
say, u64 and u32. An example JSON could look as follows:
342352

343353
`[ 22, 33 ]`
@@ -366,10 +376,11 @@ as above, followed by a u32 number, an example JSON representation could be as f
366376
"owner": "7kP8oaxopsWi7g6kNGtX3PHVekMF8RKRRx74tqoo1xLmh2zGVN2FmJ5EFg7UJV9stk"
367377
},
368378
"value": "4014086097495"
369-
},
379+
},
370380
33
371381
]
372382
```
383+
373384
In the above example, we can see JSON representation of a Stake object and a number 33, being passed as two named
374385
parameters to a smart contract method. Parameter names are ignored in serialization formats, as Dusk smart
375386
contract methods assume that all input function parameters form a tuple. A tuple is represented as an array in JSON.

data-drivers/stake-contract/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Data Driver for the Stake Contract
32

43
This module provides data-driver implementation for the Stake Contract.

data-drivers/transfer-contract/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Data Driver for the Transfer Contract
32

43
This module provides data-driver implementation for the Transfer Contract.

0 commit comments

Comments
 (0)