monero: Use fee priority enums from monero repo CLI/RPC wallets (#499)

* monero: Use fee priority enums from monero repo CLI/RPC wallets

* Update processor for fee priority change

* Remove FeePriority::Default

Done in consultation with @j-berman.

The RPC/CLI/GUI almost always adjust up except barring very explicit commands,
hence why FeePriority 0 is now only exposed via the explicit command of
FeePriority::Custom { priority: 0 }.

Also helps with terminology.

---------

Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
This commit is contained in:
Justin Berman 2024-02-19 18:03:27 -08:00 committed by GitHub
parent 6f5d794f10
commit cda14ac8b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 17 additions and 17 deletions

View file

@ -274,20 +274,22 @@ impl Fee {
#[derive(Clone, Copy, PartialEq, Eq, Debug)] #[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub enum FeePriority { pub enum FeePriority {
Lowest, Unimportant,
Low, Normal,
Medium, Elevated,
High, Priority,
Custom { priority: u32 }, Custom { priority: u32 },
} }
/// https://github.com/monero-project/monero/blob/ac02af92867590ca80b2779a7bbeafa99ff94dcb/
/// src/simplewallet/simplewallet.cpp#L161
impl FeePriority { impl FeePriority {
pub(crate) fn fee_priority(&self) -> u32 { pub(crate) fn fee_priority(&self) -> u32 {
match self { match self {
FeePriority::Lowest => 0, FeePriority::Unimportant => 1,
FeePriority::Low => 1, FeePriority::Normal => 2,
FeePriority::Medium => 2, FeePriority::Elevated => 3,
FeePriority::High => 3, FeePriority::Priority => 4,
FeePriority::Custom { priority, .. } => *priority, FeePriority::Custom { priority, .. } => *priority,
} }
} }

View file

@ -212,7 +212,7 @@ macro_rules! test {
let builder = SignableTransactionBuilder::new( let builder = SignableTransactionBuilder::new(
protocol, protocol,
rpc.get_fee(protocol, FeePriority::Low).await.unwrap(), rpc.get_fee(protocol, FeePriority::Unimportant).await.unwrap(),
Change::new( Change::new(
&ViewPair::new( &ViewPair::new(
&random_scalar(&mut OsRng) * ED25519_BASEPOINT_TABLE, &random_scalar(&mut OsRng) * ED25519_BASEPOINT_TABLE,

View file

@ -110,7 +110,7 @@ test!(
let mut builder = SignableTransactionBuilder::new( let mut builder = SignableTransactionBuilder::new(
protocol, protocol,
rpc.get_fee(protocol, FeePriority::Low).await.unwrap(), rpc.get_fee(protocol, FeePriority::Unimportant).await.unwrap(),
Change::new(&change_view, false), Change::new(&change_view, false),
); );
add_inputs(protocol, &rpc, vec![outputs.first().unwrap().clone()], &mut builder).await; add_inputs(protocol, &rpc, vec![outputs.first().unwrap().clone()], &mut builder).await;
@ -294,7 +294,7 @@ test!(
let mut builder = SignableTransactionBuilder::new( let mut builder = SignableTransactionBuilder::new(
protocol, protocol,
rpc.get_fee(protocol, FeePriority::Low).await.unwrap(), rpc.get_fee(protocol, FeePriority::Unimportant).await.unwrap(),
Change::fingerprintable(None), Change::fingerprintable(None),
); );
add_inputs(protocol, &rpc, vec![outputs.first().unwrap().clone()], &mut builder).await; add_inputs(protocol, &rpc, vec![outputs.first().unwrap().clone()], &mut builder).await;

View file

@ -90,9 +90,7 @@ async fn from_wallet_rpc_to_self(spec: AddressSpec) {
// TODO: Needs https://github.com/monero-project/monero/pull/8882 // TODO: Needs https://github.com/monero-project/monero/pull/8882
// let fee_rate = daemon_rpc // let fee_rate = daemon_rpc
// // Uses `FeePriority::Low` instead of `FeePriority::Lowest` because wallet RPC // .get_fee(daemon_rpc.get_protocol().await.unwrap(), FeePriority::Unimportant)
// // adjusts `monero_rpc::TransferPriority::Default` up by 1
// .get_fee(daemon_rpc.get_protocol().await.unwrap(), FeePriority::Low)
// .await // .await
// .unwrap(); // .unwrap();

View file

@ -761,7 +761,7 @@ impl Network for Monero {
vec![(address.into(), amount - fee)], vec![(address.into(), amount - fee)],
&Change::fingerprintable(Some(Self::test_address().into())), &Change::fingerprintable(Some(Self::test_address().into())),
vec![], vec![],
self.rpc.get_fee(protocol, FeePriority::Low).await.unwrap(), self.rpc.get_fee(protocol, FeePriority::Unimportant).await.unwrap(),
) )
.unwrap() .unwrap()
.sign(&mut OsRng, &Zeroizing::new(Scalar::ONE.0)) .sign(&mut OsRng, &Zeroizing::new(Scalar::ONE.0))

View file

@ -389,7 +389,7 @@ async fn mint_and_burn_test() {
)], )],
&Change::new(&view_pair, false), &Change::new(&view_pair, false),
vec![Shorthand::transfer(None, serai_addr).encode()], vec![Shorthand::transfer(None, serai_addr).encode()],
rpc.get_fee(Protocol::v16, FeePriority::Low).await.unwrap(), rpc.get_fee(Protocol::v16, FeePriority::Unimportant).await.unwrap(),
) )
.unwrap() .unwrap()
.sign(&mut OsRng, &Zeroizing::new(Scalar::ONE)) .sign(&mut OsRng, &Zeroizing::new(Scalar::ONE))

View file

@ -342,7 +342,7 @@ impl Wallet {
vec![(to_addr, AMOUNT)], vec![(to_addr, AMOUNT)],
&Change::new(view_pair, false), &Change::new(view_pair, false),
data, data,
rpc.get_fee(Protocol::v16, FeePriority::Low).await.unwrap(), rpc.get_fee(Protocol::v16, FeePriority::Unimportant).await.unwrap(),
) )
.unwrap() .unwrap()
.sign(&mut OsRng, spend_key) .sign(&mut OsRng, spend_key)