Skip to content

Commit

Permalink
add conway certs
Browse files Browse the repository at this point in the history
  • Loading branch information
lisicky committed Oct 24, 2023
1 parent 8ce03c4 commit 7b8bce8
Show file tree
Hide file tree
Showing 7 changed files with 425 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = ["Santiago Carmuega <santiago@carmuega.me>"]


[dependencies]
pallas = "0.18.0"
pallas = { git = "https://github.com/lisicky/pallas", branch = "hotfix/v0.18" }
# pallas = { git = "https://github.com/txpipe/pallas" }
# pallas = { path = "../pallas/pallas" }
hex = "0.4.3"
Expand Down
60 changes: 60 additions & 0 deletions src/filters/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,66 @@ fn build_fingerprint(event: &Event, seed: u32) -> Result<String, Error> {
.with_prefix("move")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.certificate_idx)?,
EventData::RegCert { .. } => b
.with_slot(&event.context.slot)
.with_prefix("regc")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.certificate_idx)?,
EventData::UnRegCert { .. } => b
.with_slot(&event.context.slot)
.with_prefix("unrc")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.certificate_idx)?,
EventData::VoteDeleg { .. } => b
.with_slot(&event.context.slot)
.with_prefix("vode")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.certificate_idx)?,
EventData::StakeVoteDeleg { .. } => b
.with_slot(&event.context.slot)
.with_prefix("stvo")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.certificate_idx)?,
EventData::StakeRegDeleg { .. } => b
.with_slot(&event.context.slot)
.with_prefix("stre")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.certificate_idx)?,
EventData::VoteRegDeleg { .. } => b
.with_slot(&event.context.slot)
.with_prefix("vore")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.certificate_idx)?,
EventData::StakeVoteRegDeleg { .. } => b
.with_slot(&event.context.slot)
.with_prefix("stvr")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.certificate_idx)?,
EventData::AuthCommitteeHot { .. } => b
.with_slot(&event.context.slot)
.with_prefix("auth")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.certificate_idx)?,
EventData::ResignCommitteeCold { .. } => b
.with_slot(&event.context.slot)
.with_prefix("resi")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.certificate_idx)?,
EventData::RegDRepCert { .. } => b
.with_slot(&event.context.slot)
.with_prefix("regd")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.certificate_idx)?,
EventData::UnRegDRepCert { .. } => b
.with_slot(&event.context.slot)
.with_prefix("unrd")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.certificate_idx)?,
EventData::UpdateDRepCert { .. } => b
.with_slot(&event.context.slot)
.with_prefix("updd")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.certificate_idx)?,
EventData::RollBack {
block_slot,
block_hash,
Expand Down
137 changes: 135 additions & 2 deletions src/mapper/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ use pallas::ledger::primitives::{
use pallas::network::miniprotocols::Point;
use serde_json::{json, Value as JsonValue};

use crate::model::{BlockRecord, CertificateRecord, CostModelRecord, CostModelsRecord, Era, EventData, ExUnitsRecord, GenesisKeyDelegationRecord, LanguageVersionRecord, MetadataRecord, MetadatumRendition, MintRecord, MoveInstantaneousRewardsCertRecord, NativeWitnessRecord, NonceRecord, NonceVariantRecord, OutputAssetRecord, PlutusDatumRecord, PlutusRedeemerRecord, PlutusWitnessRecord, PoolRegistrationRecord, PoolRetirementRecord, PositiveIntervalRecord, ProtocolParamUpdateRecord, RationalNumberRecord, ScriptRefRecord, StakeCredential, StakeDelegationRecord, StakeDeregistrationRecord, StakeRegistrationRecord, TransactionRecord, TxInputRecord, TxOutputRecord, UnitIntervalRecord, UpdateRecord, VKeyWitnessRecord};
use crate::model::{AnchorRecord, AuthCommitteeHotCertRecord, BlockRecord, CertificateRecord, CostModelRecord, CostModelsRecord, DRep, Era, EventData, ExUnitsRecord, GenesisKeyDelegationRecord, LanguageVersionRecord, MetadataRecord, MetadatumRendition, MintRecord, MoveInstantaneousRewardsCertRecord, NativeWitnessRecord, NonceRecord, NonceVariantRecord, OutputAssetRecord, PlutusDatumRecord, PlutusRedeemerRecord, PlutusWitnessRecord, PoolRegistrationRecord, PoolRetirementRecord, PositiveIntervalRecord, ProtocolParamUpdateRecord, RationalNumberRecord, RegCertRecord, RegDRepCertRecord, ResignCommitteeColdCertRecord, ScriptRefRecord, StakeCredential, StakeDelegationRecord, StakeDeregistrationRecord, StakeRegDelegCertRecord, StakeRegistrationRecord, StakeVoteDelegCertRecord, StakeVoteRegDelegCertRecord, TransactionRecord, TxInputRecord, TxOutputRecord, UnitIntervalRecord, UnRegCertRecord, UnRegDRepCertRecord, UpdateDRepCertRecord, UpdateRecord, VKeyWitnessRecord, VoteDelegCertRecord, VoteRegDelegCertRecord};

use crate::utils::time::TimeProvider;
use crate::Error;
use crate::model::ScriptRefRecord::{NativeScript, PlutusV1, PlutusV2};
use crate::model::ScriptRefRecord::{NativeScript, PlutusV1, PlutusV2, PlutusV3};

use super::EventWriter;

Expand Down Expand Up @@ -56,6 +56,34 @@ impl From<&alonzo::StakeCredential> for StakeCredential {
}
}

impl From<&alonzo::DRep> for DRep {
fn from(other: &alonzo::DRep) -> Self {
match other {
alonzo::DRep::Key(x) => DRep::KeyHash(x.to_hex()),
alonzo::DRep::Script(x) => DRep::ScriptHash(x.to_hex()),
alonzo::DRep::Abstain => DRep::Abstain,
alonzo::DRep::NoConfidence => DRep::NoConfidence,
}
}
}

impl From<&alonzo::Anchor> for AnchorRecord {
fn from(other: &alonzo::Anchor) -> Self {
AnchorRecord {
url: other.0.clone(),
data_hash: other.1.to_hex(),
}
}
}

fn to_option_anchor_record(anchor: &Option<alonzo::Anchor>) -> Option<AnchorRecord> {
match anchor {
Some(anchor) => Some(anchor.into()),
None => None,
}
}


fn ip_string_from_bytes(bytes: &[u8]) -> String {
format!("{}.{}.{}.{}", bytes[0], bytes[1], bytes[2], bytes[3])
}
Expand Down Expand Up @@ -312,6 +340,10 @@ impl EventWriter {
script_hash: script.compute_hash().to_hex(),
script_hex: script.as_ref().to_hex(),
}),
Script::PlutusV3Script(script) => Ok(PlutusV3 {
script_hash: script.compute_hash().to_hex(),
script_hex: script.as_ref().to_hex(),
}),
Script::NativeScript(script) => Ok(NativeScript {
policy_id: script.compute_hash().to_hex(),
script_json: script.to_json(),
Expand Down Expand Up @@ -395,6 +427,83 @@ impl EventWriter {
genesis_delegate_hash: genesis_delegate_hash.to_hex(),
vrf_key_hash: vrf_key_hash.to_hex(),
}),
Certificate::Reg(credential, coin) => CertificateRecord::RegCert(
RegCertRecord {
credential: credential.into(),
coin: *coin,
}
),
Certificate::UnReg(credential, coin) => CertificateRecord::UnRegCert(
UnRegCertRecord {
credential: credential.into(),
coin: *coin,
}
),
Certificate::VoteDeleg(credential, drep) => CertificateRecord::VoteDeleg(
VoteDelegCertRecord {
credential: credential.into(),
drep: drep.into(),
}
),
Certificate::StakeVoteDeleg(credential, pool, drep) => CertificateRecord::StakeVoteDeleg(
StakeVoteDelegCertRecord {
credential: credential.into(),
pool_keyhash: pool.to_hex(),
drep: drep.into(),
}
),
Certificate::StakeRegDeleg(credential, pool, coin) => CertificateRecord::StakeRegDeleg(
StakeRegDelegCertRecord {
credential: credential.into(),
pool_keyhash: pool.to_hex(),
coin: *coin,
}
),
Certificate::VoteRegDeleg(credential, drep, coin) => CertificateRecord::VoteRegDeleg(
VoteRegDelegCertRecord {
credential: credential.into(),
drep: drep.into(),
coin: *coin,
}
),
Certificate::StakeVoteRegDeleg(credential, pool, drep, coin) => CertificateRecord::StakeVoteRegDeleg(
StakeVoteRegDelegCertRecord {
credential: credential.into(),
pool_keyhash: pool.to_hex(),
drep: drep.into(),
coin: *coin,
}
),
Certificate::AuthCommitteeHot(cold, hot) => CertificateRecord::AuthCommitteeHot(
AuthCommitteeHotCertRecord {
committee_cold_credential: cold.into(),
committee_hot_credential: hot.into(),
}
),
Certificate::ResignCommitteeCold(cold) => CertificateRecord::ResignCommitteeCold(
ResignCommitteeColdCertRecord {
committee_cold_credential: cold.into(),
}
),
Certificate::RegDRepCert(drep, coin, anchor) => CertificateRecord::RegDRepCert(
RegDRepCertRecord {
credential: drep.into(),
coin: *coin,
anchor: to_option_anchor_record(anchor),
}
),
Certificate::UnRegDRepCert(drep, coin) => CertificateRecord::UnRegDRepCert(
UnRegDRepCertRecord {
credential: drep.into(),
coin: *coin,
}
),
Certificate::UpdateDRepCert(credential, anchor) => CertificateRecord::UpdateDRepCert(
UpdateDRepCertRecord {
credential: credential.into(),
anchor: to_option_anchor_record(anchor),
}
),
}
}

Expand Down Expand Up @@ -495,6 +604,30 @@ impl EventWriter {
EventData::MoveInstantaneousRewardsCert(cert_record),
CertificateRecord::GenesisKeyDelegation(cert_record) =>
EventData::GenesisKeyDelegation(cert_record),
CertificateRecord::RegCert(cert_record) =>
EventData::RegCert(cert_record),
CertificateRecord::UnRegCert(cert_record) =>
EventData::UnRegCert(cert_record),
CertificateRecord::VoteDeleg(cert_record) =>
EventData::VoteDeleg(cert_record),
CertificateRecord::StakeVoteDeleg(cert_record) =>
EventData::StakeVoteDeleg(cert_record),
CertificateRecord::StakeRegDeleg(cert_record) =>
EventData::StakeRegDeleg(cert_record),
CertificateRecord::VoteRegDeleg(cert_record) =>
EventData::VoteRegDeleg(cert_record),
CertificateRecord::StakeVoteRegDeleg(cert_record) =>
EventData::StakeVoteRegDeleg(cert_record),
CertificateRecord::AuthCommitteeHot(cert_record) =>
EventData::AuthCommitteeHot(cert_record),
CertificateRecord::ResignCommitteeCold(cert_record) =>
EventData::ResignCommitteeCold(cert_record),
CertificateRecord::RegDRepCert(cert_record) =>
EventData::RegDRepCert(cert_record),
CertificateRecord::UnRegDRepCert(cert_record) =>
EventData::UnRegDRepCert(cert_record),
CertificateRecord::UpdateDRepCert(cert_record) =>
EventData::UpdateDRepCert(cert_record),
}
}

Expand Down
Loading

0 comments on commit 7b8bce8

Please sign in to comment.