Skip to content

[not fully tested] Wh/wallet signer #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
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
194 changes: 125 additions & 69 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ alloy = { version = "0.8.1", features = [
"json-rpc",
"rpc-client",
"rpc-types",
"signers",
"signer-local",
"consensus",
"network",
] }
hex = "0.4.3"
sha3 = "0.10.8"
anyhow = "1.0"
bincode = "1.3.3"
color-eyre = { version = "0.6", features = ["capture-spantrace"], optional = true }
Expand Down
50 changes: 42 additions & 8 deletions src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ impl<'de> Deserialize<'de> for NodeOrRpcUrl {
/// for that chain.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Provider {
chain_id: u64,
request_timeout: u64,
pub chain_id: u64,
pub request_timeout: u64,
}

impl Provider {
Expand Down Expand Up @@ -756,21 +756,55 @@ impl Provider {
print_verbosity_success: u8,
print_verbosity_error: u8,
) {
let mut delay_secs = 5; // Initial delay
const MAX_DELAY_SECS: u64 = 60; // Maximum delay

loop {
match self.subscribe(sub_id, filter.clone()) {
Ok(()) => break,
Err(_) => {
Ok(()) => break, // Success, exit loop
Err(e) => {
// Log the actual error
crate::print_to_terminal(
print_verbosity_error,
"failed to subscribe to chain! trying again in 5s...",
&format!(
"Failed to subscribe to chain (sub_id {}): {:?}. Retrying in {}s...",
sub_id, e, delay_secs
),
);
std::thread::sleep(std::time::Duration::from_secs(5));
continue;
std::thread::sleep(std::time::Duration::from_secs(delay_secs));
// Increase delay for next attempt, capped at maximum
delay_secs = (delay_secs * 2).min(MAX_DELAY_SECS);
continue; // Retry
}
}
}
crate::print_to_terminal(print_verbosity_success, "subscribed to logs successfully");
crate::print_to_terminal(
print_verbosity_success,
&format!("Subscribed successfully (sub_id {})", sub_id),
);
}
//pub fn subscribe_loop(
// &self,
// sub_id: u64,
// filter: Filter,
// print_verbosity_success: u8,
// print_verbosity_error: u8,
//) {
// loop {
// match self.subscribe(sub_id, filter.clone()) {
// Ok(()) => break,
// Err(_) => {
// crate::print_to_terminal(
// print_verbosity_error,
// "failed to subscribe to chain! trying again in 5s...",
// );
// std::thread::sleep(std::time::Duration::from_secs(5));
// continue;
// }
// }
// }
// crate::print_to_terminal(print_verbosity_success, "subscribed to logs successfully");
//}

/// Unsubscribes from a previously created subscription.
///
Expand Down
49 changes: 49 additions & 0 deletions src/hypermap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,4 +619,53 @@ impl Hypermap {
.collect::<Vec<_>>(),
)
}

/// Gets the list of delegate addresses stored via the standard Hypermap access control pattern.
/// This involves reading the `~access-list` note for the given `entry_path` to find the
/// namehash of the permissions note, then reading that permissions note to get the
/// ABI-encoded `Vec<Address>` of delegates.
///
/// # Arguments
/// * `entry_path` - The base hypermap path (e.g., "myname.hypr") for which to find delegates.
///
/// # Returns
/// A `Result<Vec<Address>, EthError>` containing the list of delegate addresses if found
/// and decoded successfully, or an error otherwise.
pub fn get_access_list_delegates(&self, entry_path: &str) -> Result<Vec<Address>, EthError> {
// 1. Construct the path to the ~access-list note
let access_list_path = format!("~access-list.{}", entry_path);

// 2. Get the ~access-list note data (expecting a B256 namehash)
let (_tba, _owner, access_list_data_opt) = self.get(&access_list_path)?;

let access_list_data = access_list_data_opt.ok_or_else(|| {
// Note not found or has no data - considered a malformed/unexpected response
EthError::RpcMalformedResponse
})?;

// 3. Decode the data as the permissions note hash (B256)
// We expect the raw bytes stored in the note to be exactly 32 bytes.
if access_list_data.len() != 32 {
// Invalid data length - malformed response
return Err(EthError::RpcMalformedResponse);
}
let perms_note_hash = B256::from_slice(access_list_data.as_ref());
let perms_note_hash_str = format!("0x{}", hex::encode(perms_note_hash));

// 4. Get the permissions note using the hash
let (_perms_tba, _perms_owner, perms_data_opt) = self.get_hash(&perms_note_hash_str)?;

let perms_data = perms_data_opt.ok_or_else(|| {
// Permissions note not found or has no data - malformed/unexpected response
EthError::RpcMalformedResponse
})?;

// 5. Decode the permissions data as Vec<Address>
let delegates = Vec::<Address>::abi_decode(&perms_data, true).map_err(|_e| {
// Failed to decode Vec<Address> - malformed response
EthError::RpcMalformedResponse
})?;

Ok(delegates)
}
}
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ wit_bindgen::generate!({

/// Interact with the eth provider module.
pub mod eth;
/// Interact with the system homepage.
///
/// Your process must have the [`Capability`] to message
/// `homepage:homepage:sys` to use this module.
pub mod homepage;
Expand All @@ -41,6 +39,8 @@ pub mod hypermap;
/// be incompatible with WIT types in some cases, leading to annoying errors.
/// Use only to interact with the kernel or runtime in certain ways.
pub mod kernel_types;
/// Tools for exploring and working with Token-Bound Accounts (TBAs) in Hypermap
//pub mod tba_explorer;
/// Interact with the key_value module
///
/// Your process must have the [`Capability`] to message and receive messages from
Expand All @@ -54,6 +54,8 @@ pub mod logging;
/// Your process must have the [`Capability`] to message and receive messages from
/// `net:distro:sys` to use this module.
pub mod net;
/// Low-level Ethereum signing operations and key management.
pub mod signer;
/// Interact with the sqlite module
///
/// Your process must have the [`Capability] to message and receive messages from
Expand All @@ -68,6 +70,8 @@ pub mod timer;
/// Your process must have the [`Capability`] to message and receive messages from
/// `vfs:distro:sys` to use this module.
pub mod vfs;
/// Ethereum wallet management with transaction preparation and submission.
pub mod wallet;

/// A set of types and macros for writing "script" processes.
pub mod scripting;
Expand Down
Loading