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

Commit 807cc55

Browse files
committed
more cleanup
1 parent d5644f9 commit 807cc55

File tree

5 files changed

+89
-58
lines changed

5 files changed

+89
-58
lines changed

xrpl-std/src/core/tx/current_transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::core::amount::xrp_amount::XrpAmount;
21
use crate::core::amount::Amount;
32
use crate::core::amount::Amount::Xrp;
3+
use crate::core::amount::xrp_amount::XrpAmount;
44
use crate::core::field_codes::{
55
SF_ACCOUNT, SF_ACCOUNT_TXN_ID, SF_CONDITION, SF_FEE, SF_FLAGS, SF_FULFILLMENT, SF_HASH,
66
SF_LAST_LEDGER_SEQUENCE, SF_NETWORK_ID, SF_OFFER_SEQUENCE, SF_OWNER, SF_SEQUENCE,

xrpl-std/src/host/host_bindings.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ unsafe extern "C" {
159159
///
160160
/// # Parameters
161161
///
162-
/// - `slot`: An integer representing the slot index of the ledger object.
162+
/// - `cache_num`: An integer representing the cache index of the ledger object.
163163
/// - `field`: An integer representing the specific field to retrieve from the ledger object.
164164
/// - `out_buff_ptr`: A mutable pointer to a buffer where the retrieved field data will be written.
165165
/// - `out_buff_len`: The size of the output buffer in bytes.
@@ -170,7 +170,7 @@ unsafe extern "C" {
170170
/// - Returns a negative error code on failure. The list of error codes is defined in
171171
/// ../core/error_codes.rs
172172
pub fn get_ledger_obj_field(
173-
slot: i32,
173+
cache_num: i32,
174174
field: i32,
175175
out_buff_ptr: *mut u8,
176176
out_buff_len: usize,
@@ -221,10 +221,10 @@ unsafe extern "C" {
221221
out_buff_len: usize,
222222
) -> i32;
223223

224-
/// Retrieves a nested field from a ledger object in a specific slot and writes the result into an output buffer.
224+
/// Retrieves a nested field from a ledger object in a specific cache_num and writes the result into an output buffer.
225225
///
226226
/// # Parameters
227-
/// - `slot`: The slot index of the ledger object to access.
227+
/// - `cache_num`: The cache index of the ledger object to access.
228228
/// - `locator_ptr`: A pointer to the memory location containing the locator string data
229229
/// (used to identify the nested field in the ledger object).
230230
/// - `locator_len`: The length of the locator string.
@@ -237,7 +237,7 @@ unsafe extern "C" {
237237
/// - Returns a negative error code on failure. The list of error codes is defined in
238238
/// ../core/error_codes.rs
239239
pub fn get_ledger_obj_nested_field(
240-
slot: i32,
240+
cache_num: i32,
241241
locator_ptr: *const u8,
242242
locator_len: usize,
243243
out_buff_ptr: *mut u8,
@@ -268,18 +268,18 @@ unsafe extern "C" {
268268
/// ../core/error_codes.rs
269269
pub fn get_current_ledger_obj_array_len(field: i32) -> i32;
270270

271-
/// Retrieves the length of an array based on the provided slot number and field value.
271+
/// Retrieves the length of an array based on the provided cache number and field value.
272272
///
273273
/// # Parameters
274-
/// - `slot`: The slot index of the ledger object to access.
274+
/// - `cache_num`: The cache index of the ledger object to access.
275275
/// - `field` (i32): The integer identifier for the desired field.
276276
///
277277
/// # Returns
278278
///
279279
/// - Returns a positive number of array length on success
280280
/// - Returns a negative error code on failure. The list of error codes is defined in
281281
/// ../core/error_codes.rs
282-
pub fn get_ledger_obj_array_len(slot: i32, field: i32) -> i32;
282+
pub fn get_ledger_obj_array_len(cache_num: i32, field: i32) -> i32;
283283

284284
/// Retrieves the length of an array based on the provided locator.
285285
///
@@ -313,7 +313,7 @@ unsafe extern "C" {
313313
/// Retrieves the length of an array based on the provided locator.
314314
///
315315
/// # Parameters
316-
/// - `slot`: The slot index of the ledger object to access.
316+
/// - `cache_num`: The cache index of the ledger object to access.
317317
/// - `locator_ptr`: A pointer to a byte array containing the locator for the nested field.
318318
/// - `locator_len`: The length of the locator data in bytes.
319319
///
@@ -323,7 +323,7 @@ unsafe extern "C" {
323323
/// - Returns a negative error code on failure. The list of error codes is defined in
324324
/// ../core/error_codes.rs
325325
pub fn get_ledger_obj_nested_array_len(
326-
slot: i32,
326+
cache_num: i32,
327327
locator_ptr: *const u8,
328328
locator_len: usize,
329329
) -> i32;

xrpl-std/src/keylet.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,32 @@ use crate::host;
22
use crate::types::{AccountID, Keylet, XRPL_KEYLET_SIZE};
33

44
pub fn account_keylet(aid: &AccountID) -> Option<Keylet> {
5-
let mut key_let: Keylet = [0; XRPL_KEYLET_SIZE];
5+
let mut keylet: Keylet = [0; XRPL_KEYLET_SIZE];
6+
let retcode =
7+
unsafe { host::account_keylet(aid.as_ptr(), aid.len(), keylet.as_mut_ptr(), keylet.len()) };
8+
if retcode > 0 { Some(keylet) } else { None }
9+
}
10+
11+
pub fn escrow_keylet(owner: &AccountID, sequence: i32) -> Option<Keylet> {
12+
let mut keylet: Keylet = [0; XRPL_KEYLET_SIZE];
613
let retcode = unsafe {
7-
host::account_keylet(aid.as_ptr(), aid.len(), key_let.as_mut_ptr(), key_let.len())
14+
host::escrow_keylet(
15+
owner.as_ptr(),
16+
owner.len(),
17+
sequence,
18+
keylet.as_mut_ptr(),
19+
keylet.len(),
20+
)
821
};
9-
if retcode > 0 { Some(key_let) } else { None }
22+
if retcode > 0 { Some(keylet) } else { None }
1023
}
1124

1225
pub fn credential_keylet(
1326
subject: &AccountID,
1427
issuer: &AccountID,
1528
credential_type: &[u8],
1629
) -> Option<Keylet> {
17-
let mut key_let: Keylet = [0; XRPL_KEYLET_SIZE];
30+
let mut keylet: Keylet = [0; XRPL_KEYLET_SIZE];
1831
let retcode = unsafe {
1932
host::credential_keylet(
2033
subject.as_ptr(),
@@ -23,23 +36,23 @@ pub fn credential_keylet(
2336
issuer.len(),
2437
credential_type.as_ptr(),
2538
credential_type.len(),
26-
key_let.as_mut_ptr(),
27-
key_let.len(),
39+
keylet.as_mut_ptr(),
40+
keylet.len(),
2841
)
2942
};
30-
if retcode > 0 { Some(key_let) } else { None }
43+
if retcode > 0 { Some(keylet) } else { None }
3144
}
3245

3346
pub fn oracle_keylet(owner: &AccountID, document_id: i32) -> Option<Keylet> {
34-
let mut key_let: Keylet = [0; XRPL_KEYLET_SIZE];
47+
let mut keylet: Keylet = [0; XRPL_KEYLET_SIZE];
3548
let retcode = unsafe {
3649
host::oracle_keylet(
3750
owner.as_ptr(),
3851
owner.len(),
3952
document_id,
40-
key_let.as_mut_ptr(),
41-
key_let.len(),
53+
keylet.as_mut_ptr(),
54+
keylet.len(),
4255
)
4356
};
44-
if retcode > 0 { Some(key_let) } else { None }
57+
if retcode > 0 { Some(keylet) } else { None }
4558
}

xrpl-std/src/lib.rs

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,69 +18,75 @@ use crate::types::{AccountID, ContractData, NFT, XRPL_ACCOUNT_ID_SIZE, XRPL_CONT
1818

1919
pub fn get_tx_account_id() -> Option<AccountID> {
2020
let mut account_id: AccountID = [0; XRPL_ACCOUNT_ID_SIZE];
21-
if unsafe { host::get_tx_field(sfield::Account, account_id.as_mut_ptr(), account_id.len()) } > 0
22-
{
21+
let retcode =
22+
unsafe { host::get_tx_field(sfield::Account, account_id.as_mut_ptr(), account_id.len()) };
23+
if retcode > 0 {
2324
Some(account_id)
2425
} else {
26+
let _ = trace_num("get_tx_account_id error", i64::from(retcode));
2527
None
2628
}
2729
}
2830

2931
pub fn get_current_escrow_account_id() -> Option<AccountID> {
3032
let mut account_id: AccountID = [0; XRPL_ACCOUNT_ID_SIZE];
31-
if unsafe {
33+
let retcode = unsafe {
3234
host::get_current_ledger_obj_field(
3335
sfield::Account,
3436
account_id.as_mut_ptr(),
3537
account_id.len(),
3638
)
37-
} > 0
38-
{
39+
};
40+
if retcode > 0 {
3941
Some(account_id)
4042
} else {
43+
let _ = trace_num("get_current_escrow_account_id error", i64::from(retcode));
4144
None
4245
}
4346
}
4447

4548
pub fn get_current_escrow_destination() -> Option<AccountID> {
4649
let mut account_id: AccountID = [0; XRPL_ACCOUNT_ID_SIZE];
47-
if unsafe {
50+
let retcode = unsafe {
4851
host::get_current_ledger_obj_field(
4952
sfield::Destination,
5053
account_id.as_mut_ptr(),
5154
account_id.len(),
5255
)
53-
} > 0
54-
{
56+
};
57+
if retcode > 0 {
5558
Some(account_id)
5659
} else {
60+
let _ = trace_num("get_current_escrow_destination error", i64::from(retcode));
5761
None
5862
}
5963
}
6064

6165
pub fn get_current_escrow_data() -> Option<ContractData> {
6266
let mut data: ContractData = [0; XRPL_CONTRACT_DATA_SIZE];
63-
if unsafe { host::get_current_ledger_obj_field(sfield::Data, data.as_mut_ptr(), data.len()) }
64-
> 0
65-
{
67+
let retcode =
68+
unsafe { host::get_current_ledger_obj_field(sfield::Data, data.as_mut_ptr(), data.len()) };
69+
if retcode > 0 {
6670
Some(data)
6771
} else {
72+
let _ = trace_num("get_current_escrow_data error", i64::from(retcode));
6873
None
6974
}
7075
}
7176

7277
pub fn get_current_escrow_finish_after() -> Option<i32> {
7378
let mut after = 0i32;
74-
if unsafe {
79+
let retcode = unsafe {
7580
host::get_current_ledger_obj_field(
7681
sfield::FinishAfter,
7782
(&mut after) as *mut i32 as *mut u8,
7883
4,
7984
)
80-
} > 0
81-
{
85+
};
86+
if retcode > 0 {
8287
Some(after)
8388
} else {
89+
let _ = trace_num("get_current_escrow_finish_after error", i64::from(retcode));
8490
None
8591
}
8692
}
@@ -93,6 +99,10 @@ pub fn get_account_balance(aid: &AccountID) -> Option<u64> {
9399
// let _ = trace_data("std-lib keylet ", &keylet, DataRepr::AsHex);
94100
let slot = unsafe { host::cache_ledger_obj(keylet.as_ptr(), keylet.len(), 0) };
95101
if slot <= 0 {
102+
let _ = trace_num(
103+
"get_account_balance cache_ledger_obj failed",
104+
i64::from(slot),
105+
);
96106
return None;
97107
}
98108
// let _ = trace("std-lib slot ");
@@ -121,40 +131,42 @@ pub fn get_account_balance(aid: &AccountID) -> Option<u64> {
121131

122132
pub fn get_nft(owner: &AccountID, nft: &NFT) -> Option<ContractData> {
123133
let mut data: ContractData = [0; XRPL_CONTRACT_DATA_SIZE];
124-
unsafe {
125-
let retcode = host::get_NFT(
134+
135+
let retcode = unsafe {
136+
host::get_NFT(
126137
owner.as_ptr(),
127138
owner.len(),
128139
nft.as_ptr(),
129140
nft.len(),
130141
data.as_mut_ptr(),
131142
data.len(),
132-
);
133-
if retcode > 0 {
134-
Some(data)
135-
} else {
136-
let _ = trace_num("get_nft error", i64::from(retcode));
137-
None
138-
}
143+
)
144+
};
145+
if retcode > 0 {
146+
Some(data)
147+
} else {
148+
let _ = trace_num("get_nft error", i64::from(retcode));
149+
None
139150
}
140151
}
141152

142153
pub fn get_ledger_obj_nested_field(slot: i32, locator: &LocatorPacker) -> Option<ContractData> {
143154
let mut data: ContractData = [0; XRPL_CONTRACT_DATA_SIZE];
144-
unsafe {
145-
let retcode = host::get_ledger_obj_nested_field(
155+
156+
let retcode = unsafe {
157+
host::get_ledger_obj_nested_field(
146158
slot,
147159
locator.get_addr(),
148160
locator.num_packed_bytes(),
149161
data.as_mut_ptr(),
150162
data.len(),
151-
);
152-
if retcode > 0 {
153-
Some(data)
154-
} else {
155-
let _ = trace_num("get_ledger_obj_nested_field error", i64::from(retcode));
156-
None
157-
}
163+
)
164+
};
165+
if retcode > 0 {
166+
Some(data)
167+
} else {
168+
let _ = trace_num("get_ledger_obj_nested_field error", i64::from(retcode));
169+
None
158170
}
159171
}
160172

xrpl-std/src/types.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
pub const XRPL_ACCOUNT_ID_SIZE: usize = 20;
2-
pub const XRPL_NFTID_SIZE: usize = 32;
3-
pub const XRPL_HASH256_SIZE: usize = 32;
4-
pub const XRPL_CONTRACT_DATA_SIZE: usize = 4096; //TODO size??
52
pub type AccountID = [u8; XRPL_ACCOUNT_ID_SIZE];
3+
4+
pub const XRPL_NFTID_SIZE: usize = 32;
65
pub type NFT = [u8; XRPL_NFTID_SIZE];
6+
7+
pub const XRPL_HASH256_SIZE: usize = 32;
78
pub type Hash256 = [u8; XRPL_HASH256_SIZE];
9+
10+
pub const XRPL_CONTRACT_DATA_SIZE: usize = 4096; //TODO size??
811
pub type ContractData = [u8; XRPL_CONTRACT_DATA_SIZE];
12+
913
// use keylet hash only (i.e. without 2-byte LedgerEntryType) for now.
1014
// TODO Check rippled
1115
pub const XRPL_KEYLET_SIZE: usize = 32;
12-
1316
pub type Keylet = [u8; XRPL_KEYLET_SIZE];
17+
18+
pub const XRPL_NFT_URI_SIZE: usize = 256;
19+
pub type NFT_URI = [u8; XRPL_NFT_URI_SIZE];

0 commit comments

Comments
 (0)