mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-12 22:19:26 +00:00
Clean and document monero-address
This commit is contained in:
@@ -3,7 +3,7 @@ use curve25519_dalek::constants::ED25519_BASEPOINT_POINT;
|
||||
use monero_serai::transaction::Transaction;
|
||||
use monero_wallet::{
|
||||
rpc::Rpc,
|
||||
address::{AddressType, AddressMeta, MoneroAddress},
|
||||
address::{AddressType, MoneroAddress},
|
||||
send::Eventuality,
|
||||
};
|
||||
|
||||
@@ -17,7 +17,8 @@ test!(
|
||||
// Each have their own slight implications to eventualities
|
||||
builder.add_payment(
|
||||
MoneroAddress::new(
|
||||
AddressMeta::new(Network::Mainnet, AddressType::Standard),
|
||||
Network::Mainnet,
|
||||
AddressType::Legacy,
|
||||
ED25519_BASEPOINT_POINT,
|
||||
ED25519_BASEPOINT_POINT,
|
||||
),
|
||||
@@ -25,7 +26,8 @@ test!(
|
||||
);
|
||||
builder.add_payment(
|
||||
MoneroAddress::new(
|
||||
AddressMeta::new(Network::Mainnet, AddressType::Integrated([0xaa; 8])),
|
||||
Network::Mainnet,
|
||||
AddressType::LegacyIntegrated([0xaa; 8]),
|
||||
ED25519_BASEPOINT_POINT,
|
||||
ED25519_BASEPOINT_POINT,
|
||||
),
|
||||
@@ -33,7 +35,8 @@ test!(
|
||||
);
|
||||
builder.add_payment(
|
||||
MoneroAddress::new(
|
||||
AddressMeta::new(Network::Mainnet, AddressType::Subaddress),
|
||||
Network::Mainnet,
|
||||
AddressType::Subaddress,
|
||||
ED25519_BASEPOINT_POINT,
|
||||
ED25519_BASEPOINT_POINT,
|
||||
),
|
||||
@@ -41,10 +44,8 @@ test!(
|
||||
);
|
||||
builder.add_payment(
|
||||
MoneroAddress::new(
|
||||
AddressMeta::new(
|
||||
Network::Mainnet,
|
||||
AddressType::Featured { subaddress: false, payment_id: None, guaranteed: true },
|
||||
),
|
||||
Network::Mainnet,
|
||||
AddressType::Featured { subaddress: false, payment_id: None, guaranteed: true },
|
||||
ED25519_BASEPOINT_POINT,
|
||||
ED25519_BASEPOINT_POINT,
|
||||
),
|
||||
|
||||
@@ -14,7 +14,7 @@ use monero_wallet::{
|
||||
transaction::Transaction,
|
||||
rpc::{Rpc, FeeRate},
|
||||
ViewPair,
|
||||
address::{Network, AddressType, AddressSpec, AddressMeta, MoneroAddress},
|
||||
address::{Network, AddressType, AddressSpec, MoneroAddress},
|
||||
scan::{SpendableOutput, Scanner},
|
||||
};
|
||||
|
||||
@@ -36,11 +36,12 @@ pub fn random_address() -> (Scalar, ViewPair, MoneroAddress) {
|
||||
(
|
||||
spend,
|
||||
ViewPair::new(spend_pub, view.clone()),
|
||||
MoneroAddress {
|
||||
meta: AddressMeta::new(Network::Mainnet, AddressType::Standard),
|
||||
spend: spend_pub,
|
||||
view: view.deref() * ED25519_BASEPOINT_TABLE,
|
||||
},
|
||||
MoneroAddress::new(
|
||||
Network::Mainnet,
|
||||
AddressType::Legacy,
|
||||
spend_pub,
|
||||
view.deref() * ED25519_BASEPOINT_TABLE,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -82,7 +83,7 @@ pub async fn get_miner_tx_output(rpc: &SimpleRequestRpc, view: &ViewPair) -> Spe
|
||||
// Mine 60 blocks to unlock a miner TX
|
||||
let start = rpc.get_height().await.unwrap();
|
||||
rpc
|
||||
.generate_blocks(&view.address(Network::Mainnet, AddressSpec::Standard).to_string(), 60)
|
||||
.generate_blocks(&view.address(Network::Mainnet, AddressSpec::Legacy).to_string(), 60)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -112,11 +113,12 @@ pub async fn rpc() -> SimpleRequestRpc {
|
||||
return rpc;
|
||||
}
|
||||
|
||||
let addr = MoneroAddress {
|
||||
meta: AddressMeta::new(Network::Mainnet, AddressType::Standard),
|
||||
spend: &Scalar::random(&mut OsRng) * ED25519_BASEPOINT_TABLE,
|
||||
view: &Scalar::random(&mut OsRng) * ED25519_BASEPOINT_TABLE,
|
||||
}
|
||||
let addr = MoneroAddress::new(
|
||||
Network::Mainnet,
|
||||
AddressType::Legacy,
|
||||
&Scalar::random(&mut OsRng) * ED25519_BASEPOINT_TABLE,
|
||||
&Scalar::random(&mut OsRng) * ED25519_BASEPOINT_TABLE,
|
||||
)
|
||||
.to_string();
|
||||
|
||||
// Mine 40 blocks to ensure decoy availability
|
||||
@@ -222,7 +224,7 @@ macro_rules! test {
|
||||
|
||||
let view_priv = Zeroizing::new(Scalar::random(&mut OsRng));
|
||||
let view = ViewPair::new(spend_pub, view_priv.clone());
|
||||
let addr = view.address(Network::Mainnet, AddressSpec::Standard);
|
||||
let addr = view.address(Network::Mainnet, AddressSpec::Legacy);
|
||||
|
||||
let miner_tx = get_miner_tx_output(&rpc, &view).await;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ test!(
|
||||
|_, mut builder: Builder, _| async move {
|
||||
let view = runner::random_address().1;
|
||||
let scanner = Scanner::from_view(view.clone(), Some(HashSet::new()));
|
||||
builder.add_payment(view.address(Network::Mainnet, AddressSpec::Standard), 5);
|
||||
builder.add_payment(view.address(Network::Mainnet, AddressSpec::Legacy), 5);
|
||||
(builder.build().unwrap(), scanner)
|
||||
},
|
||||
|_, tx: Transaction, _, mut state: Scanner| async move {
|
||||
@@ -54,7 +54,8 @@ test!(
|
||||
let mut payment_id = [0u8; 8];
|
||||
OsRng.fill_bytes(&mut payment_id);
|
||||
|
||||
builder.add_payment(view.address(Network::Mainnet, AddressSpec::Integrated(payment_id)), 5);
|
||||
builder
|
||||
.add_payment(view.address(Network::Mainnet, AddressSpec::LegacyIntegrated(payment_id)), 5);
|
||||
(builder.build().unwrap(), (scanner, payment_id))
|
||||
},
|
||||
|_, tx: Transaction, _, mut state: (Scanner, [u8; 8])| async move {
|
||||
|
||||
@@ -117,11 +117,11 @@ async fn from_wallet_rpc_to_self(spec: AddressSpec) {
|
||||
assert_eq!(output.metadata.subaddress, Some(index));
|
||||
assert_eq!(output.metadata.payment_id, Some(PaymentId::Encrypted([0u8; 8])));
|
||||
}
|
||||
AddressSpec::Integrated(payment_id) => {
|
||||
AddressSpec::LegacyIntegrated(payment_id) => {
|
||||
assert_eq!(output.metadata.payment_id, Some(PaymentId::Encrypted(payment_id)));
|
||||
assert_eq!(output.metadata.subaddress, None);
|
||||
}
|
||||
AddressSpec::Standard | AddressSpec::Featured { .. } => {
|
||||
AddressSpec::Legacy | AddressSpec::Featured { .. } => {
|
||||
assert_eq!(output.metadata.subaddress, None);
|
||||
assert_eq!(output.metadata.payment_id, Some(PaymentId::Encrypted([0u8; 8])));
|
||||
}
|
||||
@@ -131,7 +131,7 @@ async fn from_wallet_rpc_to_self(spec: AddressSpec) {
|
||||
|
||||
async_sequential!(
|
||||
async fn receipt_of_wallet_rpc_tx_standard() {
|
||||
from_wallet_rpc_to_self(AddressSpec::Standard).await;
|
||||
from_wallet_rpc_to_self(AddressSpec::Legacy).await;
|
||||
}
|
||||
|
||||
async fn receipt_of_wallet_rpc_tx_subaddress() {
|
||||
@@ -141,7 +141,7 @@ async_sequential!(
|
||||
async fn receipt_of_wallet_rpc_tx_integrated() {
|
||||
let mut payment_id = [0u8; 8];
|
||||
OsRng.fill_bytes(&mut payment_id);
|
||||
from_wallet_rpc_to_self(AddressSpec::Integrated(payment_id)).await;
|
||||
from_wallet_rpc_to_self(AddressSpec::LegacyIntegrated(payment_id)).await;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user