Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ restore.sh
startup.sh
configuration/
docker-compose.yaml
.DS_Store

# Nix
result
Expand All @@ -13,3 +14,6 @@ result-*
.direnv/
.envrc.local
tests/fixtures/134092758.670ca68c3de580f8469677754a725e86ca72a7be381d3108569f0704a5fca327.cbor

downloads/
fjall-*/
47 changes: 33 additions & 14 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions common/src/queries/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use crate::queries::errors::QueryError;
use crate::{
queries::misc::Order,
serialization::{Bech32Conversion, Bech32WithHrp},
Address, BlockHash, GenesisDelegate, HeavyDelegate, KeyHash, TxHash, TxIdentifier,
VrfKeyHash,
Address, BlockHash, GenesisDelegate, HeavyDelegate, KeyHash, TxHash, TxIdentifier, VrfKeyHash,
};
use cryptoxide::hashing::blake2b::Blake2b;
use serde::ser::{Serialize, SerializeStruct, Serializer};
Expand Down
12 changes: 9 additions & 3 deletions common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2410,12 +2410,18 @@ mod tests {

#[test]
fn test_utxo_identifier_to_bytes() -> Result<()> {
let tx_hash = TxHash::try_from(hex::decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f").unwrap()).unwrap();
let tx_hash = TxHash::try_from(
hex::decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")
.unwrap(),
)
.unwrap();
let output_index = 42;
let utxo = UTxOIdentifier::new(tx_hash, output_index);
let bytes = utxo.to_bytes();
assert_eq!(hex::encode(bytes),
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f002a");
assert_eq!(
hex::encode(bytes),
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f002a"
);

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions modules/address_state/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# fjall immutable db
fjall-*/
db/
25 changes: 17 additions & 8 deletions modules/address_state/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl State {
#[cfg(test)]
mod tests {
use super::*;
use acropolis_common::{Address, AddressDelta, UTxOIdentifier, Value};
use acropolis_common::{Address, AddressDelta, TxHash, UTxOIdentifier, Value};
use tempfile::tempdir;

fn dummy_address() -> Address {
Expand Down Expand Up @@ -284,7 +284,7 @@ mod tests {
let mut state = setup_state_and_store().await?;

let addr = dummy_address();
let utxo = UTxOIdentifier::new(0, 0, 0);
let utxo = UTxOIdentifier::new(TxHash::default(), 0);
let tx_id = TxIdentifier::new(0, 0);
let deltas = vec![delta(&addr, tx_id, vec![], vec![utxo], 0, 1)];

Expand All @@ -295,7 +295,10 @@ mod tests {
let utxos = state.get_address_utxos(&addr).await?;
assert!(utxos.is_some());
assert_eq!(utxos.as_ref().unwrap().len(), 1);
assert_eq!(utxos.as_ref().unwrap()[0], UTxOIdentifier::new(0, 0, 0));
assert_eq!(
utxos.as_ref().unwrap()[0],
UTxOIdentifier::new(TxHash::default(), 0)
);

// Drain volatile to immutable
state.volatile.epoch_start_block = 1;
Expand All @@ -305,7 +308,10 @@ mod tests {
let utxos = state.get_address_utxos(&addr).await?;
assert!(utxos.is_some());
assert_eq!(utxos.as_ref().unwrap().len(), 1);
assert_eq!(utxos.as_ref().unwrap()[0], UTxOIdentifier::new(0, 0, 0));
assert_eq!(
utxos.as_ref().unwrap()[0],
UTxOIdentifier::new(TxHash::default(), 0)
);

// Perisist immutable to disk
state.immutable.persist_epoch(0, &state.config).await?;
Expand All @@ -314,7 +320,10 @@ mod tests {
let utxos = state.get_address_utxos(&addr).await?;
assert!(utxos.is_some());
assert_eq!(utxos.as_ref().unwrap().len(), 1);
assert_eq!(utxos.as_ref().unwrap()[0], UTxOIdentifier::new(0, 0, 0));
assert_eq!(
utxos.as_ref().unwrap()[0],
UTxOIdentifier::new(TxHash::default(), 0)
);

Ok(())
}
Expand All @@ -326,7 +335,7 @@ mod tests {
let mut state = setup_state_and_store().await?;

let addr = dummy_address();
let utxo = UTxOIdentifier::new(0, 0, 0);
let utxo = UTxOIdentifier::new(TxHash::default(), 0);
let tx_id_create = TxIdentifier::new(0, 0);
let tx_id_spend = TxIdentifier::new(1, 0);

Expand Down Expand Up @@ -377,8 +386,8 @@ mod tests {
let mut state = setup_state_and_store().await?;

let addr = dummy_address();
let utxo_old = UTxOIdentifier::new(0, 0, 0);
let utxo_new = UTxOIdentifier::new(0, 1, 0);
let utxo_old = UTxOIdentifier::new(TxHash::default(), 0);
let utxo_new = UTxOIdentifier::new(TxHash::default(), 1);
let tx_id_create_old = TxIdentifier::new(0, 0);
let tx_id_spend_old_create_new = TxIdentifier::new(1, 0);

Expand Down
22 changes: 11 additions & 11 deletions modules/assets_state/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,8 @@ mod tests {
};
use acropolis_common::{
Address, AddressDelta, AssetInfoRecord, AssetMetadata, AssetMetadataStandard, AssetName,
Datum, NativeAsset, NativeAssetDelta, PolicyId, ShelleyAddress, TxIdentifier, TxOutput,
TxUTxODeltas, UTxOIdentifier, Value,
Datum, NativeAsset, NativeAssetDelta, PolicyId, ShelleyAddress, TxHash, TxIdentifier,
TxOutput, TxUTxODeltas, UTxOIdentifier, Value,
};
use serde_cbor::Value as CborValue;

Expand Down Expand Up @@ -845,7 +845,7 @@ mod tests {

fn make_output(policy_id: PolicyId, asset_name: AssetName, datum: Option<Vec<u8>>) -> TxOutput {
TxOutput {
utxo_identifier: UTxOIdentifier::new(0, 0, 0),
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
address: dummy_address(),
value: Value {
lovelace: 0,
Expand Down Expand Up @@ -1263,7 +1263,7 @@ mod tests {
StoreTransactions::None,
);

let input = UTxOIdentifier::new(0, 0, 0);
let input = UTxOIdentifier::new(TxHash::default(), 0);
let output = make_output(policy_id, name, None);

let tx_deltas = TxUTxODeltas {
Expand Down Expand Up @@ -1428,15 +1428,15 @@ mod tests {
tx_identifier,
inputs: Vec::new(),
outputs: vec![TxOutput {
utxo_identifier: UTxOIdentifier::new(0, 0, 0),
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
..output.clone()
}],
};
let tx2 = TxUTxODeltas {
tx_identifier,
inputs: Vec::new(),
outputs: vec![TxOutput {
utxo_identifier: UTxOIdentifier::new(0, 0, 1),
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 1),
..output
}],
};
Expand Down Expand Up @@ -1470,15 +1470,15 @@ mod tests {
tx_identifier: TxIdentifier::new(9, 0),
inputs: Vec::new(),
outputs: vec![TxOutput {
utxo_identifier: UTxOIdentifier::new(9, 0, 0),
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
..out1
}],
};
let tx2 = TxUTxODeltas {
tx_identifier: TxIdentifier::new(10, 0),
inputs: Vec::new(),
outputs: vec![TxOutput {
utxo_identifier: UTxOIdentifier::new(10, 0, 0),
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
..out2
}],
};
Expand Down Expand Up @@ -1513,23 +1513,23 @@ mod tests {
tx_identifier: TxIdentifier::new(9, 0),
inputs: Vec::new(),
outputs: vec![TxOutput {
utxo_identifier: UTxOIdentifier::new(9, 0, 0),
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
..base_output.clone()
}],
};
let tx2 = TxUTxODeltas {
tx_identifier: TxIdentifier::new(8, 0),
inputs: Vec::new(),
outputs: vec![TxOutput {
utxo_identifier: UTxOIdentifier::new(8, 0, 0),
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
..base_output.clone()
}],
};
let tx3 = TxUTxODeltas {
tx_identifier: TxIdentifier::new(7, 0),
inputs: Vec::new(),
outputs: vec![TxOutput {
utxo_identifier: UTxOIdentifier::new(7, 0, 0),
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
..base_output
}],
};
Expand Down
8 changes: 5 additions & 3 deletions modules/chain_store/src/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,11 @@ impl ChainStore {
// TODO! Look up TxHash to get block hash, and index of Tx in block
}

Ok(BlocksStateQueryResponse::BlockHashesAndIndexOfTransactionHashes(
block_hashes_and_indexes,
))
Ok(
BlocksStateQueryResponse::BlockHashesAndIndexOfTransactionHashes(
block_hashes_and_indexes,
),
)
}
BlocksStateQuery::GetTransactionHashesAndTimestamps { tx_ids } => {
let mut tx_hashes = Vec::with_capacity(tx_ids.len());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Acropolis indexer module

[package]
name = "acropolis_module_indexer"
name = "acropolis_module_custom_indexer"
version = "0.1.0"
edition = "2021"
authors = ["William Hankins <william@sundae.fi>"]
Expand All @@ -14,9 +14,13 @@ acropolis_common = { path = "../../common" }
caryatid_sdk = { workspace = true }

anyhow = { workspace = true }
bincode = "1"
config = { workspace = true }
fjall = "2.7.0"
pallas = { workspace = true}
serde = { workspace = true, features = ["rc"] }
tokio = { workspace = true }
tracing = { workspace = true }

[lib]
path = "src/indexer.rs"
path = "src/custom_indexer.rs"
4 changes: 4 additions & 0 deletions modules/custom_indexer/config.default.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# The topic to publish sync commands on
sync-command-publisher-topic = "cardano.sync.command"
# The topic to receive txs on
txs-subscribe-topic = "cardano.txs"
19 changes: 19 additions & 0 deletions modules/custom_indexer/src/chain_index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use acropolis_common::{BlockInfo, Point};
use anyhow::Result;
use caryatid_sdk::async_trait;
use pallas::ledger::traverse::MultiEraTx;

#[async_trait]
pub trait ChainIndex: Send + Sync + 'static {
fn name(&self) -> String;

async fn handle_onchain_tx(&mut self, info: &BlockInfo, tx: &MultiEraTx<'_>) -> Result<()> {
let _ = (info, tx);
Ok(())
}

async fn handle_rollback(&mut self, point: &Point) -> Result<()> {
let _ = point;
Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use config::Config;

#[derive(serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct IndexerConfig {
pub sync_command_topic: String,
pub struct CustomIndexerConfig {
pub sync_command_publisher_topic: String,
pub txs_subscribe_topic: String,
}

impl IndexerConfig {
impl CustomIndexerConfig {
pub fn try_load(config: &Config) -> Result<Self> {
let full_config = Config::builder()
.add_source(config::File::from_str(
Expand Down
Loading