Skip to content

Commit

Permalink
Merge branch 'oreoslabs:developer' into developer
Browse files Browse the repository at this point in the history
  • Loading branch information
dguenther authored Feb 7, 2025
2 parents 6ae1a69 + 46d8a28 commit 6a9342c
Show file tree
Hide file tree
Showing 51 changed files with 1,757 additions and 1,776 deletions.
Binary file removed .DS_Store
Binary file not shown.
1,104 changes: 370 additions & 734 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
resolver = "2"
members = [
"crates/networking",
"crates/constants",
"crates/db_handler",
"crates/oreo_errors",
"crates/server",
"crates/utils",
"crates/prover",
"crates/dworker",
"crates/dservice",
"crates/chain_loader", "crates/transfer-tool",
"crates/scanner",
"crates/params",
]
102 changes: 52 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
## 1. Overview

This repo consists of `chain_loader`, `dservice`, `dworker`, `server` and `prover`, is the core service of `OreoWallet`.

### 1.1 crates/server
Core service stores imported viewKeys from users and serves as data provider of OreoWallet.

### 1.2 crates/prover
Standalone service to generate zk proof for user transactions, serves as prover of OreoWallet.

### 1.3 crates/dservice
Quickscan server to schedule decryption tasks among all connected dworkers.

### 1.4 crates/dworker
Decryption worker connects to dservice and handles decryption tasks from dservice.

### 1.5 crates/chain_loader
A tool to fetch blocks from rpc and save in local db for better performance during dservice getBlocks.

## 2. Guide-level explanation

![basic arch](assets/arch_v2.png)

## Docker

Build

```bash
docker build -t oreowallet .
```

Run node:

```bash
ironfish start -d ~/.ironfish-testnet --rpc.http --rpc.http.port 9092 --rpc.http.host 0.0.0.0
```

Run

```bash
DB_USER=postgres \
DB_PASSWORD=postgres \
DB_PORT=5444 \
NODE_HOST=host.docker.internal \
NODE_PORT=9092 \
SECRET_KEY=a0882c5ac5e2fa771dde52b2d5639734a4411df14f4748c6f991a96e5dd9f997 \
PUBLIC_KEY=03221b2a0ebd9d6798aadee2861a5307ced1a33d143f34c571a98ab4fa534b7d3e \
SERVER_PORT=8080 \
docker-compose up
```
<p align="center">
<img src="assets/logo.svg" width="80" alt="Logo for OreoWallet" />
</p>

<h1 align="center">
OreoWallet-mono
</h1>

<p align="center">
A repository maintains backend/server-side components that power OreoWallet.
</p>

<div align="center">

[![Twitter Follow](https://img.shields.io/twitter/follow/oreowallet?style=social)](https://twitter.com/oreowallet)

</div>

## Introduction

There are 4 types wallet for privacy blockchain like IronFish.

- Type1: Cex wallet, fully-custodial wallet.
- Type2: PrivateKey is safely saved locally while viewkey is uploaded to a backend server for better experience. Transactions are signed locally while transaction decryption and utxos-indexing rely on customsized remote server.
- Type3: Both transaction decryption and creation are performed locally while transaction fetching/broadcasting rely on a public remote rpc like metamask.
- Type4: A wallet embedded with a full node, syncs blocks/transactions with P2P network directly.

OreoWallet aims to build an easy-to-use Type2 extension wallet for Ironfish blockchain. To make OreoWallet easy to use, we need server-side transaction indexing, quick-scanning and fast proof generation, and this repo maintains necessary components mentioned above.

## Features

| Feature | Status |
| ------------------------ | ------ |
| Account creation/import ||
| IRON native token ||
| User created asset ||
| Orescriptions NFT ||
| Dapp provider ||
| Local data provider ||
| Local prover ||
| Privacy on routing layer ||
| Quick scan ||
| ... | ... |

## Project structure
<pre>
OreoWallet
├── crates/server: OreoWallet data provider, stores viewkey in db and handles api service
├── crates/prover: OreoWallet prover, generate proof for IronFish transaction
├── crates/scanner: OreoWallet scanner, quick scanning service
├── crates/dworker: OreoWallet worker, running decryption taskes
</pre>
4 changes: 4 additions & 0 deletions assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 0 additions & 18 deletions crates/chain_loader/Cargo.toml

This file was deleted.

58 changes: 0 additions & 58 deletions crates/chain_loader/src/lib.rs

This file was deleted.

34 changes: 0 additions & 34 deletions crates/chain_loader/src/main.rs

This file was deleted.

8 changes: 0 additions & 8 deletions crates/constants/Cargo.toml

This file was deleted.

15 changes: 0 additions & 15 deletions crates/constants/src/lib.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/db_handler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ sqlx = { version = "0.7.0", features = ["runtime-tokio-rustls", "postgres"] }
substring = "1.4.5"
tracing = "0.1.40"
oreo_errors = { path = "../oreo_errors" }
constants = { path = "../constants" }
redis = { version = "0.25.2", features = [
"tokio-comp",
"tokio-native-tls-comp",
] }
params = { path = "../params" }

[dev-dependencies]
sqlx-db-tester = "0.4.0"
Expand Down
10 changes: 10 additions & 0 deletions crates/db_handler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use tracing::info;

use std::{fs, path::Path};

use crate::DBType;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DbConfig {
pub host: String,
Expand Down Expand Up @@ -44,6 +46,14 @@ impl DbConfig {
pub fn url(&self) -> String {
format!("{}/{}", self.server_url(), self.dbname)
}

pub fn protocol(&self) -> DBType {
match self.protocol.as_str() {
"postgres" => DBType::Postgres,
"redis" => DBType::Redis,
_ => DBType::Unknown,
}
}
}

impl DbConfig {
Expand Down
46 changes: 43 additions & 3 deletions crates/db_handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ mod config;
mod pg_handler;
mod redis_handler;

use std::{path::Path, str::FromStr};

use anyhow::anyhow;
pub use config::DbConfig;
use futures::executor::block_on;
pub use pg_handler::*;
pub use redis_handler::*;

pub use sqlx::types::Json;

use oreo_errors::OreoError;
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use sqlx::{postgres::PgConnectOptions, ConnectOptions, FromRow, PgPool};
use substring::Substring;

#[async_trait::async_trait]
pub trait DBHandler {
/// Initialize a DB handler
fn from_config(config: &DbConfig) -> Self;
//// DB type: postgres and redis for now
fn db_type(&self) -> String;
/// Save account in db and return account name
async fn save_account(&self, account: Account, worker_id: u32) -> Result<String, OreoError>;
/// Get account name from db
Expand Down Expand Up @@ -75,3 +79,39 @@ pub struct BonusAddress {
pub address: String,
pub paid: bool,
}

pub enum DBType {
Postgres,
Redis,
Unknown,
}

impl DbConfig {
pub fn build(&self) -> anyhow::Result<Box<dyn DBHandler + Send + Sync>> {
match self.protocol() {
DBType::Postgres => {
let url = self.server_url();
let options = PgConnectOptions::from_str(&url)
.unwrap()
.disable_statement_logging()
.clone();
let pool = block_on(async { PgPool::connect_with(options).await });
match pool {
Ok(pool) => Ok(Box::new(PgHandler::new(pool))),
Err(e) => Err(anyhow!("Failed to connect pgsql {}", e)),
}
}
DBType::Redis => {
let client = RedisClient::connect(&self.server_url(), self.default_pool_size)?;
Ok(Box::new(client))
}
DBType::Unknown => {
panic!("Invalid database used")
}
}
}
}

pub fn load_db(filename: impl AsRef<Path>) -> anyhow::Result<Box<dyn DBHandler + Send + Sync>> {
DbConfig::load(filename)?.build()
}
Loading

0 comments on commit 6a9342c

Please sign in to comment.