Skip to content

Commit

Permalink
add callback when tx is submitted
Browse files Browse the repository at this point in the history
  • Loading branch information
SupernaviX committed Jan 14, 2025
1 parent 9231be8 commit e869019
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions firefly-balius/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ repository = "https://github.com/blockfrost/firefly-cardano"

[dependencies]
balius-sdk = { git = "https://github.com/txpipe/balius.git", rev = "a72601f" }
serde = { version = "1", features = ["derive"] }
7 changes: 7 additions & 0 deletions firefly-balius/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use balius_sdk::txbuilder::{
primitives::TransactionInput, BuildContext, BuildError, InputExpr, UtxoSource,
};
use serde::Deserialize;

pub struct CoinSelectionInput(pub UtxoSource, pub u64);

Expand Down Expand Up @@ -43,3 +44,9 @@ impl InputExpr for CoinSelectionInput {
}
}
}

#[derive(Deserialize)]
pub struct SubmittedTx {
pub method: String,
pub hash: String,
}
11 changes: 11 additions & 0 deletions firefly-cardanoconnect/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ impl ContractManager {
}
}

pub async fn handle_submit(&self, contract: &str, method: &str, tx_id: &str) {
let params = serde_json::json!({
"method": method,
"hash": tx_id,
});
let runtime = self.get_contract_runtime(contract).await;
let mut lock = runtime.lock().await;

let _: Result<_, _> = lock.invoke("__tx_submitted", params).await;
}

pub async fn listen(&self, listener: &Listener) -> ContractListener {
let contracts = find_contract_names(&listener.filters);
let mut runtimes = vec![];
Expand Down
4 changes: 3 additions & 1 deletion firefly-cardanoconnect/src/operations/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ impl OperationsManager {
}
};
if let Some(tx) = value {
op.tx_id = Some(self.submit_transaction(from, tx).await?);
let tx_id = self.submit_transaction(from, tx).await?;
op.tx_id = Some(tx_id.clone());
self.contracts.handle_submit(contract, method, &tx_id).await;
}

op.status = OperationStatus::Succeeded;
Expand Down
1 change: 1 addition & 0 deletions wasm/simple-tx/Cargo.lock

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

0 comments on commit e869019

Please sign in to comment.