Skip to content

Commit 76a782c

Browse files
authored
Merge branch 'main' into refactor/chain-follower-decoder
2 parents 7423351 + f9b60fa commit 76a782c

File tree

49 files changed

+414
-688
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+414
-688
lines changed

catalyst-gateway/bin/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repository.workspace = true
1515
workspace = true
1616

1717
[dependencies]
18-
cardano-chain-follower = { version = "0.0.4", git = "https://github.com/input-output-hk/catalyst-libs.git", rev = "de7fa876a738182e9db7ac710975bf853b78f554"}
18+
cardano-chain-follower = { version = "0.0.5", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-chain-follower-v0.0.5" }
1919
c509-certificate = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.3" }
2020

2121
pallas = { version = "0.31.0", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "51c0aa752926ecebafbf7b4ba90f62f835b78805" }

catalyst-gateway/bin/src/db/index/block/txo/cql/insert_txo_asset.cql

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ INSERT INTO txo_assets_by_stake (
66
txn,
77
txo,
88
policy_id,
9-
policy_name,
9+
asset_name,
1010
value
1111
) VALUES (
1212
:stake_address,
1313
:slot_no,
1414
:txn,
1515
:txo,
1616
:policy_id,
17-
:policy_name,
17+
:asset_name,
1818
:value
1919
);

catalyst-gateway/bin/src/db/index/block/txo/cql/insert_unstaked_txo_asset.cql

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ INSERT INTO unstaked_txo_assets_by_txn_hash (
33
txn_hash,
44
txo,
55
policy_id,
6-
policy_name,
6+
asset_name,
77
slot_no,
88
txn,
99
value
1010
) VALUES (
1111
:txn_hash,
1212
:txo,
1313
:policy_id,
14-
:policy_name,
14+
:asset_name,
1515
:slot_no,
1616
:txn,
1717
:value

catalyst-gateway/bin/src/db/index/block/txo/insert_txo_asset.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub(super) struct Params {
2727
txo: i16,
2828
/// Policy hash of the asset
2929
policy_id: Vec<u8>,
30-
/// Policy name of the asset
31-
policy_name: String,
30+
/// Name of the asset, within the Policy.
31+
asset_name: Vec<u8>,
3232
/// Value of the asset
3333
value: num_bigint::BigInt,
3434
}
@@ -41,15 +41,15 @@ impl Params {
4141
#[allow(clippy::too_many_arguments)]
4242
pub(super) fn new(
4343
stake_address: &[u8], slot_no: u64, txn: i16, txo: i16, policy_id: &[u8],
44-
policy_name: &str, value: i128,
44+
asset_name: &[u8], value: i128,
4545
) -> Self {
4646
Self {
4747
stake_address: stake_address.to_vec(),
4848
slot_no: slot_no.into(),
4949
txn,
5050
txo,
5151
policy_id: policy_id.to_vec(),
52-
policy_name: policy_name.to_owned(),
52+
asset_name: asset_name.to_vec(),
5353
value: value.into(),
5454
}
5555
}

catalyst-gateway/bin/src/db/index/block/txo/insert_unstaked_txo_asset.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(super) struct Params {
2424
/// Policy hash of the asset
2525
policy_id: Vec<u8>,
2626
/// Policy name of the asset
27-
policy_name: String,
27+
asset_name: Vec<u8>,
2828
/// Block Slot Number
2929
slot_no: num_bigint::BigInt,
3030
/// Transaction Offset inside the block.
@@ -40,14 +40,14 @@ impl Params {
4040
/// values.
4141
#[allow(clippy::too_many_arguments)]
4242
pub(super) fn new(
43-
txn_hash: &[u8], txo: i16, policy_id: &[u8], policy_name: &str, slot_no: u64, txn: i16,
43+
txn_hash: &[u8], txo: i16, policy_id: &[u8], asset_name: &[u8], slot_no: u64, txn: i16,
4444
value: i128,
4545
) -> Self {
4646
Self {
4747
txn_hash: txn_hash.to_vec(),
4848
txo,
4949
policy_id: policy_id.to_vec(),
50-
policy_name: policy_name.to_owned(),
50+
asset_name: asset_name.to_vec(),
5151
slot_no: slot_no.into(),
5252
txn,
5353
value: value.into(),

catalyst-gateway/bin/src/db/index/block/txo/mod.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl TxoInsertQuery {
181181
let policy_id = asset.policy().to_vec();
182182
for policy_asset in asset.assets() {
183183
if policy_asset.is_output() {
184-
let policy_name = policy_asset.to_ascii_name().unwrap_or_default();
184+
let asset_name = policy_asset.name();
185185
let value = policy_asset.any_coin();
186186

187187
if staked {
@@ -191,19 +191,13 @@ impl TxoInsertQuery {
191191
txn,
192192
txo_index,
193193
&policy_id,
194-
&policy_name,
194+
asset_name,
195195
value,
196196
);
197197
self.staked_txo_asset.push(params);
198198
} else {
199199
let params = insert_unstaked_txo_asset::Params::new(
200-
txn_hash,
201-
txo_index,
202-
&policy_id,
203-
&policy_name,
204-
slot_no,
205-
txn,
206-
value,
200+
txn_hash, txo_index, &policy_id, asset_name, slot_no, txn, value,
207201
);
208202
self.unstaked_txo_asset.push(params);
209203
}

catalyst-gateway/bin/src/db/index/queries/cql/get_assets_by_stake_address.cql

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SELECT
33
txo,
44
slot_no,
55
policy_id,
6-
policy_name,
6+
asset_name,
77
value
88
FROM txo_assets_by_stake
99
WHERE stake_address = :stake_address

catalyst-gateway/bin/src/db/index/queries/staked_ada/get_assets_by_stake_address.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ mod result {
5454
/// Asset hash.
5555
pub policy_id: Vec<u8>,
5656
/// Asset name.
57-
pub policy_name: String,
57+
pub asset_name: Vec<u8>,
5858
/// Asset value.
5959
pub value: num_bigint::BigInt,
6060
}

catalyst-gateway/bin/src/db/index/schema/cql/txo_assets_by_stake_table.cql

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ CREATE TABLE IF NOT EXISTS txo_assets_by_stake (
77
txn smallint, -- Which Transaction in the Slot is the TXO.
88
txo smallint, -- offset in the txo list of the transaction the txo is in.
99
policy_id blob, -- asset policy hash (id) (28 byte binary hash)
10-
policy_name text, -- name of the policy (UTF8) TODO: https://github.com/input-output-hk/catalyst-voices/issues/1121
10+
asset_name blob, -- name of the asset policy (UTF8) (32 bytes)
1111

1212

1313
-- None Key Data of the asset.
1414
value varint, -- Value of the asset (i128)
1515

16-
PRIMARY KEY (stake_address, slot_no, txn, txo, policy_id, policy_name)
16+
PRIMARY KEY (stake_address, slot_no, txn, txo, policy_id, asset_name)
1717
);

catalyst-gateway/bin/src/db/index/schema/cql/unstaked_txo_assets_by_txn_hash.cql

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS unstaked_txo_assets_by_txn_hash (
44
txn_hash blob, -- 32 byte hash of this transaction.
55
txo smallint, -- offset in the txo list of the transaction the txo is in.
66
policy_id blob, -- asset policy hash (id) (28 byte binary hash)
7-
policy_name text, -- name of the policy (UTF8)
7+
asset_name blob, -- name of the policy (UTF8) (32 bytes)
88

99
-- Secondary Location information for the transaction.
1010
slot_no varint, -- slot number the txo was created in.
@@ -13,5 +13,5 @@ CREATE TABLE IF NOT EXISTS unstaked_txo_assets_by_txn_hash (
1313
-- Value of the asset.
1414
value varint, -- Value of the asset (u64)
1515

16-
PRIMARY KEY (txn_hash, txo, policy_id, policy_name)
16+
PRIMARY KEY (txn_hash, txo, policy_id, asset_name)
1717
);

catalyst-gateway/bin/src/db/index/schema/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{settings::cassandra_db, utils::blake2b_hash::generate_uuid_string_fr
1717
/// change accidentally, and is NOT to be used directly to set the schema version of the
1818
/// table namespaces.
1919
#[allow(dead_code)]
20-
const SCHEMA_VERSION: &str = "08193dfe-698a-8177-bdf8-20c5691a06e7";
20+
const SCHEMA_VERSION: &str = "75ae6ac9-ddd8-8472-8a7a-8676d04f8679";
2121

2222
/// Keyspace Create (Templated)
2323
const CREATE_NAMESPACE_CQL: &str = include_str!("./cql/namespace.cql");

catalyst-gateway/bin/src/service/api/cardano/staking/assets_get.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::{
2727
stake_info::{FullStakeInfo, StakeInfo, StakedNativeTokenInfo},
2828
},
2929
responses::WithErrorResponses,
30-
types::cardano::cip19_stake_address::Cip19StakeAddress,
30+
types::cardano::{asset_name::AssetName, cip19_stake_address::Cip19StakeAddress},
3131
},
3232
};
3333

@@ -79,8 +79,7 @@ struct TxoAssetInfo {
7979
/// Asset hash.
8080
id: Vec<u8>,
8181
/// Asset name.
82-
// TODO: https://github.com/input-output-hk/catalyst-voices/issues/1121
83-
name: String,
82+
name: AssetName,
8483
/// Asset amount.
8584
amount: num_bigint::BigInt,
8685
}
@@ -100,8 +99,7 @@ struct TxoInfo {
10099
/// Whether the TXO was spent.
101100
spent_slot_no: Option<num_bigint::BigInt>,
102101
/// TXO assets.
103-
// TODO: https://github.com/input-output-hk/catalyst-voices/issues/1121
104-
assets: HashMap<Vec<u8>, TxoAssetInfo>,
102+
assets: HashMap<Vec<u8>, Vec<TxoAssetInfo>>,
105103
}
106104

107105
/// Calculate the stake info for a given stake address.
@@ -186,12 +184,18 @@ async fn get_txo_by_txn(
186184
let entry = txo_info
187185
.assets
188186
.entry(row.policy_id.clone())
189-
.or_insert(TxoAssetInfo {
190-
id: row.policy_id,
191-
name: row.policy_name,
192-
amount: num_bigint::BigInt::ZERO,
193-
});
194-
entry.amount += row.value;
187+
.or_insert_with(Vec::new);
188+
189+
match entry.iter_mut().find(|item| item.id == row.policy_id) {
190+
Some(item) => item.amount += row.value,
191+
None => {
192+
entry.push(TxoAssetInfo {
193+
id: row.policy_id,
194+
name: row.asset_name.into(),
195+
amount: row.value,
196+
});
197+
},
198+
}
195199
}
196200

197201
let mut txos_by_txn = HashMap::new();
@@ -274,10 +278,10 @@ fn build_stake_info(
274278
stake_info.ada_amount +=
275279
i64::try_from(txo_info.value).map_err(|err| anyhow!(err))?;
276280

277-
for asset in txo_info.assets.into_values() {
281+
for asset in txo_info.assets.into_values().flatten() {
278282
stake_info.native_tokens.push(StakedNativeTokenInfo {
279283
policy_hash: asset.id.try_into()?,
280-
asset_name: asset.name.into(),
284+
asset_name: asset.name,
281285
amount: asset.amount.try_into()?,
282286
});
283287
}

catalyst-gateway/bin/src/service/common/types/cardano/asset_name.rs

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ impl Example for AssetName {
6565
}
6666
}
6767

68-
// TODO: https://github.com/input-output-hk/catalyst-voices/issues/1121
6968
impl From<Vec<u8>> for AssetName {
7069
fn from(value: Vec<u8>) -> Self {
7170
match String::from_utf8(value.clone()) {

catalyst-gateway/bin/src/service/common/types/cardano/cip19_stake_address.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(crate) const PATTERN: &str = concatcp!(
4242
/// Length of the encoded address.
4343
const ENCODED_ADDR_LEN: usize = 53;
4444
/// Length of the decoded address.
45-
const DECODED_ADDR_LEN: usize = 28;
45+
const DECODED_ADDR_LEN: usize = 29;
4646
/// Minimum length
4747
pub(crate) const MIN_LENGTH: usize = PROD_STAKE.len() + 1 + ENCODED_ADDR_LEN;
4848
/// Minimum length
@@ -150,3 +150,34 @@ impl Example for Cip19StakeAddress {
150150
Self(EXAMPLE.to_owned())
151151
}
152152
}
153+
154+
#[cfg(test)]
155+
mod tests {
156+
use super::*;
157+
158+
// cspell: disable
159+
const VALID_PROD_STAKE_ADDRESS: &str =
160+
"stake1u94ullc9nj9gawc08990nx8hwgw80l9zpmr8re44kydqy9cdjq6rq";
161+
const VALID_TEST_STAKE_ADDRESS: &str =
162+
"stake_test1uqehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gssrtvn";
163+
const INVALID_STAKE_ADDRESS: &str =
164+
"invalid1u9nlq5nmuzthw3vhgakfpxyq4r0zl2c0p8uqy24gpyjsa6c3df4h6";
165+
// cspell: enable
166+
167+
#[test]
168+
fn test_valid_stake_address_from_string() {
169+
let stake_address_prod = Cip19StakeAddress::try_from(VALID_PROD_STAKE_ADDRESS.to_string());
170+
let stake_address_test = Cip19StakeAddress::try_from(VALID_TEST_STAKE_ADDRESS.to_string());
171+
172+
assert!(stake_address_prod.is_ok());
173+
assert!(stake_address_test.is_ok());
174+
assert_eq!(stake_address_prod.unwrap().0, VALID_PROD_STAKE_ADDRESS);
175+
assert_eq!(stake_address_test.unwrap().0, VALID_TEST_STAKE_ADDRESS);
176+
}
177+
178+
#[test]
179+
fn test_invalid_stake_address_from_string() {
180+
let stake_address = Cip19StakeAddress::try_from(INVALID_STAKE_ADDRESS.to_string());
181+
assert!(stake_address.is_err());
182+
}
183+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Get staked ADA amount: zero assets
2+
GET http://localhost:3030/api/draft/cardano/assets/stake_test1ursne3ndzr4kz8gmhmstu5026erayrnqyj46nqkkfcn0ufss2t7vt
3+
HTTP 200
4+
{"persistent":{"ada_amount":9809147618,"native_tokens":[],"slot_number":76323283},"volatile":{"ada_amount":0,"native_tokens":[],"slot_number":0}}
5+
6+
# Get staked ADA amount: single asset
7+
GET http://localhost:3030/api/draft/cardano/assets/stake_test1uq7cnze6az9f8ffjrvkxx4ad77jz088frkhzupxcc7y4x8q5x808s
8+
HTTP 200
9+
{"persistent":{"ada_amount":8870859858,"native_tokens":[{"amount":3,"asset_name":"GoldRelic","policy_hash":"0x2862c9b33e98096107e2d8b8c072070834db9c91c0d2f3743e75df65"}],"slot_number":76572358},"volatile":{"ada_amount":0,"native_tokens":[],"slot_number":0}}
10+
11+
# Get staked ADA amount: multiple assets
12+
GET http://localhost:3030/api/draft/cardano/assets/stake_test1ur66dds0pkf3j5tu7py9tqf7savpv7pgc5g3dd74xy0x2vsldf2mx
13+
HTTP 200
14+
[Asserts]
15+
jsonpath "$.persistent.native_tokens" count == 9

catalyst_voices/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ This repository contains the Catalyst Voices app and packages.
4343
```sh
4444
git clone https://github.com/input-output-hk/catalyst-voices.git
4545
cd catalyst_voices
46-
melos bootstrap
46+
just bootstrap
4747
```
4848

4949
### Packages

catalyst_voices/apps/voices/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies:
3434
path: ../../packages/internal/catalyst_voices_view_models
3535
collection: ^1.18.0
3636
dotted_border: ^2.1.0
37-
equatable: ^2.0.5
37+
equatable: ^2.0.7
3838
file_picker: ^8.0.7
3939
flutter:
4040
sdk: flutter

catalyst_voices/justfile

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
#!/usr/bin/env just --justfile
2-
32
# cspell: words justfile
43

54
default:
65
@just --list --unsorted
76

7+
# Linking of all packages
8+
setup-code:
9+
melos bs
10+
11+
# Builds generated code
12+
generate-code: setup-code
13+
melos l10n
14+
melos build_runner
15+
just generate-gateway-services
16+
17+
# Syntax sugar for linking packages and building generated code
18+
bootstrap: generate-code
19+
820
# Runs all static code checks
921
check-code:
1022
earthly +check-static-analysis

catalyst_voices/melos.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ command:
9292
cryptography: ^2.7.0
9393
dotted_border: ^2.1.0
9494
ed25519_hd_key: ^2.3.0
95-
equatable: ^2.0.5
95+
equatable: ^2.0.7
9696
ffi: ^2.1.0
9797
ffigen: ^11.0.0
9898
file_picker: ^8.0.7

catalyst_voices/packages/internal/catalyst_voices_blocs/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies:
2626
catalyst_voices_view_models:
2727
path: ../catalyst_voices_view_models
2828
collection: ^1.18.0
29-
equatable: ^2.0.5
29+
equatable: ^2.0.7
3030
flutter:
3131
sdk: flutter
3232
flutter_bloc: ^8.1.5

0 commit comments

Comments
 (0)