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
@@ -32,12 +32,12 @@ impl SlatePutter for PathToSlate {
if false {
warn!("Transaction contains features that require grin-wallet 4.0.0 or later");
warn!("Please ensure the other party is running grin-wallet v4.0.0 or later before sending");
VersionedSlate::into_version(slate.clone(), SlateVersion::V4)
VersionedSlate::into_version(slate.clone(), SlateVersion::V4)?
} else {
let mut s = slate.clone();
s.version_info.version = 3;
s.version_info.orig_version = 3;
VersionedSlate::into_version(s, SlateVersion::V3)
VersionedSlate::into_version(s, SlateVersion::V3)?
}
};
pub_tx.write_all(
+2 -2
View File
@@ -181,7 +181,7 @@ impl SlateSender for HttpSlateSender {
}
let slate_send = match self.check_other_version(&url_str)? {
SlateVersion::V4 => VersionedSlate::into_version(slate.clone(), SlateVersion::V4),
SlateVersion::V4 => VersionedSlate::into_version(slate.clone(), SlateVersion::V4)?,
SlateVersion::V3 => {
let mut slate = slate.clone();
let _r: crate::adapters::Reminder;
@@ -191,7 +191,7 @@ impl SlateSender for HttpSlateSender {
}
slate.version_info.version = 3;
slate.version_info.orig_version = 3;
VersionedSlate::into_version(slate, SlateVersion::V3)
VersionedSlate::into_version(slate, SlateVersion::V3)?
}
};
// Note: not using easy-jsonrpc as don't want the dependencies in this crate
+1 -1
View File
@@ -380,7 +380,7 @@ where
let mut tx_f = File::open(tx_file)?;
let mut content = String::new();
tx_f.read_to_string(&mut content)?;
let tx_bin = util::from_hex(content).unwrap();
let tx_bin = util::from_hex(&content).unwrap();
Ok(Some(
ser::deserialize::<Transaction>(&mut &tx_bin[..], ser::ProtocolVersion(1)).unwrap(),
))
+5 -5
View File
@@ -49,8 +49,8 @@ impl WalletSeed {
}
pub fn _from_hex(hex: &str) -> Result<WalletSeed, Error> {
let bytes = util::from_hex(hex.to_string())
.context(ErrorKind::GenericError("Invalid hex".to_owned()))?;
let bytes = util::from_hex(&hex.to_string())
.map_err(|_| ErrorKind::GenericError("Invalid hex".to_owned()))?;
Ok(WalletSeed::from_bytes(&bytes))
}
@@ -274,15 +274,15 @@ impl EncryptedWalletSeed {
/// Decrypt seed
pub fn decrypt(&self, password: &str) -> Result<WalletSeed, Error> {
let mut encrypted_seed = match util::from_hex(self.encrypted_seed.clone()) {
let mut encrypted_seed = match util::from_hex(&self.encrypted_seed.clone()) {
Ok(s) => s,
Err(_) => return Err(ErrorKind::Encryption.into()),
};
let salt = match util::from_hex(self.salt.clone()) {
let salt = match util::from_hex(&self.salt.clone()) {
Ok(s) => s,
Err(_) => return Err(ErrorKind::Encryption.into()),
};
let nonce = match util::from_hex(self.nonce.clone()) {
let nonce = match util::from_hex(&self.nonce.clone()) {
Ok(s) => s,
Err(_) => return Err(ErrorKind::Encryption.into()),
};
+1 -1
View File
@@ -262,7 +262,7 @@ where
let w = w_lock.lc_provider()?.wallet_inst()?;
w.w2n_client().clone()
};
owner::post_tx(&client, &slate.tx, false)?; // mines a block
owner::post_tx(&client, slate.tx_or_err()?, false)?; // mines a block
Ok(())
}
+2 -2
View File
@@ -276,7 +276,7 @@ where
if o_str.is_empty() {
continue;
}
let c = util::from_hex(o_str).unwrap();
let c = util::from_hex(&o_str).unwrap();
let commit = Commitment::from_vec(c);
let out = super::get_output_local(&self.chain.clone(), &commit);
if let Some(o) = out {
@@ -345,7 +345,7 @@ where
let excess = split[0].parse::<String>().unwrap();
let min = split[1].parse::<u64>().unwrap();
let max = split[2].parse::<u64>().unwrap();
let commit_bytes = util::from_hex(excess).unwrap();
let commit_bytes = util::from_hex(&excess).unwrap();
let commit = pedersen::Commitment::from_vec(commit_bytes);
let min = match min {
0 => None,