Me and @sway tried to understand how to do that using the doc, and on the Deploying a contract binary page we have next example:
But we can’t understand, in this example author uses key and value as Bytes32
.
For example, we have that type of storage
storage {
collateral_configurations: StorageMap<AssetId, CollateralConfiguration> = StorageMap {},
collateral_configurations_keys: StorageVec<AssetId> = StorageVec {},
pause_config: PauseConfiguration = PauseConfiguration::default(),
totals_collateral: StorageMap<AssetId, u64> = StorageMap {},
user_collateral: StorageMap<(Address, AssetId), u64> = StorageMap {},
user_basic: StorageMap<Address, UserBasic> = StorageMap {},
market_basic: MarketBasics = MarketBasics::default(),
debug_timestamp: u64 = 0,
}
Can you explain please how to define all of the storage here?
I expected something like this as an answer:
let rng = &mut StdRng::seed_from_u64(2322u64);
let salt: [u8; 32] = rng.gen();
// Optional: Configure storage
let mut storage_configuration = StorageConfiguration::default();
storage_configuration.add("collateral_configurations", vec![]);
storage_configuration.add("collateral_configurations_keys", vec![]);
storage_configuration.add("pause_config", PauseConfiguration::default());
storage_configuration.add("totals_collateral", HashMap::new());
storage_configuration.add("user_collateral", HashMap::new());
storage_configuration.add("user_basic", HashMap::new());
storage_configuration.add("market_basic", MarketBasics::default());
debug_timestamp.add("market_basic", 0);
let configuration = LoadConfiguration::default()
.with_storage_configuration(storage_configuration)
.with_salt(salt);
// Optional: Configure deployment parameters
let tx_parameters = TxParameters::default()
.with_gas_price(0)
.with_gas_limit(1_000_000)
.with_maturity(0);
let contract_id_2 = Contract::load_from(
"../../packages/fuels/tests/contracts/contract_test/out/debug/contract_test.bin",
configuration,
)?
.deploy(&wallet, tx_parameters)
.await?;
println!("Contract deployed @ {contract_id_2}");
Toolchain
Default host: aarch64-apple-darwin
fuelup home: /Users/alexey/.fuelup
installed toolchains
--------------------
beta-3-aarch64-apple-darwin
beta-4-rc.2-aarch64-apple-darwin
latest-aarch64-apple-darwin (default)
hotfix
my-custom-toolchain
active toolchain
-----------------
latest-aarch64-apple-darwin (default)
forc : 0.44.1
- forc-client
- forc-deploy : 0.44.1
- forc-run : 0.44.1
- forc-doc : 0.44.1
- forc-explore : 0.28.1
- forc-fmt : 0.44.1
- forc-index : 0.20.7
- forc-lsp : 0.44.1
- forc-tx : 0.44.1
- forc-wallet : 0.3.0
fuel-core : 0.20.4
fuel-core-keygen : Error getting version string
fuel-indexer : 0.20.7
fuels versions
---------------
forc : 0.45
forc-wallet : 0.45
P.S.
I found how to load default storage slots, but still don’t know how to edit it
let mut rng = rand::thread_rng();
let salt = rng.gen::<[u8; 32]>();
let configurables = MarketContractConfigurables::default()
.with_MARKET_CONFIGURATION(Option::Some(market_configuration))
.with_DEBUG_STEP(debug_step);
let storage = StorageConfiguration::load_from("./out/debug/market-storage_slots.json").unwrap();
let config = LoadConfiguration::default()
.with_configurables(configurables)
.with_storage_configuration(storage);
let id = Contract::load_from("./out/debug/market.bin", config)
.unwrap()
.with_salt(salt)
.deploy(wallet, TxParameters::default().with_gas_price(1))
.await
.unwrap();
MarketContract::new(id, wallet.clone())