let contract = Invoice {
                origin: from.clone(),
                to: to.clone(),
                status: false,
                id: 0,
                msg: msg.clone(),

            let mut invoice_vec: Vec<Invoice<T::AccountId, T::AccountId, BalanceOf<T>>> = Vec::new();

            // Save in storage the sender and the invoices
            <InvoiceSender<T>>::insert(from.clone(), &invoice_vec);

Above I do have a struct and I put it into an array and then I store it as a value.

It is very difficult for me to mutate the value in storage. Let's assume I would like to change the status from false to true if the id is equal to 17

if(id == 17){
<InvoiceSender<T>>::try_mutate(from.clone(), .....

Can you help me complete the above line of code?

1 Answer 1

InvoiceSender::<T>::mutate(&from, |invoices| 
    invoices.iter_mut().filter(|i| i.id == 17).for_each(|i| {
        i.status = true;

This should achieve what you want.

  • It does not work actually :/
    – P.E
    Dec 5, 2022 at 23:14
  • Why? Is it not compiling or what is the error?
    – bkchr
    Dec 6, 2022 at 8:28
  • It does not store/mutate the new invoice.
    – P.E
    Dec 13, 2022 at 10:57
  • What new invoice, you mean that status = true is not stored? Are you sure that you have matching ids?
    – bkchr
    Dec 13, 2022 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.