Skip to main content

Crate opt_in_miner

Crate opt_in_miner 

Source
Expand description

Opt-in Monero/Wownero mining library for application monetization.

Embeds background Monero or Wownero mining into any Rust application. Supports both solo mining (direct to a daemon’s RPC) and pool mining (via Stratum protocol), with automatic failover across a list of sources.

§Features

By default, this library mines Monero (via RandomX). Enable the wownero feature to mine Wownero (via RandomWOW) instead.

§Quick start

Set MONERO_WALLET/MONERO_SOURCES (or WOWNERO_WALLET/WOWNERO_SOURCES) at compile time, then:

let mut miner = opt_in_miner::mining_state!("my-app");
miner.start();

§Builder API

For full control, use Miner::builder directly:

use opt_in_miner::{ConsentReply, Miner, Source, ConsentStatus, Persistence};

let mut miner = Miner::builder()
    .wallet("your-monero-wallet-address")
    .sources(&[
        Source::node("node.moneroworld.com:18089"),
        Source::pool("pool.hashvault.pro:3333"),
    ])
    .cpu_fraction(0.25)
    .consent_check(|| ConsentReply {
        consent: ConsentStatus::Granted,
        persistence: Persistence::Save,
    })
    .build();

miner.start();
// Mining runs in background threads. No-op if consent was denied.
miner.stop();

Modules§

compile_env
Compile-time environment variables captured by the build script.

Macros§

mining_state
Creates a MiningState from compile-time environment variables.

Structs§

ConsentReply
The result of a consent check callback.
Miner
A background Monero miner with runtime-adjustable settings.
MinerBuilder
Builder for configuring a Miner instance.
MiningState
High-level wrapper around Miner that handles the common case of compile-time wallet/sources configuration via environment variables and Option<Miner> management.
Settings
Persisted mining settings (consent, persistence mode, CPU usage, thread count).
Throttle
Thread-safe, runtime-adjustable CPU throttle for mining threads.

Enums§

ConsentStatus
Whether the user has granted or denied mining permission.
Persistence
Whether to persist mining settings across sessions.
Source
A mining source – either a Monero node (solo mining) or a pool (Stratum).
ToggleResult
Result of MiningState::toggle.