Add account_index parameter to Monero configuration
This commit is contained in:
parent
7640598431
commit
9a513c928f
7 changed files with 40 additions and 34 deletions
|
@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Added `fep-e232` feature flag (disabled by default).
|
- Added `fep-e232` feature flag (disabled by default).
|
||||||
|
- Added `account_index` parameter to Monero configuration.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|
|
@ -15,27 +15,28 @@ registration:
|
||||||
type: open
|
type: open
|
||||||
|
|
||||||
blockchains:
|
blockchains:
|
||||||
# Parameters for hardhat local node
|
# Parameters for local Monero node
|
||||||
- chain_id: eip155:31337
|
- chain_id: monero:regtest
|
||||||
chain_metadata:
|
node_url: 'http://127.0.0.1:58081'
|
||||||
chain_name: localhost
|
wallet_url: 'http://127.0.0.1:58083'
|
||||||
currency_name: ETH
|
wallet_name: test
|
||||||
currency_symbol: ETH
|
wallet_password: test
|
||||||
currency_decimals: 18
|
account_index: 0
|
||||||
public_api_url: 'http://127.0.0.1:8546'
|
# # Parameters for hardhat local node
|
||||||
explorer_url: null
|
# - chain_id: eip155:31337
|
||||||
contract_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
|
# chain_metadata:
|
||||||
contract_dir: contracts
|
# chain_name: localhost
|
||||||
api_url: 'http://127.0.0.1:8546'
|
# currency_name: ETH
|
||||||
signing_key: 'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
|
# currency_symbol: ETH
|
||||||
chain_sync_step: 100
|
# currency_decimals: 18
|
||||||
chain_reorg_max_depth: 0
|
# public_api_url: 'http://127.0.0.1:8546'
|
||||||
# # Parameters for local Monero node
|
# explorer_url: null
|
||||||
# - chain_id: monero:regtest
|
# contract_address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
|
||||||
# node_url: 'http://127.0.0.1:58081'
|
# contract_dir: contracts
|
||||||
# wallet_url: 'http://127.0.0.1:58083'
|
# api_url: 'http://127.0.0.1:8546'
|
||||||
# wallet_name: test
|
# signing_key: 'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
|
||||||
# wallet_password: test
|
# chain_sync_step: 100
|
||||||
|
# chain_reorg_max_depth: 0
|
||||||
|
|
||||||
ipfs_api_url: 'http://127.0.0.1:5001'
|
ipfs_api_url: 'http://127.0.0.1:5001'
|
||||||
ipfs_gateway_url: 'http://127.0.0.1:8001'
|
ipfs_gateway_url: 'http://127.0.0.1:8001'
|
||||||
|
|
|
@ -65,6 +65,7 @@ retention:
|
||||||
# wallet_url: 'http://127.0.0.1:18083'
|
# wallet_url: 'http://127.0.0.1:18083'
|
||||||
# wallet_name: null
|
# wallet_name: null
|
||||||
# wallet_password: null
|
# wallet_password: null
|
||||||
|
# account_index: 0
|
||||||
# - chain_id: eip155:31337
|
# - chain_id: eip155:31337
|
||||||
# chain_metadata:
|
# chain_metadata:
|
||||||
# chain_name: localhost
|
# chain_name: localhost
|
||||||
|
|
|
@ -49,6 +49,8 @@ impl EthereumConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_wallet_account_index() -> u32 { 0 }
|
||||||
|
|
||||||
#[derive(Clone, Deserialize)]
|
#[derive(Clone, Deserialize)]
|
||||||
pub struct MoneroConfig {
|
pub struct MoneroConfig {
|
||||||
pub chain_id: ChainId,
|
pub chain_id: ChainId,
|
||||||
|
@ -59,6 +61,8 @@ pub struct MoneroConfig {
|
||||||
// monero-wallet-rpc is running with --wallet-dir option
|
// monero-wallet-rpc is running with --wallet-dir option
|
||||||
pub wallet_name: Option<String>,
|
pub wallet_name: Option<String>,
|
||||||
pub wallet_password: Option<String>,
|
pub wallet_password: Option<String>,
|
||||||
|
#[serde(default = "default_wallet_account_index")]
|
||||||
|
pub account_index: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize)]
|
#[derive(Clone, Deserialize)]
|
||||||
|
|
|
@ -17,7 +17,6 @@ use crate::models::{
|
||||||
};
|
};
|
||||||
use super::wallet::{
|
use super::wallet::{
|
||||||
open_monero_wallet,
|
open_monero_wallet,
|
||||||
DEFAULT_ACCOUNT,
|
|
||||||
MoneroError,
|
MoneroError,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,7 +44,7 @@ pub async fn check_expired_invoice(
|
||||||
let address_index = wallet_client.get_address_index(address).await?;
|
let address_index = wallet_client.get_address_index(address).await?;
|
||||||
let transfers = wallet_client.incoming_transfers(
|
let transfers = wallet_client.incoming_transfers(
|
||||||
TransferType::Available,
|
TransferType::Available,
|
||||||
Some(DEFAULT_ACCOUNT),
|
Some(config.account_index),
|
||||||
Some(vec![address_index.minor]),
|
Some(vec![address_index.minor]),
|
||||||
).await?
|
).await?
|
||||||
.transfers
|
.transfers
|
||||||
|
|
|
@ -29,7 +29,6 @@ use super::wallet::{
|
||||||
get_subaddress_balance,
|
get_subaddress_balance,
|
||||||
open_monero_wallet,
|
open_monero_wallet,
|
||||||
send_monero,
|
send_monero,
|
||||||
DEFAULT_ACCOUNT,
|
|
||||||
MoneroError,
|
MoneroError,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,7 +67,7 @@ pub async fn check_monero_subscriptions(
|
||||||
log::info!("{} invoices are waiting for payment", address_waitlist.len());
|
log::info!("{} invoices are waiting for payment", address_waitlist.len());
|
||||||
let incoming_transfers = wallet_client.incoming_transfers(
|
let incoming_transfers = wallet_client.incoming_transfers(
|
||||||
TransferType::Available,
|
TransferType::Available,
|
||||||
Some(DEFAULT_ACCOUNT),
|
Some(config.account_index),
|
||||||
Some(address_waitlist),
|
Some(address_waitlist),
|
||||||
).await?;
|
).await?;
|
||||||
incoming_transfers.transfers
|
incoming_transfers.transfers
|
||||||
|
@ -78,7 +77,7 @@ pub async fn check_monero_subscriptions(
|
||||||
if let Some(transfers) = maybe_incoming_transfers {
|
if let Some(transfers) = maybe_incoming_transfers {
|
||||||
for transfer in transfers {
|
for transfer in transfers {
|
||||||
let address_data = wallet_client.get_address(
|
let address_data = wallet_client.get_address(
|
||||||
DEFAULT_ACCOUNT,
|
config.account_index,
|
||||||
Some(vec![transfer.subaddr_index.minor]),
|
Some(vec![transfer.subaddr_index.minor]),
|
||||||
).await?;
|
).await?;
|
||||||
let subaddress_data = get_single_item(address_data.addresses)?;
|
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_address = Address::from_str(&payment_info.payout_address)?;
|
||||||
let payout_amount = send_monero(
|
let payout_amount = send_monero(
|
||||||
&wallet_client,
|
&wallet_client,
|
||||||
|
config.account_index,
|
||||||
address_index.minor,
|
address_index.minor,
|
||||||
payout_address,
|
payout_address,
|
||||||
).await?;
|
).await?;
|
||||||
|
|
|
@ -17,8 +17,6 @@ use mitra_config::MoneroConfig;
|
||||||
|
|
||||||
use crate::database::DatabaseError;
|
use crate::database::DatabaseError;
|
||||||
|
|
||||||
pub const DEFAULT_ACCOUNT: u32 = 0;
|
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum MoneroError {
|
pub enum MoneroError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
|
@ -71,9 +69,10 @@ pub async fn create_monero_address(
|
||||||
config: &MoneroConfig,
|
config: &MoneroConfig,
|
||||||
) -> Result<Address, MoneroError> {
|
) -> Result<Address, MoneroError> {
|
||||||
let wallet_client = open_monero_wallet(config).await?;
|
let wallet_client = open_monero_wallet(config).await?;
|
||||||
|
let account_index = config.account_index;
|
||||||
let (address, address_index) =
|
let (address, address_index) =
|
||||||
wallet_client.create_address(DEFAULT_ACCOUNT, None).await?;
|
wallet_client.create_address(account_index, None).await?;
|
||||||
log::info!("created monero address {}/{}", DEFAULT_ACCOUNT, address_index);
|
log::info!("created monero address {}/{}", account_index, address_index);
|
||||||
Ok(address)
|
Ok(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,12 +99,13 @@ pub async fn get_subaddress_balance(
|
||||||
/// https://monerodocs.org/interacting/monero-wallet-rpc-reference/#sweep_all
|
/// https://monerodocs.org/interacting/monero-wallet-rpc-reference/#sweep_all
|
||||||
pub async fn send_monero(
|
pub async fn send_monero(
|
||||||
wallet_client: &WalletClient,
|
wallet_client: &WalletClient,
|
||||||
|
from_account: u32,
|
||||||
from_address: u32,
|
from_address: u32,
|
||||||
to_address: Address,
|
to_address: Address,
|
||||||
) -> Result<Amount, MoneroError> {
|
) -> Result<Amount, MoneroError> {
|
||||||
let sweep_args = SweepAllArgs {
|
let sweep_args = SweepAllArgs {
|
||||||
address: to_address,
|
address: to_address,
|
||||||
account_index: DEFAULT_ACCOUNT,
|
account_index: from_account,
|
||||||
subaddr_indices: Some(vec![from_address]),
|
subaddr_indices: Some(vec![from_address]),
|
||||||
priority: TransferPriority::Default,
|
priority: TransferPriority::Default,
|
||||||
mixin: 15,
|
mixin: 15,
|
||||||
|
@ -126,7 +126,7 @@ pub async fn send_monero(
|
||||||
// https://github.com/monero-project/monero/issues/8372
|
// https://github.com/monero-project/monero/issues/8372
|
||||||
let maybe_transfer = wallet_client.get_transfer(
|
let maybe_transfer = wallet_client.get_transfer(
|
||||||
tx_hash,
|
tx_hash,
|
||||||
Some(DEFAULT_ACCOUNT),
|
Some(from_account),
|
||||||
).await?;
|
).await?;
|
||||||
let transfer_status = maybe_transfer
|
let transfer_status = maybe_transfer
|
||||||
.map(|data| data.transfer_type.into())
|
.map(|data| data.transfer_type.into())
|
||||||
|
@ -135,7 +135,7 @@ pub async fn send_monero(
|
||||||
log::error!(
|
log::error!(
|
||||||
"sent transaction {:x} from {}/{}, {}",
|
"sent transaction {:x} from {}/{}, {}",
|
||||||
tx_hash,
|
tx_hash,
|
||||||
DEFAULT_ACCOUNT,
|
from_account,
|
||||||
from_address,
|
from_address,
|
||||||
transfer_status,
|
transfer_status,
|
||||||
);
|
);
|
||||||
|
@ -145,7 +145,7 @@ pub async fn send_monero(
|
||||||
log::info!(
|
log::info!(
|
||||||
"sent transaction {:x} from {}/{}, amount {}, fee {}",
|
"sent transaction {:x} from {}/{}, amount {}, fee {}",
|
||||||
tx_hash,
|
tx_hash,
|
||||||
DEFAULT_ACCOUNT,
|
from_account,
|
||||||
from_address,
|
from_address,
|
||||||
amount,
|
amount,
|
||||||
fee,
|
fee,
|
||||||
|
|
Loading…
Reference in a new issue