Skip to content

Commit

Permalink
Implemented submit_and_await_commit_with_receipts method (#1304)
Browse files Browse the repository at this point in the history
Closes #1178
  • Loading branch information
xgreenx authored Aug 16, 2023
1 parent f034c0b commit 2a8dba8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Description of the upcoming release here.

- [#1263](https://github.com/FuelLabs/fuel-core/pull/1263): Add gas benchmarks for `ED19` and `ECR1` instructions.
- [#1286](https://github.com/FuelLabs/fuel-core/pull/1286): Include readable names for test cases where missing.
- [#1304](https://github.com/FuelLabs/fuel-core/pull/1304): Implemented `submit_and_await_commit_with_receipts` method for `FuelClient`.

### Changed

Expand Down
13 changes: 13 additions & 0 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,19 @@ impl FuelClient {
Ok(status)
}

#[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 = self.receipts(&tx_id).await?;

Ok((status, receipts))
}

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

Expand Down
3 changes: 1 addition & 2 deletions crates/fuel-core/src/database/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ use fuel_core_types::{
use itertools::Itertools;
use std::{
borrow::{
Borrow,
BorrowMut,
Cow,
},
Expand Down Expand Up @@ -271,7 +270,7 @@ impl Database {
.get(commit_block_height)?
.ok_or(not_found!(FuelBlockMerkleMetadata))?;

let storage = self.borrow();
let storage = self;
let tree: MerkleTree<FuelBlockMerkleData, _> =
MerkleTree::load(storage, commit_merkle_metadata.version)
.map_err(|err| StorageError::Other(err.into()))?;
Expand Down
13 changes: 6 additions & 7 deletions tests/tests/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ async fn can_get_message_proof() {
vec![],
);

let transaction_id = script.id(&ChainId::default());

// setup server & client
let srv = FuelService::new_node(config).await.unwrap();
let client = FuelClient::from(srv.bound_address);
Expand All @@ -281,13 +279,14 @@ async fn can_get_message_proof() {
.await
.expect("Should be able to estimate deploy tx");
// Call the contract.
matches!(
client.submit_and_await_commit(&script).await,
Ok(TransactionStatus::Success { .. })
);
let (status, receipts) = client
.submit_and_await_commit_with_receipts(&script)
.await
.unwrap();
matches!(status, TransactionStatus::Success { .. });

// Get the receipts from the contract call.
let receipts = client.receipts(&transaction_id).await.unwrap().unwrap();
let receipts = receipts.unwrap();
let logd = receipts
.iter()
.find(|f| matches!(f, Receipt::LogData { .. }))
Expand Down

0 comments on commit 2a8dba8

Please sign in to comment.