Skip to content

Commit f51e27a

Browse files
committed
merged main into wh/wallet-signer
2 parents 98e5aad + 860c2b4 commit f51e27a

File tree

4 files changed

+152
-153
lines changed

4 files changed

+152
-153
lines changed

src/eth_utils.rs

+43-43
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
////!
33
////! This module provides utility functions for common Ethereum operations in the Hyperware
44
////! ecosystem, particularly focusing on integrating with Hypermap for name resolution.
5-
////!
5+
////!
66
////! The main goals of this module are:
77
////! 1. Provide simple, developer-friendly functions for common operations
88
////! 2. Abstract away the complexity of blockchain interactions
@@ -12,24 +12,24 @@
1212
////!
1313
////! ```rust
1414
////! use hyperware_process_lib::eth_utils;
15-
////!
15+
////!
1616
////! // Send ETH to a Hypermap name
1717
////! let tx_hash = eth_utils::send_eth("alice.hypr", 1.3)?;
18-
////!
18+
////!
1919
////! // Check if a wallet owns an NFT
2020
////! let has_token = eth_utils::has_nft(contract_address, token_id, wallet_address)?;
21-
////!
21+
////!
2222
////! // Get a token balance
2323
////! let balance = eth_utils::get_token_balance(token_address, wallet_address)?;
24-
////!
24+
////!
2525
////! // Send tokens to a Hypermap name
2626
////! let tx_hash = eth_utils::send_token_to_name(token_address, "bob.hypr", amount)?;
2727
////! ```
2828
//
2929
//use crate::eth::{
30-
// Address,
31-
// EthError,
32-
// TxHash,
30+
// Address,
31+
// EthError,
32+
// TxHash,
3333
// U256
3434
//};
3535
//use crate::hypermap::{Hypermap, HYPERMAP_ADDRESS};
@@ -56,13 +56,13 @@
5656
//
5757
// #[error("Name resolution error: {0}")]
5858
// NameResolution(String),
59-
//
59+
//
6060
// #[error("Transaction error: {0}")]
6161
// Transaction(String),
6262
//}
6363
//
6464
///// Send Ether to an address
65-
/////
65+
/////
6666
///// This function creates, signs, and sends a transaction to send ETH to an address.
6767
/////
6868
///// # Parameters
@@ -75,13 +75,13 @@
7575
/////
7676
///// # Returns
7777
///// A `Result<TxHash, EthUtilsError>` representing the transaction hash if successful
78-
/////
78+
/////
7979
///// # Example
8080
///// ```rust
8181
///// use hyperware_process_lib::{eth_utils, wallet, eth};
8282
///// use alloy_primitives::{Address, U256};
8383
///// use std::str::FromStr;
84-
/////
84+
/////
8585
///// // Create wallet and provider
8686
///// let wallet = wallet::Wallet::from_private_key(
8787
///// "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
@@ -90,7 +90,7 @@
9090
///// let provider = eth::Provider::new(8453, 60000);
9191
///// let to = Address::from_str("0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf")?;
9292
///// let amount = U256::from(1000000000000000000u64); // 1 ETH
93-
/////
93+
/////
9494
///// // Send ETH
9595
///// let tx_hash = eth_utils::send_eth(&provider, &wallet, to, amount, None, None)?;
9696
///// println!("Transaction hash: {}", tx_hash);
@@ -106,18 +106,18 @@
106106
// // Create RLP-encoded transaction
107107
// let nonce = provider.get_transaction_count(wallet.address(), None)?;
108108
// let nonce_u64 = u64::try_from(nonce).unwrap_or(0);
109-
//
109+
//
110110
// // Get gas price if not provided
111111
// let gas_price_value = if let Some(price) = gas_price {
112112
// price
113113
// } else {
114114
// let current_gas_price = provider.get_gas_price()?;
115115
// u128::try_from(current_gas_price).unwrap_or(20000000000)
116116
// };
117-
//
117+
//
118118
// // Get gas limit
119119
// let gas_limit_value = gas_limit.unwrap_or(21000);
120-
//
120+
//
121121
// // Create and sign a transaction manually
122122
// // First, construct the RLP-encoded transaction
123123
// let mut rlp_data = Vec::new();
@@ -126,23 +126,23 @@
126126
// rlp_data.extend_from_slice(&nonce_u64.to_be_bytes());
127127
// rlp_data.extend_from_slice(&gas_limit_value.to_be_bytes());
128128
// rlp_data.extend_from_slice(&gas_price_value.to_be_bytes());
129-
//
129+
//
130130
// // Hash the transaction data with keccak256
131131
// let mut hasher = sha3::Keccak256::new();
132132
// hasher.update(&rlp_data);
133133
// let tx_hash = hasher.finalize();
134-
//
134+
//
135135
// // Sign the transaction hash
136136
// let signed_tx = wallet.sign_transaction_hash(&tx_hash)?;
137-
//
137+
//
138138
// // Send raw transaction
139139
// let tx_hash = provider.send_raw_transaction(signed_tx)?;
140-
//
140+
//
141141
// Ok(tx_hash)
142142
//}
143143
//
144144
///// Sends Ether to the owner of the specified Hypermap name.
145-
/////
145+
/////
146146
///// This function first resolves the name to its owner address using Hypermap,
147147
///// then sends the specified amount of Ether to that address.
148148
/////
@@ -154,30 +154,30 @@
154154
/////
155155
///// # Returns
156156
///// A `Result<TxHash, EthUtilsError>` representing the transaction hash if successful
157-
/////
157+
/////
158158
///// # Example
159159
///// ```rust
160160
///// use hyperware_process_lib::{eth_utils, wallet, eth};
161-
/////
161+
/////
162162
///// // Create wallet and provider
163163
///// let wallet = wallet::Wallet::from_private_key(
164164
///// "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
165165
///// 8453 // Base chain ID
166166
///// )?;
167167
///// let provider = eth::Provider::new(8453, 60000);
168-
/////
168+
/////
169169
///// // Send 1.3 ETH to alice.hypr
170170
///// let tx_hash = eth_utils::send_eth_to_name(&provider, &wallet, "alice.hypr", 1.3)?;
171171
///// println!("Transaction hash: {}", tx_hash);
172172
///// ```
173173
//pub fn send_eth_to_name(
174174
// provider: &crate::eth::Provider,
175175
// wallet: &Wallet,
176-
// name: &str,
176+
// name: &str,
177177
// amount_eth: f64
178178
//) -> Result<TxHash, EthUtilsError> {
179179
// // Get Hypermap instance using our provider
180-
// let hypermap = Hypermap::new(provider.clone(),
180+
// let hypermap = Hypermap::new(provider.clone(),
181181
// Address::from_str(HYPERMAP_ADDRESS).unwrap());
182182
//
183183
// // Format the name if needed (add .hypr if missing)
@@ -186,49 +186,49 @@
186186
// // Resolve name to owner address
187187
// let (_, owner, _) = hypermap.get(&formatted_name)
188188
// .map_err(|e| EthUtilsError::NameResolution(format!("Failed to resolve name '{}': {}", formatted_name, e)))?;
189-
//
189+
//
190190
// // Convert amount to wei (1 ETH = 10^18 wei)
191191
// let amount_wei = (amount_eth * 1e18) as u128;
192192
// let amount_in_wei = U256::from(amount_wei);
193-
//
193+
//
194194
// // Send ETH to the resolved address
195195
// send_eth(provider, wallet, owner, amount_in_wei, None, None)
196196
//}
197197
//
198198
///// Format a name for Hypermap resolution
199-
/////
199+
/////
200200
///// If the name already contains a dot (.), it's returned as is.
201201
///// Otherwise, ".hypr" is appended to the name.
202-
/////
202+
/////
203203
///// # Parameters
204204
///// - `name`: The name to format
205-
/////
205+
/////
206206
///// # Returns
207207
///// A formatted name suitable for Hypermap resolution
208208
//fn format_hypermap_name(name: &str) -> String {
209209
// // If name already has a domain extension, return as is
210210
// if name.contains('.') {
211211
// return name.to_string();
212212
// }
213-
//
213+
//
214214
// // Otherwise, add the default .hypr extension
215215
// format!("{}.hypr", name)
216216
//}
217217
//
218218
///// Resolve a Hypermap name to its owner's Ethereum address
219-
/////
219+
/////
220220
///// # Parameters
221221
///// - `name`: The Hypermap name to resolve
222222
///// - `chain_id`: Optional chain ID to use (defaults to Base chain)
223223
///// - `timeout_ms`: Optional timeout in milliseconds (defaults to 60 seconds)
224-
/////
224+
/////
225225
///// # Returns
226226
///// A `Result<Address, EthError>` representing the owner's Ethereum address
227-
/////
227+
/////
228228
///// # Example
229229
///// ```rust
230230
///// use hyperware_process_lib::eth_utils;
231-
/////
231+
/////
232232
///// let owner = eth_utils::resolve_name("alice.hypr", None, None)?;
233233
///// println!("Owner address: {}", owner);
234234
///// ```
@@ -240,20 +240,20 @@
240240
// // Use provided chain ID or default
241241
// let chain_id = chain_id.unwrap_or(DEFAULT_CHAIN_ID);
242242
// let timeout = timeout_ms.unwrap_or(DEFAULT_TIMEOUT_MS);
243-
//
243+
//
244244
// // Create provider
245245
// let provider = crate::eth::Provider::new(chain_id, timeout);
246-
//
246+
//
247247
// // Get Hypermap instance using our provider
248-
// let hypermap = Hypermap::new(provider,
248+
// let hypermap = Hypermap::new(provider,
249249
// Address::from_str(HYPERMAP_ADDRESS).unwrap());
250250
//
251251
// // Format the name if needed (add .hypr if missing)
252252
// let formatted_name = format_hypermap_name(name);
253253
//
254254
// // Resolve name to owner address
255255
// let (_, owner, _) = hypermap.get(&formatted_name)?;
256-
//
256+
//
257257
// Ok(owner)
258258
//}
259259
//
@@ -268,15 +268,15 @@
268268
// // Test with name that already has dot
269269
// let name_with_dot = "test.hypr";
270270
// assert_eq!(format_hypermap_name(name_with_dot), name_with_dot);
271-
//
271+
//
272272
// // Test with name that doesn't have dot
273273
// let name_without_dot = "test";
274274
// assert_eq!(format_hypermap_name(name_without_dot), "test.hypr");
275275
// }
276276
//
277277
// // Note: These tests would need real providers and wallets to run
278278
// // We'll implement placeholders that describe what should be tested
279-
//
279+
//
280280
// #[test]
281281
// #[ignore] // Ignore this test since it requires network connectivity
282282
// fn test_resolve_name() {
@@ -295,4 +295,4 @@
295295
// // let result = send_eth_to_name(&provider, &wallet, "test.hypr", 0.001);
296296
// // assert!(result.is_ok());
297297
// }
298-
//}
298+
//}

src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ wit_bindgen::generate!({
2626
pub mod eth;
2727
/// High-level Ethereum utilities for common operations.
2828
pub mod eth_utils;
29-
/// Ethereum wallet management with transaction preparation and submission.
30-
pub mod wallet;
31-
/// Low-level Ethereum signing operations and key management.
32-
pub mod signer;
3329
/// Your process must have the [`Capability`] to message
3430
/// `homepage:homepage:sys` to use this module.
3531
pub mod homepage;
@@ -39,12 +35,12 @@ pub mod homepage;
3935
/// Your process must have the [`Capability`] to message and receive messages from
4036
/// `http-server:distro:sys` and/or `http-client:distro:sys` to use this module.
4137
pub mod http;
38+
/// Interact with hypermap, the onchain namespace
39+
pub mod hypermap;
4240
/// The types that the kernel itself uses -- warning -- these will
4341
/// be incompatible with WIT types in some cases, leading to annoying errors.
4442
/// Use only to interact with the kernel or runtime in certain ways.
4543
pub mod kernel_types;
46-
/// Interact with hypermap, the onchain namespace
47-
pub mod hypermap;
4844
/// Tools for exploring and working with Token-Bound Accounts (TBAs) in Hypermap
4945
//pub mod tba_explorer;
5046
/// Interact with the key_value module
@@ -60,6 +56,8 @@ pub mod logging;
6056
/// Your process must have the [`Capability`] to message and receive messages from
6157
/// `net:distro:sys` to use this module.
6258
pub mod net;
59+
/// Low-level Ethereum signing operations and key management.
60+
pub mod signer;
6361
/// Interact with the sqlite module
6462
///
6563
/// Your process must have the [`Capability] to message and receive messages from
@@ -74,6 +72,8 @@ pub mod timer;
7472
/// Your process must have the [`Capability`] to message and receive messages from
7573
/// `vfs:distro:sys` to use this module.
7674
pub mod vfs;
75+
/// Ethereum wallet management with transaction preparation and submission.
76+
pub mod wallet;
7777

7878
/// A set of types and macros for writing "script" processes.
7979
pub mod scripting;

0 commit comments

Comments
 (0)