Skip to content

Commit

Permalink
feat: wallet prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Nov 8, 2023
1 parent 92213d5 commit 868680c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion packages/rs-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ drive = { path = "../rs-drive", default-features = false, features = [
] }
drive-proof-verifier = { path = "../rs-drive-proof-verifier" }
dapi-grpc-macros = { path = "../rs-dapi-grpc-macros" }

simple-signer = { path = "../simple-signer" }
bincode = { version = "2.0.0-rc.3", features = ["serde"], optional = true }
thiserror = "1.0.47"
tokio = { version = "1.32.0", features = ["macros"] }
Expand Down
1 change: 1 addition & 0 deletions packages/rs-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub mod error;
pub mod mock;
pub mod platform;
pub mod sdk;
pub mod wallet;

pub use error::Error;
pub use sdk::{Sdk, SdkBuilder};
77 changes: 77 additions & 0 deletions packages/rs-sdk/src/wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//! Wallet for managing keys assets in Dash Core and Platform.
use dashcore_rpc::dashcore::address::NetworkUnchecked;
use dashcore_rpc::dashcore::Address;
use dashcore_rpc::json;
use dpp::bls_signatures::PrivateKey;
pub use dpp::identity::signer::Signer;
use dpp::prelude::AssetLockProof;
use rs_dapi_client::transport::CoreGrpcClient;
use simple_signer::signer::SimpleSigner;

use crate::{core_client::CoreClient, Error, Sdk};

/// Default wallet implementation for Dash Platform SDK.
///
/// This wallet uses Dash Core wallet RPC client to manage Core keys, and [Signer] instance to manage Platform keys.
///
pub struct Wallet {
core_wallet: CoreWallet,
platform_wallet: SimpleSigner,
}

impl Wallet {
/// Create new wallet.
///
/// Create new wallet using dash core wallet RPC client to manage Core keys, and Signer instance to manage Platform keys.
///
/// # Arguments
///
/// * `core` - Dash Core RPC client [CoreClient]. Should be owned by [Sdk].
/// * `signer` - [Signer] instance, for example [simple_signer::signer::SimpleSigner].
/// Should be owned by [Sdk].
pub(crate) fn new_with_clients<S: Signer>(
core_client: CoreClient,
signer: SimpleSigner,
) -> Self {
Self {
core_wallet: CoreWallet { core_client },
platform_wallet: signer,
}
}

/// Return Core wallet client.
pub(crate) fn core<'a>(&'a self) -> &'a CoreWallet {
&self.core_wallet
}

/// Return Platform wallet client.
pub(crate) fn platform<'a>(&'a self) -> &'a SimpleSigner {
&self.platform_wallet
}
}

pub(crate) struct CoreWallet {
core_client: CoreClient,
}
impl CoreWallet {
/// Create new asset lock transaction that locks some amount of Dash to be used in Platform.
///
/// # Arguments
///
/// * `amount` - Amount of Dash to lock.
///
/// # Returns
///
/// * `AssetLockProof` - Asset lock proof.
/// * `PrivateKey` - One-time private key used to use locked Dash in Platform.
/// This key should be used to sign Platform transactions.
pub(crate) async fn lock_assets(
&self,
sdk: &Sdk,
amount: u64,
) -> Result<(AssetLockProof, PrivateKey), Error> {
let change = self.core_client.change_address();
todo!("implement asset lock tx")
}
}

0 comments on commit 868680c

Please sign in to comment.