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

Commit 6391f78

Browse files
pwang200mvadari
authored andcommitted
added devnet 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 8ffebd0 commit 6391f78

File tree

21 files changed

+3123
-459
lines changed

21 files changed

+3123
-459
lines changed

Cargo.lock

Lines changed: 731 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/xrpl_std_example/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ lto = true
1515
opt-level = 's'
1616

1717
[dependencies]
18-
xrpl-std = { path = "../../xrpl-std" }
18+
xrpl-std = { path = "../../xrpl-std" }
19+
#hex = "0.4.3"
Lines changed: 92 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,96 @@
1-
use xrpl_std::{account_keylet, get_tx_account_id, print_data};
2-
// use xrpl_std::{
3-
// account_keylet, credential_keylet, escrow_keylet, get_tx_account_id, oracle_keylet, print_data,
4-
// print_number,
5-
// };
6-
pub use xrpl_std::{allocate, deallocate};
1+
#![no_std]
2+
#![allow(unused_imports)]
3+
use xrpl_std::{get_account_balance, get_current_escrow_account_id, get_current_escrow_destination, get_current_escrow_finish_after, get_tx_account_id, host_lib};
4+
use xrpl_std::locator::LocatorPacker;
5+
use xrpl_std::sfield::{SignerEntries, SignerEntry, SignerWeight};
76

87
#[no_mangle]
9-
pub extern "C" fn ready() -> bool {
10-
unsafe {
11-
let sender = get_tx_account_id();
12-
let account_keylet = account_keylet(&sender);
13-
14-
print_data(&account_keylet);
15-
16-
true
8+
pub extern "C" fn finish() -> i32 {
9+
{
10+
// let account_id_tx = match get_tx_account_id() {
11+
// Some(v) => v,
12+
// None => return -1,
13+
// };
14+
// println!("wasm finish {:?}", account_id_tx);
15+
//
16+
// let account_id_clo = match get_current_escrow_account_id() {
17+
// Some(v) => v,
18+
// None => return -2,
19+
// };
20+
//
21+
// let destination = match get_current_escrow_destination() {
22+
// Some(v) => v,
23+
// None => return -3,
24+
// };
25+
// if account_id_clo != account_id_tx {
26+
// return -6;
27+
// }
28+
// if destination == account_id_tx {
29+
// return -7;
30+
// }
31+
}
32+
{
33+
// let finish_after = match get_current_escrow_finish_after() {
34+
// Some(v) => v,
35+
// None => return -4,
36+
// };
37+
// if finish_after == 0 {
38+
// return -8;
39+
// }
40+
}
41+
{
42+
let account_id_tx = match get_tx_account_id() {
43+
Some(v) => v,
44+
None => return -1,
45+
};
46+
// println!("wasm finish account_id_tx {:?}", account_id_tx);
47+
let balance = match get_account_balance(&account_id_tx) {
48+
Some(v) => v,
49+
None => return -5,
50+
};
51+
// println!("wasm finish balance {:?}", balance);
52+
if balance <= 0 {
53+
return -9;
54+
}
55+
}
56+
{
57+
// let mut ledger_sqn = 0i32;
58+
// if unsafe { xrpl_std::host_lib::get_ledger_sqn((&mut ledger_sqn) as *mut i32 as *mut u8, 4) }
59+
// <= 0
60+
// {
61+
// return -10;
62+
// }
63+
}
64+
{
65+
// let s = "342F9E0D242EDB43A0FBFC672B302CC8BB904993172E57FBFF4C5D4A1EB85AB9";
66+
// let keylet = hex::decode(s).unwrap();
67+
// println!("wasm finish keylet {:?}", keylet);
68+
//
69+
// let slot = unsafe { host_lib::ledger_slot_set(keylet.as_ptr(), keylet.len(), 0) };
70+
//
71+
// println!("wasm finish slot {:?}", slot);
72+
//
73+
// let mut locator = LocatorPacker::new();
74+
// locator.pack(SignerEntries);
75+
// let array_len = unsafe {
76+
// host_lib::get_ledger_obj_nested_array_len(slot, locator.get_addr(), locator.num_packed_bytes())
77+
// };
78+
// println!("wasm finish array_len {:?}", array_len);
79+
//
80+
// locator.pack(0);
81+
// locator.pack(SignerEntry);
82+
// locator.pack(SignerWeight);
83+
//
84+
// let mut weight = 0i32;
85+
// let nfr = unsafe {
86+
// host_lib::get_ledger_obj_nested_field(
87+
// slot, locator.get_addr(), locator.num_packed_bytes(),
88+
// (&mut weight) as *mut i32 as *mut u8, 4
89+
// )
90+
// };
91+
//
92+
// println!("wasm finish get_ledger_obj_nested_field {:?} {}", nfr, weight);
1793
}
94+
95+
1
1896
}

wasm-host/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
anyhow = "1.0"
87
clap = { version = "4.4", features = ["derive"] }
9-
serde = { version = "1.0", features = ["derive"] }
108
serde_json = "1.0"
119
wasmedge-sdk = { version = "0.14.0", features = ["standalone"] }
1210
log = "0.4"
13-
env_logger = "0.11"
11+
env_logger = "0.11"
12+
sha2 = "0.11.0-pre.5"
13+
xrpl-rust = { version = "0.5.0", default-features = false, features = ["core"] }
14+
hex = "0.4.3"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"342F9E0D242EDB43A0FBFC672B302CC8BB904993172E57FBFF4C5D4A1EB85AB9": {
3+
"Flags": 0,
4+
"TransactionType": "SignerListSet",
5+
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
6+
"Fee": "12",
7+
"SignerQuorum": 3,
8+
"SignerEntries": [
9+
{
10+
"SignerEntry": {
11+
"Account": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW",
12+
"SignerWeight": 2
13+
}
14+
},
15+
{
16+
"SignerEntry": {
17+
"Account": "rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v",
18+
"SignerWeight": 1
19+
}
20+
},
21+
{
22+
"SignerEntry": {
23+
"Account": "raKEEVSGnKSD9Zyvxu4z6Pqpm4ABH8FS6n",
24+
"SignerWeight": 1
25+
}
26+
}
27+
]
28+
},
29+
"977A4B2767DCAA2DED68630E4039E7EFFDD3739717056610754E7921FED19E98": {
30+
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
31+
"AccountTxnID": "932CC7E9BAC1F7B9FA5381679F293EEC0A646E5E7F2F6D14C85FEE2102F0E66C",
32+
"Balance": "1138222650",
33+
"Domain": "6D64756F31332E636F6D",
34+
"EmailHash": "98B4375E1D753E5B91627516F6D70977",
35+
"Flags": 9568256,
36+
"LedgerEntryType": "AccountRoot",
37+
"MessageKey": "0000000000000000000000070000000300",
38+
"OwnerCount": 17,
39+
"PreviousTxnID": "E5C3578BDBEBDCDE7E1697E3BA6A1CF04B17CCEBDE4939200680FEF530C7978E",
40+
"PreviousTxnLgrSeq": 94448149,
41+
"RegularKey": "rD9iJmieYHn8jTtPjwwkW2Wm9sVDvPXLoJ",
42+
"Sequence": 393,
43+
"TicketCount": 5,
44+
"TransferRate": 4294967295,
45+
"index": "13F1A95D7AAB7108D5CE7EEAF504B2894B8C674E6D68499076441C4837282BF8",
46+
"urlgravatar": "http://www.gravatar.com/avatar/98b4375e1d753e5b91627516f6d70977"
47+
}
48+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"account_hash": "F457CED76CA8B83B1E1443A354E9F20644E847DF2D852954232FAA21E3136B16",
3+
"close_flags": 0,
4+
"close_time": 797572861,
5+
"close_time_human": "2025-Apr-10 04:01:01.000000000 UTC",
6+
"close_time_iso": "2025-04-10T04:01:01Z",
7+
"close_time_resolution": 10,
8+
"closed": true,
9+
"ledger_hash": "342F9E0D242EDB43A0FBFC672B302CC8BB904993172E57FBFF4C5D4A1EB85AB9",
10+
"ledger_index": 95354542,
11+
"parent_close_time": 797572860,
12+
"parent_hash": "E367C455467EF560515AB024C736359C50D52194BD4C6CA037F3A988984357F3",
13+
"total_coins": "99986243899809091",
14+
"transaction_hash": "E812AAA38BDD51DBCF667F87942989BD6D0897795189ED199ED84810AC068994"
15+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
[
2+
{
3+
"342F9E0D242EDB43A0FBFC672B302CC8BB904993172E57FBFF4C5D4A1EB85AB9": {
4+
"Flags": 0,
5+
"TransactionType": "SignerListSet",
6+
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
7+
"Fee": "12",
8+
"SignerQuorum": 3,
9+
"SignerEntries": [
10+
{
11+
"SignerEntry": {
12+
"Account": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW",
13+
"SignerWeight": 2
14+
}
15+
},
16+
{
17+
"SignerEntry": {
18+
"Account": "rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v",
19+
"SignerWeight": 1
20+
}
21+
},
22+
{
23+
"SignerEntry": {
24+
"Account": "raKEEVSGnKSD9Zyvxu4z6Pqpm4ABH8FS6n",
25+
"SignerWeight": 1
26+
}
27+
}
28+
]
29+
}
30+
},
31+
{
32+
"977A4B2767DCAA2DED68630E4039E7EFFDD3739717056610754E7921FED19E98": {
33+
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
34+
"AccountTxnID": "932CC7E9BAC1F7B9FA5381679F293EEC0A646E5E7F2F6D14C85FEE2102F0E66C",
35+
"Balance": "1138222650",
36+
"Domain": "6D64756F31332E636F6D",
37+
"EmailHash": "98B4375E1D753E5B91627516F6D70977",
38+
"Flags": 9568256,
39+
"LedgerEntryType": "AccountRoot",
40+
"MessageKey": "0000000000000000000000070000000300",
41+
"OwnerCount": 17,
42+
"PreviousTxnID": "E5C3578BDBEBDCDE7E1697E3BA6A1CF04B17CCEBDE4939200680FEF530C7978E",
43+
"PreviousTxnLgrSeq": 94448149,
44+
"RegularKey": "rD9iJmieYHn8jTtPjwwkW2Wm9sVDvPXLoJ",
45+
"Sequence": 393,
46+
"TicketCount": 5,
47+
"TransferRate": 4294967295,
48+
"index": "13F1A95D7AAB7108D5CE7EEAF504B2894B8C674E6D68499076441C4837282BF8",
49+
"urlgravatar": "http://www.gravatar.com/avatar/98b4375e1d753e5b91627516f6d70977"
50+
}
51+
},
52+
{
53+
"2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8": {
54+
"Account": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
55+
"Balance": "55426479402",
56+
"Flags": 1703936,
57+
"LedgerEntryType": "AccountRoot",
58+
"OwnerCount": 1,
59+
"PreviousTxnID": "BC8E8B46D1C403B168EE6402769065EBDAD78E5EA3A043D8E041372EDF14A11F",
60+
"PreviousTxnLgrSeq": 95945324,
61+
"RegularKey": "rBmVUQNF6tJy4cLvoKdPXb4BNqKBk5JY1Y",
62+
"Sequence": 44196,
63+
"TransferRate": 1220000000,
64+
"index": "2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8"
65+
}
66+
}
67+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"account_hash": "F457CED76CA8B83B1E1443A354E9F20644E847DF2D852954232FAA21E3136B16",
3+
"close_flags": 0,
4+
"close_time": 797572861,
5+
"close_time_human": "2025-Apr-10 04:01:01.000000000 UTC",
6+
"close_time_iso": "2025-04-10T04:01:01Z",
7+
"close_time_resolution": 10,
8+
"closed": true,
9+
"ledger_hash": "342F9E0D242EDB43A0FBFC672B302CC8BB904993172E57FBFF4C5D4A1EB85AB9",
10+
"ledger_index": 95354542,
11+
"parent_close_time": 797572860,
12+
"parent_hash": "E367C455467EF560515AB024C736359C50D52194BD4C6CA037F3A988984357F3",
13+
"total_coins": "99986243899809091",
14+
"transaction_hash": "E812AAA38BDD51DBCF667F87942989BD6D0897795189ED199ED84810AC068994"
15+
}

0 commit comments

Comments
 (0)