Skip to content

Commit

Permalink
Version 2.0.0
Browse files Browse the repository at this point in the history
* Major refactor, added Farmer and Harvester Websocket Servers, Slight speed increase of lookups for larger farms
  • Loading branch information
DaOneLuna authored Dec 12, 2023
1 parent 2a5c479 commit a1673e6
Show file tree
Hide file tree
Showing 72 changed files with 6,031 additions and 1,539 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"

members = [
"cli",
Expand All @@ -9,5 +10,6 @@ members = [
"proof_of_space",
"puzzles",
"serialize",
"servers",
"tests"
]
14 changes: 7 additions & 7 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dg_xch_cli"
version = "1.2.1"
version = "2.0.0"
edition = "2021"
authors = ["James Hoerr"]
description = "CLI Utilities for the Chia Blockchain"
Expand All @@ -22,12 +22,12 @@ bip39 = {version= "2.0.0", features=["rand"] }
blst = "0.3.11"
clap = { version = "4.4.8", features = ["derive"] }
dashmap = "5.5.3"
dg_xch_clients = {path = "../clients", version="1.2.1"}
dg_xch_core = {path = "../core", version = "1.2.1", features = ["paperclip"] }
dg_xch_keys = {path = "../keys", version="1.2.1"}
dg_xch_pos = {path = "../proof_of_space", version="1.2.1"}
dg_xch_puzzles = {path = "../puzzles", version="1.2.1"}
dg_xch_serialize= {path = "../serialize", version="1.2.1"}
dg_xch_clients = {path = "../clients", version="2.0.0"}
dg_xch_core = {path = "../core", version = "2.0.0", features = ["paperclip"] }
dg_xch_keys = {path = "../keys", version="2.0.0"}
dg_xch_pos = {path = "../proof_of_space", version="2.0.0"}
dg_xch_puzzles = {path = "../puzzles", version="2.0.0"}
dg_xch_serialize= {path = "../serialize", version="2.0.0"}
hex = "0.4.3"
lazy_static = "1.4.0"
log = "0.4.20"
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cli::*;
use dg_xch_cli::wallet_commands::{
create_cold_wallet, get_plotnft_ready_state, migrate_plot_nft, migrate_plot_nft_with_owner_key,
};
use dg_xch_clients::protocols::pool::create_pool_login_url;
use dg_xch_clients::api::pool::create_pool_login_url;
use dg_xch_clients::rpc::full_node::FullnodeClient;
use dg_xch_core::blockchain::sized_bytes::Bytes32;
use simple_logger::SimpleLogger;
Expand Down
4 changes: 1 addition & 3 deletions cli/src/wallet_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ use bip39::Mnemonic;
use blst::min_pk::SecretKey;
use dg_xch_clients::api::full_node::FullnodeAPI;
use dg_xch_clients::api::pool::{DefaultPoolClient, PoolClient};
use dg_xch_clients::protocols::pool::{
GetPoolInfoResponse, FARMING_TO_POOL, POOL_PROTOCOL_VERSION,
};
use dg_xch_clients::rpc::full_node::FullnodeClient;
use dg_xch_core::blockchain::coin_spend::CoinSpend;
use dg_xch_core::blockchain::sized_bytes::{Bytes32, Bytes48};
use dg_xch_core::plots::PlotNft;
use dg_xch_core::pool::PoolState;
use dg_xch_core::protocols::pool::{GetPoolInfoResponse, FARMING_TO_POOL, POOL_PROTOCOL_VERSION};
use dg_xch_keys::*;
use dg_xch_puzzles::p2_delegated_puzzle_or_hidden_puzzle::{
calculate_synthetic_secret_key, puzzle_hash_for_pk, DEFAULT_HIDDEN_PUZZLE_HASH,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/wallets/plotnft_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::wallets::{Wallet, WalletInfo};
use async_trait::async_trait;
use blst::min_pk::SecretKey;
use dg_xch_clients::api::full_node::FullnodeAPI;
use dg_xch_clients::protocols::pool::{FARMING_TO_POOL, LEAVING_POOL, POOL_PROTOCOL_VERSION};
use dg_xch_clients::rpc::full_node::FullnodeClient;
use dg_xch_core::blockchain::announcement::Announcement;
use dg_xch_core::blockchain::coin_record::CoinRecord;
Expand All @@ -17,6 +16,7 @@ use dg_xch_core::blockchain::wallet_type::WalletType;
use dg_xch_core::consensus::constants::ConsensusConstants;
use dg_xch_core::plots::PlotNft;
use dg_xch_core::pool::PoolState;
use dg_xch_core::protocols::pool::{FARMING_TO_POOL, LEAVING_POOL, POOL_PROTOCOL_VERSION};
use dg_xch_keys::{
master_sk_to_singleton_owner_sk, master_sk_to_wallet_sk, master_sk_to_wallet_sk_unhardened,
};
Expand Down
22 changes: 14 additions & 8 deletions clients/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dg_xch_clients"
version = "1.2.1"
version = "2.0.0"
edition = "2021"
authors = ["James Hoerr"]
description = "RPC and Websocket Clients the Chia Blockchain"
Expand All @@ -12,22 +12,28 @@ repository = "https://github.com/GalactechsLLC/dg_xch_utils/clients"
async-trait = "0.1.74"
blst = "0.3.11"
dashmap = "5.5.3"
dg_xch_core = {path = "../core", version = "1.2.1", features = ["paperclip"] }
dg_xch_macros = {path = "../macros", version="1.2.1"}
dg_xch_pos = {path = "../proof_of_space", version="1.2.1"}
dg_xch_serialize = {path = "../serialize", version="1.2.1"}
dg_xch_core = {path = "../core", version = "2.0.0", features = ["paperclip"] }
dg_xch_keys = {path = "../keys", version="2.0.0"}
dg_xch_macros = {path = "../macros", version="2.0.0"}
dg_xch_pos = {path = "../proof_of_space", version="2.0.0"}
dg_xch_serialize = {path = "../serialize", version="2.0.0"}
futures-util = "0.3.29"
hex = "0.4.3"
hyper = {version="1.0.1", features=["full"]}
hyper-util = {version="0.1.1", features=["full"]}
log = "0.4.20"
prometheus = {version="0.13.3", features=["protobuf"], optional = true}
reqwest = {version="0.11.22", default-features = false, features =["rustls-tls-webpki-roots", "json"]}
rustls = {version = "0.21.8", features = ["dangerous_configuration"] }
rustls-pemfile = "1.0.3"
rustls = {version = "0.21.9", features = ["dangerous_configuration"] }
rustls-pemfile = "1.0.4"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
time = "0.3.30"
tokio = {version = "1.34.0", features=["rt-multi-thread", "sync", "signal", "macros", "process", "time", "fs", "net"]}
tokio-tungstenite = {version = "0.20.1", features = ["rustls-tls-webpki-roots", "rustls"] }
urlencoding = "2.1.3"
uuid = {version="1.6.1", features=["v4"]}
uuid = {version="1.6.1", features=["v4"]}

[features]
metrics = ["dep:prometheus", "dg_xch_core/metrics"]
default = []
4 changes: 2 additions & 2 deletions clients/src/api/full_node.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::protocols::full_node::BlockCountMetrics;
use crate::protocols::full_node::FeeEstimate;
use async_trait::async_trait;
use dg_xch_core::blockchain::block_record::BlockRecord;
use dg_xch_core::blockchain::blockchain_state::BlockchainState;
Expand All @@ -13,6 +11,8 @@ use dg_xch_core::blockchain::sized_bytes::Bytes32;
use dg_xch_core::blockchain::spend_bundle::SpendBundle;
use dg_xch_core::blockchain::tx_status::TXStatus;
use dg_xch_core::blockchain::unfinished_block::UnfinishedBlock;
use dg_xch_core::protocols::full_node::BlockCountMetrics;
use dg_xch_core::protocols::full_node::FeeEstimate;
use std::collections::HashMap;
use std::io::Error;

Expand Down
83 changes: 78 additions & 5 deletions clients/src/api/pool.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use crate::api::RequestMode;
use crate::protocols::pool::{
GetFarmerRequest, GetFarmerResponse, GetPoolInfoResponse, PoolError, PoolErrorCode,
PostFarmerRequest, PostFarmerResponse, PostPartialRequest, PostPartialResponse,
PutFarmerRequest, PutFarmerResponse,
};
use async_trait::async_trait;
use blst::min_pk::{AggregateSignature, SecretKey, Signature};
use dg_xch_core::blockchain::sized_bytes::{Bytes32, SizedBytes};
use dg_xch_core::clvm::bls_bindings::sign;
use dg_xch_core::protocols::pool::{
get_current_authentication_token, AuthenticationPayload, GetFarmerRequest, GetFarmerResponse,
GetPoolInfoResponse, PoolError, PoolErrorCode, PostFarmerRequest, PostFarmerResponse,
PostPartialRequest, PostPartialResponse, PutFarmerRequest, PutFarmerResponse,
};
use dg_xch_serialize::{hash_256, ChiaSerialize};
use log::warn;
use reqwest::{Client, RequestBuilder};
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::collections::HashMap;
use std::io::{Error, ErrorKind};

#[async_trait]
pub trait PoolClient {
Expand Down Expand Up @@ -194,3 +199,71 @@ async fn send_request<T: Serialize, R: DeserializeOwned>(
}
}
}

#[derive(serde::Serialize, serde::Deserialize, Debug)]
pub struct PoolLoginParts {
pub auth_token: u64,
pub aggregate_signature: String,
}

pub async fn create_pool_login_url(
target_pool: &str,
keys_and_launcher_ids: &[(SecretKey, Bytes32)],
) -> Result<String, Error> {
let parts = create_pool_login_parts(target_pool, keys_and_launcher_ids).await?;
let mut ids = String::new();
for (index, (_, launcher_id)) in keys_and_launcher_ids.iter().enumerate() {
if index != 0 {
ids.push(',')
}
ids.push_str(&hex::encode(launcher_id.as_slice()));
}
Ok(format!(
"{target_pool}/login?launcher_id={ids}&authentication_token={}&signature={})",
parts.auth_token, parts.aggregate_signature
))
}

pub async fn create_pool_login_parts(
target_pool: &str,
keys_and_launcher_ids: &[(SecretKey, Bytes32)],
) -> Result<PoolLoginParts, Error> {
let pool_client = DefaultPoolClient::new();
let pool_info = pool_client
.get_pool_info(target_pool)
.await
.map_err(|e| Error::new(ErrorKind::Other, format!("{:?}", e)))?;
let current_auth_token =
get_current_authentication_token(pool_info.authentication_token_timeout);
let mut sigs = vec![];
for (sec_key, launcher_id) in keys_and_launcher_ids {
let payload = AuthenticationPayload {
method_name: String::from("get_login"),
launcher_id: *launcher_id,
target_puzzle_hash: pool_info.target_puzzle_hash,
authentication_token: current_auth_token,
};
let to_sign = hash_256(payload.to_bytes());
let sig = sign(sec_key, &to_sign);
sigs.push(sig);
}
if !sigs.is_empty() {
let aggregate_signature =
AggregateSignature::aggregate(sigs.iter().collect::<Vec<&Signature>>().as_ref(), true)
.map_err(|e| {
Error::new(
ErrorKind::InvalidInput,
format!("Failed to calculate signature: {:?}", e),
)
})?;
Ok(PoolLoginParts {
auth_token: current_auth_token,
aggregate_signature: hex::encode(aggregate_signature.to_signature().to_bytes()),
})
} else {
Err(Error::new(
ErrorKind::NotFound,
"No Launcher IDs with Keys found",
))
}
}
4 changes: 2 additions & 2 deletions clients/src/api/responses.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::protocols::full_node::BlockCountMetrics;
use crate::protocols::full_node::FeeEstimate;
use dg_xch_core::blockchain::block_record::BlockRecord;
use dg_xch_core::blockchain::blockchain_state::BlockchainState;
use dg_xch_core::blockchain::coin_record::{CoinRecord, HintedCoinRecord};
Expand All @@ -13,6 +11,8 @@ use dg_xch_core::blockchain::tx_status::TXStatus;
use dg_xch_core::blockchain::unfinished_block::UnfinishedBlock;
use dg_xch_core::blockchain::wallet_balance::WalletBalance;
use dg_xch_core::blockchain::wallet_info::WalletInfo;
use dg_xch_core::protocols::full_node::BlockCountMetrics;
use dg_xch_core::protocols::full_node::FeeEstimate;

use dg_xch_core::blockchain::sized_bytes::Bytes32;
use serde::{Deserialize, Serialize};
Expand Down
1 change: 0 additions & 1 deletion clients/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod api;
pub mod protocols;
pub mod rpc;
pub mod websocket;
108 changes: 0 additions & 108 deletions clients/src/protocols/farmer.rs

This file was deleted.

Loading

0 comments on commit a1673e6

Please sign in to comment.