Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "Apache-2.0"
[features]
hyperapp = ["dep:futures-util", "dep:uuid", "logging"]
logging = ["dep:color-eyre", "dep:tracing", "dep:tracing-error", "dep:tracing-subscriber"]
hyperwallet = []
hyperwallet = ["dep:hex", "dep:sha3"]
simulation-mode = []

[dependencies]
Expand Down Expand Up @@ -48,3 +48,6 @@ color-eyre = { version = "0.6", features = ["capture-spantrace"], optional = tru
tracing = { version = "0.1", optional = true }
tracing-error = { version = "0.2", optional = true }
tracing-subscriber = { version = "0.3", features = ["env-filter", "json", "std"], optional = true }

hex = { version = "0.4.3", optional = true }
sha3 = { version = "0.10.8", optional = true }
1 change: 0 additions & 1 deletion src/hyperwallet_client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::println as kiprintln;
use crate::Request;
use thiserror::Error;

Expand Down
File renamed without changes.
106 changes: 52 additions & 54 deletions src/vfs/file_async.rs → src/vfs/file/file_async.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use super::{
parse_response, vfs_request, FileMetadata, SeekFrom, VfsAction, VfsError, VfsResponse,
};
use super::{vfs_request, FileMetadata, SeekFrom, VfsAction, VfsError, VfsResponse};
use crate::{get_blob, hyperapp, PackageId};

#[derive(serde::Deserialize, serde::Serialize)]
Expand All @@ -20,11 +18,11 @@ impl FileAsync {
pub async fn read(&self) -> Result<Vec<u8>, VfsError> {
let request = vfs_request(&self.path, VfsAction::Read).expects_response(self.timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Read => {
let data = match get_blob() {
Some(bytes) => bytes.bytes,
Expand All @@ -48,11 +46,11 @@ impl FileAsync {
pub async fn read_into(&self, buffer: &mut [u8]) -> Result<usize, VfsError> {
let request = vfs_request(&self.path, VfsAction::Read).expects_response(self.timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Read => {
let data = get_blob().unwrap_or_default().bytes;
let len = std::cmp::min(data.len(), buffer.len());
Expand All @@ -73,11 +71,11 @@ impl FileAsync {
let request =
vfs_request(&self.path, VfsAction::ReadExact { length }).expects_response(self.timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Read => {
let data = get_blob().unwrap_or_default().bytes;
let len = std::cmp::min(data.len(), buffer.len());
Expand All @@ -95,11 +93,11 @@ impl FileAsync {
pub async fn read_to_end(&self) -> Result<Vec<u8>, VfsError> {
let request = vfs_request(&self.path, VfsAction::ReadToEnd).expects_response(self.timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Read => Ok(get_blob().unwrap_or_default().bytes),
VfsResponse::Err(e) => Err(e),
_ => Err(VfsError::ParseError {
Expand All @@ -113,11 +111,11 @@ impl FileAsync {
let request =
vfs_request(&self.path, VfsAction::ReadToString).expects_response(self.timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::ReadToString(s) => Ok(s),
VfsResponse::Err(e) => Err(e),
_ => Err(VfsError::ParseError {
Expand All @@ -132,11 +130,11 @@ impl FileAsync {
.blob_bytes(buffer)
.expects_response(self.timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Ok => Ok(()),
VfsResponse::Err(e) => Err(e),
_ => Err(VfsError::ParseError {
Expand All @@ -151,11 +149,11 @@ impl FileAsync {
.blob_bytes(buffer)
.expects_response(self.timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Ok => Ok(()),
VfsResponse::Err(e) => Err(e),
_ => Err(VfsError::ParseError {
Expand All @@ -170,11 +168,11 @@ impl FileAsync {
.blob_bytes(buffer)
.expects_response(self.timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Ok => Ok(()),
VfsResponse::Err(e) => Err(e),
_ => Err(VfsError::ParseError {
Expand All @@ -187,11 +185,11 @@ impl FileAsync {
pub async fn seek(&mut self, pos: SeekFrom) -> Result<u64, VfsError> {
let request = vfs_request(&self.path, VfsAction::Seek(pos)).expects_response(self.timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::SeekFrom {
new_offset: new_pos,
} => Ok(new_pos),
Expand All @@ -212,11 +210,11 @@ impl FileAsync {
)
.expects_response(self.timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Ok => Ok(FileAsync {
path: path.to_string(),
timeout: self.timeout,
Expand All @@ -233,11 +231,11 @@ impl FileAsync {
let request =
vfs_request(&self.path, VfsAction::SetLen(size)).expects_response(self.timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Ok => Ok(()),
VfsResponse::Err(e) => Err(e),
_ => Err(VfsError::ParseError {
Expand All @@ -250,11 +248,11 @@ impl FileAsync {
pub async fn metadata(&self) -> Result<FileMetadata, VfsError> {
let request = vfs_request(&self.path, VfsAction::Metadata).expects_response(self.timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Metadata(metadata) => Ok(metadata),
VfsResponse::Err(e) => Err(e),
_ => Err(VfsError::ParseError {
Expand All @@ -267,11 +265,11 @@ impl FileAsync {
pub async fn sync_all(&self) -> Result<(), VfsError> {
let request = vfs_request(&self.path, VfsAction::SyncAll).expects_response(self.timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Ok => Ok(()),
VfsResponse::Err(e) => Err(e),
_ => Err(VfsError::ParseError {
Expand Down Expand Up @@ -300,11 +298,11 @@ pub async fn create_drive_async(

let request = vfs_request(&path, VfsAction::CreateDrive).expects_response(timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Ok => Ok(path),
VfsResponse::Err(e) => Err(e),
_ => Err(VfsError::ParseError {
Expand All @@ -323,11 +321,11 @@ pub async fn open_file_async(

let request = vfs_request(path, VfsAction::OpenFile { create }).expects_response(timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Ok => Ok(FileAsync {
path: path.to_string(),
timeout,
Expand All @@ -345,11 +343,11 @@ pub async fn create_file_async(path: &str, timeout: Option<u64>) -> Result<FileA

let request = vfs_request(path, VfsAction::CreateFile).expects_response(timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Ok => Ok(FileAsync {
path: path.to_string(),
timeout,
Expand All @@ -367,11 +365,11 @@ pub async fn remove_file_async(path: &str, timeout: Option<u64>) -> Result<(), V

let request = vfs_request(path, VfsAction::RemoveFile).expects_response(timeout);

let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
let response = hyperapp::send::<VfsResponse>(request)
.await
.map_err(|e| VfsError::SendError(crate::SendErrorKind::Timeout))?;
.map_err(|_e| VfsError::SendError(crate::SendErrorKind::Timeout))?;

match parse_response(&resp_bytes)? {
match response {
VfsResponse::Ok => Ok(()),
VfsResponse::Err(e) => Err(e.into()),
_ => Err(VfsError::ParseError {
Expand Down