diff --git a/.github/workflows/build_dockers_workflow.yml b/.github/workflows/build_dockers_workflow.yml index 39edcb316..a33e5a3e8 100644 --- a/.github/workflows/build_dockers_workflow.yml +++ b/.github/workflows/build_dockers_workflow.yml @@ -102,7 +102,7 @@ jobs: - name: Docker image build and push id: docker_build - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . file: ./docker_rig/${{ env.IMAGE_NAME }}.Dockerfile diff --git a/applications/tari_dan_wallet_daemon/src/handlers/substates.rs b/applications/tari_dan_wallet_daemon/src/handlers/substates.rs index 640b426a2..21754b3a0 100644 --- a/applications/tari_dan_wallet_daemon/src/handlers/substates.rs +++ b/applications/tari_dan_wallet_daemon/src/handlers/substates.rs @@ -47,19 +47,22 @@ pub async fn handle_list( let sdk = context.wallet_sdk().clone(); sdk.jwt_api().check_auth(token, &[JrpcPermission::SubstatesRead])?; - // TODO: pagination - let substates = - sdk.substate_api() - .list_substates(req.filter_by_type, req.filter_by_template.as_ref(), None, None)?; + let result = sdk + .get_network_interface() + .list_substates(req.filter_by_template, req.filter_by_type, req.limit, req.offset) + .await?; - let substates = substates + let substates = result + .substates .into_iter() - .map(|substate| WalletSubstateRecord { - substate_id: substate.address.substate_id, - parent_id: substate.parent_address, - version: substate.address.version, - template_address: substate.template_address, - module_name: substate.module_name, + // TODO: should also add the "timestamp" and "type" fields from the indexer list items? + .map(|s| WalletSubstateRecord { + substate_id: s.substate_id, + // TODO: should we remove the "parent_id" field from the wallet API? is it really needed somewhere? + parent_id: None, + version: s.version, + template_address: s.template_address, + module_name: s.module_name, }) .collect(); diff --git a/applications/tari_dan_wallet_daemon/src/indexer_jrpc_impl.rs b/applications/tari_dan_wallet_daemon/src/indexer_jrpc_impl.rs index 7474aa6c9..a5472d270 100644 --- a/applications/tari_dan_wallet_daemon/src/indexer_jrpc_impl.rs +++ b/applications/tari_dan_wallet_daemon/src/indexer_jrpc_impl.rs @@ -5,8 +5,10 @@ use std::sync::{Arc, Mutex}; use axum::async_trait; use reqwest::{IntoUrl, Url}; -use tari_dan_common_types::optional::IsNotFoundError; +use tari_dan_common_types::{optional::IsNotFoundError, substate_type::SubstateType}; use tari_dan_wallet_sdk::network::{ + SubstateListItem, + SubstateListResult, SubstateQueryResult, TransactionFinalizedResult, TransactionQueryResult, @@ -20,6 +22,8 @@ use tari_indexer_client::{ GetSubstateRequest, GetTransactionResultRequest, IndexerTransactionFinalizedResult, + ListSubstateItem, + ListSubstatesRequest, SubmitTransactionRequest, }, }; @@ -84,6 +88,45 @@ impl WalletNetworkInterface for IndexerJsonRpcNetworkInterface { }) } + async fn list_substates( + &self, + filter_by_template: Option, + filter_by_type: Option, + limit: Option, + offset: Option, + ) -> Result { + let mut client = self.get_client()?; + let result = client + .list_substates(ListSubstatesRequest { + filter_by_template, + filter_by_type, + limit, + offset, + }) + .await?; + let substates = result + .substates + .into_iter() + .map(|s| { + let ListSubstateItem { + substate_id, + module_name, + version, + template_address, + timestamp, + } = s; + SubstateListItem { + substate_id, + module_name, + version, + template_address, + timestamp, + } + }) + .collect(); + Ok(SubstateListResult { substates }) + } + async fn submit_transaction( &self, transaction: Transaction, diff --git a/applications/tari_indexer/src/substate_manager.rs b/applications/tari_indexer/src/substate_manager.rs index a7ad36475..d1fbd0113 100644 --- a/applications/tari_indexer/src/substate_manager.rs +++ b/applications/tari_indexer/src/substate_manager.rs @@ -25,10 +25,10 @@ use std::{convert::TryInto, sync::Arc}; use serde::{Deserialize, Serialize}; use tari_common_types::types::FixedHash; use tari_dan_app_utilities::substate_file_cache::SubstateFileCache; -use tari_dan_common_types::PeerAddress; +use tari_dan_common_types::{substate_type::SubstateType, PeerAddress}; use tari_engine_types::substate::{Substate, SubstateId}; use tari_epoch_manager::base_layer::EpochManagerHandle; -use tari_indexer_client::types::{ListSubstateItem, SubstateType}; +use tari_indexer_client::types::ListSubstateItem; use tari_indexer_lib::{substate_scanner::SubstateScanner, NonFungibleSubstate}; use tari_template_lib::models::TemplateAddress; use tari_transaction::TransactionId; diff --git a/applications/tari_indexer/src/substate_storage_sqlite/sqlite_substate_store_factory.rs b/applications/tari_indexer/src/substate_storage_sqlite/sqlite_substate_store_factory.rs index aabda07fd..427dc9bc5 100644 --- a/applications/tari_indexer/src/substate_storage_sqlite/sqlite_substate_store_factory.rs +++ b/applications/tari_indexer/src/substate_storage_sqlite/sqlite_substate_store_factory.rs @@ -38,11 +38,11 @@ use diesel::{ }; use diesel_migrations::{EmbeddedMigrations, MigrationHarness}; use log::*; -use tari_dan_common_types::{shard::Shard, Epoch}; +use tari_dan_common_types::{shard::Shard, substate_type::SubstateType, Epoch}; use tari_dan_storage::{consensus_models::BlockId, StorageError}; use tari_dan_storage_sqlite::{error::SqliteStorageError, SqliteTransaction}; use tari_engine_types::substate::SubstateId; -use tari_indexer_client::types::{ListSubstateItem, SubstateType}; +use tari_indexer_client::types::ListSubstateItem; use tari_template_lib::models::TemplateAddress; use tari_transaction::TransactionId; use thiserror::Error; diff --git a/applications/tari_swarm_daemon/src/process_definitions/definition.rs b/applications/tari_swarm_daemon/src/process_definitions/definition.rs index 520a97873..c5bd0035b 100644 --- a/applications/tari_swarm_daemon/src/process_definitions/definition.rs +++ b/applications/tari_swarm_daemon/src/process_definitions/definition.rs @@ -1,6 +1,8 @@ // Copyright 2024 The Tari Project // SPDX-License-Identifier: BSD-3-Clause +use std::path::PathBuf; + use async_trait::async_trait; use tokio::process::Command; @@ -9,4 +11,7 @@ use super::context::ProcessContext; #[async_trait] pub trait ProcessDefinition: Send { async fn get_command(&self, context: ProcessContext<'_>) -> anyhow::Result; + fn get_relative_data_path(&self) -> Option { + None + } } diff --git a/applications/tari_swarm_daemon/src/process_definitions/indexer.rs b/applications/tari_swarm_daemon/src/process_definitions/indexer.rs index f17e3b792..6df7d0d3b 100644 --- a/applications/tari_swarm_daemon/src/process_definitions/indexer.rs +++ b/applications/tari_swarm_daemon/src/process_definitions/indexer.rs @@ -1,6 +1,8 @@ // Copyright 2024 The Tari Project // SPDX-License-Identifier: BSD-3-Clause +use std::path::PathBuf; + use anyhow::anyhow; use async_trait::async_trait; use tokio::process::Command; @@ -54,4 +56,8 @@ impl ProcessDefinition for Indexer { Ok(command) } + + fn get_relative_data_path(&self) -> Option { + Some("data".into()) + } } diff --git a/applications/tari_swarm_daemon/src/process_definitions/minotari_node.rs b/applications/tari_swarm_daemon/src/process_definitions/minotari_node.rs index ba2d9293d..a8f7d4fdf 100644 --- a/applications/tari_swarm_daemon/src/process_definitions/minotari_node.rs +++ b/applications/tari_swarm_daemon/src/process_definitions/minotari_node.rs @@ -1,6 +1,8 @@ // Copyright 2024 The Tari Project // SPDX-License-Identifier: BSD-3-Clause +use std::path::PathBuf; + use async_trait::async_trait; use log::debug; use tokio::process::Command; @@ -63,7 +65,7 @@ impl ProcessDefinition for MinotariNode { Ok(command) } - // fn get_relative_data_path(&self) -> Option { - // Some(Path::new("network/data")) - // } + fn get_relative_data_path(&self) -> Option { + Some("data".into()) + } } diff --git a/applications/tari_swarm_daemon/src/process_definitions/minotari_wallet.rs b/applications/tari_swarm_daemon/src/process_definitions/minotari_wallet.rs index b12b32501..3b9eb32fc 100644 --- a/applications/tari_swarm_daemon/src/process_definitions/minotari_wallet.rs +++ b/applications/tari_swarm_daemon/src/process_definitions/minotari_wallet.rs @@ -1,6 +1,8 @@ // Copyright 2024 The Tari Project // SPDX-License-Identifier: BSD-3-Clause +use std::path::PathBuf; + use anyhow::anyhow; use async_trait::async_trait; use log::*; @@ -65,4 +67,8 @@ impl ProcessDefinition for MinotariWallet { Ok(command) } + + fn get_relative_data_path(&self) -> Option { + Some("data".into()) + } } diff --git a/applications/tari_swarm_daemon/src/process_definitions/validator_node.rs b/applications/tari_swarm_daemon/src/process_definitions/validator_node.rs index c25061f62..a0f82e8c9 100644 --- a/applications/tari_swarm_daemon/src/process_definitions/validator_node.rs +++ b/applications/tari_swarm_daemon/src/process_definitions/validator_node.rs @@ -1,6 +1,8 @@ // Copyright 2024 The Tari Project // SPDX-License-Identifier: BSD-3-Clause +use std::path::PathBuf; + use anyhow::anyhow; use async_trait::async_trait; use log::debug; @@ -63,4 +65,8 @@ impl ProcessDefinition for ValidatorNode { Ok(command) } + + fn get_relative_data_path(&self) -> Option { + Some("data".into()) + } } diff --git a/applications/tari_swarm_daemon/src/process_definitions/wallet_daemon.rs b/applications/tari_swarm_daemon/src/process_definitions/wallet_daemon.rs index aa0e02abf..2b66e88d3 100644 --- a/applications/tari_swarm_daemon/src/process_definitions/wallet_daemon.rs +++ b/applications/tari_swarm_daemon/src/process_definitions/wallet_daemon.rs @@ -1,6 +1,8 @@ // Copyright 2024 The Tari Project // SPDX-License-Identifier: BSD-3-Clause +use std::path::PathBuf; + use anyhow::anyhow; use async_trait::async_trait; use tokio::process::Command; @@ -69,4 +71,8 @@ impl ProcessDefinition for WalletDaemon { Ok(command) } + + fn get_relative_data_path(&self) -> Option { + Some("data".into()) + } } diff --git a/applications/tari_swarm_daemon/src/process_manager/handle.rs b/applications/tari_swarm_daemon/src/process_manager/handle.rs index 1cda16a1d..bfe273700 100644 --- a/applications/tari_swarm_daemon/src/process_manager/handle.rs +++ b/applications/tari_swarm_daemon/src/process_manager/handle.rs @@ -33,6 +33,10 @@ pub enum ProcessManagerRequest { instance_id: InstanceId, reply: Reply<()>, }, + DeleteInstanceData { + instance_id: InstanceId, + reply: Reply<()>, + }, MineBlocks { blocks: u64, reply: Reply<()>, @@ -200,6 +204,18 @@ impl ProcessManagerHandle { rx_reply.await? } + pub async fn delete_instance_data(&self, instance_id: InstanceId) -> anyhow::Result<()> { + let (tx_reply, rx_reply) = oneshot::channel(); + self.tx_request + .send(ProcessManagerRequest::DeleteInstanceData { + instance_id, + reply: tx_reply, + }) + .await?; + + rx_reply.await? + } + pub async fn register_validator_node(&self, instance_id: InstanceId) -> anyhow::Result<()> { let (tx_reply, rx_reply) = oneshot::channel(); self.tx_request diff --git a/applications/tari_swarm_daemon/src/process_manager/instances/manager.rs b/applications/tari_swarm_daemon/src/process_manager/instances/manager.rs index 82c82eaf9..75dde04c9 100644 --- a/applications/tari_swarm_daemon/src/process_manager/instances/manager.rs +++ b/applications/tari_swarm_daemon/src/process_manager/instances/manager.rs @@ -10,6 +10,7 @@ use std::{ }; use anyhow::anyhow; +use log::info; use tari_common::configuration::Network; use tokio::{ fs, @@ -300,6 +301,26 @@ impl InstanceManager { Ok(()) } + pub async fn delete_instance_data(&mut self, id: InstanceId) -> anyhow::Result<()> { + let instance = self + .instances_mut() + .find(|i| i.id() == id) + .ok_or_else(|| anyhow!("Instance not found"))?; + + let definition = get_definition(instance.instance_type()); + + if let Some(data_path) = definition.get_relative_data_path() { + let path = instance.base_path().join(data_path); + info!( + "Deleting data directory for instance {}: {}", + instance.name(), + path.display() + ); + fs::remove_dir_all(path).await?; + } + Ok(()) + } + pub fn instances_mut(&mut self) -> impl Iterator { self.minotari_nodes .values_mut() diff --git a/applications/tari_swarm_daemon/src/process_manager/manager.rs b/applications/tari_swarm_daemon/src/process_manager/manager.rs index 28c906230..ec2b3a810 100644 --- a/applications/tari_swarm_daemon/src/process_manager/manager.rs +++ b/applications/tari_swarm_daemon/src/process_manager/manager.rs @@ -150,6 +150,12 @@ impl ProcessManager { log::warn!("Request cancelled before response could be sent") } }, + DeleteInstanceData { instance_id, reply } => { + let result = self.instance_manager.delete_instance_data(instance_id).await; + if reply.send(result).is_err() { + log::warn!("Request cancelled before response could be sent") + } + }, MineBlocks { blocks, reply } => { let result = self.mine(blocks).await; if reply.send(result).is_err() { diff --git a/applications/tari_swarm_daemon/src/webserver/rpc/instances.rs b/applications/tari_swarm_daemon/src/webserver/rpc/instances.rs index dc8bee3e8..054167539 100644 --- a/applications/tari_swarm_daemon/src/webserver/rpc/instances.rs +++ b/applications/tari_swarm_daemon/src/webserver/rpc/instances.rs @@ -104,3 +104,35 @@ pub async fn list(context: &HandlerContext, req: ListInstancesRequest) -> Result instances: instances.into_iter().map(Into::into).collect(), }) } + +#[derive(Debug, Clone, Deserialize)] +pub struct DeleteInstanceDataRequest { + pub name: String, +} + +#[derive(Debug, Clone, Serialize)] +pub struct DeleteInstanceDataResponse { + pub success: bool, +} + +pub async fn delete_data( + context: &HandlerContext, + req: DeleteInstanceDataRequest, +) -> Result { + let instance = context + .process_manager() + .get_instance_by_name(req.name) + .await? + .ok_or_else(|| { + JsonRpcError::new( + JsonRpcErrorReason::ApplicationError(404), + "Instance not found".to_string(), + serde_json::Value::Null, + ) + })?; + + context.process_manager().stop_instance(instance.id).await?; + context.process_manager().delete_instance_data(instance.id).await?; + + Ok(DeleteInstanceDataResponse { success: true }) +} diff --git a/applications/tari_swarm_daemon/src/webserver/server.rs b/applications/tari_swarm_daemon/src/webserver/server.rs index 1eae7a5a2..6cecd9de7 100644 --- a/applications/tari_swarm_daemon/src/webserver/server.rs +++ b/applications/tari_swarm_daemon/src/webserver/server.rs @@ -110,6 +110,7 @@ async fn json_rpc_handler(Extension(context): Extension>, va "start" => call_handler(context, value, rpc::instances::start).await, "stop" => call_handler(context, value, rpc::instances::stop).await, "list_instances" => call_handler(context, value, rpc::instances::list).await, + "delete_data" => call_handler(context, value, rpc::instances::delete_data).await, _ => Ok(value.method_not_found(&value.method)), } } diff --git a/applications/tari_swarm_daemon/webui/src/routes/Main.tsx b/applications/tari_swarm_daemon/webui/src/routes/Main.tsx index 3ce74d067..415736ae8 100644 --- a/applications/tari_swarm_daemon/webui/src/routes/Main.tsx +++ b/applications/tari_swarm_daemon/webui/src/routes/Main.tsx @@ -172,27 +172,23 @@ function ExtraInfoVN({name, url, setRow, addTxToPool, autoRefresh, state, horizo return (<>

Pool transaction

-
- Tx Id - Ready - Local_Decision - Remote_Decision - Stage - {pool.map((tx) => ( - <> -
copyToClipboard(tx.transaction.id)}>{copied && "Copied" || shorten(tx.transaction.id)}
-
{tx.is_ready && "Yes" || "No"}
-
{tx.local_decision || "_"}
-
{tx.remote_decision || "_"}
-
{tx.stage}
- ))} -
+ + + + + + + + {pool.map(({atom}, i) => ( + + + + + + ))} +
Tx IdReadyDecisionStage
copyToClipboard(atom.id)}>{copied && "Copied" || shorten(atom.id)}{atom.is_ready && "Yes" || "No"}{atom.decision || "_"}{atom.stage}
); }; @@ -302,7 +298,7 @@ function ShowInfo(params: any) { }; const handleDeleteData = () => { - console.log("Sorry not implemented"); + jsonRpc("delete_data", {name}).then(onReload); }; diff --git a/bindings/src/types/tari-indexer-client/ListSubstatesRequest.ts b/bindings/src/types/tari-indexer-client/ListSubstatesRequest.ts index 6adf828ca..44b339b16 100644 --- a/bindings/src/types/tari-indexer-client/ListSubstatesRequest.ts +++ b/bindings/src/types/tari-indexer-client/ListSubstatesRequest.ts @@ -1,5 +1,5 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -import type { SubstateType } from "./SubstateType"; +import type { SubstateType } from "../SubstateType"; export interface ListSubstatesRequest { filter_by_template: string | null; diff --git a/bindings/src/types/tari-indexer-client/SubstateType.ts b/bindings/src/types/tari-indexer-client/SubstateType.ts deleted file mode 100644 index 72e7c5a85..000000000 --- a/bindings/src/types/tari-indexer-client/SubstateType.ts +++ /dev/null @@ -1,10 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -export type SubstateType = - | "Component" - | "Resource" - | "Vault" - | "UnclaimedConfidentialOutput" - | "NonFungible" - | "TransactionReceipt" - | "FeeClaim"; diff --git a/bindings/src/types/wallet-daemon-client/SubstatesListRequest.ts b/bindings/src/types/wallet-daemon-client/SubstatesListRequest.ts index fd8e5a310..15620e1e1 100644 --- a/bindings/src/types/wallet-daemon-client/SubstatesListRequest.ts +++ b/bindings/src/types/wallet-daemon-client/SubstatesListRequest.ts @@ -4,4 +4,6 @@ import type { SubstateType } from "../SubstateType"; export interface SubstatesListRequest { filter_by_template: string | null; filter_by_type: SubstateType | null; + limit: bigint | null; + offset: bigint | null; } diff --git a/bindings/tari-indexer-client.ts b/bindings/tari-indexer-client.ts index 4d3719552..105eea636 100644 --- a/bindings/tari-indexer-client.ts +++ b/bindings/tari-indexer-client.ts @@ -21,7 +21,6 @@ export * from "./src/types/tari-indexer-client/GetNonFungibleCountRequest"; export * from "./src/types/tari-indexer-client/GetTransactionResultRequest"; export * from "./src/types/tari-indexer-client/GetRelatedTransactionsResponse"; export * from "./src/types/tari-indexer-client/GetNonFungiblesResponse"; -export * from "./src/types/tari-indexer-client/SubstateType"; export * from "./src/types/tari-indexer-client/GetRelatedTransactionsRequest"; export * from "./src/types/tari-indexer-client/GetEpochManagerStatsResponse"; export * from "./src/types/tari-indexer-client/AddPeerRequest"; diff --git a/clients/tari_indexer_client/src/json_rpc_client.rs b/clients/tari_indexer_client/src/json_rpc_client.rs index ad7ed4817..2440e76c7 100644 --- a/clients/tari_indexer_client/src/json_rpc_client.rs +++ b/clients/tari_indexer_client/src/json_rpc_client.rs @@ -39,6 +39,8 @@ use crate::{ GetTemplateDefinitionResponse, GetTransactionResultRequest, GetTransactionResultResponse, + ListSubstatesRequest, + ListSubstatesResponse, SubmitTransactionRequest, SubmitTransactionResponse, }, @@ -81,6 +83,13 @@ impl IndexerJsonRpcClient { self.send_request("get_substate", req).await } + pub async fn list_substates( + &mut self, + req: ListSubstatesRequest, + ) -> Result { + self.send_request("list_substates", req).await + } + pub async fn submit_transaction( &mut self, req: SubmitTransactionRequest, diff --git a/clients/tari_indexer_client/src/types.rs b/clients/tari_indexer_client/src/types.rs index 623d30e4d..a4582026b 100644 --- a/clients/tari_indexer_client/src/types.rs +++ b/clients/tari_indexer_client/src/types.rs @@ -9,7 +9,7 @@ use serde_json::Value as JsonValue; use serde_with::{serde_as, DisplayFromStr}; use tari_base_node_client::types::BaseLayerValidatorNode; use tari_common_types::types::{FixedHash, PublicKey}; -use tari_dan_common_types::Epoch; +use tari_dan_common_types::{substate_type::SubstateType, Epoch}; use tari_dan_storage::consensus_models::Decision; use tari_engine_types::{ commit_result::ExecuteResult, @@ -22,36 +22,6 @@ use tari_transaction::{SubstateRequirement, Transaction, TransactionId}; #[cfg(feature = "ts")] use ts_rs::TS; -#[derive(Debug, Clone, Copy, Deserialize, Serialize)] -#[cfg_attr( - feature = "ts", - derive(ts_rs::TS), - ts(export, export_to = "../../bindings/src/types/tari-indexer-client/") -)] -pub enum SubstateType { - Component, - Resource, - Vault, - UnclaimedConfidentialOutput, - NonFungible, - TransactionReceipt, - FeeClaim, -} - -impl SubstateType { - pub fn as_prefix_str(&self) -> &str { - match self { - SubstateType::Component => "component", - SubstateType::Resource => "resource", - SubstateType::Vault => "vault", - SubstateType::UnclaimedConfidentialOutput => "commitment", - SubstateType::NonFungible => "nft", - SubstateType::TransactionReceipt => "txreceipt", - SubstateType::FeeClaim => "feeclaim", - } - } -} - #[derive(Debug, Clone, Deserialize, Serialize)] #[cfg_attr( feature = "ts", diff --git a/clients/wallet_daemon_client/src/types.rs b/clients/wallet_daemon_client/src/types.rs index add008ae2..2be9be5b1 100644 --- a/clients/wallet_daemon_client/src/types.rs +++ b/clients/wallet_daemon_client/src/types.rs @@ -29,10 +29,10 @@ use std::{collections::HashMap, time::Duration}; use chrono::NaiveDateTime; use serde::{Deserialize, Serialize}; use tari_common_types::types::PublicKey; -use tari_dan_common_types::{Epoch, SubstateAddress}; +use tari_dan_common_types::{substate_type::SubstateType, Epoch, SubstateAddress}; use tari_dan_wallet_sdk::{ apis::{confidential_transfer::ConfidentialTransferInputSelection, jwt::Claims, key_manager}, - models::{Account, ConfidentialProofId, NonFungibleToken, SubstateType, TransactionStatus}, + models::{Account, ConfidentialProofId, NonFungibleToken, TransactionStatus}, }; use tari_engine_types::{ commit_result::{ExecuteResult, FinalizeResult}, @@ -1095,6 +1095,8 @@ pub struct SubstatesListRequest { #[cfg_attr(feature = "ts", ts(type = "string | null"))] pub filter_by_template: Option, pub filter_by_type: Option, + pub limit: Option, + pub offset: Option, } #[derive(Debug, Clone, Deserialize, Serialize)] diff --git a/dan_layer/common_types/src/lib.rs b/dan_layer/common_types/src/lib.rs index 476a27dac..757d3cc19 100644 --- a/dan_layer/common_types/src/lib.rs +++ b/dan_layer/common_types/src/lib.rs @@ -27,6 +27,8 @@ pub mod services; mod substate_address; pub use substate_address::SubstateAddress; +pub mod substate_type; + mod peer_address; pub use peer_address::*; pub mod uint; diff --git a/dan_layer/common_types/src/substate_type.rs b/dan_layer/common_types/src/substate_type.rs new file mode 100644 index 000000000..76b1ddc75 --- /dev/null +++ b/dan_layer/common_types/src/substate_type.rs @@ -0,0 +1,34 @@ +// Copyright 2024 The Tari Project +// SPDX-License-Identifier: BSD-3-Clause + +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Copy, Deserialize, Serialize)] +#[cfg_attr( + feature = "ts", + derive(ts_rs::TS), + ts(export, export_to = "../../bindings/src/types/") +)] +pub enum SubstateType { + Component, + Resource, + Vault, + UnclaimedConfidentialOutput, + NonFungible, + TransactionReceipt, + FeeClaim, +} + +impl SubstateType { + pub fn as_prefix_str(&self) -> &str { + match self { + SubstateType::Component => "component", + SubstateType::Resource => "resource", + SubstateType::Vault => "vault", + SubstateType::UnclaimedConfidentialOutput => "commitment", + SubstateType::NonFungible => "nft", + SubstateType::TransactionReceipt => "txreceipt", + SubstateType::FeeClaim => "feeclaim", + } + } +} diff --git a/dan_layer/wallet/sdk/src/apis/substate.rs b/dan_layer/wallet/sdk/src/apis/substate.rs index fb75dbd54..d30c4c5d1 100644 --- a/dan_layer/wallet/sdk/src/apis/substate.rs +++ b/dan_layer/wallet/sdk/src/apis/substate.rs @@ -4,7 +4,10 @@ use std::collections::HashMap; use log::*; -use tari_dan_common_types::optional::{IsNotFoundError, Optional}; +use tari_dan_common_types::{ + optional::{IsNotFoundError, Optional}, + substate_type::SubstateType, +}; use tari_engine_types::{ indexed_value::{IndexedValueError, IndexedWellKnownTypes}, substate::{SubstateId, SubstateValue}, @@ -14,7 +17,7 @@ use tari_engine_types::{ use tari_transaction::TransactionId; use crate::{ - models::{SubstateModel, SubstateType, VersionedSubstateId}, + models::{SubstateModel, VersionedSubstateId}, network::WalletNetworkInterface, storage::{WalletStorageError, WalletStore, WalletStoreReader, WalletStoreWriter}, }; diff --git a/dan_layer/wallet/sdk/src/models/substate.rs b/dan_layer/wallet/sdk/src/models/substate.rs index b6c1259b7..b9fa54a91 100644 --- a/dan_layer/wallet/sdk/src/models/substate.rs +++ b/dan_layer/wallet/sdk/src/models/substate.rs @@ -17,36 +17,6 @@ pub struct SubstateModel { pub template_address: Option, } -#[derive(Debug, Clone, Copy, Deserialize, Serialize)] -#[cfg_attr( - feature = "ts", - derive(ts_rs::TS), - ts(export, export_to = "../../bindings/src/types/") -)] -pub enum SubstateType { - Component, - Resource, - Vault, - UnclaimedConfidentialOutput, - NonFungible, - TransactionReceipt, - FeeClaim, -} - -impl SubstateType { - pub fn as_prefix_str(&self) -> &str { - match self { - SubstateType::Component => "component", - SubstateType::Resource => "resource", - SubstateType::Vault => "vault", - SubstateType::UnclaimedConfidentialOutput => "commitment", - SubstateType::NonFungible => "nft", - SubstateType::TransactionReceipt => "txreceipt", - SubstateType::FeeClaim => "feeclaim", - } - } -} - #[derive(Debug, Clone, Deserialize, Serialize)] pub struct VersionedSubstateId { #[serde(with = "serde_with::string")] diff --git a/dan_layer/wallet/sdk/src/network.rs b/dan_layer/wallet/sdk/src/network.rs index 8e1db401c..fe729b73d 100644 --- a/dan_layer/wallet/sdk/src/network.rs +++ b/dan_layer/wallet/sdk/src/network.rs @@ -6,6 +6,7 @@ use std::time::Duration; use async_trait::async_trait; use serde::{Deserialize, Serialize}; use serde_json::Value; +use tari_dan_common_types::substate_type::SubstateType; use tari_dan_storage::consensus_models::Decision; use tari_engine_types::{ commit_result::ExecuteResult, @@ -26,6 +27,14 @@ pub trait WalletNetworkInterface { local_search_only: bool, ) -> Result; + async fn list_substates( + &self, + filter_by_template: Option, + filter_by_type: Option, + limit: Option, + offset: Option, + ) -> Result; + async fn submit_transaction( &self, transaction: Transaction, @@ -54,6 +63,20 @@ pub struct SubstateQueryResult { pub created_by_transaction: TransactionId, } +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct SubstateListResult { + pub substates: Vec, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct SubstateListItem { + pub substate_id: SubstateId, + pub module_name: Option, + pub version: u32, + pub template_address: Option, + pub timestamp: u64, +} + #[derive(Debug, Clone, Deserialize, Serialize)] pub struct TransactionQueryResult { pub result: TransactionFinalizedResult, diff --git a/dan_layer/wallet/sdk/src/storage.rs b/dan_layer/wallet/sdk/src/storage.rs index 6be3582a2..eeafde31d 100644 --- a/dan_layer/wallet/sdk/src/storage.rs +++ b/dan_layer/wallet/sdk/src/storage.rs @@ -7,7 +7,7 @@ use std::{ }; use tari_common_types::types::Commitment; -use tari_dan_common_types::optional::IsNotFoundError; +use tari_dan_common_types::{optional::IsNotFoundError, substate_type::SubstateType}; use tari_dan_storage::consensus_models::QuorumCertificate; use tari_engine_types::{commit_result::FinalizeResult, substate::SubstateId, TemplateAddress}; use tari_template_lib::{ @@ -25,7 +25,6 @@ use crate::models::{ NonFungibleToken, OutputStatus, SubstateModel, - SubstateType, TransactionStatus, VaultModel, VersionedSubstateId, diff --git a/dan_layer/wallet/sdk/tests/confidential_output_api.rs b/dan_layer/wallet/sdk/tests/confidential_output_api.rs index ade16ea14..9376f7d50 100644 --- a/dan_layer/wallet/sdk/tests/confidential_output_api.rs +++ b/dan_layer/wallet/sdk/tests/confidential_output_api.rs @@ -269,4 +269,14 @@ impl WalletNetworkInterface for PanicIndexer { async fn fetch_template_definition(&self, _template_address: TemplateAddress) -> Result { panic!("PanicIndexer called") } + + async fn list_substates( + &self, + _filter_by_template: Option, + _filter_by_type: Option, + _limit: Option, + _offset: Option, + ) -> Result { + panic!("PanicIndexer called") + } } diff --git a/dan_layer/wallet/storage_sqlite/src/reader.rs b/dan_layer/wallet/storage_sqlite/src/reader.rs index 8ea1b375b..6de72e07d 100644 --- a/dan_layer/wallet/storage_sqlite/src/reader.rs +++ b/dan_layer/wallet/storage_sqlite/src/reader.rs @@ -18,6 +18,7 @@ use diesel::{ use log::error; use serde::de::DeserializeOwned; use tari_common_types::types::Commitment; +use tari_dan_common_types::substate_type::SubstateType; use tari_dan_wallet_sdk::{ models::{ Account, @@ -27,7 +28,6 @@ use tari_dan_wallet_sdk::{ NonFungibleToken, OutputStatus, SubstateModel, - SubstateType, TransactionStatus, VaultModel, WalletTransaction,