Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add receipts to transaction status #1504

Merged
merged 25 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Description of the upcoming release here.
### Added

- [#1515](https://github.com/FuelLabs/fuel-core/pull/1515): Added support of `--version` command for `fuel-core-keygen` binary.
- [#1504](https://github.com/FuelLabs/fuel-core/pull/1504): A `Success` or `Failure` variant of `TransactionStatus` returned by a query now contains the associated receipts generated by transaction execution.

## [Version 0.21.0]

Expand Down
4 changes: 4 additions & 0 deletions crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,12 @@ input ExcludeInput {
}

type FailureStatus {
transactionId: TransactionId!
block: Block!
time: Tai64Timestamp!
reason: String!
programState: ProgramState
receipts: [Receipt!]!
}

type FeeParameters {
Expand Down Expand Up @@ -847,9 +849,11 @@ type Subscription {
}

type SuccessStatus {
transactionId: TransactionId!
block: Block!
time: Tai64Timestamp!
programState: ProgramState
receipts: [Receipt!]!
}

scalar Tai64Timestamp
Expand Down
20 changes: 19 additions & 1 deletion crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ 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(
Expand All @@ -434,7 +437,22 @@ impl FuelClient {
) -> io::Result<(TransactionStatus, Option<Vec<Receipt>>)> {
let tx_id = self.submit(tx).await?;
let status = self.await_transaction_commit(&tx_id).await?;
let receipts = self.receipts(&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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ query($id: TransactionId!) {
time
}
... on SuccessStatus {
transactionId
block {
id
}
Expand All @@ -53,11 +54,46 @@ query($id: TransactionId!) {
returnType
data
}
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
}
}
... on SqueezedOutStatus {
reason
}
... on FailureStatus {
transactionId
block {
id
}
Expand All @@ -67,6 +103,40 @@ query($id: TransactionId!) {
returnType
data
}
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
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ query($owner: Address!, $after: String, $before: String, $first: Int, $last: Int
time
}
... on SuccessStatus {
transactionId
block {
id
}
Expand All @@ -56,11 +57,46 @@ query($owner: Address!, $after: String, $before: String, $first: Int, $last: Int
returnType
data
}
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
}
}
... on SqueezedOutStatus {
reason
}
... on FailureStatus {
transactionId
block {
id
}
Expand All @@ -70,6 +106,40 @@ query($owner: Address!, $after: String, $before: String, $first: Int, $last: Int
returnType
data
}
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
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ query($after: String, $before: String, $first: Int, $last: Int) {
time
}
... on SuccessStatus {
transactionId
block {
id
}
Expand All @@ -56,11 +57,46 @@ query($after: String, $before: String, $first: Int, $last: Int) {
returnType
data
}
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
}
}
... on SqueezedOutStatus {
reason
}
... on FailureStatus {
transactionId
block {
id
}
Expand All @@ -70,6 +106,40 @@ query($after: String, $before: String, $first: Int, $last: Int) {
returnType
data
}
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
}
}
}
}
Expand Down
Loading
Loading