2016-12-07 02:30:31 -08:00
|
|
|
use v1::traits::Raw;
|
|
|
|
use v1::types::RawTransaction;
|
2016-12-07 11:39:12 -08:00
|
|
|
use v1::types::H256;
|
|
|
|
use v1::helpers::errors::execution;
|
2016-12-07 02:30:31 -08:00
|
|
|
use jsonrpc_core::Error;
|
2016-12-07 11:39:12 -08:00
|
|
|
use chain::Transaction;
|
|
|
|
use sync;
|
|
|
|
use ser::{Reader, deserialize};
|
|
|
|
use super::super::helpers::errors::invalid_params;
|
2016-12-07 02:30:31 -08:00
|
|
|
|
2016-12-07 11:39:12 -08:00
|
|
|
pub struct RawClient {
|
|
|
|
local_sync_node: sync::LocalNodeRef,
|
|
|
|
}
|
2016-12-07 02:30:31 -08:00
|
|
|
|
2016-12-07 05:14:52 -08:00
|
|
|
impl RawClient {
|
2016-12-07 11:39:12 -08:00
|
|
|
pub fn new(local_sync_node: sync::LocalNodeRef) -> Self {
|
|
|
|
RawClient {
|
|
|
|
local_sync_node: local_sync_node,
|
|
|
|
}
|
2016-12-07 05:14:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-07 02:30:31 -08:00
|
|
|
impl Raw for RawClient {
|
2016-12-07 11:39:12 -08:00
|
|
|
fn send_raw_transaction(&self, raw_transaction: RawTransaction) -> Result<H256, Error> {
|
|
|
|
let transaction: Transaction = try!(deserialize(Reader::new(&raw_transaction.0)).map_err(|err| invalid_params("tx", err)));
|
|
|
|
match self.local_sync_node.accept_transaction(transaction) {
|
|
|
|
// client expects to get reversed H256
|
|
|
|
Ok(hash) => Ok(hash.reversed().into()),
|
|
|
|
Err(err) => Err(execution(err)),
|
|
|
|
}
|
2016-12-07 02:30:31 -08:00
|
|
|
}
|
|
|
|
}
|