Skip to content

Commit 05bab1b

Browse files
committed
feat: update docs and connector images
Signed-off-by: Simon Gellis <simongellis@gmail.com>
1 parent 725f706 commit 05bab1b

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

doc-site/docs/tutorials/custom_contracts/cardano.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ This is describing a contract with a single method, named `send_ada`. This metho
100100

101101
It also emits three events:
102102
- `TransactionAccepted(string)` is emitted when the transaction is included in a block.
103-
- `TransactionRolledBack(string)` is emitted if the transaction was included in a block, and that block got rolled back. This happens maybe once or twice a day on the Cardano network, so it is unlikely that you will ever see it in practice (but more likely than some other chains).
103+
- `TransactionRolledBack(string)` is emitted if the transaction was included in a block, and that block got rolled back. This happens maybe once or twice a day on the Cardano network, which is more likely than some other chains, so your code must be able to gracefully handle rollbacks.
104104
- `TransactionFinalized(string)` is emitted when the transaction has been on the chain for "long enough" that it is effectively immutable. It is up to your tolerance risk.
105105

106106
These three events are all automatically handled by the connector.
@@ -119,7 +119,7 @@ edition = "2021"
119119

120120
[dependencies]
121121
# The version of firefly-balius should match the version of firefly-cardano which you are using.
122-
firefly-balius = { git = "https://github.com/hyperledger/firefly-cardano", rev = "0.3.1" }
122+
firefly-balius = { git = "https://github.com/hyperledger/firefly-cardano", rev = "0.4.1" }
123123
pallas-addresses = "0.32"
124124
serde = { version = "1", features = ["derive"] }
125125

@@ -138,10 +138,11 @@ use balius_sdk::{
138138
AddressPattern, BuildError, FeeChangeReturn, OutputBuilder, TxBuilder, UtxoPattern,
139139
UtxoSource,
140140
},
141-
Ack, Config, FnHandler, NewTx, Params, Worker, WorkerResult,
141+
Ack, Config, FnHandler, Params, Worker, WorkerResult,
142142
};
143143
use firefly_balius::{
144-
balius_sdk::{self, Json}, kv, CoinSelectionInput, FinalityMonitor, FinalizationCondition, SubmittedTx, WorkerExt as _
144+
balius_sdk::{self, Json},
145+
kv, CoinSelectionInput, FinalizationCondition, NewMonitoredTx, SubmittedTx, WorkerExt as _,
145146
};
146147
use pallas_addresses::Address;
147148
use serde::{Deserialize, Serialize};
@@ -163,7 +164,7 @@ struct CurrentState {
163164
}
164165

165166
/// This function builds a transaction to send ADA from one address to another.
166-
fn send_ada(_: Config<()>, req: Params<SendAdaRequest>) -> WorkerResult<NewTx> {
167+
fn send_ada(_: Config<()>, req: Params<SendAdaRequest>) -> WorkerResult<NewMonitoredTx> {
167168
let from_address =
168169
Address::from_bech32(&req.from_address).map_err(|_| BuildError::MalformedAddress)?;
169170

@@ -176,9 +177,9 @@ fn send_ada(_: Config<()>, req: Params<SendAdaRequest>) -> WorkerResult<NewTx> {
176177
});
177178

178179
// In Cardano, addresses don't hold ADA or native tokens directly.
179-
// Instead, they control uTXOS (unspent transaction outputs),
180-
// and those uTXOs contain some amount of ADA and native tokens.
181-
// You can't spent part of a uTXO in a transaction; instead, transactions
180+
// Instead, they control UTxOs (unspent transaction outputs),
181+
// and those UTxOs contain some amount of ADA and native tokens.
182+
// You can't spent part of a UTxO in a transaction; instead, transactions
182183
// include inputs with more funds than they need, and a "change" output
183184
// to give any excess funds back to the original sender.
184185

@@ -195,17 +196,18 @@ fn send_ada(_: Config<()>, req: Params<SendAdaRequest>) -> WorkerResult<NewTx> {
195196
)
196197
.with_output(FeeChangeReturn(address_source));
197198

198-
// Return that TX. The framework will sign and submit it.
199-
Ok(NewTx(Box::new(tx)))
199+
// Return that TX. The framework will sign, submit, and monitor it.
200+
// By returning a `NewMonitoredTx`, we tell the framework that we want it to monitor this transaction.
201+
// This enables the TransactionApproved, TransactionRolledBack, and TransactionFinalized events from before.
202+
// Note that we decide the transaction has been finalized after 4 blocks have reached the chain.
203+
Ok(NewMonitoredTx(
204+
Box::new(tx),
205+
FinalizationCondition::AfterBlocks(4),
206+
))
200207
}
201208

202209
/// This function is called when a TX produced by this contract is submitted to the blockchain, but before it has reached a block.
203210
fn handle_submit(_: Config<()>, tx: SubmittedTx) -> WorkerResult<Ack> {
204-
// Tell the framework that we want it to monitor this transaction.
205-
// This enables the TransactionApproved, TransactionRolledBack, and TransactionFinalized events from before.
206-
// Note that we decide the transaction has been finalized after 4 blocks have reached the chain.
207-
FinalityMonitor.monitor_tx(&tx.hash, FinalizationCondition::AfterBlocks(4))?;
208-
209211
// Keep track of which TXs have been submitted.
210212
let mut state: CurrentState = kv::get("current_state")?.unwrap_or_default();
211213
state.submitted_txs.insert(tx.hash);

manifest.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"cardanoconnect": {
33
"image": "ghcr.io/hyperledger/firefly-cardanoconnect",
4-
"tag": "v0.4.0",
5-
"sha": "d691cb0efe996b14b56ca90e88062ba79902a9d3a00c42324a6f2a6f4c769de7"
4+
"tag": "v0.4.1",
5+
"sha": "78b1008bd62892f6eda197b5047d94e61621d0f06b299422ff8ed9b34ee5ce50"
66
},
77
"cardanosigner": {
88
"image": "ghcr.io/hyperledger/firefly-cardanosigner",
9-
"tag": "v0.4.0",
10-
"sha": "d5d391a25525f33ef30d9c1a21c109c6221e7aeba6afb4bf3a11f0933f594044"
9+
"tag": "v0.4.1",
10+
"sha": "d0b76613ccc70ff63e68b137766eb009d589489631cee6aabf2b45e33a1ca5d3"
1111
},
1212
"ethconnect": {
1313
"image": "ghcr.io/hyperledger/firefly-ethconnect",

0 commit comments

Comments
 (0)