Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions contracts/src/Chainvoice.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,14 @@ contract Chainvoice {
function payInvoice(uint256 invoiceId) external payable nonReentrant {
require(invoiceId < invoices.length, "Invalid invoice ID");

InvoiceDetails storage invoice = invoices[invoiceId];
InvoiceDetails storage invoiceStorage = invoices[invoiceId]; //(read once from storage)
InvoiceDetails memory invoice = invoiceStorage; // now read all from this invoice(memory)
require(msg.sender == invoice.to, "Not authorized");
require(!invoice.isPaid, "Already paid");
require(!invoice.isCancelled, "Invoice is cancelled");

// Effects first for CEI (mark paid, bump fees), then interactions
invoice.isPaid = true;
invoiceStorage.isPaid = true;

if (invoice.tokenAddress == address(0)) {
require(msg.value == invoice.amountDue + fee, "Incorrect payment amount");
Expand Down