Skip to content

Feature/remotesend #80

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

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
8 changes: 7 additions & 1 deletion src/command/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,13 @@ fn cmd_list_address() -> Result<()> {
Ok(())
}

fn cmd_remote_send(from: &str, to: &str, amount: i32, node: &str, _mine_now: bool) -> Result<()> {
pub fn cmd_remote_send(
from: &str,
to: &str,
amount: i32,
node: &str,
_mine_now: bool,
) -> Result<()> {
let bc = Blockchain::new()?;
let utxo_set = UTXOSet { blockchain: bc };

Expand Down
1 change: 1 addition & 0 deletions src/webserver.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod createwallet;
pub mod printchain;
pub mod remotesend;
pub mod webserver;
25 changes: 25 additions & 0 deletions src/webserver/remotesend.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use crate::command::cli::cmd_remote_send;
use actix_web::{post, web, HttpResponse, Responder};
use serde::Deserialize;

#[derive(Deserialize)]
struct RemoteSendParams {
from: String,
to: String,
amount: i32,
node: String,
mine: bool,
}

#[post("/remote_send")]
pub async fn remote_send(params: web::Query<RemoteSendParams>) -> impl Responder {
let from = &params.from;
let to = &params.to;
let amount = params.amount;
let node = &params.node;
let mine = params.mine;
match cmd_remote_send(from, to, amount, node, mine) {
Ok(()) => HttpResponse::Ok().body("Complete remote send"),
Err(err) => HttpResponse::BadGateway().body(err.to_string()),
}
}
3 changes: 3 additions & 0 deletions src/webserver/webserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::webserver::createwallet;
use crate::webserver::printchain;
use actix_web::{App, HttpServer};

use super::remotesend;

pub struct WebServer {}

impl WebServer {
Expand All @@ -10,6 +12,7 @@ impl WebServer {
App::new()
.service(createwallet::create_wallet)
.service(printchain::print_chain)
.service(remotesend::remote_send)
})
.bind(("127.0.0.1", 7000))?
.run()
Expand Down