Record attribute value re-assignment

Hello all,
I am struggling to find the right syntax to re-assign values to my record attributes.

// Here is my record.
record lockContract = {
sender : address,
receiver : address,
amount : int,
hashlock : bytes(32), // sha-2 sha256 hash
timelock : int, // UNIX timestamp seconds - locked UNTIL this time
withdrawn : bool,
refunded : bool,
preimage : bytes(32)}

// Here is my function:
public stateful entrypoint withdraw(_contractId : bytes(32), _preimage : bytes(32)) : bool =
contractExists(_contractId)
hashlockMatches(_contractId, _preimage)
withdrawable(_contractId)

    let _lockContract : lockContract = state.contracts[_contractId]
    _lockContract.preimage = _preimage // Error
    _lockContract.withdrawn = true // Error
    
    spend({recipient = _lockContract.receiver,
       amount    = _lockContract.amount})
    
    Chain.event(LogHTLCWithdraw(_contractId))
    true

I am getting error on the above marked lines.
Unexpected Token ‘=’ at … …

Question: How do I re-assign values to my temporary record variables created?

Hello team,
Below is how to reassign attributes.

public stateful entrypoint withdraw(_contractId : bytes(32), _preimage : bytes(32)) : bool =
contractExists(_contractId)
hashlockMatches(_contractId, _preimage)
withdrawable(_contractId)

    let _lockContract : lockContract = { 
        sender = state.contracts[_contractId].sender,
        receiver = state.contracts[_contractId].receiver,
        amount = state.contracts[_contractId].amount,
        hashlock = state.contracts[_contractId].hashlock,
        timelock = state.contracts[_contractId].timelock,
        withdrawn = true,
        refunded = state.contracts[_contractId].refunded,
        preimage = _preimage
        }
    
    Chain.spend(_lockContract.receiver, _lockContract.amount)
    Chain.event(LogHTLCWithdraw(_contractId))
    true
1 Like