Skip to content

Commit

Permalink
Merge pull request #152 from dashpay/v0.7-dev
Browse files Browse the repository at this point in the history
v0.7-dev to master
  • Loading branch information
ogabrielides authored Jan 7, 2025
2 parents 8813b53 + c89ac35 commit bd70ef3
Show file tree
Hide file tree
Showing 46 changed files with 2,419 additions and 545 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[package]
name = "dash-evo-tool"
version = "0.6.0"
version = "0.7.0"
license = "MIT"
edition = "2021"
default-run = "dash-evo-tool"
rust-version = "1.81"
build = "build.rs"

[build]
rustflags = [
Expand All @@ -24,7 +25,7 @@ strum = { version = "0.26.1", features = ["derive"] }
bs58 = "0.5.0"
base64 = "0.22.1"
copypasta = "0.10.1"
dash-sdk = { git = "https://github.com/dashpay/platform", rev = "a4f906acd127bc9856d72452eba002da16935209" }
dash-sdk = { git = "https://github.com/dashpay/platform", rev = "8a000dfeb9c872c4bfedd8e8974ad1a9d2fdab78" }
thiserror = "1"
serde = "1.0.197"
serde_json = "1.0.120"
Expand Down
17 changes: 17 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::env;
use std::fs;
use std::path::Path;

fn main() {
// Fetch the version from CARGO_PKG_VERSION
let version = env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "??".to_string());

// Generate a Rust file with the version constant
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("version.rs");
fs::write(
dest_path,
format!(r#"pub const VERSION: &str = "{}";"#, version),
)
.expect("Failed to write version.rs");
}
19 changes: 14 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use crate::components::core_zmq_listener::{CoreZMQListener, ZMQMessage};
use crate::context::AppContext;
use crate::database::Database;
use crate::logging::initialize_logger;
use crate::ui::document_query_screen::DocumentQueryScreen;
use crate::ui::dpns_contested_names_screen::{
use crate::ui::contracts_documents::document_query_screen::DocumentQueryScreen;
use crate::ui::dpns::dpns_contested_names_screen::{
DPNSContestedNamesScreen, DPNSSubscreen, IndividualVoteCastingStatus,
};
use crate::ui::identities::identities_screen::IdentitiesScreen;
use crate::ui::network_chooser_screen::NetworkChooserScreen;
use crate::ui::tool_screens::proof_log_screen::ProofLogScreen;
use crate::ui::tool_screens::transition_visualizer_screen::TransitionVisualizerScreen;
use crate::ui::wallet::wallets_screen::WalletsBalancesScreen;
use crate::ui::tools::proof_log_screen::ProofLogScreen;
use crate::ui::tools::transition_visualizer_screen::TransitionVisualizerScreen;
use crate::ui::wallets::wallets_screen::WalletsBalancesScreen;
use crate::ui::withdrawal_statuses_screen::WithdrawsStatusScreen;
use crate::ui::{MessageType, RootScreenType, Screen, ScreenLike, ScreenType};
use dash_sdk::dpp::dashcore::Network;
Expand Down Expand Up @@ -460,6 +460,15 @@ impl App for AppState {
BackendTaskSuccessResult::ToppedUpIdentity(_) => {
self.visible_screen_mut().display_task_result(message);
}
BackendTaskSuccessResult::FetchedContract(_) => {
self.visible_screen_mut().display_task_result(message);
}
BackendTaskSuccessResult::FetchedContracts(_) => {
self.visible_screen_mut().display_task_result(message);
}
BackendTaskSuccessResult::PageDocuments(_, _) => {
self.visible_screen_mut().display_task_result(message);
}
},
TaskResult::Error(message) => {
self.visible_screen_mut()
Expand Down
23 changes: 23 additions & 0 deletions src/backend_task/broadcast_state_transition.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use dash_sdk::{
dpp::state_transition::StateTransition,
platform::transition::broadcast::BroadcastStateTransition, Sdk,
};

use crate::context::AppContext;

use super::BackendTaskSuccessResult;

impl AppContext {
pub async fn broadcast_state_transition(
&self,
state_transition: StateTransition,
sdk: &Sdk,
) -> Result<BackendTaskSuccessResult, String> {
match state_transition.broadcast_and_wait(sdk, None).await {
Ok(_) => Ok(BackendTaskSuccessResult::Message(
"State transition broadcasted successfully".to_string(),
)),
Err(e) => Err(format!("Error broadcasting state transition: {}", e)),
}
}
}
57 changes: 51 additions & 6 deletions src/backend_task/contract.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,63 @@
use crate::context::AppContext;
use dash_sdk::dpp::system_data_contracts::dpns_contract;
use dash_sdk::platform::{DataContract, Fetch, Identifier};
use dash_sdk::platform::{DataContract, Fetch, FetchMany, Identifier};
use dash_sdk::Sdk;

use super::BackendTaskSuccessResult;

#[derive(Debug, Clone, PartialEq)]
pub(crate) enum ContractTask {
FetchDPNSContract,
FetchContract(Identifier, Option<String>),
FetchContracts(Vec<Identifier>),
RemoveContract(Identifier),
}

impl AppContext {
pub async fn run_contract_task(&self, task: ContractTask, sdk: &Sdk) -> Result<(), String> {
pub async fn run_contract_task(
&self,
task: ContractTask,
sdk: &Sdk,
) -> Result<BackendTaskSuccessResult, String> {
match task {
ContractTask::FetchContract(identifier, name) => {
match DataContract::fetch(sdk, identifier).await {
Ok(Some(data_contract)) => self
.db
.insert_contract_if_not_exists(&data_contract, name.as_deref(), self)
.map_err(|e| e.to_string()),
Ok(None) => Ok(()),
Err(e) => Err(e.to_string()),
.map(|_| BackendTaskSuccessResult::FetchedContract(data_contract))
.map_err(|e| {
format!(
"Error inserting contract into the database: {}",
e.to_string()
)
}),
Ok(None) => Err("Contract not found".to_string()),
Err(e) => Err(format!("Error fetching contract: {}", e.to_string())),
}
}
ContractTask::FetchContracts(identifiers) => {
match DataContract::fetch_many(sdk, identifiers).await {
Ok(data_contracts) => {
let mut results = vec![];
for data_contract in data_contracts {
if let Some(contract) = &data_contract.1 {
self.db
.insert_contract_if_not_exists(contract, None, self)
.map_err(|e| {
format!(
"Error inserting contract into the database: {}",
e.to_string()
)
})?;
results.push(Some(contract.clone()));
} else {
results.push(None);
}
}
Ok(BackendTaskSuccessResult::FetchedContracts(results))
}
Err(e) => Err(format!("Error fetching contracts: {}", e.to_string())),
}
}
ContractTask::FetchDPNSContract => {
Expand All @@ -29,11 +67,18 @@ impl AppContext {
Ok(Some(data_contract)) => self
.db
.insert_contract_if_not_exists(&data_contract, Some("dpns"), self)
.map(|_| BackendTaskSuccessResult::FetchedContract(data_contract))
.map_err(|e| e.to_string()),
Ok(None) => Err("No DPNS contract found".to_string()),
Err(e) => Err(e.to_string()),
Err(e) => Err(format!("Error fetching DPNS contract: {}", e.to_string())),
}
}
ContractTask::RemoveContract(identifier) => self
.remove_contract(&identifier)
.map(|_| {
BackendTaskSuccessResult::Message("Successfully removed contract".to_string())
})
.map_err(|e| format!("Error removing contract: {}", e.to_string())),
}
}
}
2 changes: 1 addition & 1 deletion src/backend_task/core/refresh_wallet_info.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::backend_task::BackendTaskSuccessResult;
use crate::context::AppContext;
use crate::model::wallet::Wallet;
use crate::ui::wallet::wallets_screen::DerivationPathHelpers;
use crate::ui::wallets::wallets_screen::DerivationPathHelpers;
use dash_sdk::dashcore_rpc::RpcApi;
use dash_sdk::dpp::dashcore::Address;
use std::sync::{Arc, RwLock};
Expand Down
53 changes: 47 additions & 6 deletions src/backend_task/document.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::backend_task::BackendTaskSuccessResult;
use crate::context::AppContext;
use dash_sdk::platform::{Document, DocumentQuery, FetchMany};
use dash_sdk::platform::proto::get_documents_request::get_documents_request_v0::Start;
use dash_sdk::platform::{Document, DocumentQuery, FetchMany, Identifier};
use dash_sdk::query_types::IndexMap;
use dash_sdk::Sdk;

pub type DocumentTypeName = String;
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum DocumentTask {
FetchDocuments(DocumentQuery),
FetchDocumentsPage(DocumentQuery),
}

impl AppContext {
Expand All @@ -16,10 +18,49 @@ impl AppContext {
sdk: &Sdk,
) -> Result<BackendTaskSuccessResult, String> {
match task {
DocumentTask::FetchDocuments(drive_query) => Document::fetch_many(sdk, drive_query)
.await
.map(BackendTaskSuccessResult::Documents)
.map_err(|e| e.to_string()),
DocumentTask::FetchDocuments(document_query) => {
Document::fetch_many(sdk, document_query)
.await
.map(BackendTaskSuccessResult::Documents)
.map_err(|e| format!("Error fetching documents: {}", e.to_string()))
}
DocumentTask::FetchDocumentsPage(mut document_query) => {
// Set the limit for each page
document_query.limit = 100;

// Initialize an empty IndexMap to accumulate documents for this page
let mut page_docs: IndexMap<Identifier, Option<Document>> = IndexMap::new();

// Fetch a single page
let docs_batch_result = Document::fetch_many(sdk, document_query.clone())
.await
.map_err(|e| format!("Error fetching documents: {}", e))?;

let batch_len = docs_batch_result.len();

// Insert the batch into the page map
for (id, doc_opt) in docs_batch_result {
page_docs.insert(id, doc_opt);
}

// Determine if there's a next page
let has_next_page = batch_len == 100;

// If there's a next page, set the 'start' parameter for the next cursor
let next_cursor = if has_next_page {
page_docs.keys().last().cloned().map(|last_doc_id| {
let id_bytes = last_doc_id.to_buffer();
Start::StartAfter(id_bytes.to_vec())
})
} else {
None
};

Ok(BackendTaskSuccessResult::PageDocuments(
page_docs,
next_cursor,
))
}
}
}
}
24 changes: 18 additions & 6 deletions src/backend_task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ use crate::backend_task::withdrawal_statuses::{WithdrawStatusPartialData, Withdr
use crate::context::AppContext;
use crate::model::qualified_identity::QualifiedIdentity;
use contested_names::ScheduledDPNSVote;
use dash_sdk::dpp::prelude::DataContract;
use dash_sdk::dpp::state_transition::StateTransition;
use dash_sdk::dpp::voting::votes::Vote;
use dash_sdk::query_types::Documents;
use dash_sdk::platform::proto::get_documents_request::get_documents_request_v0::Start;
use dash_sdk::platform::{Document, Identifier};
use dash_sdk::query_types::{Documents, IndexMap};
use std::sync::Arc;
use tokio::sync::mpsc;

pub mod broadcast_state_transition;
pub mod contested_names;
pub mod contract;
pub mod core;
mod document;
pub mod document;
pub mod identity;
pub mod withdrawal_statuses;

Expand All @@ -28,6 +33,7 @@ pub(crate) enum BackendTask {
ContestedResourceTask(ContestedResourceTask),
CoreTask(CoreTask),
WithdrawalTask(WithdrawalsTask),
BroadcastStateTransition(StateTransition),
}

#[derive(Debug, Clone, PartialEq)]
Expand All @@ -42,6 +48,9 @@ pub(crate) enum BackendTaskSuccessResult {
SuccessfulVotes(Vec<Vote>),
CastScheduledVote(ScheduledDPNSVote),
WithdrawalStatus(WithdrawStatusPartialData),
FetchedContract(DataContract),
FetchedContracts(Vec<Option<DataContract>>),
PageDocuments(IndexMap<Identifier, Option<Document>>, Option<Start>),
}

impl BackendTaskSuccessResult {}
Expand All @@ -65,10 +74,9 @@ impl AppContext {
) -> Result<BackendTaskSuccessResult, String> {
let sdk = self.sdk.clone();
match task {
BackendTask::ContractTask(contract_task) => self
.run_contract_task(contract_task, &sdk)
.await
.map(|_| BackendTaskSuccessResult::None),
BackendTask::ContractTask(contract_task) => {
self.run_contract_task(contract_task, &sdk).await
}
BackendTask::ContestedResourceTask(contested_resource_task) => {
self.run_contested_resource_task(contested_resource_task, &sdk, sender)
.await
Expand All @@ -83,6 +91,10 @@ impl AppContext {
BackendTask::WithdrawalTask(withdrawal_task) => {
self.run_withdraws_task(withdrawal_task, &sdk).await
}
BackendTask::BroadcastStateTransition(state_transition) => {
self.broadcast_state_transition(state_transition, &sdk)
.await
}
}
}
}
Loading

0 comments on commit bd70ef3

Please sign in to comment.