Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rothschild: donate funds to external address with custom priority fee #482

Merged
merged 6 commits into from
Sep 23, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions rothschild/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use kaspa_rpc_core::{api::rpc::RpcApi, notify::mode::NotificationMode, RpcUtxoEn
use kaspa_txscript::pay_to_address_script;
use parking_lot::Mutex;
use rayon::prelude::*;
use secp256k1::{rand::thread_rng, Keypair};
use secp256k1::{rand::thread_rng, rand::random, Keypair};
use tokio::time::{interval, MissedTickBehavior};

const DEFAULT_SEND_AMOUNT: u64 = 10 * SOMPI_PER_KASPA;
Expand All @@ -40,6 +40,7 @@ pub struct Args {
pub rpc_server: String,
pub threads: u8,
pub unleashed: bool,
pub addr: Option<String>,
}

impl Args {
Expand All @@ -51,6 +52,7 @@ impl Args {
rpc_server: m.get_one::<String>("rpcserver").cloned().unwrap_or("localhost:16210".to_owned()),
threads: m.get_one::<u8>("threads").cloned().unwrap(),
unleashed: m.get_one::<bool>("unleashed").cloned().unwrap_or(false),
addr: m.get_one::<String>("addr").cloned(),
}
}
}
Expand Down Expand Up @@ -85,6 +87,7 @@ pub fn cli() -> Command {
.help("The number of threads to use for TX generation. Set to 0 to use 1 thread per core. Default is 2."),
)
.arg(Arg::new("unleashed").long("unleashed").action(ArgAction::SetTrue).hide(true).help("Allow higher TPS"))
.arg(Arg::new("addr").long("to-addr").short('a').value_name("addr").help("address to send to"))
}

async fn new_rpc_client(subscription_context: &SubscriptionContext, address: &str) -> GrpcClient {
Expand Down Expand Up @@ -150,9 +153,15 @@ async fn main() {

let kaspa_addr = Address::new(ADDRESS_PREFIX, ADDRESS_VERSION, &schnorr_key.x_only_public_key().0.serialize());

let kaspa_to_addr = if let Some(addr_str) = args.addr {
Address::try_from(addr_str).unwrap()
} else {
kaspa_addr.clone()
};

rayon::ThreadPoolBuilder::new().num_threads(args.threads as usize).build_global().unwrap();

info!("Using Rothschild with private key {} and address {}", schnorr_key.display_secret(), String::from(&kaspa_addr));
info!("Using Rothschild with private key {} and address {}\n\tspend to {}", schnorr_key.display_secret(), String::from(&kaspa_addr), String::from(&kaspa_to_addr));
coderofstuff marked this conversation as resolved.
Show resolved Hide resolved
let info = rpc_client.get_block_dag_info().await.unwrap();
let coinbase_maturity = match info.network.suffix {
Some(11) => TESTNET11_PARAMS.coinbase_maturity,
Expand Down Expand Up @@ -249,7 +258,7 @@ async fn main() {
let has_funds = maybe_send_tx(
txs_to_send,
&tx_sender,
kaspa_addr.clone(),
kaspa_to_addr.clone(),
&mut utxos,
&mut pending,
schnorr_key,
Expand Down Expand Up @@ -484,11 +493,12 @@ fn select_utxos(
selected.push((outpoint, entry));

let fee = required_fee(selected.len(), num_outs);
let priority_fee = (random::<f32>() * SOMPI_PER_KASPA as f32) as u64;

*next_available_utxo_index += 1;

if selected_amount >= min_amount + fee && (!maximize_utxos || selected.len() == MAX_UTXOS) {
return (selected, selected_amount - fee);
if selected_amount >= min_amount + fee + priority_fee && (!maximize_utxos || selected.len() == MAX_UTXOS) {
return (selected, selected_amount - fee - priority_fee);
}

if selected.len() > MAX_UTXOS {
Expand Down
Loading