#i128 to RawVal
48 messages · Page 1 of 1 (latest)
ok, I'm just still not quite comfortable with all the conversions (feels like we have too many...), so I wanted to check if there is something preventing us from adding this
Does try_into_val work? If so we're probably just missing the into_val equiv.
nope
Looks like the conversions are missing here, they were added for Object, but not RawVal: https://github.com/stellar/rs-soroban-env/blob/main/soroban-env-common/src/env_val.rs#L227
I mean, it works for i128 itself, but not for tuple->vec conversion nvm, that's for the literal
If you look just north of that line, you'll see the u64 conversions.
And just south of that line is the 128 conversions having Object but not RawVal.
ok
I'm not actually sure why we have the object conversions, we don't normally bother with them.
They don't do any harm though.
that's what I'm talking about 🙂
I think we could benefit from removing some conversions and replacing some of the stuff that is conversion now with named methods
Graydon has a WIP removing some conversion traits.
(we sometimes have both, like to_raw() and into() for RawVal etc)
nice
hmm, I'm still a bit confused. what is i128 in the contract context?
it seems like it's the Rust value
do we do ScVal->Object->rust i128 trip?
i.e. do we create a redundant object in host?
Object is a u60 handle.
right, but i128 doesn't fit into RawVal, right?
so it has to be an Object. but from the contract interface standpoint we pass the rust i128 type as an argument, which is not an Object
actually the same is already true for u64... I'm just trying to understand if we create objects for the contract invocation arguments that are rust integer types
Every value is converted to/from a RawVal at the boundaries of a contract.
so we create redundant objects, right? they're not accessible from the contract itself
What is a redundant object?
when we invoke a contract we create an object in host for u64/i128 etc. but the contract itself operates on the rust type, i.e. IIUC it would compile the respective integer operations in WASM. there is no access to the object that has been created in host in the first place
that's probably not a big deal, just trying to understand the data flow
there is no access to the object that has been created in host in the first place
What do you mean by this?
It might be worth sharing an annotated example.
is i128 in the contract interface an object or just a rust value?
IIUC it's not an object, hence there is no access to the original host object created during the contract invocation
hence the object is redundant
the only way to go from i128 back to the RawVal/Object etc. is to create a new host object
The contract when invoked receives RawVals, and it converts them into the native Rust types.
The contractimpl macro wraps the function the developer writes in an exported function that receives the same number of arguments, but with type RawVal.
indeed. the point is that the majority of object types hold the original host object references (bytes, vec, map etc), while integer types don't. I don't think that's a big deal, it just makes the conversions a bit more confusing
hmm, actually the conversions are there, just defined with macro
All values need converting. Some require host functions for the conversion, others do not. But all need converting.
Oh, I guess except Symbol. We never convert them, but they do get validated as part of their "conversion".
The same is true of handle types that stay in an obj. Bytes for example, no conversion actually happens, then handle is just validated (locally only) and moved into a type.
ok, I'm dumb. the conversions are in place, I just was trying to pass Vec to a method that expects &Vec 🤦♂️
Interesting. I wonder where the conversions are then. I only see the conversions to and from Object, but that isn't sufficient.
Oh, they're immediately below. Graydon created macros for them, and my eyes were glossing over the macros.
decl_int128_conversions