Description
contracts/marketplace/src/lib.rs has a load_config helper (lines 291–332) that first tries to read a DataKey::Config struct, and if absent falls back to reading individual keys (Admin, InvoiceNft, FinancingPool, Treasury, FeeBps) and writing them into a consolidated Config entry.
The problem is that initialize (lines 45–67) never writes DataKey::Config. It only writes the individual keys:
env.storage().instance().set(&DataKey::Admin, &admin);
env.storage().instance().set(&DataKey::InvoiceNft, &invoice_nft);
// ...no Config write
This means:
- Every single call to any function that uses
load_config (e.g., list_invoice, cancel_listing, whitelist_token) triggers the legacy migration path, doing 5 storage reads + 1 write instead of 1 read.
- The first call to any of those functions mutates storage as a side effect — unexpected behaviour for read-like operations.
- The
get_config test (test_get_config_returns_initialized_values) relies on get_config being available, but that function is not defined in the contract either (see related compilation issue).
Fix
At the end of initialize, write the consolidated config:
let config = MarketplaceConfig { admin, invoice_nft, financing_pool, treasury, fee_bps };
env.storage().instance().set(&DataKey::Config, &config);
Acceptance Criteria
Complexity: Low (75 points)
Description
contracts/marketplace/src/lib.rshas aload_confighelper (lines 291–332) that first tries to read aDataKey::Configstruct, and if absent falls back to reading individual keys (Admin,InvoiceNft,FinancingPool,Treasury,FeeBps) and writing them into a consolidatedConfigentry.The problem is that
initialize(lines 45–67) never writesDataKey::Config. It only writes the individual keys:This means:
load_config(e.g.,list_invoice,cancel_listing,whitelist_token) triggers the legacy migration path, doing 5 storage reads + 1 write instead of 1 read.get_configtest (test_get_config_returns_initialized_values) relies onget_configbeing available, but that function is not defined in the contract either (see related compilation issue).Fix
At the end of
initialize, write the consolidated config:Acceptance Criteria
initializewritesDataKey::Configas part of its setup.load_configreads the config in a single storage lookup on all subsequent calls.Complexity: Low (75 points)