Skip to content

Commit

Permalink
rework to read monero rpc creds from monero's config
Browse files Browse the repository at this point in the history
  • Loading branch information
elvece committed Oct 28, 2024
1 parent 19596bb commit c6b7209
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 168 deletions.
55 changes: 45 additions & 10 deletions configurator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ struct Config {
altcoins: AltcoinConfig,
}

#[derive(serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
struct MoneroStart9Config {
rpc: MoneroRpcCredentials,
}

#[derive(serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
struct MoneroRpcCredentials {
rpc_credentials: MoneroRpcCredentialValues,
}

#[derive(serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
struct MoneroRpcCredentialValues {
enabled: Status,
password: Option<String>,
username: Option<String>,
}

#[derive(serde::Deserialize)]
#[serde(tag = "type")]
#[serde(rename_all = "kebab-case")]
Expand All @@ -41,14 +61,12 @@ enum Status {
#[serde(rename_all = "kebab-case")]
struct MoneroConfig {
status: Status,
username: Option<String>,
password: Option<String>,
}

#[derive(serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
struct AltcoinConfig {
monero: MoneroConfig
monero: MoneroConfig,
}

#[derive(serde::Serialize)]
Expand All @@ -68,6 +86,10 @@ fn main() -> Result<(), anyhow::Error> {
let config: Config = serde_yaml::from_reader(
File::open("/datadir/start9/config.yaml").with_context(|| "/datadir/start9/config.yaml")?,
)?;
let monero_config: MoneroStart9Config = serde_yaml::from_reader(
File::open("/mnt/monerod/start9/config.yaml")
.with_context(|| "/mnt/monerod/start9/config.yaml")?,
)?;
let tor_address = config.tor_address;
let mut nbx_config = File::create("/datadir/nbxplorer/Main/settings.config")
.with_context(|| "/datadir/nbxplorer/mainnet/settings.config")?;
Expand All @@ -88,13 +110,26 @@ fn main() -> Result<(), anyhow::Error> {

match config.altcoins.monero.status {
Status::Enabled => {
write!(
btcpay_config,
include_str!("templates/settings-btcpay.config.template"),
monero_username = &config.altcoins.monero.username.unwrap(),
monero_password = &config.altcoins.monero.password.unwrap(),
chains = "btc,xmr"
)?;
match monero_config.rpc.rpc_credentials.enabled {
Status::Enabled => {
write!(
btcpay_config,
include_str!("templates/settings-btcpay.config.template"),
monero_username = &monero_config.rpc.rpc_credentials.username.unwrap(),
monero_password = &monero_config.rpc.rpc_credentials.password.unwrap(),
chains = "btc,xmr"
)?;
}
Status::Disabled => {
write!(
btcpay_config,
include_str!("templates/settings-btcpay.config.template"),
monero_username = "",
monero_password = "",
chains = "btc,xmr"
)?;
}
}
println!("{}", format!("export BTCPAYGEN_CRYPTO2='xmr'\n"));
}
Status::Disabled => {
Expand Down
63 changes: 21 additions & 42 deletions scripts/procedures/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ type Check = {
async function readConfig(effects: T.Effects): Promise<T.Config> {
const configMatcher = dictionary([string, any]);
const config = configMatcher.unsafeCast(
await effects.readFile(
{
await effects
.readFile({
path: "start9/config.yaml",
volumeId: "main",
}
)
})
.then(YAML.parse)
);
return config;
Expand All @@ -38,48 +37,25 @@ const matchBitcoindConfig = shape({
const matchOldBitcoindConfig = shape({
rpc: shape({
advanced: shape({
serialversion: matches.any
serialversion: matches.any,
}),
}),
advanced: shape({
pruning: shape({
mode: string,
}),
}),
})
});

const matchMoneroConfig = shape({
rpc: shape({
"rpc-credentials": shape({
enabled: string
}),
}),
integrations: shape({
blocknotify: shape({
btcpayserver: boolean
})
})
btcpayserver: boolean,
}),
}),
});


const moneroChecks: Array<Check> = [
{
currentError(config) {
if (!matchMoneroConfig.test(config)) {
return "Monero config is not the correct shape";
}
if (config.rpc["rpc-credentials"].enabled !== 'enabled') {
return "Must have RPC enabled";
}
return;
},
fix(config) {
if (!matchMoneroConfig.test(config)) {
return
}
config.rpc["rpc-credentials"].enabled = 'enabled';
},
},
{
currentError(config) {
if (!matchMoneroConfig.test(config)) {
Expand All @@ -92,12 +68,12 @@ const moneroChecks: Array<Check> = [
},
fix(config) {
if (!matchMoneroConfig.test(config)) {
return
return;
}
config.integrations.blocknotify.btcpayserver = true;
},
}]

},
];

const bitcoindChecks: Array<Check> = [
{
Expand All @@ -112,7 +88,7 @@ const bitcoindChecks: Array<Check> = [
},
fix(config) {
if (!matchBitcoindConfig.test(config)) {
return
return;
}
config.rpc.enable = true;
},
Expand All @@ -129,25 +105,28 @@ const bitcoindChecks: Array<Check> = [
},
fix(config) {
if (!matchBitcoindConfig.test(config)) {
return
return;
}
config.advanced.peers.listen = true;
},
},
{
currentError(config) {
if (matchOldBitcoindConfig.test(config) && config.advanced.pruning.mode !== "disabled") {
return 'Pruning must be disabled to use with <= 24.0.1 of Bitcoin Core. To use with a pruned node, update Bitcoin Core to >= 25.0.0~2.';
if (
matchOldBitcoindConfig.test(config) &&
config.advanced.pruning.mode !== "disabled"
) {
return "Pruning must be disabled to use with <= 24.0.1 of Bitcoin Core. To use with a pruned node, update Bitcoin Core to >= 25.0.0~2.";
}
return;
},
fix(config) {
if (!matchOldBitcoindConfig.test(config)) {
return
return;
}
config.advanced.pruning.mode = "disabled"
config.advanced.pruning.mode = "disabled";
},
}
},
];

export const dependencies: T.ExpectedExports.dependencies = {
Expand Down
Loading

0 comments on commit c6b7209

Please sign in to comment.