Make Transaction Field in V4 Slate Optional (#356)

* make transaction field in V4 Slate optional

* add mutable/non mutable version of tx getter

* removal of mut references where not needed

* remove more muts

* update from master

* update from master

* test fixes
This commit is contained in:
Yeastplume
2020-03-10 18:19:27 +00:00
committed by GitHub
parent aebc352fbe
commit c42d5ddcff
35 changed files with 312 additions and 205 deletions
+2 -2
View File
@@ -562,14 +562,14 @@ where
message,
)
.map_err(|e| e.kind())?;
Ok(VersionedSlate::into_version(out_slate, version))
Ok(VersionedSlate::into_version(out_slate, version).map_err(|e| e.kind())?)
}
fn finalize_invoice_tx(&self, in_slate: VersionedSlate) -> Result<VersionedSlate, ErrorKind> {
let version = in_slate.version();
let out_slate =
Foreign::finalize_invoice_tx(self, &Slate::from(in_slate)).map_err(|e| e.kind())?;
Ok(VersionedSlate::into_version(out_slate, version))
Ok(VersionedSlate::into_version(out_slate, version).map_err(|e| e.kind())?)
}
}
+5 -7
View File
@@ -677,7 +677,7 @@ where
};
if sa.post_tx {
self.post_tx(keychain_mask, &slate.tx, sa.fluff)?;
self.post_tx(keychain_mask, slate.tx_or_err()?, sa.fluff)?;
}
Ok(slate)
}
@@ -926,7 +926,7 @@ where
) -> Result<Slate, Error> {
let mut w_lock = self.wallet_inst.lock();
let w = w_lock.lc_provider()?.wallet_inst()?;
owner::finalize_tx(&mut **w, keychain_mask, &slate)
owner::finalize_tx(&mut **w, keychain_mask, slate)
}
/// Posts a completed transaction to the listening node for validation and inclusion in a block
@@ -976,7 +976,7 @@ where
/// // Retrieve slate back from recipient
/// //
/// let res = api_owner.finalize_tx(None, &slate);
/// let res = api_owner.post_tx(None, &slate.tx, true);
/// let res = api_owner.post_tx(None, slate.tx_or_err().unwrap(), true);
/// }
/// ```
@@ -1598,10 +1598,8 @@ where
let secp = secp_inst.lock();
return Ok(Some(SecretKey::from_slice(
&secp,
&from_hex(
"d096b3cb75986b3b13f80b8f5243a9edf0af4c74ac37578c5a12cfb5b59b1868".to_owned(),
)
.unwrap(),
&from_hex("d096b3cb75986b3b13f80b8f5243a9edf0af4c74ac37578c5a12cfb5b59b1868")
.unwrap(),
)?));
}
let mut w_lock = self.wallet_inst.lock();
+5 -5
View File
@@ -2059,7 +2059,7 @@ where
let slate = Owner::init_send_tx(self, (&token.keychain_mask).as_ref(), args)
.map_err(|e| e.kind())?;
let version = SlateVersion::V4;
Ok(VersionedSlate::into_version(slate, version))
Ok(VersionedSlate::into_version(slate, version).map_err(|e| e.kind())?)
}
fn issue_invoice_tx(
@@ -2070,7 +2070,7 @@ where
let slate = Owner::issue_invoice_tx(self, (&token.keychain_mask).as_ref(), args)
.map_err(|e| e.kind())?;
let version = SlateVersion::V4;
Ok(VersionedSlate::into_version(slate, version))
Ok(VersionedSlate::into_version(slate, version).map_err(|e| e.kind())?)
}
fn process_invoice_tx(
@@ -2087,7 +2087,7 @@ where
)
.map_err(|e| e.kind())?;
let version = SlateVersion::V4;
Ok(VersionedSlate::into_version(out_slate, version))
Ok(VersionedSlate::into_version(out_slate, version).map_err(|e| e.kind())?)
}
fn finalize_tx(
@@ -2102,7 +2102,7 @@ where
)
.map_err(|e| e.kind())?;
let version = SlateVersion::V4;
Ok(VersionedSlate::into_version(out_slate, version))
Ok(VersionedSlate::into_version(out_slate, version).map_err(|e| e.kind())?)
}
fn tx_lock_outputs(
@@ -2527,7 +2527,7 @@ pub fn run_doctest_owner(
}
if payment_proof {
api_impl::owner::post_tx(&client1, &slate_outer.tx, true).unwrap();
api_impl::owner::post_tx(&client1, slate_outer.tx_or_err().unwrap(), true).unwrap();
}
if perform_tx && lock_tx && finalize_tx {
+4 -4
View File
@@ -125,9 +125,9 @@ impl EncryptedBody {
let mut to_decrypt = base64::decode(&self.body_enc).context(ErrorKind::APIEncryption(
"EncryptedBody Dec: Encrypted request contains invalid Base64".to_string(),
))?;
let nonce = from_hex(self.nonce.clone()).context(ErrorKind::APIEncryption(
"EncryptedBody Dec: Invalid Nonce".to_string(),
))?;
let nonce = from_hex(&self.nonce).map_err(|_| {
ErrorKind::APIEncryption("EncryptedBody Dec: Invalid Nonce".to_string())
})?;
if nonce.len() < 12 {
return Err(ErrorKind::APIEncryption(
"EncryptedBody Dec: Invalid Nonce length".to_string(),
@@ -321,7 +321,7 @@ fn encrypted_request() -> Result<(), Error> {
let secp_inst = static_secp_instance();
let secp = secp_inst.lock();
let sec_key_bytes = from_hex(sec_key_str.to_owned()).unwrap();
let sec_key_bytes = from_hex(sec_key_str).unwrap();
SecretKey::from_slice(&secp, &sec_key_bytes)?
};
let req = serde_json::json!({