Skip to content
This repository was archived by the owner on Oct 28, 2025. It is now read-only.

Commit 5d504b8

Browse files
committed
added devent 3 host functions, mock data from json decoded to binary
* added sfield constants * added mock_data, data is read from json file. Hashes and AccountIDs fields are decoded to binary when requested by host functions to match ripples. * added Locator string * refactored main and vm * some basic tests done, more tests are needed
1 parent 4d6a67d commit 5d504b8

File tree

1 file changed

+15
-43
lines changed

1 file changed

+15
-43
lines changed

wasm-host/src/vm.rs

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,56 +21,28 @@ pub fn run_func(wasm_file: String, func_name: &str, data_source: MockData) -> Wa
2121
let data_provider = DataProvider::new(data_source);
2222

2323
debug!("Setting up instance map and registering host functions");
24-
let mut instances: HashMap<String, &mut dyn SyncInst> = HashMap::new();
24+
let mut instances : HashMap<String, &mut dyn SyncInst> = HashMap::new();
2525
let mut import_builder = ImportObjectBuilder::new("host_lib", data_provider)?;
2626
import_builder.with_func::<(i32, i32), i32>("get_ledger_sqn", get_ledger_sqn)?;
27-
import_builder
28-
.with_func::<(i32, i32), i32>("get_parent_ledger_time", get_parent_ledger_time)?;
29-
import_builder
30-
.with_func::<(i32, i32), i32>("get_parent_ledger_hash", get_parent_ledger_hash)?;
27+
import_builder.with_func::<(i32, i32), i32>("get_parent_ledger_time", get_parent_ledger_time)?;
28+
import_builder.with_func::<(i32, i32), i32>("get_parent_ledger_hash", get_parent_ledger_hash)?;
3129
import_builder.with_func::<(i32, i32, i32), i32>("ledger_slot_set", ledger_slot_set)?;
3230
import_builder.with_func::<(i32, i32, i32), i32>("get_tx_field", get_tx_field)?;
33-
import_builder.with_func::<(i32, i32, i32), i32>(
34-
"get_current_ledger_obj_field",
35-
get_current_ledger_obj_field,
36-
)?;
37-
import_builder
38-
.with_func::<(i32, i32, i32, i32), i32>("get_ledger_obj_field", get_ledger_obj_field)?;
39-
import_builder
40-
.with_func::<(i32, i32, i32, i32), i32>("get_tx_nested_field", get_tx_nested_field)?;
41-
import_builder.with_func::<(i32, i32, i32, i32), i32>(
42-
"get_current_ledger_obj_nested_field",
43-
get_current_ledger_obj_nested_field,
44-
)?;
45-
import_builder.with_func::<(i32, i32, i32, i32, i32), i32>(
46-
"get_ledger_obj_nested_field",
47-
get_ledger_obj_nested_field,
48-
)?;
31+
import_builder.with_func::<(i32, i32, i32), i32>("get_current_ledger_obj_field", get_current_ledger_obj_field)?;
32+
import_builder.with_func::<(i32, i32, i32, i32), i32>("get_ledger_obj_field", get_ledger_obj_field)?;
33+
import_builder.with_func::<(i32, i32, i32, i32), i32>("get_tx_nested_field", get_tx_nested_field)?;
34+
import_builder.with_func::<(i32, i32, i32, i32), i32>("get_current_ledger_obj_nested_field", get_current_ledger_obj_nested_field)?;
35+
import_builder.with_func::<(i32, i32, i32, i32, i32), i32>("get_ledger_obj_nested_field", get_ledger_obj_nested_field)?;
4936
import_builder.with_func::<i32, i32>("get_tx_array_len", get_tx_array_len)?;
50-
import_builder.with_func::<i32, i32>(
51-
"get_current_ledger_obj_array_len",
52-
get_current_ledger_obj_array_len,
53-
)?;
54-
import_builder
55-
.with_func::<(i32, i32), i32>("get_ledger_obj_array_len", get_ledger_obj_array_len)?;
56-
import_builder
57-
.with_func::<(i32, i32), i32>("get_tx_nested_array_len", get_tx_nested_array_len)?;
58-
import_builder.with_func::<(i32, i32), i32>(
59-
"get_current_ledger_obj_nested_array_len",
60-
get_current_ledger_obj_nested_array_len,
61-
)?;
62-
import_builder.with_func::<(i32, i32, i32), i32>(
63-
"get_ledger_obj_nested_array_len",
64-
get_ledger_obj_nested_array_len,
65-
)?;
37+
import_builder.with_func::<i32, i32>("get_current_ledger_obj_array_len", get_current_ledger_obj_array_len)?;
38+
import_builder.with_func::<(i32, i32), i32>("get_ledger_obj_array_len", get_ledger_obj_array_len)?;
39+
import_builder.with_func::<(i32, i32), i32>("get_tx_nested_array_len", get_tx_nested_array_len)?;
40+
import_builder.with_func::<(i32, i32), i32>("get_current_ledger_obj_nested_array_len", get_current_ledger_obj_nested_array_len)?;
41+
import_builder.with_func::<(i32, i32, i32), i32>("get_ledger_obj_nested_array_len", get_ledger_obj_nested_array_len)?;
6642
import_builder.with_func::<(i32, i32), ()>("update_data", update_data)?;
67-
import_builder
68-
.with_func::<(i32, i32, i32, i32), i32>("compute_sha512_half", compute_sha512_half)?;
43+
import_builder.with_func::<(i32, i32, i32, i32), i32>("compute_sha512_half", compute_sha512_half)?;
6944
import_builder.with_func::<(i32, i32, i32, i32), i32>("account_keylet", account_keylet)?;
70-
import_builder.with_func::<(i32, i32, i32, i32, i32, i32, i32, i32), i32>(
71-
"credential_keylet",
72-
credential_keylet,
73-
)?;
45+
import_builder.with_func::<(i32, i32, i32, i32, i32, i32, i32, i32), i32>("credential_keylet", credential_keylet)?;
7446
import_builder.with_func::<(i32, i32, i32, i32, i32), i32>("escrow_keylet", escrow_keylet)?;
7547
import_builder.with_func::<(i32, i32, i32, i32, i32), i32>("oracle_keylet", oracle_keylet)?;
7648
//import_builder.with_func::<(i32, i32, i32, i32), i32>("", )?;

0 commit comments

Comments
 (0)