From a0789d0a14849f835eef16ec01558ac23d4f38f7 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 13 May 2024 02:26:42 -0600 Subject: [PATCH] simplify src/transaction/bundlr.rs Data --- Cargo.lock | 147 ++++++++++++++++++++++++++++---------- Cargo.toml | 4 +- src/bundlr.rs | 4 +- src/client/upload.rs | 25 +++---- src/transaction/bundlr.rs | 114 ++++++++++++++--------------- 5 files changed, 176 insertions(+), 118 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59d8551..268fae8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -93,7 +93,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -103,7 +103,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -264,7 +264,7 @@ dependencies = [ "futures-lite", "rustix 0.37.23", "signal-hook", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -670,7 +670,7 @@ dependencies = [ "android-tzdata", "iana-time-zone", "num-traits", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -837,7 +837,7 @@ dependencies = [ "openssl-sys", "pkg-config", "vcpkg", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1056,7 +1056,7 @@ checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" dependencies = [ "errno-dragonfly", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1659,7 +1659,7 @@ checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ "hermit-abi", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1676,7 +1676,7 @@ checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi", "rustix 0.38.14", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1828,9 +1828,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760" [[package]] name = "libc" -version = "0.2.148" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] name = "libflate" @@ -1976,13 +1976,13 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.8" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2214,7 +2214,7 @@ dependencies = [ "libc", "redox_syscall 0.3.5", "smallvec", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -2333,7 +2333,7 @@ dependencies = [ "libc", "log", "pin-project-lite", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2729,7 +2729,7 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys 0.3.8", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2742,7 +2742,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.7", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2794,7 +2794,7 @@ version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -3039,12 +3039,12 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.4" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -3231,9 +3231,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.32.0" +version = "1.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", "bytes", @@ -3243,16 +3243,16 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.4", + "socket2 0.5.7", "tokio-macros", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] name = "tokio-macros" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", @@ -3740,7 +3740,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -3749,7 +3749,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", ] [[package]] @@ -3758,13 +3767,29 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] @@ -3773,42 +3798,90 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" + [[package]] name = "winnow" version = "0.5.15" @@ -3825,7 +3898,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ "cfg-if", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 11060e7..f4cdd37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,8 +44,8 @@ sha2 = "0.10.2" strum = { version = "0.24", features = ["derive"] } strum_macros = "0.24" thiserror = "1.0.30" -tokio = { version = "1.14.0", features = [ "fs" ]} -tokio-util = "0.6.9" +tokio = { version = "1.37.0", features = [ "fs" ]} +tokio-util = { version = "0.6.9", features = [ "io" ]} validator = { version = "0.16", features = ["derive"] } web3 = { version = "0.19.0", optional = true, default-features = false, features = ["http-rustls-tls", "signing"]} diff --git a/src/bundlr.rs b/src/bundlr.rs index b002b25..d7a2a15 100644 --- a/src/bundlr.rs +++ b/src/bundlr.rs @@ -266,7 +266,7 @@ where /// ``` pub fn create_transaction( &self, - data: Vec, + data: tokio::fs::File, additional_tags: Vec, ) -> Result { BundlrTx::new(vec![], data, additional_tags) @@ -352,7 +352,7 @@ where /// # } /// ``` pub async fn send_transaction(&self, tx: BundlrTx) -> Result { - let tx = tx.as_bytes()?; + let tx = tx.as_bytes().await?; let response = self .client diff --git a/src/client/upload.rs b/src/client/upload.rs index 24aae75..c9e9bf2 100644 --- a/src/client/upload.rs +++ b/src/client/upload.rs @@ -1,9 +1,6 @@ -use std::{ - fs::File, - io::{BufReader, Read}, - path::PathBuf, - str::FromStr, -}; +use std::{path::PathBuf, str::FromStr}; + +use tokio::fs::File; use crate::{ bundlr::BundlrBuilder, @@ -22,12 +19,10 @@ pub async fn run_upload( wallet: &str, currency: CurrencyType, ) -> Result { - let f = File::open(file_path.clone()).expect("Invalid file path"); - let mut reader = BufReader::new(f); - let mut buffer = Vec::new(); - - // Read file into vector. - reader.read_to_end(&mut buffer)?; + let mut f = File::open(file_path.clone()) + .await + .expect("Invalid file path"); + f.set_max_buf_size(8 * 1024 * 1024); let base_tag = Tag::new("User-Agent", &format!("bundlr-sdk-rs/{}", VERSION)); @@ -42,7 +37,7 @@ pub async fn run_upload( .fetch_pub_info() .await? .build()?; - let mut tx = bundlr.create_transaction(buffer, vec![base_tag])?; + let mut tx = bundlr.create_transaction(f, vec![base_tag])?; let sig = bundlr.sign_transaction(&mut tx).await; assert!(sig.is_ok()); match bundlr.send_transaction(tx).await { @@ -58,7 +53,7 @@ pub async fn run_upload( .fetch_pub_info() .await? .build()?; - let mut tx = bundlr.create_transaction(buffer, vec![base_tag])?; + let mut tx = bundlr.create_transaction(f, vec![base_tag])?; let sig = bundlr.sign_transaction(&mut tx).await; assert!(sig.is_ok()); match bundlr.send_transaction(tx).await { @@ -74,7 +69,7 @@ pub async fn run_upload( .fetch_pub_info() .await? .build()?; - let mut tx = bundlr.create_transaction(buffer, vec![base_tag])?; + let mut tx = bundlr.create_transaction(f, vec![base_tag])?; let sig = bundlr.sign_transaction(&mut tx).await; assert!(sig.is_ok()); match bundlr.send_transaction(tx).await { diff --git a/src/transaction/bundlr.rs b/src/transaction/bundlr.rs index 4a3b9ed..e93e385 100644 --- a/src/transaction/bundlr.rs +++ b/src/transaction/bundlr.rs @@ -1,10 +1,13 @@ +use anyhow::Error; use async_stream::try_stream; -use bytes::{BufMut, Bytes}; -use futures::Stream; +use bytes::{BufMut, Bytes, BytesMut}; +use futures::{future, stream, Stream, StreamExt, TryStreamExt}; use ring::rand::SecureRandom; use std::cmp; use std::fs::File; use std::pin::Pin; +use tokio::io::AsyncRead; +use tokio_util::io::ReaderStream; use crate::consts::{CHUNK_SIZE, DATAITEM_AS_BUFFER, ONE_AS_BUFFER}; use crate::deep_hash::{deep_hash, DeepHashChunk}; @@ -15,11 +18,7 @@ use crate::signers::Signer; use crate::tags::{AvroDecode, AvroEncode, Tag}; use crate::utils::read_offset; -enum Data { - None, - Bytes(Vec), - Stream(Pin>>>), -} +type Data = Option>>>>; pub struct BundlrTx { signature_type: SignerMap, @@ -32,7 +31,10 @@ pub struct BundlrTx { } impl BundlrTx { - pub fn new(target: Vec, data: Vec, tags: Vec) -> Result { + pub fn new(target: Vec, data: A, tags: Vec) -> Result + where + A: AsyncRead + Send + 'static, + { let mut randoms: [u8; 32] = [0; 32]; let sr = ring::rand::SystemRandom::new(); match sr.fill(&mut randoms) { @@ -48,7 +50,7 @@ impl BundlrTx { target, anchor, tags, - data: Data::Bytes(data), + data: Some(ReaderStream::new(data).map_err(Error::from).boxed()), }) } @@ -130,10 +132,10 @@ impl BundlrTx { pub fn from_bytes(buffer: Vec) -> Result { let (bundlr_tx, data_start) = BundlrTx::from_info_bytes(&buffer)?; - let data = &buffer[data_start..buffer.len()]; + let data = stream::once(future::ready(Bytes::copy_from_slice(&buffer[data_start..]))); Ok(BundlrTx { - data: Data::Bytes(data.to_vec()), + data: Some(data.map(Ok).boxed()), ..bundlr_tx }) } @@ -161,7 +163,7 @@ impl BundlrTx { }; Ok(BundlrTx { - data: Data::Stream(Box::pin(file_stream)), + data: Some(Box::pin(file_stream)), ..bundlr_tx }) } @@ -170,22 +172,33 @@ impl BundlrTx { !self.signature.is_empty() && self.signature_type != SignerMap::None } - pub fn as_bytes(self) -> Result, BundlrError> { + pub async fn as_bytes(self) -> Result, BundlrError> { if !self.is_signed() { return Err(BundlrError::NoSignature); } - let data = match &self.data { - Data::Stream(_) => return Err(BundlrError::InvalidDataType), - Data::None => return Err(BundlrError::InvalidDataType), - Data::Bytes(data) => data, + let BundlrTx { + signature_type, + signature, + owner, + target, + anchor, + tags, + data, + } = self; + let data = match data { + Some(data) => data + .try_collect::() + .await + .map_err(|_| BundlrError::InvalidDataType)?, + None => return Err(BundlrError::InvalidDataType), }; - let encoded_tags = if !self.tags.is_empty() { - self.tags.encode()? + let encoded_tags = if !tags.is_empty() { + tags.encode()? } else { Bytes::default() }; - let config = self.signature_type.get_config(); + let config = signature_type.get_config(); let length = 2u64 + config.sig_length as u64 + config.pub_length as u64 @@ -199,25 +212,17 @@ impl BundlrTx { .map_err(|err| BundlrError::TypeParseError(err.to_string()))?, ); - let sig_type: [u8; 2] = (self.signature_type as u16).to_le_bytes(); - let target_presence_byte = if self.target.is_empty() { - &[0u8] - } else { - &[1u8] - }; - let anchor_presence_byte = if self.anchor.is_empty() { - &[0u8] - } else { - &[1u8] - }; + let sig_type: [u8; 2] = (signature_type as u16).to_le_bytes(); + let target_presence_byte = if target.is_empty() { &[0u8] } else { &[1u8] }; + let anchor_presence_byte = if anchor.is_empty() { &[0u8] } else { &[1u8] }; b.put(&sig_type[..]); - b.put(&self.signature[..]); - b.put(&self.owner[..]); + b.put(&signature[..]); + b.put(&owner[..]); b.put(&target_presence_byte[..]); - b.put(&self.target[..]); + b.put(&target[..]); b.put(&anchor_presence_byte[..]); - b.put(&self.anchor[..]); - let number_of_tags = (self.tags.len() as u64).to_le_bytes(); + b.put(&anchor[..]); + let number_of_tags = (tags.len() as u64).to_le_bytes(); let number_of_tags_bytes = (encoded_tags.len() as u64).to_le_bytes(); b.put(number_of_tags.as_slice()); b.put(number_of_tags_bytes.as_slice()); @@ -243,23 +248,8 @@ impl BundlrTx { }; match &mut self.data { - Data::None => Ok(Bytes::new()), - Data::Bytes(data) => { - let data_chunk = DeepHashChunk::Chunk(data.clone().into()); - let sig_type = &self.signature_type; - let sig_type_bytes = sig_type.as_u16().to_string().as_bytes().to_vec(); - deep_hash_sync(DeepHashChunk::Chunks(vec![ - DeepHashChunk::Chunk(DATAITEM_AS_BUFFER.into()), - DeepHashChunk::Chunk(ONE_AS_BUFFER.into()), - DeepHashChunk::Chunk(sig_type_bytes.to_vec().into()), - DeepHashChunk::Chunk(self.owner.to_vec().into()), - DeepHashChunk::Chunk(self.target.to_vec().into()), - DeepHashChunk::Chunk(self.anchor.to_vec().into()), - DeepHashChunk::Chunk(encoded_tags.clone()), - data_chunk, - ])) - } - Data::Stream(file_stream) => { + None => Ok(Bytes::new()), + Some(file_stream) => { let data_chunk = DeepHashChunk::Stream(file_stream); let sig_type = &self.signature_type; let sig_type_bytes = sig_type.as_u16().to_string().as_bytes().to_vec(); @@ -328,7 +318,7 @@ mod tests { let signer = Ed25519Signer::from_base58(secret_key).unwrap(); let mut data_item_1 = BundlrTx::new( Vec::from(""), - Vec::from("hello"), + &b"hello"[..], vec![Tag::new("name", "value")], ) .unwrap(); @@ -336,14 +326,14 @@ mod tests { assert!(res.is_ok()); let mut f = File::create(path).unwrap(); - let data_item_1_bytes = data_item_1.as_bytes().unwrap(); + let data_item_1_bytes = data_item_1.as_bytes().await.unwrap(); f.write_all(&data_item_1_bytes).unwrap(); let buffer = fs::read(path).expect("Could not read file"); let data_item_2 = BundlrTx::from_bytes(buffer).expect("Invalid bytes"); assert!(&data_item_2.is_signed()); - assert_eq!(data_item_1_bytes, data_item_2.as_bytes().unwrap()); + assert_eq!(data_item_1_bytes, data_item_2.as_bytes().await.unwrap()); } #[tokio::test] @@ -353,7 +343,7 @@ mod tests { let signer = ArweaveSigner::from_keypair_path(key_path).unwrap(); let mut data_item_1 = BundlrTx::new( Vec::from(""), - Vec::from("hello"), + &b"hello"[..], vec![Tag::new("name", "value")], ) .unwrap(); @@ -361,13 +351,13 @@ mod tests { assert!(res.is_ok()); let mut f = File::create(path).unwrap(); - let data_item_1_bytes = data_item_1.as_bytes().unwrap(); + let data_item_1_bytes = data_item_1.as_bytes().await.unwrap(); f.write_all(&data_item_1_bytes).unwrap(); let buffer = fs::read(path).expect("Could not read file"); let data_item_2 = BundlrTx::from_bytes(buffer).expect("Invalid bytes"); assert!(&data_item_2.is_signed()); - assert_eq!(data_item_1_bytes, data_item_2.as_bytes().unwrap()); + assert_eq!(data_item_1_bytes, data_item_2.as_bytes().await.unwrap()); } #[tokio::test] @@ -403,19 +393,19 @@ mod tests { let signer = Secp256k1Signer::new(secret_key); let mut data_item_1 = BundlrTx::new( Vec::from(""), - Vec::from("hello"), + &b"hello"[..], vec![Tag::new("name", "value")], ) .unwrap(); let res = data_item_1.sign(&signer).await; assert!(res.is_ok()); let mut f = File::create(path).unwrap(); - let data_item_1_bytes = data_item_1.as_bytes().unwrap(); + let data_item_1_bytes = data_item_1.as_bytes().await.unwrap(); f.write_all(&data_item_1_bytes).unwrap(); let buffer = fs::read(path).expect("Could not read file"); let data_item_2 = BundlrTx::from_bytes(buffer).expect("Invalid bytes"); assert!(&data_item_2.is_signed()); - assert_eq!(data_item_1_bytes, data_item_2.as_bytes().unwrap()); + assert_eq!(data_item_1_bytes, data_item_2.as_bytes().await.unwrap()); } }