diff --git a/Cargo.lock b/Cargo.lock index 8a61a49..92f53f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -395,18 +395,18 @@ dependencies = [ ] [[package]] -name = "croaring" -version = "0.4.4" +name = "croaring-mw" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "croaring-sys 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "croaring-sys-mw 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "croaring-sys" -version = "0.4.4" +name = "croaring-sys-mw" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bindgen 0.52.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -860,7 +860,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "grin_api" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#3bbf60ee92d789fc0a7e5b6f14db8131887ea92f" +source = "git+https://github.com/mimblewimble/grin#2397407dc4d7e196c6edc6436e9545149ccb1a21" dependencies = [ "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "easy-jsonrpc-mw 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -893,13 +893,13 @@ dependencies = [ [[package]] name = "grin_chain" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#3bbf60ee92d789fc0a7e5b6f14db8131887ea92f" +source = "git+https://github.com/mimblewimble/grin#2397407dc4d7e196c6edc6436e9545149ccb1a21" dependencies = [ "bit-vec 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "croaring 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "croaring-mw 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "grin_core 4.0.0-alpha.1 (git+https://github.com/mimblewimble/grin)", @@ -916,12 +916,12 @@ dependencies = [ [[package]] name = "grin_core" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#3bbf60ee92d789fc0a7e5b6f14db8131887ea92f" +source = "git+https://github.com/mimblewimble/grin#2397407dc4d7e196c6edc6436e9545149ccb1a21" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "croaring 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "croaring-mw 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "enum_primitive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -942,7 +942,7 @@ dependencies = [ [[package]] name = "grin_keychain" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#3bbf60ee92d789fc0a7e5b6f14db8131887ea92f" +source = "git+https://github.com/mimblewimble/grin#2397407dc4d7e196c6edc6436e9545149ccb1a21" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -964,7 +964,7 @@ dependencies = [ [[package]] name = "grin_p2p" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#3bbf60ee92d789fc0a7e5b6f14db8131887ea92f" +source = "git+https://github.com/mimblewimble/grin#2397407dc4d7e196c6edc6436e9545149ccb1a21" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -985,7 +985,7 @@ dependencies = [ [[package]] name = "grin_pool" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#3bbf60ee92d789fc0a7e5b6f14db8131887ea92f" +source = "git+https://github.com/mimblewimble/grin#2397407dc4d7e196c6edc6436e9545149ccb1a21" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1002,7 +1002,7 @@ dependencies = [ [[package]] name = "grin_secp256k1zkp" -version = "0.7.7" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1018,10 +1018,10 @@ dependencies = [ [[package]] name = "grin_store" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#3bbf60ee92d789fc0a7e5b6f14db8131887ea92f" +source = "git+https://github.com/mimblewimble/grin#2397407dc4d7e196c6edc6436e9545149ccb1a21" dependencies = [ "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "croaring 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "croaring-mw 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "grin_core 4.0.0-alpha.1 (git+https://github.com/mimblewimble/grin)", @@ -1038,12 +1038,12 @@ dependencies = [ [[package]] name = "grin_util" version = "4.0.0-alpha.1" -source = "git+https://github.com/mimblewimble/grin#3bbf60ee92d789fc0a7e5b6f14db8131887ea92f" +source = "git+https://github.com/mimblewimble/grin#2397407dc4d7e196c6edc6436e9545149ccb1a21" dependencies = [ "backtrace 0.3.45 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "grin_secp256k1zkp 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)", + "grin_secp256k1zkp 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log4rs 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3430,8 +3430,8 @@ dependencies = [ "checksum core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b" "checksum core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" "checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" -"checksum croaring 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "52e9057c1caf8e9debd6f938a12ff24028f3c7f85d24f502f46f3c9601905464" -"checksum croaring-sys 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b7d3b66d75dc466ec547604de0517eb4e1a51fd79a83eaff4409f81167dacdc8" +"checksum croaring-mw 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bcdee571ce4bf3e49c382de29c38bd33b9fa871e1358c7749b9dcc5dc2776221" +"checksum croaring-sys-mw 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea52c177269fa54c526b054dac8e623721de18143ebfd2ea84ffc023d6c271ee" "checksum crossbeam-deque 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" "checksum crossbeam-epoch 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" "checksum crossbeam-queue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db" @@ -3490,7 +3490,7 @@ dependencies = [ "checksum grin_keychain 4.0.0-alpha.1 (git+https://github.com/mimblewimble/grin)" = "" "checksum grin_p2p 4.0.0-alpha.1 (git+https://github.com/mimblewimble/grin)" = "" "checksum grin_pool 4.0.0-alpha.1 (git+https://github.com/mimblewimble/grin)" = "" -"checksum grin_secp256k1zkp 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)" = "23027a7673df2c2b20fb9589d742ff400a10a9c3e4c769a77e9fa3bd19586822" +"checksum grin_secp256k1zkp 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "a4c2e7431d1999f02112c2383c9d33e7a6212947abfba92c87ab7283ba667a8b" "checksum grin_store 4.0.0-alpha.1 (git+https://github.com/mimblewimble/grin)" = "" "checksum grin_util 4.0.0-alpha.1 (git+https://github.com/mimblewimble/grin)" = "" "checksum h2 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9d5c295d1c0c68e4e42003d75f908f5e16a1edd1cbe0b0d02e4dc2006a384f47" diff --git a/api/src/types.rs b/api/src/types.rs index 2da6a96..05f3061 100644 --- a/api/src/types.rs +++ b/api/src/types.rs @@ -15,7 +15,7 @@ use crate::core::libtx::secp_ser; use crate::libwallet::dalek_ser; use crate::libwallet::{Error, ErrorKind}; use crate::util::secp::key::{PublicKey, SecretKey}; -use crate::util::{from_hex, to_hex}; +use crate::util::{from_hex, ToHex}; use failure::ResultExt; use base64; @@ -98,7 +98,7 @@ impl EncryptedBody { } Ok(EncryptedBody { - nonce: to_hex(nonce.to_vec()), + nonce: nonce.to_hex(), body_enc: base64::encode(&to_encrypt), }) } diff --git a/controller/src/display.rs b/controller/src/display.rs index f2b4c79..15ecbda 100644 --- a/controller/src/display.rs +++ b/controller/src/display.rs @@ -17,7 +17,7 @@ use crate::core::global; use crate::libwallet::{ AcctPathMapping, Error, OutputCommitMapping, OutputStatus, TxLogEntry, WalletInfo, }; -use crate::util; +use crate::util::{static_secp_instance, ToHex}; use grin_wallet_util::OnionV3Address; use prettytable; use std::io::prelude::Write; @@ -60,7 +60,7 @@ pub fn outputs( ]); for m in outputs { - let commit = format!("{}", util::to_hex(m.commit.as_ref().to_vec())); + let commit = format!("{}", m.commit.as_ref().to_hex()); let index = match m.output.mmr_index { None => "None".to_owned(), Some(t) => t.to_string(), @@ -205,7 +205,7 @@ pub fn txs( None => "None".to_owned(), }; let kernel_excess = match t.kernel_excess { - Some(e) => util::to_hex(e.0.to_vec()), + Some(e) => e.0.as_ref().to_hex(), None => "None".to_owned(), }; let payment_proof = match t.payment_proof { @@ -485,21 +485,18 @@ pub fn tx_messages(tx: &TxLogEntry, dark_background_color_scheme: bool) -> Resul bMG->"Signature", ]); - let secp = util::static_secp_instance(); + let secp = static_secp_instance(); let secp_lock = secp.lock(); for m in msgs.messages { let id = format!("{}", m.id); - let public_key = format!( - "{}", - util::to_hex(m.public_key.serialize_vec(&secp_lock, true).to_vec()) - ); + let public_key = format!("{}", m.public_key.serialize_vec(&secp_lock, true).to_hex()); let message = match m.message { Some(m) => format!("{}", m), None => "None".to_owned(), }; let message_sig = match m.message_sig { - Some(s) => format!("{}", util::to_hex(s.serialize_der(&secp_lock))), + Some(s) => format!("{}", s.serialize_der(&secp_lock).to_hex()), None => "None".to_owned(), }; if dark_background_color_scheme { @@ -551,7 +548,7 @@ pub fn payment_proof(tx: &TxLogEntry) -> Result<(), Error> { t.fg(term::color::WHITE).unwrap(); writeln!(t).unwrap(); let receiver_signature = match pp.receiver_signature { - Some(s) => util::to_hex(s.to_bytes().to_vec()), + Some(s) => s.to_bytes().as_ref().to_hex(), None => "None".to_owned(), }; let fee = match tx.fee { @@ -568,11 +565,11 @@ pub fn payment_proof(tx: &TxLogEntry) -> Result<(), Error> { }; let sender_signature = match pp.sender_signature { - Some(s) => util::to_hex(s.to_bytes().to_vec()), + Some(s) => s.to_bytes().as_ref().to_hex(), None => "None".to_owned(), }; let kernel_excess = match tx.kernel_excess { - Some(e) => util::to_hex(e.0.to_vec()), + Some(e) => e.0.as_ref().to_hex(), None => "None".to_owned(), }; diff --git a/impls/src/backends/lmdb.rs b/impls/src/backends/lmdb.rs index 8e370c2..0394a1b 100644 --- a/impls/src/backends/lmdb.rs +++ b/impls/src/backends/lmdb.rs @@ -36,7 +36,7 @@ use crate::libwallet::{ }; use crate::util::secp::constants::SECRET_KEY_SIZE; use crate::util::secp::key::SecretKey; -use crate::util::{self, secp}; +use crate::util::{self, secp, ToHex}; use rand::rngs::mock::StepRng; use rand::thread_rng; @@ -263,12 +263,13 @@ where /*if self.config.no_commit_cache == Some(true) { Ok(None) } else {*/ - Ok(Some(util::to_hex( + Ok(Some( self.keychain(keychain_mask)? .commit(amount, &id, SwitchCommitmentType::Regular)? .0 - .to_vec(), // TODO: proper support for different switch commitment schemes - ))) + .to_vec() + .to_hex(), // TODO: proper support for different switch commitment schemes + )) /*}*/ } @@ -362,7 +363,7 @@ where .join(filename); let path_buf = Path::new(&path).to_path_buf(); let mut stored_tx = File::create(path_buf)?; - let tx_hex = util::to_hex(ser::ser_vec(tx, ser::ProtocolVersion(1)).unwrap()); + let tx_hex = ser::ser_vec(tx, ser::ProtocolVersion(1)).unwrap().to_hex(); stored_tx.write_all(&tx_hex.as_bytes())?; stored_tx.sync_all()?; Ok(()) @@ -382,7 +383,7 @@ where tx_f.read_to_string(&mut content)?; let tx_bin = util::from_hex(&content).unwrap(); Ok(Some( - ser::deserialize::(&mut &tx_bin[..], ser::ProtocolVersion(1)).unwrap(), + ser::deserialize(&mut &tx_bin[..], ser::ProtocolVersion(1)).unwrap(), )) } diff --git a/impls/src/lifecycle/seed.rs b/impls/src/lifecycle/seed.rs index f2a6708..a886ac5 100644 --- a/impls/src/lifecycle/seed.rs +++ b/impls/src/lifecycle/seed.rs @@ -26,7 +26,7 @@ use ring::aead; use ring::pbkdf2; use crate::keychain::{mnemonic, Keychain}; -use crate::util; +use crate::util::{self, ToHex}; use crate::{Error, ErrorKind}; use failure::ResultExt; @@ -55,7 +55,7 @@ impl WalletSeed { } pub fn _to_hex(&self) -> String { - util::to_hex(self.0.to_vec()) + self.0.to_vec().to_hex() } pub fn to_mnemonic(&self) -> Result { @@ -266,9 +266,9 @@ impl EncryptedWalletSeed { } Ok(EncryptedWalletSeed { - encrypted_seed: util::to_hex(enc_bytes.to_vec()), - salt: util::to_hex(salt.to_vec()), - nonce: util::to_hex(nonce.to_vec()), + encrypted_seed: enc_bytes.to_hex(), + salt: salt.to_hex(), + nonce: nonce.to_hex(), }) } diff --git a/impls/src/node_clients/http.rs b/impls/src/node_clients/http.rs index 52c1cc3..73a1fc0 100644 --- a/impls/src/node_clients/http.rs +++ b/impls/src/node_clients/http.rs @@ -27,7 +27,7 @@ use tokio::runtime::Builder; use crate::client_utils::Client; use crate::libwallet; use crate::util::secp::pedersen; -use crate::util::{self, to_hex}; +use crate::util::ToHex; use super::resp_types::*; use crate::client_utils::json_rpc::*; @@ -154,7 +154,7 @@ impl NodeClient for HTTPNodeClient { max_height: Option, ) -> Result, libwallet::Error> { let method = "get_kernel"; - let params = json!([to_hex(excess.0.to_vec()), min_height, max_height]); + let params = json!([excess.0.as_ref().to_hex(), min_height, max_height]); // have to handle this manually since the error needs to be parsed let url = format!("{}{}", self.node_url(), ENDPOINT); let client = Client::new(); @@ -198,7 +198,7 @@ impl NodeClient for HTTPNodeClient { // build vec of commits for inclusion in query let query_params: Vec = wallet_outputs .iter() - .map(|commit| format!("{}", util::to_hex(commit.as_ref().to_vec()))) + .map(|commit| format!("{}", commit.as_ref().to_hex())) .collect(); // going to leave this here even though we're moving @@ -297,7 +297,7 @@ impl NodeClient for HTTPNodeClient { }; api_outputs.insert( out.commit, - (util::to_hex(out.commit.0.to_vec()), height, out.mmr_index), + (out.commit.as_ref().to_hex(), height, out.mmr_index), ); } Ok(api_outputs) diff --git a/impls/src/test_framework/testclient.rs b/impls/src/test_framework/testclient.rs index cf3c6e1..93b311c 100644 --- a/impls/src/test_framework/testclient.rs +++ b/impls/src/test_framework/testclient.rs @@ -32,7 +32,7 @@ use crate::util; use crate::util::secp::key::SecretKey; use crate::util::secp::pedersen; use crate::util::secp::pedersen::Commitment; -use crate::util::{Mutex, RwLock}; +use crate::util::{Mutex, RwLock, ToHex}; use failure::ResultExt; use serde_json; use std::collections::HashMap; @@ -253,7 +253,7 @@ where m: WalletProxyMessage, ) -> Result { let height = self.chain.head().unwrap().height; - let hash = util::to_hex(self.chain.head().unwrap().last_block_h.to_vec()); + let hash = self.chain.head().unwrap().last_block_h.to_hex(); Ok(WalletProxyMessage { sender_id: "node".to_owned(), @@ -489,7 +489,7 @@ impl NodeClient for LocalWalletClient { ) -> Result, libwallet::Error> { let query_params: Vec = wallet_outputs .iter() - .map(|commit| util::to_hex(commit.as_ref().to_vec())) + .map(|commit| commit.as_ref().to_hex()) .collect(); let query_str = query_params.join(","); let m = WalletProxyMessage { @@ -511,7 +511,7 @@ impl NodeClient for LocalWalletClient { for out in outputs { api_outputs.insert( out.commit.commit(), - (util::to_hex(out.commit.to_vec()), out.height, out.mmr_index), + (out.commit.to_hex(), out.height, out.mmr_index), ); } Ok(api_outputs) @@ -523,7 +523,7 @@ impl NodeClient for LocalWalletClient { min_height: Option, max_height: Option, ) -> Result, libwallet::Error> { - let mut query = format!("{},", util::to_hex(excess.0.to_vec())); + let mut query = format!("{},", excess.0.as_ref().to_hex()); if let Some(h) = min_height { query += &format!("{},", h); } else { diff --git a/libwallet/src/slate.rs b/libwallet/src/slate.rs index 7fe65b9..c68a92b 100644 --- a/libwallet/src/slate.rs +++ b/libwallet/src/slate.rs @@ -29,6 +29,7 @@ use crate::grin_keychain::{BlindSum, BlindingFactor, Keychain}; use crate::grin_util::secp::key::{PublicKey, SecretKey}; use crate::grin_util::secp::pedersen::Commitment; use crate::grin_util::secp::Signature; +use crate::grin_util::ToHex; use crate::grin_util::{self, secp, RwLock}; use crate::slate_versions::ser as dalek_ser; use ed25519_dalek::PublicKey as DalekPublicKey; @@ -143,7 +144,7 @@ impl fmt::Display for ParticipantMessageData { writeln!( f, "Public Key: {}", - &grin_util::to_hex(self.public_key.serialize_vec(&static_secp, true).to_vec()) + &self.public_key.serialize_vec(&static_secp, true).to_hex() )?; let message = match self.message.clone() { None => "None".to_owned(), @@ -152,7 +153,7 @@ impl fmt::Display for ParticipantMessageData { writeln!(f, "Message: {}", message)?; let message_sig = match self.message_sig { None => "None".to_owned(), - Some(m) => grin_util::to_hex(m.to_raw_data().to_vec()), + Some(m) => m.to_raw_data().as_ref().to_hex(), }; writeln!(f, "Message Signature: {}", message_sig) } diff --git a/libwallet/src/slate_versions/ser.rs b/libwallet/src/slate_versions/ser.rs index edd88a8..67c065f 100644 --- a/libwallet/src/slate_versions/ser.rs +++ b/libwallet/src/slate_versions/ser.rs @@ -77,7 +77,7 @@ pub mod ov3_serde { /// Serializes an ed25519 PublicKey to and from hex pub mod dalek_pubkey_serde { - use crate::grin_util::{from_hex, to_hex}; + use crate::grin_util::{from_hex, ToHex}; use ed25519_dalek::PublicKey as DalekPublicKey; use serde::{Deserialize, Deserializer, Serializer}; @@ -86,7 +86,7 @@ pub mod dalek_pubkey_serde { where S: Serializer, { - serializer.serialize_str(&to_hex(key.to_bytes().to_vec())) + serializer.serialize_str(&key.to_bytes().to_hex()) } /// @@ -109,7 +109,7 @@ pub mod option_dalek_pubkey_serde { use serde::de::Error; use serde::{Deserialize, Deserializer, Serializer}; - use crate::grin_util::{from_hex, to_hex}; + use crate::grin_util::{from_hex, ToHex}; /// pub fn serialize(key: &Option, serializer: S) -> Result @@ -117,7 +117,7 @@ pub mod option_dalek_pubkey_serde { S: Serializer, { match key { - Some(key) => serializer.serialize_str(&to_hex(key.to_bytes().to_vec())), + Some(key) => serializer.serialize_str(&key.to_bytes().to_hex()), None => serializer.serialize_none(), } } @@ -148,14 +148,14 @@ pub mod dalek_sig_serde { use serde::de::Error; use serde::{Deserialize, Deserializer, Serializer}; - use crate::grin_util::{from_hex, to_hex}; + use crate::grin_util::{from_hex, ToHex}; /// - pub fn serialize(key: &DalekSignature, serializer: S) -> Result + pub fn serialize(sig: &DalekSignature, serializer: S) -> Result where S: Serializer, { - serializer.serialize_str(&to_hex(key.to_bytes().to_vec())) + serializer.serialize_str(&sig.to_bytes().as_ref().to_hex()) } /// @@ -179,15 +179,15 @@ pub mod option_dalek_sig_serde { use serde::de::Error; use serde::{Deserialize, Deserializer, Serializer}; - use crate::grin_util::{from_hex, to_hex}; + use crate::grin_util::{from_hex, ToHex}; /// - pub fn serialize(key: &Option, serializer: S) -> Result + pub fn serialize(sig: &Option, serializer: S) -> Result where S: Serializer, { - match key { - Some(key) => serializer.serialize_str(&to_hex(key.to_bytes().to_vec())), + match sig { + Some(s) => serializer.serialize_str(&s.to_bytes().as_ref().to_hex()), None => serializer.serialize_none(), } } diff --git a/libwallet/src/types.rs b/libwallet/src/types.rs index c84a492..609a367 100644 --- a/libwallet/src/types.rs +++ b/libwallet/src/types.rs @@ -25,7 +25,7 @@ use crate::grin_keychain::{Identifier, Keychain}; use crate::grin_util::logger::LoggingConfig; use crate::grin_util::secp::key::{PublicKey, SecretKey}; use crate::grin_util::secp::{self, pedersen, Secp256k1}; -use crate::grin_util::ZeroingString; +use crate::grin_util::{ToHex, ZeroingString}; use crate::slate::ParticipantMessages; use crate::slate_versions::ser as dalek_ser; use chrono::prelude::*; @@ -437,7 +437,7 @@ impl ser::Writeable for OutputData { } impl ser::Readable for OutputData { - fn read(reader: &mut dyn ser::Reader) -> Result { + fn read(reader: &mut R) -> Result { let data = reader.read_bytes_len_prefix()?; serde_json::from_slice(&data[..]).map_err(|_| ser::Error::CorruptedData) } @@ -633,7 +633,7 @@ impl ser::Writeable for Context { } impl ser::Readable for Context { - fn read(reader: &mut dyn ser::Reader) -> Result { + fn read(reader: &mut R) -> Result { let data = reader.read_bytes_len_prefix()?; serde_json::from_slice(&data[..]).map_err(|_| ser::Error::CorruptedData) } @@ -823,7 +823,7 @@ impl ser::Writeable for TxLogEntry { } impl ser::Readable for TxLogEntry { - fn read(reader: &mut dyn ser::Reader) -> Result { + fn read(reader: &mut R) -> Result { let data = reader.read_bytes_len_prefix()?; serde_json::from_slice(&data[..]).map_err(|_| ser::Error::CorruptedData) } @@ -896,7 +896,7 @@ impl ser::Writeable for StoredProofInfo { } impl ser::Readable for StoredProofInfo { - fn read(reader: &mut dyn ser::Reader) -> Result { + fn read(reader: &mut R) -> Result { let data = reader.read_bytes_len_prefix()?; serde_json::from_slice(&data[..]).map_err(|_| ser::Error::CorruptedData) } @@ -918,7 +918,7 @@ impl ser::Writeable for AcctPathMapping { } impl ser::Readable for AcctPathMapping { - fn read(reader: &mut dyn ser::Reader) -> Result { + fn read(reader: &mut R) -> Result { let data = reader.read_bytes_len_prefix()?; serde_json::from_slice(&data[..]).map_err(|_| ser::Error::CorruptedData) } @@ -951,7 +951,7 @@ impl ser::Writeable for ScannedBlockInfo { } impl ser::Readable for ScannedBlockInfo { - fn read(reader: &mut dyn ser::Reader) -> Result { + fn read(reader: &mut R) -> Result { let data = reader.read_bytes_len_prefix()?; serde_json::from_slice(&data[..]).map_err(|_| ser::Error::CorruptedData) } @@ -988,7 +988,7 @@ impl ser::Writeable for WalletInitStatus { } impl ser::Readable for WalletInitStatus { - fn read(reader: &mut dyn ser::Reader) -> Result { + fn read(reader: &mut R) -> Result { let data = reader.read_bytes_len_prefix()?; serde_json::from_slice(&data[..]).map_err(|_| ser::Error::CorruptedData) }