-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from renegade-fi/joey/add-gas-wallet
funds-manager: custody-client: Add endpoint for creating gas wallets
- Loading branch information
Showing
7 changed files
with
133 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
funds-manager/funds-manager-server/src/custody_client/gas_wallets.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! Handlers for gas wallet operations | ||
|
||
use ethers::{ | ||
signers::{LocalWallet, Signer}, | ||
utils::hex::ToHexExt, | ||
}; | ||
use rand::thread_rng; | ||
use tracing::info; | ||
|
||
use crate::{error::FundsManagerError, helpers::create_secrets_manager_entry_with_description}; | ||
|
||
use super::CustodyClient; | ||
|
||
impl CustodyClient { | ||
/// Create a new gas wallet | ||
pub(crate) async fn create_gas_wallet(&self) -> Result<String, FundsManagerError> { | ||
// Sample a new ethereum keypair | ||
let keypair = LocalWallet::new(&mut thread_rng()); | ||
let address = keypair.address().encode_hex(); | ||
|
||
// Add the gas wallet to the database | ||
self.add_gas_wallet(&address).await?; | ||
|
||
// Store the private key in secrets manager | ||
let secret_name = Self::gas_wallet_secret_name(&address); | ||
let private_key = keypair.signer().to_bytes(); | ||
let secret_value = hex::encode(private_key); | ||
let description = "Gas wallet private key for use by Renegade relayers"; | ||
create_secrets_manager_entry_with_description( | ||
&secret_name, | ||
&secret_value, | ||
&self.aws_config, | ||
description, | ||
) | ||
.await?; | ||
info!("Created gas wallet with address: {}", address); | ||
|
||
Ok(address) | ||
} | ||
|
||
/// Get the secret name for a gas wallet's private key | ||
fn gas_wallet_secret_name(address: &str) -> String { | ||
format!("gas-wallet-{}", address) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters