#Is there a way to generate the asset contract id from inside the contract?

1 messages · Page 1 of 1 (latest)

latent rock
#

I want to be able to manually generate the id of an asset contract by following the ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET specified in https://github.com/stellar/stellar-protocol/blob/master/core/cap-0046.md.

I know how to do this on Javascript and python but not sure what will be the best way to do it inside a smart contract. I saw there is a stellar-xdr (which is in early development) but again not sure if it's the best way to do it

What is the goal: My protocol issues different assets based on a single issuer so I want to be able to just save the issuer and let the protocol generate the contract ids when necessary based on values sent

#

I'm currently saving those contracts ids in the storage, but I'm thinking in ways to reduce the usage of storage since they are multiple assets

proud plank
#

currently it's probably tricky to do in the contract

#

it's ok to use stellar-xdr if you can make it build with wasm... but that's not really efficient

#

I wonder though if you save much by not storing the contract ids... you do need to store the asset names, right?

#

so you optimize 32 bytes to, say, 10 bytes at cost of increasing the wasm size and gas costs for every transaction... it may or may not be more cheap, but I'd expect the difference to be marginal enough to not care

latent rock
#

It wasn't with the idea of efficiency but ratter convenience, that way I don't need to manually add them to the storage after a deploy because the storage usage will be only for the issuer (I don't need to save the asset's name either since the contract id can be generated when passing the name as a parameter)

But yeah if it's going to be tricky maybe it's better to avoid that path

proud plank
#

hmm, but you still need something to identify the contract

#

if you don't want to store it, you can pass it in the calls...