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

Commit b6e6895

Browse files
committed
added get_NFT, added get_tx_field2 ~ get_tx_field6
1 parent 5d504b8 commit b6e6895

File tree

11 files changed

+306
-38
lines changed

11 files changed

+306
-38
lines changed

projects/xrpl_std_example/Cargo.toml

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

1717
[dependencies]
18-
xrpl-std = { path = "../../xrpl-std" }
19-
#hex = "0.4.3"
18+
xrpl-std = { path = "../../xrpl-std" }

projects/xrpl_std_example/src/lib.rs

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,29 @@ use xrpl_std::{
88
};
99

1010
#[no_mangle]
11-
pub extern "C" fn finish() -> bool {
12-
unsafe {
13-
let sender = get_tx_account_id();
14-
let account_keylet = account_keylet(&sender);
15-
16-
print_data(&account_keylet);
17-
18-
true
11+
pub extern "C" fn finish() -> i32 {
12+
{
13+
// let account_id_tx = match get_tx_account_id() {
14+
// Some(v) => v,
15+
// None => return -1,
16+
// };
17+
// println!("wasm finish {:?}", account_id_tx);
18+
//
19+
// let account_id_clo = match get_current_escrow_account_id() {
20+
// Some(v) => v,
21+
// None => return -2,
22+
// };
23+
//
24+
// let destination = match get_current_escrow_destination() {
25+
// Some(v) => v,
26+
// None => return -3,
27+
// };
28+
// if account_id_clo != account_id_tx {
29+
// return -6;
30+
// }
31+
// if destination == account_id_tx {
32+
// return -7;
33+
// }
1934
}
2035
{
2136
// let finish_after = match get_current_escrow_finish_after() {
@@ -50,8 +65,10 @@ pub extern "C" fn finish() -> bool {
5065
// }
5166
}
5267
{
53-
// let s = "342F9E0D242EDB43A0FBFC672B302CC8BB904993172E57FBFF4C5D4A1EB85AB9";
54-
// let keylet = hex::decode(s).unwrap();
68+
// let keylet = [
69+
// 52, 47, 158, 13, 36, 46, 219, 67, 160, 251, 252, 103, 43, 48, 44, 200, 187, 144, 73,
70+
// 147, 23, 46, 87, 251, 255, 76, 93, 74, 30, 184, 90, 185,
71+
// ];
5572
// println!("wasm finish keylet {:?}", keylet);
5673
//
5774
// let slot = unsafe { host_lib::ledger_slot_set(keylet.as_ptr(), keylet.len(), 0) };
@@ -79,6 +96,31 @@ pub extern "C" fn finish() -> bool {
7996
//
8097
// println!("wasm finish get_ledger_obj_nested_field {:?} {}", nfr, weight);
8198
}
99+
{
100+
// let nft_id = [
101+
// 0, 8, 39, 16, 104, 7, 191, 132, 143, 172, 217, 114, 242, 246, 23, 226, 112, 3, 215, 91,
102+
// 44, 170, 201, 129, 108, 238, 20, 132, 5, 33, 209, 233,
103+
// ];
104+
// let owner = get_tx_account_id().unwrap();
105+
// if owner.len() != 20 {
106+
// return -21;
107+
// }
108+
// let mut arr = [0u8; 256];
109+
// let res = unsafe {
110+
// host_lib::get_NFT(
111+
// owner.as_ptr(),
112+
// owner.len(),
113+
// nft_id.as_ptr(),
114+
// nft_id.len(),
115+
// arr.as_mut_ptr(),
116+
// arr.len(),
117+
// )
118+
// };
119+
//
120+
// if res != 106 {
121+
// return -22;
122+
// }
123+
}
82124

83125
1
84126
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"nft_id": "000827106807BF848FACD972F2F617E27003D75B2CAAC9816CEE14840521D1E9",
4+
"ledger_index": 86802013,
5+
"owner": "rBodLLeMx7mqEBv4B2BsaWeTJYnALQddd6",
6+
"is_burned": false,
7+
"flags": 8,
8+
"transfer_fee": 10000,
9+
"issuer": "rwVhZJLcdtioxdETLq31Ne2K97xm4zA8Jv",
10+
"nft_taxon": 0,
11+
"nft_serial": 86102505,
12+
"validated": true,
13+
"uri": "697066733A2F2F516D57515A4167695A337041327065654A4D7441703663326A394151666E78706A754E62674D5A505748617A3267"
14+
}
15+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"nft_id": "000827106807BF848FACD972F2F617E27003D75B2CAAC9816CEE14840521D1E9",
4+
"ledger_index": 86802013,
5+
"owner": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
6+
"is_burned": false,
7+
"flags": 8,
8+
"transfer_fee": 10000,
9+
"issuer": "rwVhZJLcdtioxdETLq31Ne2K97xm4zA8Jv",
10+
"nft_taxon": 0,
11+
"nft_serial": 86102505,
12+
"validated": true,
13+
"uri": "697066733A2F2F516D57515A4167695A337041327065654A4D7441703663326A394151666E78706A754E62674D5A505748617A3267"
14+
}
15+
]

wasm-host/src/data_provider.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::decoding::{decode, Decodable};
1+
use crate::decoding::{decode, AccountId, Decodable};
22
use crate::hashing::Hash256;
33
use crate::mock_data::{DataSource, Keylet, MockData};
44

@@ -135,6 +135,16 @@ impl DataProvider {
135135
Self::fill_buf(field_result, buf_cap, Decodable::UINT256)
136136
}
137137

138+
pub fn get_nft_uri(
139+
&self,
140+
nft_id: &Hash256,
141+
account_id: &AccountId,
142+
buf_cap: usize,
143+
) -> (i32, Vec<u8>) {
144+
let field_result = self.data_source.get_nft_uri(nft_id, account_id);
145+
Self::fill_buf(field_result, buf_cap, Decodable::NOT)
146+
}
147+
138148
pub fn set_current_ledger_obj_data(&mut self, data: Vec<u8>) {
139149
self.data_source.set_current_ledger_obj_data(data);
140150
}

wasm-host/src/decoding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use hex;
33
use xrpl::core::addresscodec::utils::decode_base58;
44

55
pub const ACCOUNT_ID_LEN: usize = 20;
6-
// pub type AccountId = Vec<u8>;
6+
pub type AccountId = Vec<u8>;
77

88
pub enum Decodable {
99
UINT256 = 5,

wasm-host/src/host_functions.rs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,109 @@ pub fn get_tx_field(
124124
Ok(vec![WasmValue::from_i32(dp_res.0)])
125125
}
126126

127+
pub fn get_tx_field2(
128+
_data_provider: &mut DataProvider,
129+
_inst: &mut Instance,
130+
_caller: &mut CallingFrame,
131+
_inputs: Vec<WasmValue>,
132+
) -> Result<Vec<WasmValue>, CoreError> {
133+
let field: i32 = _inputs[0].to_i32();
134+
let field2: i32 = _inputs[1].to_i32();
135+
let out_buf_ptr: i32 = _inputs[2].to_i32();
136+
let out_buf_cap: i32 = _inputs[3].to_i32();
137+
let dp_res =
138+
_data_provider.get_field_value(DataSource::Tx, vec![field, field2], out_buf_cap as usize);
139+
set_data(dp_res.0, out_buf_ptr, dp_res.1, _caller)?;
140+
Ok(vec![WasmValue::from_i32(dp_res.0)])
141+
}
142+
143+
pub fn get_tx_field3(
144+
_data_provider: &mut DataProvider,
145+
_inst: &mut Instance,
146+
_caller: &mut CallingFrame,
147+
_inputs: Vec<WasmValue>,
148+
) -> Result<Vec<WasmValue>, CoreError> {
149+
let field: i32 = _inputs[0].to_i32();
150+
let field2: i32 = _inputs[1].to_i32();
151+
let field3: i32 = _inputs[2].to_i32();
152+
let out_buf_ptr: i32 = _inputs[3].to_i32();
153+
let out_buf_cap: i32 = _inputs[4].to_i32();
154+
let dp_res = _data_provider.get_field_value(
155+
DataSource::Tx,
156+
vec![field, field2, field3],
157+
out_buf_cap as usize,
158+
);
159+
set_data(dp_res.0, out_buf_ptr, dp_res.1, _caller)?;
160+
Ok(vec![WasmValue::from_i32(dp_res.0)])
161+
}
162+
163+
pub fn get_tx_field4(
164+
_data_provider: &mut DataProvider,
165+
_inst: &mut Instance,
166+
_caller: &mut CallingFrame,
167+
_inputs: Vec<WasmValue>,
168+
) -> Result<Vec<WasmValue>, CoreError> {
169+
let field: i32 = _inputs[0].to_i32();
170+
let field2: i32 = _inputs[1].to_i32();
171+
let field3: i32 = _inputs[2].to_i32();
172+
let field4: i32 = _inputs[3].to_i32();
173+
let out_buf_ptr: i32 = _inputs[4].to_i32();
174+
let out_buf_cap: i32 = _inputs[5].to_i32();
175+
let dp_res = _data_provider.get_field_value(
176+
DataSource::Tx,
177+
vec![field, field2, field3, field4],
178+
out_buf_cap as usize,
179+
);
180+
set_data(dp_res.0, out_buf_ptr, dp_res.1, _caller)?;
181+
Ok(vec![WasmValue::from_i32(dp_res.0)])
182+
}
183+
184+
pub fn get_tx_field5(
185+
_data_provider: &mut DataProvider,
186+
_inst: &mut Instance,
187+
_caller: &mut CallingFrame,
188+
_inputs: Vec<WasmValue>,
189+
) -> Result<Vec<WasmValue>, CoreError> {
190+
let field: i32 = _inputs[0].to_i32();
191+
let field2: i32 = _inputs[1].to_i32();
192+
let field3: i32 = _inputs[2].to_i32();
193+
let field4: i32 = _inputs[3].to_i32();
194+
let field5: i32 = _inputs[4].to_i32();
195+
let out_buf_ptr: i32 = _inputs[5].to_i32();
196+
let out_buf_cap: i32 = _inputs[6].to_i32();
197+
let dp_res = _data_provider.get_field_value(
198+
DataSource::Tx,
199+
vec![field, field2, field3, field4, field5],
200+
out_buf_cap as usize,
201+
);
202+
set_data(dp_res.0, out_buf_ptr, dp_res.1, _caller)?;
203+
Ok(vec![WasmValue::from_i32(dp_res.0)])
204+
}
205+
206+
pub fn get_tx_field6(
207+
_data_provider: &mut DataProvider,
208+
_inst: &mut Instance,
209+
_caller: &mut CallingFrame,
210+
_inputs: Vec<WasmValue>,
211+
) -> Result<Vec<WasmValue>, CoreError> {
212+
let field: i32 = _inputs[0].to_i32();
213+
let field2: i32 = _inputs[1].to_i32();
214+
let field3: i32 = _inputs[2].to_i32();
215+
let field4: i32 = _inputs[3].to_i32();
216+
let field5: i32 = _inputs[4].to_i32();
217+
let field6: i32 = _inputs[5].to_i32();
218+
219+
let out_buf_ptr: i32 = _inputs[6].to_i32();
220+
let out_buf_cap: i32 = _inputs[7].to_i32();
221+
let dp_res = _data_provider.get_field_value(
222+
DataSource::Tx,
223+
vec![field, field2, field3, field4, field5, field6],
224+
out_buf_cap as usize,
225+
);
226+
set_data(dp_res.0, out_buf_ptr, dp_res.1, _caller)?;
227+
Ok(vec![WasmValue::from_i32(dp_res.0)])
228+
}
229+
127230
pub fn get_current_ledger_obj_field(
128231
_data_provider: &mut DataProvider,
129232
_inst: &mut Instance,
@@ -480,3 +583,23 @@ pub fn oracle_keylet(
480583
set_data(keylet_hash.len() as i32, out_buf_ptr, keylet_hash, _caller)?;
481584
Ok(vec![WasmValue::from_i32(HASH256_LEN as i32)])
482585
}
586+
587+
pub fn get_nft(
588+
_data_provider: &mut DataProvider,
589+
_inst: &mut Instance,
590+
_caller: &mut CallingFrame,
591+
_inputs: Vec<WasmValue>,
592+
) -> Result<Vec<WasmValue>, CoreError> {
593+
let owner_ptr: i32 = _inputs[0].to_i32();
594+
let owner_len: i32 = _inputs[1].to_i32();
595+
let nft_id_ptr: i32 = _inputs[2].to_i32();
596+
let nft_id_len: i32 = _inputs[3].to_i32();
597+
let out_buf_ptr: i32 = _inputs[4].to_i32();
598+
let out_buf_cap: i32 = _inputs[5].to_i32();
599+
600+
let owner_id = get_data(owner_ptr, owner_len, _caller)?;
601+
let nft_id = get_data(nft_id_ptr, nft_id_len, _caller)?;
602+
let dp_res = _data_provider.get_nft_uri(&nft_id, &owner_id, out_buf_cap as usize);
603+
set_data(dp_res.0, out_buf_ptr, dp_res.1, _caller)?;
604+
Ok(vec![WasmValue::from_i32(dp_res.0)])
605+
}

wasm-host/src/main.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct Args {
3939

4040
fn load_test_data(
4141
test_case: &str,
42-
) -> Result<(String, String, String, String), Box<dyn std::error::Error>> {
42+
) -> Result<(String, String, String, String, String), Box<dyn std::error::Error>> {
4343
let base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
4444
.join("fixtures")
4545
.join("escrow")
@@ -49,13 +49,15 @@ fn load_test_data(
4949
let lo_path = base_path.join("ledger_object.json");
5050
let lh_path = base_path.join("ledger_header.json");
5151
let l_path = base_path.join("ledger.json");
52+
let nfts_path = base_path.join("nfts.json");
5253

5354
let tx_json = fs::read_to_string(tx_path)?;
5455
let lo_json = fs::read_to_string(lo_path)?;
5556
let lh_json = fs::read_to_string(lh_path)?;
5657
let l_json = fs::read_to_string(l_path)?;
58+
let nft_json = fs::read_to_string(nfts_path)?;
5759

58-
Ok((tx_json, lo_json, lh_json, l_json))
60+
Ok((tx_json, lo_json, lh_json, l_json, nft_json))
5961
}
6062

6163
fn main() {
@@ -96,18 +98,18 @@ fn main() {
9698
info!("Target function: finish (XLS-100d)");
9799
info!("Using test case: {}", args.test_case);
98100
info!("Loading test data from fixtures");
99-
let (tx_json, lo_json, lh_json, l_json) = match load_test_data(&args.test_case) {
100-
Ok((tx, lo, lh, l)) => {
101+
let (tx_json, lo_json, lh_json, l_json, nft_json) = match load_test_data(&args.test_case) {
102+
Ok((tx, lo, lh, l, nft)) => {
101103
debug!("Test data loaded successfully");
102-
(tx, lo, lh, l)
104+
(tx, lo, lh, l, nft)
103105
}
104106
Err(e) => {
105107
error!("Failed to load test data: {}", e);
106108
return;
107109
}
108110
};
109111

110-
let data_source = MockData::new(&tx_json, &lo_json, &lh_json, &l_json);
112+
let data_source = MockData::new(&tx_json, &lo_json, &lh_json, &l_json, &nft_json);
111113
info!("Executing function: finish");
112114
match run_func(wasm_file, "finish", data_source) {
113115
Ok(result) => {

0 commit comments

Comments
 (0)