Skip to content

Commit

Permalink
Use transaction outputs to retrieve contract id
Browse files Browse the repository at this point in the history
  • Loading branch information
acerone85 committed Feb 3, 2025
1 parent 785e76f commit 0f91ceb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 15 additions & 7 deletions crates/fraud_proofs/global_merkle_root/storage/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,21 @@ where
let bytecode_witness_index = tx.bytecode_witness_index();
let witnesses = tx.witnesses();
let bytecode = witnesses[usize::from(*bytecode_witness_index)].as_vec();
let contract_id = tx
.metadata()
.as_ref()
.map(|metadata| metadata.body.contract_id)
.ok_or(anyhow::anyhow!(
"Create transaction does not have a contract ID in its metadata"
))?;
// The Fuel specs mandate that each create transaction has exactly one output of type `Output::ContractCreated`.
// See https://docs.fuel.network/docs/specs/tx-format/transaction/#transactioncreate
let Some(Output::ContractCreated { contract_id, .. }) = tx
.outputs()
.iter()
.filter(|output| match output {
Output::ContractCreated { .. } => true,
_ => false,
})
.take(1)
.collect::<Vec<&Output>>()
.first()
else {
anyhow::bail!("Create transaction does not have contract created output")
};

self.storage
.storage_as_mut::<ContractsRawCode>()
Expand Down

0 comments on commit 0f91ceb

Please sign in to comment.