mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 08:47:57 +00:00
Support u128/i128 in runtime interface (#4703)
* Support `u128`/`i128` in runtime interface This implements support for `u128`/`i128` as parameters/return value in runtime interfaces. As we can not pass them as identity, as for the other primitives types, we pass them as an pointer to an `[u8; 16]` array. * Remove some unsafe code usage
This commit is contained in:
@@ -82,6 +82,16 @@ pub trait TestApi {
|
||||
fn overwrite_native_function_implementation() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Gets an `u128` and returns this value
|
||||
fn get_and_return_u128(val: u128) -> u128 {
|
||||
val
|
||||
}
|
||||
|
||||
/// Gets an `i128` and returns this value
|
||||
fn get_and_return_i128(val: i128) -> i128 {
|
||||
val
|
||||
}
|
||||
}
|
||||
|
||||
/// Two random external functions from the old runtime interface.
|
||||
@@ -191,4 +201,14 @@ wasm_export_functions! {
|
||||
|
||||
assert!(test_api::overwrite_native_function_implementation());
|
||||
}
|
||||
|
||||
fn test_u128_i128_as_parameter_and_return_value() {
|
||||
for val in &[u128::max_value(), 1u128, 5000u128, u64::max_value() as u128] {
|
||||
assert_eq!(*val, test_api::get_and_return_u128(*val));
|
||||
}
|
||||
|
||||
for val in &[i128::max_value(), i128::min_value(), 1i128, 5000i128, u64::max_value() as i128] {
|
||||
assert_eq!(*val, test_api::get_and_return_i128(*val));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user