Skip to content

Commit e9c8cd5

Browse files
chore: Update u5c to 0.18.1 (#97)
1 parent 99f0218 commit e9c8cd5

11 files changed

Lines changed: 73 additions & 37 deletions

File tree

‎Cargo.lock‎

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎balius-runtime/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ tracing = "0.1.40"
2323
hex = "0.4.3"
2424
itertools = "0.14.0"
2525
async-trait = "0.1.83"
26-
utxorpc = { version = "0.12.0" }
26+
utxorpc = { version = "0.13.0" }
2727
# utxorpc = { path = "../../../utxorpc/rust-sdk" }
2828
tokio-util = "0.7.12"
2929
prost = "0.13"

‎balius-runtime/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ impl Block {
290290
slot: block.header.as_ref().unwrap().slot,
291291
hash: block.header.as_ref().unwrap().hash.clone(),
292292
height: block.header.as_ref().unwrap().height,
293+
timestamp: block.timestamp,
293294
}),
294295
}
295296
}

‎balius-runtime/src/submit/u5c.rs‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,18 @@ impl Submit {
3030
}
3131

3232
pub async fn submit_tx(&mut self, tx: wit::Cbor) -> Result<(), wit::SubmitError> {
33-
self.client
34-
.submit_tx(vec![tx])
35-
.await
36-
.map_err(|err| match err {
37-
utxorpc::Error::GrpcError(status) => {
38-
let code: i32 = status.code().into();
39-
if code == 3 {
40-
wit::SubmitError::Invalid(status.to_string())
41-
} else {
42-
wit::SubmitError::Internal(status.to_string())
43-
}
33+
self.client.submit_tx(tx).await.map_err(|err| match err {
34+
utxorpc::Error::GrpcError(status) => {
35+
let code: i32 = status.code().into();
36+
if code == 3 {
37+
wit::SubmitError::Invalid(status.to_string())
38+
} else {
39+
wit::SubmitError::Internal(status.to_string())
4440
}
45-
utxorpc::Error::TransportError(err) => wit::SubmitError::Internal(err.to_string()),
46-
utxorpc::Error::ParseError(err) => wit::SubmitError::Internal(err.to_string()),
47-
})?;
41+
}
42+
utxorpc::Error::TransportError(err) => wit::SubmitError::Internal(err.to_string()),
43+
utxorpc::Error::ParseError(err) => wit::SubmitError::Internal(err.to_string()),
44+
})?;
4845
Ok(())
4946
}
5047
}

‎balius-runtime/tests/e2e.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async fn faucet_claim() {
4343

4444
let store = Store::open("tests/balius.db", None).unwrap();
4545

46-
let mut runtime = Runtime::builder(store)
46+
let runtime = Runtime::builder(store)
4747
.with_ledger(ledgers::mock::Ledger.into())
4848
.build()
4949
.unwrap();

‎balius-runtime/tests/u5c-chainsync.rs‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![cfg(test)]
2-
#![cfg(feature = "utxorpc")]
2+
3+
use std::collections::HashMap;
34

45
use balius_runtime::{drivers, Runtime, Store};
56
use serde_json::json;
@@ -8,21 +9,24 @@ use tokio_util::sync::CancellationToken;
89
#[tokio::test]
910
async fn wallet_balance() {
1011
let store = Store::open("tests/balius.db", None).unwrap();
11-
12-
let mut runtime = Runtime::builder(store).build().unwrap();
13-
12+
let runtime = Runtime::builder(store).build().unwrap();
1413
let config = json!({
1514
"address": "addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x"
1615
});
1716

17+
let wasm = std::fs::read("tests/wallet.wasm").unwrap();
1818
runtime
19-
.register_worker("wallet", "tests/wallet.wasm", config)
19+
.register_worker("wallet", &wasm, config)
2020
.await
2121
.unwrap();
2222

2323
let chainsync_config = drivers::chainsync::Config {
2424
endpoint_url: "https://mainnet.utxorpc-v0.demeter.run".to_string(),
25-
api_key: "dmtr_utxorpc1wgnnj0qcfj32zxsz2uc8d4g7uclm2s2w".to_string(),
25+
headers: Some(HashMap::from([(
26+
"api-key".to_string(),
27+
"dmtr_utxorpc1wgnnj0qcfj32zxsz2uc8d4g7uclm2s2w".to_string(),
28+
)])),
29+
// api_key: "dmtr_utxorpc1wgnnj0qcfj32zxsz2uc8d4g7uclm2s2w".to_string(),
2630
};
2731

2832
drivers::chainsync::run(chainsync_config, runtime, CancellationToken::new())

‎balius-runtime/tests/u5c-ledger.rs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
#![cfg(test)]
2-
#![cfg(feature = "utxorpc")]
32

43
use balius_runtime::{ledgers, Runtime, Store};
54
use serde_json::json;
5+
use std::collections::HashMap;
66

77
#[tokio::test]
88
async fn faucet_claim() {
99
let store = Store::open("tests/balius.db", None).unwrap();
10-
11-
let ledger = ledgers::u5c::Ledger::new(ledgers::u5c::Config {
10+
let ledger = ledgers::u5c::Ledger::new(&ledgers::u5c::Config {
1211
endpoint_url: "https://mainnet.utxorpc-v0.demeter.run".to_string(),
13-
api_key: "dmtr_utxorpc1wgnnj0qcfj32zxsz2uc8d4g7uclm2s2w".to_string(),
12+
headers: Some(HashMap::from([
13+
("api-key".to_string(), "dmtr_utxorpc1wgnnj0qcfj32zxsz2uc8d4g7uclm2s2w".to_string()),
14+
])),
1415
})
1516
.await
1617
.unwrap();
1718

18-
let mut runtime = Runtime::builder(store)
19+
let runtime = Runtime::builder(store)
1920
.with_ledger(ledger.into())
2021
.build()
2122
.unwrap();
@@ -31,8 +32,9 @@ async fn faucet_claim() {
3132
}
3233
});
3334

35+
let wasm = std::fs::read("tests/faucet.wasm").unwrap();
3436
runtime
35-
.register_worker("faucet", "tests/faucet.wasm", config)
37+
.register_worker("faucet", &wasm, config)
3638
.await
3739
.unwrap();
3840

‎balius-sdk/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repository = "https://github.com/txpipe/balius"
99
readme = "README.md"
1010

1111
[dependencies]
12-
utxorpc-spec = { version = "0.16.0", features = ["ledgers"], default-features = false }
12+
utxorpc-spec = { version = "0.18.1", features = ["ledgers"], default-features = false }
1313
balius-macros = { version = "0.5.2", path = "../balius-macros" }
1414
hex = "0.4.3"
1515
pallas-addresses = { version = "0.32.0" }

‎balius-sdk/src/qol.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,23 @@ pub struct Utxo<D> {
281281
pub datum: Option<D>,
282282
}
283283

284+
impl<D> Utxo<D> {
285+
pub fn coin(&self) -> u64 {
286+
self.utxo
287+
.coin
288+
.as_ref()
289+
.and_then(|x| {
290+
x.big_int.as_ref().and_then(|y| match y {
291+
utxorpc_spec::utxorpc::v1alpha::cardano::big_int::BigInt::Int(z) => {
292+
Some(*z as u64)
293+
}
294+
_ => None,
295+
})
296+
})
297+
.unwrap_or_default()
298+
}
299+
}
300+
284301
impl<D> TryFrom<wit::Event> for Utxo<D> {
285302
type Error = Error;
286303

‎balius-sdk/src/txbuilder/dsl.rs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,22 @@ impl ValueExpr for MinUtxoLovelace {
340340
};
341341

342342
let serialized = pallas_codec::minicbor::to_vec(parent).unwrap();
343-
let min_lovelace = (160u64 + serialized.len() as u64) * ctx.pparams.coins_per_utxo_byte;
343+
let coins_per_utxo_byte = ctx
344+
.pparams
345+
.coins_per_utxo_byte
346+
.as_ref()
347+
.and_then(|x| {
348+
x.big_int.as_ref().and_then(|y| match y {
349+
utxorpc_spec::utxorpc::v1alpha::cardano::big_int::BigInt::Int(z) => {
350+
Some(*z as u64)
351+
}
352+
_ => None,
353+
})
354+
})
355+
.ok_or(BuildError::LedgerError(
356+
"Missing coins_per_utxo_byte protocol parameter".to_string(),
357+
))?;
358+
let min_lovelace = (160u64 + serialized.len() as u64) * coins_per_utxo_byte;
344359
let current_value = match parent {
345360
conway::PseudoTransactionOutput::PostAlonzo(x) => &x.value,
346361
_ => unimplemented!(),

0 commit comments

Comments
 (0)