Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add logging and config to collectibles #3781

Merged
merged 4 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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 Cargo.lock

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

4 changes: 4 additions & 0 deletions applications/tari_collectibles/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ tauri-build = { version = "1.0.0-beta.4" }

[dependencies]
tari_app_grpc = { path = "../../tari_app_grpc" }
tari_app_utilities = { path = "../../tari_app_utilities" }
tari_common = { path = "../../../common" }
tari_common_types = { path = "../../../base_layer/common_types" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", branch = "main" }
tari_key_manager = { path = "../../../base_layer/key_manager" }
tari_mmr = { path = "../../../base_layer/mmr"}
tari_utilities = "*"
tari_dan_common_types = { path = "../../../dan_layer/common_types"}
log = { version = "0.4.8", features = ["std"] }

blake2 = "^0.9.0"
futures = "0.3.17"
Expand All @@ -38,6 +41,7 @@ uuid = { version = "0.8.2", features = ["serde"] }
prost = "0.9"
prost-types = "0.9"
structopt = "0.3.25"
tokio = { version = "1.11", features = ["signal"] }

[features]
default = [ "custom-protocol" ]
Expand Down
31 changes: 21 additions & 10 deletions applications/tari_collectibles/src-tauri/src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ use crate::{
clients::{BaseNodeClient, GrpcValidatorNodeClient, WalletClient},
error::CollectiblesError,
providers::ConcreteKeyManagerProvider,
settings::Settings,
storage::{
sqlite::{SqliteCollectiblesStorage, SqliteDbFactory},
StorageError,
},
};
use std::sync::Arc;
use std::{path::PathBuf, sync::Arc};

use tari_common::configuration::CollectiblesConfig;
use tauri::async_runtime::RwLock;
use uuid::Uuid;

pub struct AppState {
config: Settings,
config: CollectiblesConfig,
db_factory: SqliteDbFactory,
current_wallet_id: Option<Uuid>,
}
Expand All @@ -47,27 +47,38 @@ pub struct ConcurrentAppState {
}

impl ConcurrentAppState {
pub fn new() -> Self {
let settings = Settings::new();
let db_factory = SqliteDbFactory::new(settings.data_dir.as_path());
pub fn new(base_path: PathBuf, config: CollectiblesConfig) -> Self {
let db_factory = SqliteDbFactory::new(base_path.as_path());

Self {
inner: Arc::new(RwLock::new(AppState {
config,
db_factory,
config: settings,
current_wallet_id: None,
})),
}
}

pub async fn create_wallet_client(&self) -> WalletClient {
WalletClient::new(self.inner.read().await.config.wallet_grpc_address.clone())
WalletClient::new(
self
.inner
.read()
.await
.config
.wallet_grpc_address
.clone()
.to_string(),
)
}

pub async fn connect_base_node_client(&self) -> Result<BaseNodeClient, CollectiblesError> {
let lock = self.inner.read().await;
let client =
BaseNodeClient::connect(format!("http://{}", lock.config.base_node_grpc_address)).await?;
let client = BaseNodeClient::connect(format!(
"http://{}",
lock.config.base_node_grpc_address.to_string()
))
.await?;
Ok(client)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@

use crate::error::CollectiblesError;
use futures::StreamExt;
use log::debug;
use tari_app_grpc::tari_rpc as grpc;
use tari_common_types::types::PublicKey;
use tari_utilities::ByteArray;

const LOG_TARGET: &str = "collectibles::base";

pub struct BaseNodeClient {
client: grpc::base_node_client::BaseNodeClient<tonic::transport::Channel>,
}
Expand Down Expand Up @@ -79,7 +82,7 @@ impl BaseNodeClient {
let request = grpc::GetAssetMetadataRequest {
asset_public_key: Vec::from(asset_public_key.as_bytes()),
};
dbg!(&request);
debug!(target: LOG_TARGET, "request {:?}", request);
let response = client
.get_asset_metadata(request)
.await
Expand All @@ -88,7 +91,7 @@ impl BaseNodeClient {
request: "get_asset_metadata".to_string(),
source: s,
})?;
dbg!(&response);
debug!(target: LOG_TARGET, "response {:?}", response);
Ok(response)
}

Expand All @@ -103,7 +106,7 @@ impl BaseNodeClient {
unique_ids: vec![vec![3u8; 32]],
};

dbg!(&request);
debug!(target: LOG_TARGET, "request {:?}", request);
let mut stream = client
.get_tokens(request)
.await
Expand All @@ -117,7 +120,7 @@ impl BaseNodeClient {
if i > 10 {
break;
}
dbg!(&response);
debug!(target: LOG_TARGET, "response {:?}", response);
let features = response
.map_err(|status| format!("Got an error status from GRPC:{}", status))?
.features;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
use crate::error::CollectiblesError;
use log::{debug, error};
use tari_app_grpc::tari_rpc as grpc;
use tari_common_types::types::PublicKey;
use tari_utilities::ByteArray;

const LOG_TARGET: &str = "collectibles::validator_node";

pub trait ValidatorNodeClient {}

pub struct GrpcValidatorNodeClient {
Expand Down Expand Up @@ -57,21 +60,21 @@ impl GrpcValidatorNodeClient {
method,
args,
};
dbg!(&req);
debug!(target: LOG_TARGET, "req {:?}", req);
let response = self
.client
.invoke_read_method(req)
.await
.map(|resp| resp.into_inner())
.map_err(|e| {
dbg!(&e);
error!(target: LOG_TARGET, "{}", e);

CollectiblesError::ClientRequestError {
source: e,
request: "invoke_read_method".to_string(),
}
})?;
dbg!(&response);
debug!(target: LOG_TARGET, "response {:?}", response);
Ok(response.result)
}

Expand All @@ -88,21 +91,21 @@ impl GrpcValidatorNodeClient {
method,
args,
};
dbg!(&req);
debug!(target: LOG_TARGET, "req {:?}", req);
let response = self
.client
.invoke_method(req)
.await
.map(|resp| resp.into_inner())
.map_err(|e| {
dbg!(&e);
error!(target: LOG_TARGET, "{}", e);

CollectiblesError::ClientRequestError {
source: e,
request: "invoke_method".to_string(),
}
})?;
dbg!(&response);
debug!(target: LOG_TARGET, "response {:?}", response);
Ok(response.result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use crate::error::CollectiblesError;
use log::debug;
use tari_app_grpc::{tari_rpc as grpc, tari_rpc::RegisterAssetRequest};
use tari_common_types::types::PublicKey;
use tari_utilities::{hex::Hex, ByteArray};

const LOG_TARGET: &str = "collectibles::wallet";

pub struct WalletClient {
endpoint: String,
inner: Option<grpc::wallet_client::WalletClient<tonic::transport::Channel>>,
Expand Down Expand Up @@ -76,7 +79,7 @@ impl WalletClient {
source: error,
}
})?;
dbg!(&result);
debug!(target: LOG_TARGET, "result {:?}", result);
Ok(result.into_inner().public_key.to_hex())
}

Expand All @@ -91,7 +94,7 @@ impl WalletClient {
source,
}
})?;
dbg!(&result);
debug!(target: LOG_TARGET, "result {:?}", result);
Ok(result.into_inner())
}

Expand All @@ -117,7 +120,7 @@ impl WalletClient {
request: "create_initial_asset_checkpoint".to_string(),
source,
})?;
dbg!(&result);
debug!(target: LOG_TARGET, "result {:?}", result);
Ok(result.into_inner())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ use crate::{
StorageTransaction,
},
};
use log::{debug, error};
use prost::Message;
use tari_common_types::types::PublicKey;
use tari_dan_common_types::proto::tips::tip002;
use tari_utilities::{hex::Hex, ByteArray};
use tauri::Manager;
use uuid::Uuid;

const LOG_TARGET: &str = "collectibles::asset_wallets";

#[tauri::command]
pub(crate) async fn asset_wallets_create(
asset_public_key: String,
Expand Down Expand Up @@ -84,7 +87,7 @@ pub(crate) async fn asset_wallets_create(
}
}
Err(e) => {
dbg!(e);
error!(target: LOG_TARGET, "{}", e);
None
}
};
Expand Down Expand Up @@ -121,7 +124,10 @@ pub(crate) async fn asset_wallets_get_balance(
asset_public_key: String,
state: tauri::State<'_, ConcurrentAppState>,
) -> Result<u64, Status> {
dbg!(&asset_public_key);
debug!(
target: LOG_TARGET,
"asset_public_key {:?}", asset_public_key
);
let asset_public_key = PublicKey::from_hex(&asset_public_key)?;

let wallet_id = state
Expand All @@ -143,7 +149,7 @@ pub(crate) async fn asset_wallets_get_balance(
let args = tip002::BalanceOfRequest {
owner: Vec::from(owner.public_key.as_bytes()),
};
dbg!(&args);
debug!(target: LOG_TARGET, "args {:?}", args);
let mut args_bytes = vec![];
args.encode(&mut args_bytes)?;
// let req = grpc::InvokeReadMethodRequest{
Expand All @@ -162,7 +168,7 @@ pub(crate) async fn asset_wallets_get_balance(
)
.await?;

dbg!(&resp);
debug!(target: LOG_TARGET, "resp {:?}", resp);
let proto_resp: tip002::BalanceOfResponse = Message::decode(&*resp)?;
total += proto_resp.balance;
}
Expand Down Expand Up @@ -219,7 +225,7 @@ pub(crate) async fn asset_wallets_create_address(
public_key: address_public_key,
key_manager_path,
};
dbg!(&address);
debug!(target: LOG_TARGET, "address {:?}", address);
db.addresses().insert(&address, &transaction)?;
transaction.commit()?;
Ok(address)
Expand Down Expand Up @@ -295,6 +301,6 @@ pub(crate) async fn asset_wallets_send_to(
.invoke_method(asset_public_key, 2, "transfer".to_string(), args_bytes)
.await?;

dbg!(&resp);
debug!(target: LOG_TARGET, "resp {:?}", resp);
Ok(())
}
Loading