#Any method for converting Address into BytesN?

11 messages · Page 1 of 1 (latest)

tiny grove
#

When instantiating a contract Client interface it requires a BytesN<32> arg. I feel we should be storing Addresses vs BytesN for contract ids so is there a way to go from Address to BytesN and eventually will we migrate away from BytesN for contract id stuff and move to Addresses?

#

lib.rs

let token_id = BytesN::from_val(&env, &token_address.to_raw());
let token_client = token::Client::new(&env, &token_id);

Looks like it should work but
test.rs

let token_id = env.register_stellar_asset_contract(admin.clone());
let token_address = Address::from_contract_id(&env, &token_id);

Fails with

running 1 test
thread 'test::test_faucet' panicked at 'HostError
Value: Status(UnknownError(0))

Debug events (newest first):
   0: "escalating error '' to panic"
   1: "contract call invocation resulted in error Status(UnknownError(0))"
   2: "unexpected missing nonce"
   3: "caught panic 'called `Result::unwrap()` on an `Err` value: ConversionError' from contract function 'Symbol(faucet)'"
   4: "invoker account is not configured"
   5: "no frames to derive the invoker from"
   6: "unexpected missing nonce"
   7: "invoker account is not configured"
   8: "no frames to derive the invoker from"
   9: "unexpected missing nonce"
   10: ... elided ...
modest rover
#

not sure why your code fails though

#

ah, let token_id = BytesN::from_val(&env, &token_address.to_raw()); shouldn't work

#

I don't quite understand what is the intent here. if you have something specific you want to deal with in this release, we can figure out a way around that, but in the next release it should become more straightforward

tiny grove
#

I can wait for next release. Your issue you linked is what I'll keep my eye on. Thanks

modest rover
#

FWIW the only broken case I'm aware of for today is deploying and funding a contract in the same invocation

tiny grove
#

Mine is less of a case of broken and more "this is weird". Should we not allow cross contract calls to be instantiated with an Address vs BytesN? Like for example the token contract when fire that up from within a contract it'd be nice to be able to fire it up via an Address

modest rover
#

yeah, that's probably what we'll do

#

it's still a bit awkward because you'd be able to 'invoke' a stellar account, but that's that different from invoking a non-existent contract or non-existent function etc.