mirror of
https://github.com/mimblewimble/grin-wallet.git
synced 2025-01-20 19:11:09 +03:00
Remove V2 Owner API (#351)
* remove v2 owner API * rename former owner_rpc_s to owner_rpc * remove use_token arg from doc tests
This commit is contained in:
parent
decdd173a0
commit
62e3aed00d
5 changed files with 1163 additions and 2718 deletions
|
@ -42,7 +42,6 @@ mod foreign_rpc;
|
|||
|
||||
mod owner;
|
||||
mod owner_rpc;
|
||||
mod owner_rpc_s;
|
||||
|
||||
mod types;
|
||||
|
||||
|
@ -50,7 +49,6 @@ pub use crate::foreign::{Foreign, ForeignCheckMiddleware, ForeignCheckMiddleware
|
|||
pub use crate::foreign_rpc::ForeignRpc;
|
||||
pub use crate::owner::Owner;
|
||||
pub use crate::owner_rpc::OwnerRpc;
|
||||
pub use crate::owner_rpc_s::OwnerRpcS;
|
||||
|
||||
pub use crate::foreign_rpc::foreign_rpc as foreign_rpc_client;
|
||||
pub use crate::foreign_rpc::run_doctest_foreign;
|
||||
|
|
1360
api/src/owner_rpc.rs
1360
api/src/owner_rpc.rs
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -40,7 +40,7 @@ use crate::impls::tor::process as tor_process;
|
|||
|
||||
use crate::apiwallet::{
|
||||
EncryptedRequest, EncryptedResponse, EncryptionErrorResponse, Foreign,
|
||||
ForeignCheckMiddlewareFn, ForeignRpc, Owner, OwnerRpc, OwnerRpcS,
|
||||
ForeignCheckMiddlewareFn, ForeignRpc, Owner, OwnerRpc,
|
||||
};
|
||||
use easy_jsonrpc_mw;
|
||||
use easy_jsonrpc_mw::{Handler, MaybeReply};
|
||||
|
@ -205,7 +205,6 @@ where
|
|||
running_foreign = true;
|
||||
}
|
||||
|
||||
let api_handler_v2 = OwnerAPIHandlerV2::new(wallet.clone());
|
||||
let api_handler_v3 = OwnerAPIHandlerV3::new(
|
||||
wallet.clone(),
|
||||
keychain_mask.clone(),
|
||||
|
@ -213,10 +212,6 @@ where
|
|||
running_foreign,
|
||||
);
|
||||
|
||||
router
|
||||
.add_route("/v2/owner", Arc::new(api_handler_v2))
|
||||
.map_err(|_| ErrorKind::GenericError("Router failed to add route".to_string()))?;
|
||||
|
||||
router
|
||||
.add_route("/v3/owner", Arc::new(api_handler_v3))
|
||||
.map_err(|_| ErrorKind::GenericError("Router failed to add route".to_string()))?;
|
||||
|
@ -301,76 +296,6 @@ where
|
|||
.map_err(|e| ErrorKind::GenericError(format!("API thread panicked :{:?}", e)).into())
|
||||
}
|
||||
|
||||
/// V2 API Handler/Wrapper for owner functions
|
||||
pub struct OwnerAPIHandlerV2<L, C, K>
|
||||
where
|
||||
L: WalletLCProvider<'static, C, K> + 'static,
|
||||
C: NodeClient + 'static,
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
/// Wallet instance
|
||||
pub wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
}
|
||||
|
||||
impl<L, C, K> OwnerAPIHandlerV2<L, C, K>
|
||||
where
|
||||
L: WalletLCProvider<'static, C, K> + 'static,
|
||||
C: NodeClient + 'static,
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
/// Create a new owner API handler for GET methods
|
||||
pub fn new(
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
) -> OwnerAPIHandlerV2<L, C, K> {
|
||||
OwnerAPIHandlerV2 { wallet }
|
||||
}
|
||||
|
||||
async fn call_api(req: Request<Body>, api: Owner<L, C, K>) -> Result<serde_json::Value, Error> {
|
||||
let val: serde_json::Value = parse_body(req).await?;
|
||||
match OwnerRpc::handle_request(&api, val) {
|
||||
MaybeReply::Reply(r) => Ok(r),
|
||||
MaybeReply::DontReply => {
|
||||
// Since it's http, we need to return something. We return [] because jsonrpc
|
||||
// clients will parse it as an empty batch response.
|
||||
Ok(serde_json::json!([]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_post_request(
|
||||
req: Request<Body>,
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
) -> Result<Response<Body>, Error> {
|
||||
let api = Owner::new(wallet, None);
|
||||
let res = Self::call_api(req, api).await?;
|
||||
Ok(json_response_pretty(&res))
|
||||
}
|
||||
}
|
||||
|
||||
impl<L, C, K> api::Handler for OwnerAPIHandlerV2<L, C, K>
|
||||
where
|
||||
L: WalletLCProvider<'static, C, K> + 'static,
|
||||
C: NodeClient + 'static,
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
fn post(&self, req: Request<Body>) -> ResponseFuture {
|
||||
let wallet = self.wallet.clone();
|
||||
Box::pin(async move {
|
||||
match Self::handle_post_request(req, wallet).await {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => {
|
||||
error!("Request Error: {:?}", e);
|
||||
Ok(create_error_response(e))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn options(&self, _req: Request<Body>) -> ResponseFuture {
|
||||
Box::pin(async { Ok(create_ok_response("{}")) })
|
||||
}
|
||||
}
|
||||
|
||||
/// V3 API Handler/Wrapper for owner functions, which include a secure
|
||||
/// mode + lifecycle functions
|
||||
pub struct OwnerAPIHandlerV3<L, C, K>
|
||||
|
@ -657,7 +582,7 @@ where
|
|||
is_init_secure_api = OwnerV3Helpers::is_init_secure_api(&val);
|
||||
// also need to intercept open/close wallet requests
|
||||
let is_open_wallet = OwnerV3Helpers::is_open_wallet(&val);
|
||||
match OwnerRpcS::handle_request(&*api, val) {
|
||||
match OwnerRpc::handle_request(&*api, val) {
|
||||
MaybeReply::Reply(mut r) => {
|
||||
let (_was_error, unencrypted_intercept) =
|
||||
OwnerV3Helpers::check_error_response(&r.clone());
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
// Copyright 2019 The Grin Developers
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
extern crate grin_wallet;
|
||||
|
||||
use grin_wallet_impls::test_framework::{self, LocalWalletClient, WalletProxy};
|
||||
|
||||
use clap::App;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use grin_wallet_impls::DefaultLCProvider;
|
||||
use grin_wallet_util::grin_keychain::ExtKeychain;
|
||||
|
||||
#[macro_use]
|
||||
mod common;
|
||||
use common::RetrieveSummaryInfoResp;
|
||||
use common::{
|
||||
clean_output_dir, execute_command, initial_setup_wallet, instantiate_wallet, send_request,
|
||||
setup,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn owner_v2_sanity() -> Result<(), grin_wallet_controller::Error> {
|
||||
let test_dir = "target/test_output/owner_v2_sanity";
|
||||
setup(test_dir);
|
||||
|
||||
setup_proxy!(test_dir, chain, wallet1, client1, mask1, wallet2, client2, _mask2);
|
||||
|
||||
// add some blocks manually
|
||||
let bh = 10u64;
|
||||
let _ =
|
||||
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, bh as usize, false);
|
||||
let client1_2 = client1.clone();
|
||||
|
||||
// run the owner listener on wallet 1
|
||||
let arg_vec = vec!["grin-wallet", "-p", "password", "owner_api"];
|
||||
// Set running
|
||||
thread::spawn(move || {
|
||||
let yml = load_yaml!("../src/bin/grin-wallet.yml");
|
||||
let app = App::from_yaml(yml);
|
||||
execute_command(&app, test_dir, "wallet1", &client1, arg_vec.clone()).unwrap();
|
||||
});
|
||||
|
||||
// run the foreign listener for wallet 2
|
||||
let arg_vec = vec![
|
||||
"grin-wallet",
|
||||
"-p",
|
||||
"password",
|
||||
"listen",
|
||||
"-l",
|
||||
"23415",
|
||||
"-n",
|
||||
];
|
||||
// Set owner listener running
|
||||
thread::spawn(move || {
|
||||
let yml = load_yaml!("../src/bin/grin-wallet.yml");
|
||||
let app = App::from_yaml(yml);
|
||||
execute_command(&app, test_dir, "wallet2", &client2, arg_vec.clone()).unwrap();
|
||||
});
|
||||
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
|
||||
// 1) Send simple retrieve_info request to owner listener
|
||||
let req = include_str!("data/v2_reqs/retrieve_info.req.json");
|
||||
let res = send_request(1, "http://127.0.0.1:3420/v2/owner", req)?;
|
||||
assert!(res.is_ok());
|
||||
let value: RetrieveSummaryInfoResp = res.unwrap();
|
||||
assert_eq!(value.1.amount_currently_spendable, 420000000000);
|
||||
println!("Response 1: {:?}", value);
|
||||
|
||||
// 2) Send to wallet 2 foreign listener
|
||||
let arg_vec = vec![
|
||||
"grin-wallet",
|
||||
"-p",
|
||||
"password",
|
||||
"send",
|
||||
"-d",
|
||||
"http://127.0.0.1:23415",
|
||||
"10",
|
||||
];
|
||||
let yml = load_yaml!("../src/bin/grin-wallet.yml");
|
||||
let app = App::from_yaml(yml);
|
||||
let res = execute_command(&app, test_dir, "wallet1", &client1_2, arg_vec.clone());
|
||||
println!("Response 2: {:?}", res);
|
||||
assert!(res.is_ok());
|
||||
|
||||
clean_output_dir(test_dir);
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in a new issue