rename JSONPartialTx -> PartialTx (#252)

This commit is contained in:
AntiochP 2017-11-09 15:42:19 -05:00 committed by GitHub
parent c1656f7660
commit 2238495d23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 15 deletions

View file

@ -55,11 +55,11 @@ where
Ok(res)
}
pub fn send_partial_tx(url: &str, partial_tx: &JSONPartialTx) -> Result<(), Error> {
pub fn send_partial_tx(url: &str, partial_tx: &PartialTx) -> Result<(), Error> {
single_send_partial_tx(url, partial_tx)
}
fn single_send_partial_tx(url: &str, partial_tx: &JSONPartialTx) -> Result<(), Error> {
fn single_send_partial_tx(url: &str, partial_tx: &PartialTx) -> Result<(), Error> {
let mut core = reactor::Core::new()?;
let client = hyper::Client::new(&core.handle());

View file

@ -52,7 +52,7 @@ pub fn receive_json_tx_str(
pub fn receive_json_tx(
config: &WalletConfig,
keychain: &Keychain,
partial_tx: &JSONPartialTx,
partial_tx: &PartialTx,
) -> Result<(), Error> {
let (amount, blinding, tx) = read_partial_tx(keychain, partial_tx)?;
let final_tx = receive_transaction(config, keychain, amount, blinding, tx)?;
@ -74,7 +74,7 @@ pub struct WalletReceiver {
impl Handler for WalletReceiver {
fn handle(&self, req: &mut Request) -> IronResult<Response> {
let struct_body = req.get::<bodyparser::Struct<JSONPartialTx>>();
let struct_body = req.get::<bodyparser::Struct<PartialTx>>();
if let Ok(Some(partial_tx)) = struct_body {
receive_json_tx(&self.config, &self.keychain, &partial_tx)

View file

@ -531,20 +531,19 @@ impl WalletData {
/// Helper in serializing the information a receiver requires to build a
/// transaction.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct JSONPartialTx {
pub struct PartialTx {
amount: u64,
blind_sum: String,
tx: String,
}
/// Encodes the information for a partial transaction (not yet completed by the
/// receiver) into JSON.
/// Builds a PartialTx from data sent by a sender (not yet completed by the receiver).
pub fn build_partial_tx(
receive_amount: u64,
blind_sum: keychain::BlindingFactor,
tx: Transaction,
) -> JSONPartialTx {
JSONPartialTx {
) -> PartialTx {
PartialTx {
amount: receive_amount,
blind_sum: util::to_hex(blind_sum.secret_key().as_ref().to_vec()),
tx: util::to_hex(ser::ser_vec(&tx).unwrap()),
@ -555,19 +554,14 @@ pub fn build_partial_tx(
/// factors and the transaction itself.
pub fn read_partial_tx(
keychain: &keychain::Keychain,
partial_tx: &JSONPartialTx,
partial_tx: &PartialTx,
) -> Result<(u64, keychain::BlindingFactor, Transaction), Error> {
// let partial_tx: JSONPartialTx = serde_json::from_str(json_str)?;
let blind_bin = util::from_hex(partial_tx.blind_sum.clone())?;
let blinding = keychain::BlindingFactor::from_slice(keychain.secp(), &blind_bin[..])?;
let tx_bin = util::from_hex(partial_tx.tx.clone())?;
let tx = ser::deserialize(&mut &tx_bin[..]).map_err(|_| {
Error::Format("Could not deserialize transaction, invalid format.".to_string())
})?;
Ok((partial_tx.amount, blinding, tx))
}