Post
Share your knowledge.
How to update a merchant's key in ObjectTable when it changes in the struct?
Hi everyone, I'm just getting started with writing smart contracts and I'm working on my very first project. I'd love some help with an issue I'm stuck on.
So far, I’ve created a Merchant
struct that looks like this:
id
: a unique identifier (UID)owner
: the address of the merchantkey
: a String used as a unique keybalance
: a u64 representing their balance
I also made a MerchantRegistry
struct to manage all merchants:
id
: another UIDmerchant_to_address
: anObjectTable<address, Merchant>
mapping addresses to merchantsmerchant_to_key
: anObjectTable<String, Merchant>
mapping keys to merchants
I want to be able to look up a merchant either by their address or by their key.
When a user updates their key inside the Merchant
struct, the change doesn’t automatically update the key in the merchant_to_key
table. That means the old key still points to the merchant, which breaks things.
I tried removing the entry from the table and inserting it back with the new key, but I keep running into errors like:
"Cannot ignore values without drop ability"
I'm pretty sure this is a beginner mistake, but I haven't been able to find a clear explanation or solution anywhere. Is there a proper way to handle updating the key in both the struct and the lookup table?
- Sui
- Move
Do you know the answer?
Please log in and share it.
Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.
- Why does BCS require exact field order for deserialization when Move structs have named fields?53
- Multiple Source Verification Errors" in Sui Move Module Publications - Automated Error Resolution42
- Sui Transaction Failing: Objects Reserved for Another Transaction24
- How do ability constraints interact with dynamic fields in heterogeneous collections?04