mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-13 14:39:25 +00:00
Document the RPC
This commit is contained in:
@@ -10,7 +10,7 @@ use rand_distr::num_traits::Float;
|
||||
use curve25519_dalek::edwards::EdwardsPoint;
|
||||
|
||||
use monero_serai::{DEFAULT_LOCK_WINDOW, COINBASE_LOCK_WINDOW, BLOCK_TIME};
|
||||
use monero_rpc::{RpcError, RpcConnection, Rpc};
|
||||
use monero_rpc::{RpcError, Rpc};
|
||||
use crate::SpendableOutput;
|
||||
|
||||
const RECENT_WINDOW: usize = 15;
|
||||
@@ -19,9 +19,9 @@ const BLOCKS_PER_YEAR: usize = 365 * 24 * 60 * 60 / BLOCK_TIME;
|
||||
const TIP_APPLICATION: f64 = (DEFAULT_LOCK_WINDOW * BLOCK_TIME) as f64;
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn select_n<'a, R: RngCore + CryptoRng, RPC: RpcConnection>(
|
||||
async fn select_n<'a, R: RngCore + CryptoRng>(
|
||||
rng: &mut R,
|
||||
rpc: &Rpc<RPC>,
|
||||
rpc: &impl Rpc,
|
||||
distribution: &[u64],
|
||||
height: usize,
|
||||
high: u64,
|
||||
@@ -129,9 +129,9 @@ fn offset(ring: &[u64]) -> Vec<u64> {
|
||||
res
|
||||
}
|
||||
|
||||
async fn select_decoys<R: RngCore + CryptoRng, RPC: RpcConnection>(
|
||||
async fn select_decoys<R: RngCore + CryptoRng>(
|
||||
rng: &mut R,
|
||||
rpc: &Rpc<RPC>,
|
||||
rpc: &impl Rpc,
|
||||
ring_len: usize,
|
||||
height: usize,
|
||||
inputs: &[SpendableOutput],
|
||||
@@ -278,20 +278,17 @@ pub use monero_serai::primitives::Decoys;
|
||||
#[cfg(feature = "std")]
|
||||
#[async_trait::async_trait]
|
||||
pub trait DecoySelection {
|
||||
async fn select<R: Send + Sync + RngCore + CryptoRng, RPC: Send + Sync + RpcConnection>(
|
||||
async fn select<R: Send + Sync + RngCore + CryptoRng>(
|
||||
rng: &mut R,
|
||||
rpc: &Rpc<RPC>,
|
||||
rpc: &impl Rpc,
|
||||
ring_len: usize,
|
||||
height: usize,
|
||||
inputs: &[SpendableOutput],
|
||||
) -> Result<Vec<Decoys>, RpcError>;
|
||||
|
||||
async fn fingerprintable_canonical_select<
|
||||
R: Send + Sync + RngCore + CryptoRng,
|
||||
RPC: Send + Sync + RpcConnection,
|
||||
>(
|
||||
async fn fingerprintable_canonical_select<R: Send + Sync + RngCore + CryptoRng>(
|
||||
rng: &mut R,
|
||||
rpc: &Rpc<RPC>,
|
||||
rpc: &impl Rpc,
|
||||
ring_len: usize,
|
||||
height: usize,
|
||||
inputs: &[SpendableOutput],
|
||||
@@ -303,9 +300,9 @@ pub trait DecoySelection {
|
||||
impl DecoySelection for Decoys {
|
||||
/// Select decoys using the same distribution as Monero. Relies on the monerod RPC
|
||||
/// response for an output's unlocked status, minimizing trips to the daemon.
|
||||
async fn select<R: Send + Sync + RngCore + CryptoRng, RPC: Send + Sync + RpcConnection>(
|
||||
async fn select<R: Send + Sync + RngCore + CryptoRng>(
|
||||
rng: &mut R,
|
||||
rpc: &Rpc<RPC>,
|
||||
rpc: &impl Rpc,
|
||||
ring_len: usize,
|
||||
height: usize,
|
||||
inputs: &[SpendableOutput],
|
||||
@@ -321,12 +318,9 @@ impl DecoySelection for Decoys {
|
||||
///
|
||||
/// TODO: upstream change to monerod get_outs RPC to accept a height param for checking
|
||||
/// output's unlocked status and remove all usage of fingerprintable_canonical
|
||||
async fn fingerprintable_canonical_select<
|
||||
R: Send + Sync + RngCore + CryptoRng,
|
||||
RPC: Send + Sync + RpcConnection,
|
||||
>(
|
||||
async fn fingerprintable_canonical_select<R: Send + Sync + RngCore + CryptoRng>(
|
||||
rng: &mut R,
|
||||
rpc: &Rpc<RPC>,
|
||||
rpc: &impl Rpc,
|
||||
ring_len: usize,
|
||||
height: usize,
|
||||
inputs: &[SpendableOutput],
|
||||
|
||||
@@ -47,7 +47,7 @@ pub mod decoys {
|
||||
pub use decoys::{DecoySelection, Decoys};
|
||||
|
||||
mod send;
|
||||
pub use send::{FeePriority, Fee, TransactionError, Change, SignableTransaction, Eventuality};
|
||||
pub use send::{FeePriority, FeeRate, TransactionError, Change, SignableTransaction, Eventuality};
|
||||
#[cfg(feature = "std")]
|
||||
pub use send::SignableTransactionBuilder;
|
||||
#[cfg(feature = "multisig")]
|
||||
|
||||
@@ -9,7 +9,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop};
|
||||
|
||||
use curve25519_dalek::{constants::ED25519_BASEPOINT_TABLE, scalar::Scalar, edwards::EdwardsPoint};
|
||||
|
||||
use monero_rpc::{RpcError, RpcConnection, Rpc};
|
||||
use monero_rpc::{RpcError, Rpc};
|
||||
use monero_serai::{
|
||||
io::*,
|
||||
primitives::Commitment,
|
||||
@@ -240,10 +240,7 @@ pub struct SpendableOutput {
|
||||
impl SpendableOutput {
|
||||
/// Update the spendable output's global index. This is intended to be called if a
|
||||
/// re-organization occurred.
|
||||
pub async fn refresh_global_index<RPC: RpcConnection>(
|
||||
&mut self,
|
||||
rpc: &Rpc<RPC>,
|
||||
) -> Result<(), RpcError> {
|
||||
pub async fn refresh_global_index(&mut self, rpc: &impl Rpc) -> Result<(), RpcError> {
|
||||
self.global_index = *rpc
|
||||
.get_o_indexes(self.output.absolute.tx)
|
||||
.await?
|
||||
@@ -254,10 +251,7 @@ impl SpendableOutput {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn from<RPC: RpcConnection>(
|
||||
rpc: &Rpc<RPC>,
|
||||
output: ReceivedOutput,
|
||||
) -> Result<SpendableOutput, RpcError> {
|
||||
pub async fn from(rpc: &impl Rpc, output: ReceivedOutput) -> Result<SpendableOutput, RpcError> {
|
||||
let mut output = SpendableOutput { output, global_index: 0 };
|
||||
output.refresh_global_index(rpc).await?;
|
||||
Ok(output)
|
||||
@@ -466,9 +460,9 @@ impl Scanner {
|
||||
/// transactions is a dead giveaway for which transactions you successfully scanned. This
|
||||
/// function obtains the output indexes for the miner transaction, incrementing from there
|
||||
/// instead.
|
||||
pub async fn scan<RPC: RpcConnection>(
|
||||
pub async fn scan(
|
||||
&mut self,
|
||||
rpc: &Rpc<RPC>,
|
||||
rpc: &impl Rpc,
|
||||
block: &Block,
|
||||
) -> Result<Vec<Timelocked<SpendableOutput>>, RpcError> {
|
||||
let mut index = rpc.get_o_indexes(block.miner_tx.hash()).await?[0];
|
||||
|
||||
@@ -4,14 +4,14 @@ use zeroize::{Zeroize, ZeroizeOnDrop, Zeroizing};
|
||||
|
||||
use monero_serai::Protocol;
|
||||
use crate::{
|
||||
address::MoneroAddress, Fee, SpendableOutput, Change, Decoys, SignableTransaction,
|
||||
address::MoneroAddress, FeeRate, SpendableOutput, Change, Decoys, SignableTransaction,
|
||||
TransactionError, extra::MAX_ARBITRARY_DATA_SIZE,
|
||||
};
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Zeroize, ZeroizeOnDrop)]
|
||||
struct SignableTransactionBuilderInternal {
|
||||
protocol: Protocol,
|
||||
fee_rate: Fee,
|
||||
fee_rate: FeeRate,
|
||||
|
||||
r_seed: Option<Zeroizing<[u8; 32]>>,
|
||||
inputs: Vec<(SpendableOutput, Decoys)>,
|
||||
@@ -23,7 +23,7 @@ struct SignableTransactionBuilderInternal {
|
||||
impl SignableTransactionBuilderInternal {
|
||||
// Takes in the change address so users don't miss that they have to manually set one
|
||||
// If they don't, all leftover funds will become part of the fee
|
||||
fn new(protocol: Protocol, fee_rate: Fee, change_address: Change) -> Self {
|
||||
fn new(protocol: Protocol, fee_rate: FeeRate, change_address: Change) -> Self {
|
||||
Self {
|
||||
protocol,
|
||||
fee_rate,
|
||||
@@ -88,7 +88,7 @@ impl SignableTransactionBuilder {
|
||||
Self(self.0.clone())
|
||||
}
|
||||
|
||||
pub fn new(protocol: Protocol, fee_rate: Fee, change_address: Change) -> Self {
|
||||
pub fn new(protocol: Protocol, fee_rate: FeeRate, change_address: Change) -> Self {
|
||||
Self(Arc::new(RwLock::new(SignableTransactionBuilderInternal::new(
|
||||
protocol,
|
||||
fee_rate,
|
||||
|
||||
@@ -22,7 +22,7 @@ use curve25519_dalek::{
|
||||
use frost::FrostError;
|
||||
|
||||
use monero_rpc::RpcError;
|
||||
pub use monero_rpc::{Fee, FeePriority};
|
||||
pub use monero_rpc::{FeePriority, FeeRate};
|
||||
use monero_serai::{
|
||||
io::*,
|
||||
primitives::{Commitment, keccak256},
|
||||
@@ -216,7 +216,7 @@ fn calculate_weight_and_fee(
|
||||
decoy_weights: &[usize],
|
||||
n_outputs: usize,
|
||||
extra: usize,
|
||||
fee_rate: Fee,
|
||||
fee_rate: FeeRate,
|
||||
) -> (usize, u64) {
|
||||
// Starting the fee at 0 here is different than core Monero's wallet2.cpp, which starts its fee
|
||||
// calculation with an estimate.
|
||||
@@ -291,7 +291,7 @@ pub struct SignableTransaction {
|
||||
payments: Vec<InternalPayment>,
|
||||
data: Vec<Vec<u8>>,
|
||||
fee: u64,
|
||||
fee_rate: Fee,
|
||||
fee_rate: FeeRate,
|
||||
}
|
||||
|
||||
/// Specification for a change output.
|
||||
@@ -398,7 +398,7 @@ impl SignableTransaction {
|
||||
payments: Vec<(MoneroAddress, u64)>,
|
||||
change: &Change,
|
||||
data: Vec<Vec<u8>>,
|
||||
fee_rate: Fee,
|
||||
fee_rate: FeeRate,
|
||||
) -> Result<SignableTransaction, TransactionError> {
|
||||
// Make sure there's only one payment ID
|
||||
let mut has_payment_id = {
|
||||
@@ -559,7 +559,7 @@ impl SignableTransaction {
|
||||
self.fee
|
||||
}
|
||||
|
||||
pub fn fee_rate(&self) -> Fee {
|
||||
pub fn fee_rate(&self) -> FeeRate {
|
||||
self.fee_rate
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user