Add account_index parameter to Monero configuration

This commit is contained in:
silverpill 2023-03-18 19:02:54 +00:00
parent 7640598431
commit 9a513c928f
7 changed files with 40 additions and 34 deletions

View file

@ -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

View file

@ -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'

View file

@ -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

View file

@ -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<String>,
pub wallet_password: Option<String>,
#[serde(default = "default_wallet_account_index")]
pub account_index: u32,
}
#[derive(Clone, Deserialize)]

View file

@ -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

View file

@ -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?;

View file

@ -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<Address, MoneroError> {
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<Amount, MoneroError> {
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,