mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-11 21:49:26 +00:00
Smash out RPC, wallet
This commit is contained in:
@@ -27,7 +27,8 @@ rand_core = { version = "0.6", default-features = false }
|
||||
curve25519-dalek = { version = "4", features = ["rand_core"] }
|
||||
|
||||
bitcoin-serai = { path = "../../coins/bitcoin" }
|
||||
monero-serai = { path = "../../coins/monero" }
|
||||
monero-simple-request-rpc = { path = "../../coins/monero/rpc/simple-request" }
|
||||
monero-wallet = { path = "../../coins/monero/wallet" }
|
||||
|
||||
scale = { package = "parity-scale-codec", version = "3" }
|
||||
serde = "1"
|
||||
|
||||
@@ -53,8 +53,8 @@ impl Handles {
|
||||
pub async fn monero(
|
||||
&self,
|
||||
ops: &DockerOperations,
|
||||
) -> monero_serai::rpc::Rpc<monero_serai::rpc::HttpRpc> {
|
||||
use monero_serai::rpc::HttpRpc;
|
||||
) -> monero_wallet::rpc::Rpc<monero_simple_request_rpc::SimpleRequestRpc> {
|
||||
use monero_simple_request_rpc::SimpleRequestRpc;
|
||||
|
||||
let rpc = ops.handle(&self.monero.0).host_port(self.monero.1).unwrap();
|
||||
let rpc = format!("http://{RPC_USER}:{RPC_PASS}@{}:{}", rpc.0, rpc.1);
|
||||
@@ -62,7 +62,7 @@ impl Handles {
|
||||
// If the RPC server has yet to start, sleep for up to 60s until it does
|
||||
for _ in 0 .. 60 {
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
let Ok(client) = HttpRpc::new(rpc.clone()).await else { continue };
|
||||
let Ok(client) = SimpleRequestRpc::new(rpc.clone()).await else { continue };
|
||||
if client.get_height().await.is_err() {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ async fn mint_and_burn_test() {
|
||||
// Mine a Monero block
|
||||
let monero_blocks = {
|
||||
use curve25519_dalek::{constants::ED25519_BASEPOINT_POINT, scalar::Scalar};
|
||||
use monero_serai::wallet::{
|
||||
use monero_wallet::{
|
||||
ViewPair,
|
||||
address::{Network, AddressSpec},
|
||||
};
|
||||
@@ -345,14 +345,10 @@ async fn mint_and_burn_test() {
|
||||
// Send in XMR
|
||||
{
|
||||
use curve25519_dalek::{constants::ED25519_BASEPOINT_POINT, scalar::Scalar};
|
||||
use monero_serai::{
|
||||
Protocol,
|
||||
transaction::Timelock,
|
||||
wallet::{
|
||||
ViewPair, Scanner, DecoySelection, Decoys, Change, FeePriority, SignableTransaction,
|
||||
address::{Network, AddressType, AddressMeta, MoneroAddress},
|
||||
},
|
||||
io::decompress_point,
|
||||
use monero_wallet::{
|
||||
monero::{io::decompress_point, Protocol, transaction::Timelock},
|
||||
ViewPair, Scanner, DecoySelection, Decoys, Change, FeePriority, SignableTransaction,
|
||||
address::{Network, AddressType, AddressMeta, MoneroAddress},
|
||||
};
|
||||
|
||||
// Grab the first output on the chain
|
||||
@@ -473,7 +469,7 @@ async fn mint_and_burn_test() {
|
||||
let spend = ED25519_BASEPOINT_TABLE * &Scalar::random(&mut OsRng);
|
||||
let view = Scalar::random(&mut OsRng);
|
||||
|
||||
use monero_serai::wallet::address::{Network, AddressType, AddressMeta, MoneroAddress};
|
||||
use monero_wallet::address::{Network, AddressType, AddressMeta, MoneroAddress};
|
||||
let addr = MoneroAddress::new(
|
||||
AddressMeta::new(Network::Mainnet, AddressType::Standard),
|
||||
spend,
|
||||
@@ -578,7 +574,7 @@ async fn mint_and_burn_test() {
|
||||
|
||||
// Verify the received Monero TX
|
||||
{
|
||||
use monero_serai::wallet::{ViewPair, Scanner};
|
||||
use monero_wallet::{ViewPair, Scanner};
|
||||
let rpc = handles[0].monero(&ops).await;
|
||||
let mut scanner = Scanner::from_view(
|
||||
ViewPair::new(monero_spend, Zeroizing::new(monero_view)),
|
||||
|
||||
@@ -42,3 +42,5 @@ monero-mlsag = { path = "../../coins/monero/ringct/mlsag", default-features = fa
|
||||
monero-clsag = { path = "../../coins/monero/ringct/clsag", default-features = false }
|
||||
monero-bulletproofs = { path = "../../coins/monero/ringct/bulletproofs", default-features = false }
|
||||
monero-serai = { path = "../../coins/monero", default-features = false }
|
||||
monero-rpc = { path = "../../coins/monero/rpc", default-features = false }
|
||||
monero-wallet = { path = "../../coins/monero/wallet", default-features = false }
|
||||
|
||||
@@ -27,3 +27,4 @@ pub use monero_mlsag;
|
||||
pub use monero_clsag;
|
||||
pub use monero_bulletproofs;
|
||||
pub use monero_serai;
|
||||
pub use monero_rpc;
|
||||
|
||||
@@ -31,7 +31,8 @@ bitcoin-serai = { path = "../../coins/bitcoin" }
|
||||
k256 = "0.13"
|
||||
ethereum-serai = { path = "../../coins/ethereum" }
|
||||
|
||||
monero-serai = { path = "../../coins/monero" }
|
||||
monero-simple-request-rpc = { path = "../../coins/monero/rpc/simple-request" }
|
||||
monero-wallet = { path = "../../coins/monero/wallet" }
|
||||
|
||||
messages = { package = "serai-processor-messages", path = "../../processor/messages" }
|
||||
|
||||
|
||||
@@ -274,11 +274,11 @@ impl Coordinator {
|
||||
}
|
||||
}
|
||||
NetworkId::Monero => {
|
||||
use monero_serai::rpc::HttpRpc;
|
||||
use monero_simple_request_rpc::SimpleRequestRpc;
|
||||
|
||||
// Monero's won't, so call get_height
|
||||
if handle
|
||||
.block_on(HttpRpc::new(rpc_url.clone()))
|
||||
.block_on(SimpleRequestRpc::new(rpc_url.clone()))
|
||||
.ok()
|
||||
.and_then(|rpc| handle.block_on(rpc.get_height()).ok())
|
||||
.is_some()
|
||||
@@ -403,15 +403,13 @@ impl Coordinator {
|
||||
}
|
||||
NetworkId::Monero => {
|
||||
use curve25519_dalek::{constants::ED25519_BASEPOINT_POINT, scalar::Scalar};
|
||||
use monero_serai::{
|
||||
wallet::{
|
||||
ViewPair,
|
||||
address::{Network, AddressSpec},
|
||||
},
|
||||
rpc::HttpRpc,
|
||||
use monero_simple_request_rpc::SimpleRequestRpc;
|
||||
use monero_wallet::{
|
||||
ViewPair,
|
||||
address::{Network, AddressSpec},
|
||||
};
|
||||
|
||||
let rpc = HttpRpc::new(rpc_url).await.expect("couldn't connect to the Monero RPC");
|
||||
let rpc = SimpleRequestRpc::new(rpc_url).await.expect("couldn't connect to the Monero RPC");
|
||||
let _: EmptyResponse = rpc
|
||||
.json_rpc_call(
|
||||
"generateblocks",
|
||||
@@ -517,15 +515,18 @@ impl Coordinator {
|
||||
}
|
||||
}
|
||||
NetworkId::Monero => {
|
||||
use monero_serai::rpc::HttpRpc;
|
||||
use monero_simple_request_rpc::SimpleRequestRpc;
|
||||
|
||||
let rpc = HttpRpc::new(rpc_url).await.expect("couldn't connect to the Monero RPC");
|
||||
let rpc = SimpleRequestRpc::new(rpc_url).await.expect("couldn't connect to the Monero RPC");
|
||||
let to = rpc.get_height().await.unwrap();
|
||||
for coordinator in others {
|
||||
let other_rpc =
|
||||
HttpRpc::new(network_rpc(coordinator.network, ops, &coordinator.network_handle))
|
||||
.await
|
||||
.expect("couldn't connect to the Monero RPC");
|
||||
let other_rpc = SimpleRequestRpc::new(network_rpc(
|
||||
coordinator.network,
|
||||
ops,
|
||||
&coordinator.network_handle,
|
||||
))
|
||||
.await
|
||||
.expect("couldn't connect to the Monero RPC");
|
||||
|
||||
let from = other_rpc.get_height().await.unwrap();
|
||||
for b in from .. to {
|
||||
@@ -574,10 +575,12 @@ impl Coordinator {
|
||||
let _ = provider.send_raw_transaction(tx).await.unwrap();
|
||||
}
|
||||
NetworkId::Monero => {
|
||||
use monero_serai::{transaction::Transaction, rpc::HttpRpc};
|
||||
use monero_simple_request_rpc::SimpleRequestRpc;
|
||||
use monero_wallet::monero::transaction::Transaction;
|
||||
|
||||
let rpc =
|
||||
HttpRpc::new(rpc_url).await.expect("couldn't connect to the coordinator's Monero RPC");
|
||||
let rpc = SimpleRequestRpc::new(rpc_url)
|
||||
.await
|
||||
.expect("couldn't connect to the coordinator's Monero RPC");
|
||||
rpc.publish_transaction(&Transaction::read(&mut &*tx).unwrap()).await.unwrap();
|
||||
}
|
||||
NetworkId::Serai => panic!("processor tests broadcasting block to Serai"),
|
||||
@@ -672,10 +675,11 @@ impl Coordinator {
|
||||
None
|
||||
}
|
||||
NetworkId::Monero => {
|
||||
use monero_serai::rpc::HttpRpc;
|
||||
use monero_simple_request_rpc::SimpleRequestRpc;
|
||||
|
||||
let rpc =
|
||||
HttpRpc::new(rpc_url).await.expect("couldn't connect to the coordinator's Monero RPC");
|
||||
let rpc = SimpleRequestRpc::new(rpc_url)
|
||||
.await
|
||||
.expect("couldn't connect to the coordinator's Monero RPC");
|
||||
let mut hash = [0; 32];
|
||||
hash.copy_from_slice(tx);
|
||||
if let Ok(tx) = rpc.get_transaction(hash).await {
|
||||
|
||||
@@ -103,8 +103,8 @@ pub enum Wallet {
|
||||
Monero {
|
||||
handle: String,
|
||||
spend_key: Zeroizing<curve25519_dalek::scalar::Scalar>,
|
||||
view_pair: monero_serai::wallet::ViewPair,
|
||||
inputs: Vec<monero_serai::wallet::ReceivedOutput>,
|
||||
view_pair: monero_wallet::ViewPair,
|
||||
inputs: Vec<monero_wallet::ReceivedOutput>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -189,12 +189,10 @@ impl Wallet {
|
||||
|
||||
NetworkId::Monero => {
|
||||
use curve25519_dalek::{constants::ED25519_BASEPOINT_POINT, scalar::Scalar};
|
||||
use monero_serai::{
|
||||
wallet::{
|
||||
ViewPair, Scanner,
|
||||
address::{Network, AddressSpec},
|
||||
},
|
||||
rpc::HttpRpc,
|
||||
use monero_simple_request_rpc::SimpleRequestRpc;
|
||||
use monero_wallet::{
|
||||
ViewPair, Scanner,
|
||||
address::{Network, AddressSpec},
|
||||
};
|
||||
|
||||
let mut bytes = [0; 64];
|
||||
@@ -206,7 +204,7 @@ impl Wallet {
|
||||
let view_pair =
|
||||
ViewPair::new(ED25519_BASEPOINT_POINT * spend_key, Zeroizing::new(view_key));
|
||||
|
||||
let rpc = HttpRpc::new(rpc_url).await.expect("couldn't connect to the Monero RPC");
|
||||
let rpc = SimpleRequestRpc::new(rpc_url).await.expect("couldn't connect to the Monero RPC");
|
||||
|
||||
let height = rpc.get_height().await.unwrap();
|
||||
// Mines 200 blocks so sufficient decoys exist, as only 60 is needed for maturity
|
||||
@@ -436,20 +434,17 @@ impl Wallet {
|
||||
|
||||
Wallet::Monero { handle, ref spend_key, ref view_pair, ref mut inputs } => {
|
||||
use curve25519_dalek::constants::ED25519_BASEPOINT_POINT;
|
||||
use monero_serai::{
|
||||
Protocol,
|
||||
wallet::{
|
||||
address::{Network, AddressType, AddressMeta, Address},
|
||||
SpendableOutput, DecoySelection, Decoys, Change, FeePriority, Scanner,
|
||||
SignableTransaction,
|
||||
},
|
||||
rpc::HttpRpc,
|
||||
io::decompress_point,
|
||||
use monero_simple_request_rpc::SimpleRequestRpc;
|
||||
use monero_wallet::{
|
||||
monero::{Protocol, io::decompress_point},
|
||||
address::{Network, AddressType, AddressMeta, Address},
|
||||
SpendableOutput, DecoySelection, Decoys, Change, FeePriority, Scanner,
|
||||
SignableTransaction,
|
||||
};
|
||||
use processor::{additional_key, networks::Monero};
|
||||
|
||||
let rpc_url = network_rpc(NetworkId::Monero, ops, handle);
|
||||
let rpc = HttpRpc::new(rpc_url).await.expect("couldn't connect to the Monero RPC");
|
||||
let rpc = SimpleRequestRpc::new(rpc_url).await.expect("couldn't connect to the Monero RPC");
|
||||
|
||||
// Prepare inputs
|
||||
let outputs = std::mem::take(inputs);
|
||||
@@ -532,7 +527,7 @@ impl Wallet {
|
||||
)
|
||||
.unwrap(),
|
||||
Wallet::Monero { view_pair, .. } => {
|
||||
use monero_serai::wallet::address::{Network, AddressSpec};
|
||||
use monero_wallet::address::{Network, AddressSpec};
|
||||
ExternalAddress::new(
|
||||
networks::monero::Address::new(
|
||||
view_pair.address(Network::Mainnet, AddressSpec::Standard),
|
||||
|
||||
Reference in New Issue
Block a user