Skip to content

Commit

Permalink
APIV2 refactoring (#23)
Browse files Browse the repository at this point in the history
* continue refactor

* rustfmt

* further refactoring

* impl crate compiling

* main crate compilation

* rustfmt

* test fix

* rustfmt

* test compilation

* rustfmt

* refwallet tests passing

* rustfmt

* all tests passing

* move http listener startup out of adapter

* rustfmt

* rename refwallet->controller

* rustfmt

* travis tests and api doctests

* rustfmt
  • Loading branch information
yeastplume authored Mar 17, 2019
1 parent 8cca982 commit db01596
Show file tree
Hide file tree
Showing 50 changed files with 1,735 additions and 539 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ matrix:
- os: linux
env: CI_JOB="test" CI_JOB_ARGS="config libwallet api"
- os: linux
env: CI_JOB="test" CI_JOB_ARGS="refwallet ."
env: CI_JOB="test" CI_JOB_ARGS="impls"
- os: linux
env: CI_JOB="test" CI_JOB_ARGS="controller ."
- os: linux
env: CI_JOB="release" CI_JOB_ARGS=
- os: osx
Expand Down
51 changes: 40 additions & 11 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ name = "grin-wallet"
path = "src/bin/grin-wallet.rs"

[workspace]
members = ["api", "config", "libwallet", "refwallet"]
members = ["api", "config", "controller", "impls", "libwallet"]
exclude = ["integration"]

[dependencies]
Expand All @@ -30,8 +30,9 @@ log = "0.4"
linefeed = "0.5"

grin_wallet_api = { path = "./api", version = "1.1.0" }
grin_wallet_impls = { path = "./impls", version = "1.1.0" }
grin_wallet_libwallet = { path = "./libwallet", version = "1.1.0" }
grin_wallet_refwallet = { path = "./refwallet", version = "1.1.0" }
grin_wallet_controller = { path = "./controller", version = "1.1.0" }
grin_wallet_config = { path = "./config", version = "1.1.0" }

grin_core = { git = "https://github.com/mimblewimble/grin", branch = "milestone/1.1.0" }
Expand Down
2 changes: 1 addition & 1 deletion api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ grin_api = { git = "https://github.com/mimblewimble/grin", branch = "milestone/1
grin_store = { git = "https://github.com/mimblewimble/grin", branch = "milestone/1.1.0" }

[dev-dependencies]
grin_wallet_refwallet = { path = "../refwallet", version = "1.1.0" }
grin_wallet_impls = { path = "../impls", version = "1.1.0" }
serde_json = "1"
tempfile = "3.0.7"
46 changes: 7 additions & 39 deletions api/src/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@
//! seed).
use crate::keychain::Keychain;
use crate::libwallet::internal::{tx, updater};
use crate::libwallet::api_impl::foreign;
use crate::libwallet::slate::Slate;
use crate::libwallet::types::{BlockFees, CbData, NodeClient, TxLogEntryType, WalletBackend};
use crate::libwallet::{Error, ErrorKind};
use crate::util::secp::{ContextFlag, Secp256k1};
use crate::libwallet::types::{BlockFees, CbData, NodeClient, WalletBackend};
use crate::libwallet::Error;
use crate::util::Mutex;
use std::marker::PhantomData;
use std::sync::Arc;

const USER_MESSAGE_MAX_LEN: usize = 256;

/// Wrapper around external API functions, intended to communicate
/// with other parties
pub struct Foreign<W: ?Sized, C, K>
Expand Down Expand Up @@ -72,16 +69,14 @@ where
pub fn build_coinbase(&self, block_fees: &BlockFees) -> Result<CbData, Error> {
let mut w = self.wallet.lock();
w.open_with_credentials()?;
let res = updater::build_coinbase(&mut *w, block_fees);
let res = foreign::build_coinbase(&mut *w, block_fees);
w.close()?;
res
}

/// Verifies all messages in the slate match their public keys
pub fn verify_slate_messages(&self, slate: &Slate) -> Result<(), Error> {
let secp = Secp256k1::with_caps(ContextFlag::VerifyOnly);
slate.verify_messages(&secp)?;
Ok(())
foreign::verify_slate_messages(slate)
}

/// Receive a transaction from a sender
Expand All @@ -93,35 +88,8 @@ where
) -> Result<(), Error> {
let mut w = self.wallet.lock();
w.open_with_credentials()?;
let parent_key_id = match dest_acct_name {
Some(d) => {
let pm = w.get_acct_path(d.to_owned())?;
match pm {
Some(p) => p.path,
None => w.parent_key_id(),
}
}
None => w.parent_key_id(),
};
// Don't do this multiple times
let tx = updater::retrieve_txs(&mut *w, None, Some(slate.id), Some(&parent_key_id), false)?;
for t in &tx {
if t.tx_type == TxLogEntryType::TxReceived {
return Err(ErrorKind::TransactionAlreadyReceived(slate.id.to_string()).into());
}
}

let message = match message {
Some(mut m) => {
m.truncate(USER_MESSAGE_MAX_LEN);
Some(m)
}
None => None,
};

tx::add_output_to_slate(&mut *w, slate, &parent_key_id, 1, message)?;
tx::update_message(&mut *w, slate)?;
let res = foreign::receive_tx(&mut *w, slate, dest_acct_name, message);
w.close()?;
Ok(())
res
}
}
3 changes: 2 additions & 1 deletion api/src/foreign_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ macro_rules! doctest_helper_json_rpc_foreign_assert_response {
use grin_util::Mutex;
use grin_wallet_api::{Foreign, ForeignRpc};
use grin_wallet_config::WalletConfig;
use grin_wallet_refwallet::{HTTPNodeClient, LMDBBackend, WalletBackend};
use grin_wallet_impls::{HTTPNodeClient, LMDBBackend};
use grin_wallet_libwallet::types::WalletBackend;
use serde_json;
use std::sync::Arc;
use tempfile::tempdir;
Expand Down
Loading

0 comments on commit db01596

Please sign in to comment.