Skip to content

Commit

Permalink
Initial functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
gostkin committed Oct 25, 2023
1 parent d8fc630 commit c050fd5
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 236 deletions.
507 changes: 274 additions & 233 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ strip = true

[dependencies]
# [core]
dcspark-core = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "837b0135462ff7a1018942dca7198ad9c808a84c" }
dcspark-blockchain-source = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "837b0135462ff7a1018942dca7198ad9c808a84c" }
multiverse = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "837b0135462ff7a1018942dca7198ad9c808a84c" }
dcspark-core = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "572af17e3e22101dee64e0999049a571aea26e0f" }
dcspark-blockchain-source = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "572af17e3e22101dee64e0999049a571aea26e0f" }
multiverse = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "572af17e3e22101dee64e0999049a571aea26e0f" }

# [local]
entity = { path = "entity" }
Expand All @@ -23,6 +23,7 @@ anyhow = { version = "1.0.69" }
async-trait = { version = "0.1.64" }
base64 = { version = "0.21.0" }
cardano-multiplatform-lib = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", branch = "metadata-and-addr" }
projected-nft-sdk = { git = "https://github.com/dcSpark/projected-nft-whirlpool.git", rev = "8dc510c53fb86cb5c9eae746a05bb64c9b9f7f4b" }
clap = { version = "3.1", features = ["derive"] }
ctrlc = { version = "3.2.4", features = ["termination"] }
dotenv = { version = "0.15.0" }
Expand Down
1 change: 1 addition & 0 deletions indexer/entity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ pub mod native_asset;
pub mod plutus_data;
pub mod plutus_data_hash;
pub mod transaction_metadata;
pub mod projected_nft;
64 changes: 64 additions & 0 deletions indexer/entity/src/projected_nft.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)]
#[sea_orm(table_name = "ProjectedNFT")]
pub struct Model {
#[sea_orm(primary_key, column_type = "BigInteger")]
pub id: i64,
#[sea_orm(column_type = "BigInteger")]
pub utxo_id: i64,
#[sea_orm(column_type = "BigInteger")]
pub tx_id: i64,
pub operation: i32, // lock / unlock / claim
// address_id here is useful for fast pagination without joining w/ txoutput table
#[sea_orm(column_type = "BigInteger", nullable)]
pub asset_id: Option<i64>,
pub amount: u64,
pub plutus_datum: Vec<u8>,
}

#[derive(Copy, Clone, Debug, DeriveRelation, EnumIter)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::transaction_output::Entity",
from = "Column::UtxoId",
to = "super::transaction_output::Column::Id"
)]
TransactionOutput,
#[sea_orm(
belongs_to = "super::transaction::Entity",
from = "Column::TxId",
to = "super::transaction::Column::Id"
)]
Transaction,
#[sea_orm(
belongs_to = "super::native_asset::Entity",
from = "Column::AssetId",
to = "super::native_asset::Column::Id"
)]
Asset,
}

// TODO: figure out why this isn't automatically handle by the macros above
impl Related<super::native_asset::Entity> for Entity {
fn to() -> RelationDef {
Relation::Asset.def()
}
}

// TODO: figure out why this isn't automatically handle by the macros above
impl Related<super::transaction_output::Entity> for Entity {
fn to() -> RelationDef {
Relation::TransactionOutput.def()
}
}

// TODO: figure out why this isn't automatically handle by the macros above
impl Related<super::transaction::Entity> for Entity {
fn to() -> RelationDef {
Relation::Transaction.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
8 changes: 8 additions & 0 deletions indexer/tasks/src/config/AddressConfig.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use pallas::ledger::addresses::Address;
use pallas::ledger::primitives::alonzo::PlutusScript;
use pallas::ledger::primitives::babbage::PlutusV2Script;

#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct PayloadAndReadonlyConfig {
pub address: String,
}
2 changes: 2 additions & 0 deletions indexer/tasks/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ pub mod PayloadAndReadonlyConfig;
pub mod PayloadConfig;
#[allow(non_snake_case)]
pub mod ReadonlyConfig;
#[allow(non_snake_case)]
pub mod AddressConfig;
1 change: 1 addition & 0 deletions indexer/tasks/src/multiera/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ pub mod multiera_wingriders_v1_mean_price;
pub mod multiera_wingriders_v1_swap;
pub mod relation_map;
pub mod utils;
pub mod multiera_projected_nft;
49 changes: 49 additions & 0 deletions indexer/tasks/src/multiera/multiera_projected_nft.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use std::collections::BTreeSet;

use crate::config::ReadonlyConfig::ReadonlyConfig;
use crate::types::AddressCredentialRelationValue;
use entity::sea_orm::Condition;
use entity::{
prelude::*,
sea_orm::{prelude::*, DatabaseTransaction, Set},
};

use crate::dsl::task_macro::*;

use super::{
multiera_stake_credentials::MultieraStakeCredentialTask,
};

use crate::config::AddressConfig;

carp_task! {
name MultiEraProjectedNftTask;
configuration AddressConfig;
doc "Parses projected NFT contract data";
era multiera;
dependencies [MultieraStakeCredentialTask];
read [multiera_txs, multiera_stake_credential];
write [];
should_add_task |block, _properties| {
!block.1.is_empty()
};
execute |previous_data, task| handle_projeced_nft(
task.db_tx,
task.block,
&previous_data.multiera_txs,
&previous_data.multiera_stake_credential,
task.config.address
);
merge_result |previous_data, _result| {
};
}

async fn handle_projected_nft(
db_tx: &DatabaseTransaction,
block: BlockInfo<'_, MultiEraBlock<'_>, BlockGlobalInfo>,
multiera_txs: &[TransactionModel],
multiera_stake_credential: &BTreeMap<Vec<u8>, StakeCredentialModel>,
address: String,
) -> Result<(), DbErr> {
Ok(())
}

0 comments on commit c050fd5

Please sign in to comment.