Skip to content

Commit

Permalink
Import dev20
Browse files Browse the repository at this point in the history
  • Loading branch information
ddd-mtl committed Jan 29, 2025
1 parent 4e265d3 commit aa86492
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 303 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
target
test
test
.idea
19 changes: 15 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
[package]
name = "zome_utils"
version = "0.1.0"
rust-version = "1.65.0"
rust-version = "1.75.0"
edition = "2021"

[lib]
crate-type = [ "cdylib", "rlib" ]

[lints.rust]
non_upper_case_globals = "allow"
unused_doc_comments = "allow"
non_camel_case_types = "allow"
non_snake_case = "allow"
unused_attributes = "allow"

[dependencies]
serde = { version = "1.0.197", default-features = false }
serde = { version = "1.0.203", default-features = false }
hdk = { version = "=0.4.0-rc.1", features = ["encoding"] }

## Broken hdk deps
#hdk_derive = { version = "=0.4.0-dev.12", default-features = false }
#holochain_integrity_types = "=0.4.0-dev.12"

#chrono = { version = "0.4.22", default-features = false, features = ["clock", "std", "oldtime", "serde"], optional = true }
#holochain_zome_types = { version = "=0.2.4", default-features = false }
hdk = { version = "=0.4.0-dev.4", features = ["encoding"] }

# Force a specific version since hdk won't compile otherwise
#holochain_integrity_types = { version = "=0.1.1" }
65 changes: 27 additions & 38 deletions src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
//! Debugging helpers
use hdk::prelude::*;
//use holo_hash::*;

use crate as zome_utils;

// #[macro_export]
// macro_rules! zome_error {
// ($($arg:tt)*) => {
// {
// let reason = format!($($arg)*);
// let msg = format!("{} ; Context: {}", reason, zome_utils::dump_context());
// Err(wasm_error!(WasmErrorInner::Guest(msg)))
// }
// }
// }


#[macro_export]
Expand All @@ -35,6 +23,24 @@ macro_rules! zome_error {
}


///
pub fn error<T>(reason: &str) -> ExternResult<T> {
let msg = format!("{} ; Context: {}", reason, dump_context());
let error = WasmError {
file: String::new(),
line: 0,
error: WasmErrorInner::Guest(msg),
};
Err(error)
}


///
pub fn invalid(reason: &str) -> ExternResult<ValidateCallbackResult> {
Ok(ValidateCallbackResult::Invalid(reason.to_string()))
}


/// Return zome context as String
pub fn dump_context() -> String {
let mut msg = String::new();
Expand All @@ -55,15 +61,6 @@ pub fn dump_context() -> String {
}


/// Shorten AgentPubKey for printing
pub fn snip(agent: &AgentPubKey) -> String {
//format!("{:?}", agent)[12..24].to_string()
//format!("{}", agent)[..12].to_string()
let b64: AgentPubKeyB64 = AgentPubKeyB64::from(agent.clone());
format!("{:?}", b64)[24..36].to_string()
}


/// Panic hook for zome debugging
pub fn zome_panic_hook(info: &std::panic::PanicInfo) {
let mut msg = "\n\nPanic during zome call ".to_owned();
Expand All @@ -74,22 +71,6 @@ pub fn zome_panic_hook(info: &std::panic::PanicInfo) {
}


///
pub fn error<T>(reason: &str) -> ExternResult<T> {
let msg = format!("{} ; Context: {}", reason, dump_context());
let error = WasmError {
file: String::new(),
line: 0,
error: WasmErrorInner::Guest(msg),
};
Err(error)
}


pub fn invalid(reason: &str) -> ExternResult<ValidateCallbackResult> {
Ok(ValidateCallbackResult::Invalid(reason.to_string()))
}


/// Convert ZomeCallResponse to ExternResult
pub fn decode_response<T>(response: ZomeCallResponse) -> ExternResult<T>
Expand All @@ -104,9 +85,17 @@ pub fn decode_response<T>(response: ZomeCallResponse) -> ExternResult<T>
.map_err(|_| error::<T>("Deserializing response output failed").err().unwrap());
res
},
ZomeCallResponse::Unauthorized(_, _, _, _, _) => zome_error!("Unauthorized call"),
ZomeCallResponse::Unauthorized(auth, _, _, fn_name, _) => zome_error!("Unauthorized call to {}(): {:?}", fn_name, auth),
ZomeCallResponse::NetworkError(e) => zome_error!("NetworkError: {:?}", e),
ZomeCallResponse::CountersigningSession(e) => zome_error!("CountersigningSession: {:?}", e),
};
}


/// Shorten AgentPubKey for printing
pub fn snip(agent: &AgentPubKey) -> String {
//format!("{:?}", agent)[12..24].to_string()
format!("{}", agent)[5..13].to_string()
//let b64: AgentPubKeyB64 = AgentPubKeyB64::from(agent.clone());
//format!("{:?}", b64)[5..13].to_string()
}
Loading

0 comments on commit aa86492

Please sign in to comment.