Skip to content

Commit

Permalink
refactor: remove redudant receipts queries (FuelLabs#1646)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-user authored Feb 5, 2024
1 parent a33a100 commit afe109f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 154 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 27,7 @@ Description of the upcoming release here.
- [#1636](https://github.com/FuelLabs/fuel-core/pull/1636): Add more docs to GraphQL DAP API.

#### Breaking
- [#1646](https://github.com/FuelLabs/fuel-core/pull/1646): Remove redundant receipts from queries.
- [#1639](https://github.com/FuelLabs/fuel-core/pull/1639): Make Merkle metadata, i.e. `SparseMerkleMetadata` and `DenseMerkleMetadata` type version-able enums
- [#1632](https://github.com/FuelLabs/fuel-core/pull/1632): Make `Message` type a version-able enum
- [#1631](https://github.com/FuelLabs/fuel-core/pull/1631): Modify api endpoint to dry run multiple transactions.
Expand Down
14 changes: 8 additions & 6 deletions bin/e2e-test-client/src/tests/collect_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 11,21 @@ pub async fn collect_fee(ctx: &TestContext) -> Result<(), Failed> {
.alice
.collect_fee_tx(ctx.config.coinbase_contract_id, AssetId::BASE)
.await?;
let (status, receipts) = ctx
.alice
.client
.submit_and_await_commit_with_receipts(&tx)
.await?;
let tx_status = ctx.alice.client.submit_and_await_commit(&tx).await?;

if !matches!(
status,
tx_status,
fuel_core_client::client::types::TransactionStatus::Success { .. }
) {
return Err("collect fee transaction is not successful".into())
}

let receipts = match &tx_status {
fuel_core_client::client::types::TransactionStatus::Success {
receipts, ..
} => Some(receipts),
_ => None,
};
let receipts = receipts.ok_or("collect fee transaction doesn't have receipts")?;

if !receipts
Expand Down
59 changes: 20 additions & 39 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,37 447,6 @@ impl FuelClient {
Ok(status)
}

// TODO: Remove this function after the Beta 5 release when we can introduce breaking changes.
// This function is now redundant since `submit_and_await_commit` returns
// receipts for all successful and failed transactions.
#[cfg(feature = "subscriptions")]
/// Submits transaction, await confirmation and return receipts.
pub async fn submit_and_await_commit_with_receipts(
&self,
tx: &Transaction,
) -> io::Result<(TransactionStatus, Option<Vec<Receipt>>)> {
let tx_id = self.submit(tx).await?;
let status = self.await_transaction_commit(&tx_id).await?;
let receipts = match &status {
TransactionStatus::Submitted { .. } => None,
TransactionStatus::Success { receipts, .. } => Some(receipts.clone()),
TransactionStatus::SqueezedOut { .. } => {
// Note: Returns an error when the transaction has been squeezed
// out instead of returning the `SqueezedOut` status. This is
// done to maintain existing behavior where retrieving receipts
// via `self.receipts(..)` returns an error when the transaction
// cannot be found, such as in the case of a squeeze-out.
Err(io::Error::new(
ErrorKind::NotFound,
format!("transaction {tx_id} not found"),
))?
}
TransactionStatus::Failure { receipts, .. } => Some(receipts.clone()),
};

Ok((status, receipts))
}

pub async fn start_session(&self) -> io::Result<String> {
let query = schema::StartSession::build(());

Expand Down Expand Up @@ -698,14 667,26 @@ impl FuelClient {
io::Error::new(ErrorKind::NotFound, format!("transaction {id} not found"))
})?;

let receipts = tx
.receipts
.map(|vec| {
let vec: Result<Vec<Receipt>, ConversionError> =
vec.into_iter().map(TryInto::<Receipt>::try_into).collect();
vec
})
.transpose()?;
let receipts = match tx.status {
Some(status) => match status {
schema::tx::TransactionStatus::SuccessStatus(s) => Some(
s.receipts
.into_iter()
.map(TryInto::<Receipt>::try_into)
.collect::<Result<Vec<Receipt>, ConversionError>>(),
)
.transpose()?,
schema::tx::TransactionStatus::FailureStatus(s) => Some(
s.receipts
.into_iter()
.map(TryInto::<Receipt>::try_into)
.collect::<Result<Vec<Receipt>, ConversionError>>(),
)
.transpose()?,
_ => None,
},
_ => None,
};

Ok(receipts)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 5,6 @@ expression: operation.query
query($id: TransactionId!) {
transaction(id: $id) {
rawPayload
receipts {
param1
param2
amount
assetId
gas
digest
contract {
id
}
is
pc
ptr
ra
rb
rc
rd
reason
receiptType
to {
id
}
toAddress
val
len
result
gasUsed
data
sender
recipient
nonce
contractId
subId
}
status {
__typename
... on SubmittedStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 8,6 @@ query($owner: Address!, $after: String, $before: String, $first: Int, $last: Int
cursor
node {
rawPayload
receipts {
param1
param2
amount
assetId
gas
digest
contract {
id
}
is
pc
ptr
ra
rb
rc
rd
reason
receiptType
to {
id
}
toAddress
val
len
result
gasUsed
data
sender
recipient
nonce
contractId
subId
}
status {
__typename
... on SubmittedStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 8,6 @@ query($after: String, $before: String, $first: Int, $last: Int) {
cursor
node {
rawPayload
receipts {
param1
param2
amount
assetId
gas
digest
contract {
id
}
is
pc
ptr
ra
rb
rc
rd
reason
receiptType
to {
id
}
toAddress
val
len
result
gasUsed
data
sender
recipient
nonce
contractId
subId
}
status {
__typename
... on SubmittedStatus {
Expand Down
2 changes: 0 additions & 2 deletions crates/client/src/client/schema/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 98,6 @@ pub struct TransactionEdge {
#[cynic(graphql_type = "Transaction", schema_path = "./assets/schema.sdl")]
pub struct OpaqueTransaction {
pub raw_payload: HexString,
// TODO: Remove now that Success and Failure status includes receipts
pub receipts: Option<Vec<Receipt>>,
pub status: Option<TransactionStatus>,
}

Expand Down
12 changes: 7 additions & 5 deletions tests/tests/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 268,13 @@ async fn can_get_message_proof() {
.await
.expect("Should be able to estimate deploy tx");
// Call the contract.
let (status, receipts) = client
.submit_and_await_commit_with_receipts(&script)
.await
.unwrap();
matches!(status, TransactionStatus::Success { .. });
let tx_status = client.submit_and_await_commit(&script).await.unwrap();
matches!(tx_status, TransactionStatus::Success { .. });

let receipts = match tx_status {
TransactionStatus::Success { receipts, .. } => Some(receipts),
_ => None,
};

// Get the receipts from the contract call.
let receipts = receipts.unwrap();
Expand Down

0 comments on commit afe109f

Please sign in to comment.