diff --git a/CHANGELOG.md b/CHANGELOG.md index 32bf070..3fd9aca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added - Added `fep-e232` feature flag (disabled by default). +- Added `account_index` parameter to Monero configuration. ### Fixed diff --git a/config.yaml.example b/config.yaml.example index ec95f0a..0adf75b 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -15,27 +15,28 @@ registration: type: open blockchains: - # Parameters for hardhat local node - - chain_id: eip155:31337 - chain_metadata: - chain_name: localhost - currency_name: ETH - currency_symbol: ETH - currency_decimals: 18 - public_api_url: 'http://127.0.0.1:8546' - explorer_url: null - contract_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9' - contract_dir: contracts - api_url: 'http://127.0.0.1:8546' - signing_key: 'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' - chain_sync_step: 100 - chain_reorg_max_depth: 0 -# # Parameters for local Monero node -# - chain_id: monero:regtest -# node_url: 'http://127.0.0.1:58081' -# wallet_url: 'http://127.0.0.1:58083' -# wallet_name: test -# wallet_password: test + # Parameters for local Monero node + - chain_id: monero:regtest + node_url: 'http://127.0.0.1:58081' + wallet_url: 'http://127.0.0.1:58083' + wallet_name: test + wallet_password: test + account_index: 0 +# # Parameters for hardhat local node +# - chain_id: eip155:31337 +# chain_metadata: +# chain_name: localhost +# currency_name: ETH +# currency_symbol: ETH +# currency_decimals: 18 +# public_api_url: 'http://127.0.0.1:8546' +# explorer_url: null +# contract_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9' +# contract_dir: contracts +# api_url: 'http://127.0.0.1:8546' +# signing_key: 'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' +# chain_sync_step: 100 +# chain_reorg_max_depth: 0 ipfs_api_url: 'http://127.0.0.1:5001' ipfs_gateway_url: 'http://127.0.0.1:8001' diff --git a/contrib/mitra_config.yaml b/contrib/mitra_config.yaml index c08b455..20bd4bf 100644 --- a/contrib/mitra_config.yaml +++ b/contrib/mitra_config.yaml @@ -65,6 +65,7 @@ retention: # wallet_url: 'http://127.0.0.1:18083' # wallet_name: null # wallet_password: null +# account_index: 0 # - chain_id: eip155:31337 # chain_metadata: # chain_name: localhost diff --git a/mitra-config/src/blockchain.rs b/mitra-config/src/blockchain.rs index 413e8c8..2060c71 100644 --- a/mitra-config/src/blockchain.rs +++ b/mitra-config/src/blockchain.rs @@ -49,6 +49,8 @@ impl EthereumConfig { } } +fn default_wallet_account_index() -> u32 { 0 } + #[derive(Clone, Deserialize)] pub struct MoneroConfig { pub chain_id: ChainId, @@ -59,6 +61,8 @@ pub struct MoneroConfig { // monero-wallet-rpc is running with --wallet-dir option pub wallet_name: Option, pub wallet_password: Option, + #[serde(default = "default_wallet_account_index")] + pub account_index: u32, } #[derive(Clone, Deserialize)] diff --git a/src/monero/helpers.rs b/src/monero/helpers.rs index 7020a8d..a4744fb 100644 --- a/src/monero/helpers.rs +++ b/src/monero/helpers.rs @@ -17,7 +17,6 @@ use crate::models::{ }; use super::wallet::{ open_monero_wallet, - DEFAULT_ACCOUNT, MoneroError, }; @@ -45,7 +44,7 @@ pub async fn check_expired_invoice( let address_index = wallet_client.get_address_index(address).await?; let transfers = wallet_client.incoming_transfers( TransferType::Available, - Some(DEFAULT_ACCOUNT), + Some(config.account_index), Some(vec![address_index.minor]), ).await? .transfers diff --git a/src/monero/subscriptions.rs b/src/monero/subscriptions.rs index d55224f..9b80c44 100644 --- a/src/monero/subscriptions.rs +++ b/src/monero/subscriptions.rs @@ -29,7 +29,6 @@ use super::wallet::{ get_subaddress_balance, open_monero_wallet, send_monero, - DEFAULT_ACCOUNT, MoneroError, }; @@ -68,7 +67,7 @@ pub async fn check_monero_subscriptions( log::info!("{} invoices are waiting for payment", address_waitlist.len()); let incoming_transfers = wallet_client.incoming_transfers( TransferType::Available, - Some(DEFAULT_ACCOUNT), + Some(config.account_index), Some(address_waitlist), ).await?; incoming_transfers.transfers @@ -78,7 +77,7 @@ pub async fn check_monero_subscriptions( if let Some(transfers) = maybe_incoming_transfers { for transfer in transfers { let address_data = wallet_client.get_address( - DEFAULT_ACCOUNT, + config.account_index, Some(vec![transfer.subaddr_index.minor]), ).await?; let subaddress_data = get_single_item(address_data.addresses)?; @@ -143,6 +142,7 @@ pub async fn check_monero_subscriptions( let payout_address = Address::from_str(&payment_info.payout_address)?; let payout_amount = send_monero( &wallet_client, + config.account_index, address_index.minor, payout_address, ).await?; diff --git a/src/monero/wallet.rs b/src/monero/wallet.rs index 2502d6d..2d42266 100644 --- a/src/monero/wallet.rs +++ b/src/monero/wallet.rs @@ -17,8 +17,6 @@ use mitra_config::MoneroConfig; use crate::database::DatabaseError; -pub const DEFAULT_ACCOUNT: u32 = 0; - #[derive(thiserror::Error, Debug)] pub enum MoneroError { #[error(transparent)] @@ -71,9 +69,10 @@ pub async fn create_monero_address( config: &MoneroConfig, ) -> Result { let wallet_client = open_monero_wallet(config).await?; + let account_index = config.account_index; let (address, address_index) = - wallet_client.create_address(DEFAULT_ACCOUNT, None).await?; - log::info!("created monero address {}/{}", DEFAULT_ACCOUNT, address_index); + wallet_client.create_address(account_index, None).await?; + log::info!("created monero address {}/{}", account_index, address_index); Ok(address) } @@ -100,12 +99,13 @@ pub async fn get_subaddress_balance( /// https://monerodocs.org/interacting/monero-wallet-rpc-reference/#sweep_all pub async fn send_monero( wallet_client: &WalletClient, + from_account: u32, from_address: u32, to_address: Address, ) -> Result { let sweep_args = SweepAllArgs { address: to_address, - account_index: DEFAULT_ACCOUNT, + account_index: from_account, subaddr_indices: Some(vec![from_address]), priority: TransferPriority::Default, mixin: 15, @@ -126,7 +126,7 @@ pub async fn send_monero( // https://github.com/monero-project/monero/issues/8372 let maybe_transfer = wallet_client.get_transfer( tx_hash, - Some(DEFAULT_ACCOUNT), + Some(from_account), ).await?; let transfer_status = maybe_transfer .map(|data| data.transfer_type.into()) @@ -135,7 +135,7 @@ pub async fn send_monero( log::error!( "sent transaction {:x} from {}/{}, {}", tx_hash, - DEFAULT_ACCOUNT, + from_account, from_address, transfer_status, ); @@ -145,7 +145,7 @@ pub async fn send_monero( log::info!( "sent transaction {:x} from {}/{}, amount {}, fee {}", tx_hash, - DEFAULT_ACCOUNT, + from_account, from_address, amount, fee,