#Cross contract calls, env.invoke_contract() and passing arguments

19 messages · Page 1 of 1 (latest)

agile fern
#

I've been trying to make a cross contract call without importing the other contracts .wasm
So, there is env.invoke_contract() which is usable for this.

But, the arguments need to be passed in as vec<RawVal>
So, with for example an increment type function, we can pass an u32 with .into()
env.invoke_contract::<RawVal>(&target_contract, &Symbol::new(&env, "increment"), vec![&env, x.into()]);

But for Hello World, I want to pass "World".
How would one cast/convert/fit/force a String or Symbol into RawVal for use here?
env.invoke_contract::<RawVal>(&target_contract, &Symbol::new(&env, "Hello"), vec![&env, ???]);

hoary quail
#

probably like that:
env.invoke_contract::<RawVal>(&target, &Symbol::new(&env, "Hello"), vec![&env, *Symbol::new(&env, "World").as_raw()]);

agile fern
#

Yeah that seems to work, cool!
Now I'm not sure what I did earlier that kept giving me errors

#

And now I do. I tried to get my pseudo contract to return the result of Symbol::new(&env, "World").as_raw() first, to see what happens.
That causes a panic:

hoary quail
#

got that too while trying too, then tried to put RawVal as return type which is not possible

agile fern
#

That's what triggers the error, returning RawVal
Awesome, thanks

remote folio
frozen coyote
#

what about implementing intoval

remote folio
#

any contracttype implements it

#

(and any SDK type, that is)

frozen coyote
#

ah just saw the message that the error is triggered by returning a rawval not actually converting it

remote folio
#

maybe that's a bug actually

#

something about symbol conversion

#

you definitely should be able to return RawVal from a function

#

if someone has an example to share, that would be great. I'm not sure from this thread what exactly has been done here

hoary quail
#

these contract functions compile:

    pub fn get_rawvalu32(_env: Env) -> RawVal {

        let r: u32 = 42;
        r.into()
    }
    pub fn get_rawvalsym(env: Env) -> RawVal {

        *Symbol::new(&env, "raw").as_raw()
    }

Gives:

$ soroban contract invoke --wasm target/wasm32-unknown-unknown/release/game1.wasm --id 123 -- get_rawvalu32
error: cannot print result U32(42): Invalid pair U32(
    42,
) Val
$ soroban contract invoke --wasm target/wasm32-unknown-unknown/release/game1.wasm --id 123 -- get_rawvalsym
thread 'main' panicked at 'not yet implemented: Symbol(
    ScSymbol(
        StringM(raw),
    ),
) doesn't have a matching Val', .cargo/registry/src/github.com-1ecc6299db9ec823/soroban-cli-0.8.0/src/strval.rs:492:27
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
agile fern
#

The 'not yet implemented' panic implies it is on a list somewhere

remote folio
#

ah, that's a CLI issue. the tests work, right?