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) 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) 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 mut core = reactor::Core::new()?;
let client = hyper::Client::new(&core.handle()); let client = hyper::Client::new(&core.handle());

View file

@ -52,7 +52,7 @@ pub fn receive_json_tx_str(
pub fn receive_json_tx( pub fn receive_json_tx(
config: &WalletConfig, config: &WalletConfig,
keychain: &Keychain, keychain: &Keychain,
partial_tx: &JSONPartialTx, partial_tx: &PartialTx,
) -> Result<(), Error> { ) -> Result<(), Error> {
let (amount, blinding, tx) = read_partial_tx(keychain, partial_tx)?; let (amount, blinding, tx) = read_partial_tx(keychain, partial_tx)?;
let final_tx = receive_transaction(config, keychain, amount, blinding, tx)?; let final_tx = receive_transaction(config, keychain, amount, blinding, tx)?;
@ -74,7 +74,7 @@ pub struct WalletReceiver {
impl Handler for WalletReceiver { impl Handler for WalletReceiver {
fn handle(&self, req: &mut Request) -> IronResult<Response> { 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 { if let Ok(Some(partial_tx)) = struct_body {
receive_json_tx(&self.config, &self.keychain, &partial_tx) 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 /// Helper in serializing the information a receiver requires to build a
/// transaction. /// transaction.
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct JSONPartialTx { pub struct PartialTx {
amount: u64, amount: u64,
blind_sum: String, blind_sum: String,
tx: String, tx: String,
} }
/// Encodes the information for a partial transaction (not yet completed by the /// Builds a PartialTx from data sent by a sender (not yet completed by the receiver).
/// receiver) into JSON.
pub fn build_partial_tx( pub fn build_partial_tx(
receive_amount: u64, receive_amount: u64,
blind_sum: keychain::BlindingFactor, blind_sum: keychain::BlindingFactor,
tx: Transaction, tx: Transaction,
) -> JSONPartialTx { ) -> PartialTx {
JSONPartialTx { PartialTx {
amount: receive_amount, amount: receive_amount,
blind_sum: util::to_hex(blind_sum.secret_key().as_ref().to_vec()), blind_sum: util::to_hex(blind_sum.secret_key().as_ref().to_vec()),
tx: util::to_hex(ser::ser_vec(&tx).unwrap()), tx: util::to_hex(ser::ser_vec(&tx).unwrap()),
@ -555,19 +554,14 @@ pub fn build_partial_tx(
/// factors and the transaction itself. /// factors and the transaction itself.
pub fn read_partial_tx( pub fn read_partial_tx(
keychain: &keychain::Keychain, keychain: &keychain::Keychain,
partial_tx: &JSONPartialTx, partial_tx: &PartialTx,
) -> Result<(u64, keychain::BlindingFactor, Transaction), Error> { ) -> 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 blind_bin = util::from_hex(partial_tx.blind_sum.clone())?;
let blinding = keychain::BlindingFactor::from_slice(keychain.secp(), &blind_bin[..])?; let blinding = keychain::BlindingFactor::from_slice(keychain.secp(), &blind_bin[..])?;
let tx_bin = util::from_hex(partial_tx.tx.clone())?; let tx_bin = util::from_hex(partial_tx.tx.clone())?;
let tx = ser::deserialize(&mut &tx_bin[..]).map_err(|_| { let tx = ser::deserialize(&mut &tx_bin[..]).map_err(|_| {
Error::Format("Could not deserialize transaction, invalid format.".to_string()) Error::Format("Could not deserialize transaction, invalid format.".to_string())
})?; })?;
Ok((partial_tx.amount, blinding, tx)) Ok((partial_tx.amount, blinding, tx))
} }