pub struct MockAddressGenerator;
Expand description

Address generator that mimics the original wasmd behavior.

MockAddressGenerator implements AddressGenerator trait in terms of contract_address and predictable_contract_address functions:

  • contract_address generates non-predictable addresses for contracts, using the same algorithm as wasmd, see: BuildContractAddressClassic for details.
  • predictable_contract_address generates predictable addresses for contracts using instantiate2_address function defined in cosmwasm-std.

Trait Implementations§

source§

impl AddressGenerator for MockAddressGenerator

source§

fn contract_address( &self, api: &dyn Api, _storage: &mut dyn Storage, code_id: u64, instance_id: u64 ) -> AnyResult<Addr>

Generates a non-predictable contract address, like wasmd does it in real-life chain.

Note that addresses generated by wasmd may change and users should not rely on this value in any extend.

Returns the contract address after its instantiation. Address generated by this function is returned as a result of processing WasmMsg::Instantiate message.

NOTES

👉 The canonical address generated by this function is humanized using the Api::addr_humanize function, so the resulting value depends on used Api implementation. The following example uses Bech32 format for humanizing canonical addresses.

👉 Do NOT use this function directly to generate a contract address, pass this address generator to WasmKeeper: WasmKeeper::new().with_address_generator(MockAddressGenerator::default());

§Example
// use `Api` that implements Bech32 format
let api = MockApiBech32::new("juno");
// prepare mock storage
let mut storage = MockStorage::default();
// initialize the address generator
let address_generator = MockAddressGenerator::default();
// generate the address
let addr = address_generator.contract_address(&api, &mut storage, 1, 1).unwrap();

assert_eq!(addr.to_string(),
           "juno14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9skjuwg8");
source§

fn predictable_contract_address( &self, api: &dyn Api, _storage: &mut dyn Storage, _code_id: u64, _instance_id: u64, checksum: &[u8], creator: &CanonicalAddr, salt: &[u8] ) -> AnyResult<Addr>

Generates a predictable contract address, like wasmd does it in real-life chain.

Returns a contract address after its instantiation. Address generated by this function is returned as a result of processing WasmMsg::Instantiate2 message.

NOTES

👉 The canonical address generated by this function is humanized using the Api::addr_humanize function, so the resulting value depends on used Api implementation. The following example uses Bech32 format for humanizing canonical addresses.

👉 Do NOT use this function directly to generate a contract address, pass this address generator to WasmKeeper: WasmKeeper::new().with_address_generator(MockAddressGenerator::default());

§Example
// use `Api` that implements Bech32 format
let api = MockApiBech32::new("juno");
// prepare mock storage
let mut storage = MockStorage::default();
// initialize the address generator
let address_generator = MockAddressGenerator::default();
// checksum of the contract code base
let checksum = [0, 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10,
                11,12,13,14,15,16,17,18,19,20,21,
                22,23,24,25,26,27,28,29,30,31];
// creator address
let creator = api.addr_canonicalize(api.addr_make("creator").as_str()).unwrap();
// salt
let salt = [10,11,12];
// generate the address
let addr = address_generator
    .predictable_contract_address(&api, &mut storage, 1, 1, &checksum, &creator, &salt)
    .unwrap();

assert_eq!(addr.to_string(),
           "juno1sv3gjp85m3xxluxreruards8ruxk5ykys8qfljwrdj5tv8kqxuhsmlfyud");
source§

fn next_address(&self, storage: &mut dyn Storage) -> Addr

👎Deprecated since 0.18.0: use contract_address or predictable_contract_address instead; will be removed in version 1.0.0
source§

impl Default for MockAddressGenerator

source§

fn default() -> MockAddressGenerator

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<U> As for U

source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.