Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: accumulate leader fees in substate, impl claim fees in wallet #1270

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ digest = "0.10"
dirs = "4.0.0"
env_logger = "0.10.0"
ethnum = "1.5.0"
either = "1.13.0"
fern = "0.6.2"
futures = "0.3.30"
futures-bounded = "0.2.3"
Expand Down
16 changes: 6 additions & 10 deletions applications/tari_dan_wallet_cli/src/command/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use tari_template_lib::{
};
use tari_transaction::{Transaction, TransactionId, UnsignedTransaction};
use tari_transaction_manifest::{parse_manifest, ManifestValue};
use tari_utilities::{hex::to_hex, ByteArray};
use tari_utilities::ByteArray;
use tari_wallet_daemon_client::{
types::{
AccountGetResponse,
Expand Down Expand Up @@ -542,17 +542,13 @@ pub fn print_substate_diff(diff: &SubstateDiff) {
let referenced_address = SubstateId::from(index.referenced_address().clone());
println!(" ▶ NFT index {} referencing {}", address, referenced_address);
},
SubstateValue::FeeClaim(fee_claim) => {
println!(" ▶ Fee claim: {}", address);
println!(" ▶ Amount: {}", fee_claim.amount);
println!(
" ▶ validator: {}",
to_hex(fee_claim.validator_public_key.as_bytes())
);
},
SubstateValue::Template(_) => {
println!(" ▶ Template: {}", address);
},
SubstateValue::ValidatorFeePool(pool) => {
println!(" ▶ Validator Fee Pool: {}", address);
println!(" ▶ Total fees: {}", pool.amount);
},
}
println!();
}
Expand Down Expand Up @@ -844,8 +840,8 @@ impl CliArg {
SubstateId::NonFungible(v) => arg!(v),
SubstateId::NonFungibleIndex(v) => arg!(v),
SubstateId::TransactionReceipt(v) => arg!(v),
SubstateId::FeeClaim(v) => arg!(v),
SubstateId::Template(v) => arg!(v),
SubstateId::ValidatorFeePool(v) => arg!(v),
},
CliArg::TemplateAddress(v) => arg!(v),
CliArg::NonFungibleId(v) => arg!(v),
Expand Down
50 changes: 27 additions & 23 deletions applications/tari_dan_wallet_cli/src/command/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
use std::str::FromStr;

use clap::{Args, Subcommand};
use tari_common_types::types::PublicKey;
use tari_dan_common_types::Epoch;
use tari_template_lib::{crypto::RistrettoPublicKeyBytes, models::Amount};
use tari_utilities::ByteArray;
use tari_dan_common_types::{shard::Shard, ShardGroup};
use tari_template_lib::models::Amount;
use tari_wallet_daemon_client::{
types::{ClaimValidatorFeesRequest, GetValidatorFeesRequest},
types::{AccountOrKeyIndex, ClaimValidatorFeesRequest, GetValidatorFeesRequest},
ComponentAddressOrName,
WalletDaemonClient,
};

use crate::{command::transaction::summarize_finalize_result, from_hex::FromHex};
use crate::command::transaction::summarize_finalize_result;

#[derive(Debug, Subcommand, Clone)]
pub enum ValidatorSubcommand {
Expand All @@ -26,20 +24,27 @@ pub enum ValidatorSubcommand {
pub struct ClaimFeesArgs {
#[clap(long, short = 'a', alias = "account")]
pub dest_account_name: Option<String>,
#[clap(long, short = 'v')]
pub validator_public_key: FromHex<RistrettoPublicKeyBytes>,
#[clap(long, short = 'e')]
pub epoch: u64,
#[clap(long, short = 's', value_parser = parse_shard)]
pub shard: Shard,
#[clap(long)]
pub max_fee: Option<u32>,
#[clap(long)]
pub dry_run: bool,
}

fn parse_shard(s: &str) -> Result<Shard, String> {
Ok(Shard::from(
s.parse::<u32>()
.map_err(|_| "Invalid shard. Expected a number.".to_string())?,
))
}

#[derive(Debug, Args, Clone)]
pub struct GetFeesArgs {
#[clap(long, short = 'v')]
pub validator_public_key: FromHex<RistrettoPublicKeyBytes>,
#[clap(long, short = 'a')]
pub account: Option<ComponentAddressOrName>,
#[clap(long, short = 'g')]
pub shard_group: Option<ShardGroup>,
}

impl ValidatorSubcommand {
Expand All @@ -57,16 +62,17 @@ impl ValidatorSubcommand {
}

pub async fn handle_get_fees(args: GetFeesArgs, client: &mut WalletDaemonClient) -> Result<(), anyhow::Error> {
// TODO: complete this handler once this request is implemented
let resp = client
.get_validator_fee_summary(GetValidatorFeesRequest {
validator_public_key: PublicKey::from_canonical_bytes(args.validator_public_key.into_inner().as_bytes())
.map_err(anyhow::Error::msg)?,
epoch: Epoch(0),
.get_validator_fees(GetValidatorFeesRequest {
account_or_key: AccountOrKeyIndex::Account(args.account),
shard_group: args.shard_group,
})
.await?;

println!("{:?}", resp);
println!("Validator fees:");
for (shard, fee) in resp.fees {
println!("{}: {}XTR at address {}", shard, fee.amount, fee.address);
}
Ok(())
}

Expand All @@ -76,8 +82,7 @@ pub async fn handle_claim_validator_fees(
) -> Result<(), anyhow::Error> {
let ClaimFeesArgs {
dest_account_name,
validator_public_key,
epoch,
shard,
max_fee,
dry_run,
} = args;
Expand All @@ -89,10 +94,9 @@ pub async fn handle_claim_validator_fees(
account: dest_account_name
.map(|name| ComponentAddressOrName::from_str(&name))
.transpose()?,
claim_key_index: None,
max_fee: max_fee.map(Amount::from),
validator_public_key: PublicKey::from_canonical_bytes(validator_public_key.into_inner().as_bytes())
.map_err(anyhow::Error::msg)?,
epoch: Epoch(epoch),
shards: vec![shard],
dry_run,
})
.await?;
Expand Down
1 change: 1 addition & 0 deletions applications/tari_dan_wallet_daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ axum-jrpc = { workspace = true, features = ["anyhow_error"] }
base64 = { workspace = true }
clap = { workspace = true, features = ["derive", "env"] }
config = { workspace = true }
either = { workspace = true }
humantime-serde = { workspace = true }
futures = { workspace = true }
include_dir = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions applications/tari_dan_wallet_daemon/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:warning=Output: {}", String::from_utf8_lossy(&output.stdout));
println!("cargo:warning=Error: {}", String::from_utf8_lossy(&output.stderr));
exit_on_ci();
break;
// Ignore it unless on CI
continue;
},
Err(error) => {
println!("cargo:warning='npm run build' error : {:?}", error);
println!("cargo:warning=The web ui will not be included!");
exit_on_ci();
break;
continue;
},
_ => {},
}
Expand Down
21 changes: 18 additions & 3 deletions applications/tari_dan_wallet_daemon/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::net::SocketAddr;
use std::{net::SocketAddr, path::PathBuf};

use clap::Parser;
use minotari_app_utilities::common_cli_args::CommonCliArgs;
Expand All @@ -40,8 +40,8 @@ pub struct Cli {
pub signaling_server_address: Option<SocketAddr>,
#[clap(long, alias = "indexer-url")]
pub indexer_node_json_rpc_url: Option<String>,
#[clap(long)]
pub derive_secret: Option<u64>,
#[clap(subcommand)]
pub command: Option<Subcommand>,
}

impl Cli {
Expand Down Expand Up @@ -80,3 +80,18 @@ impl ConfigOverrideProvider for Cli {
overrides
}
}

#[derive(clap::Subcommand, Debug)]
pub enum Subcommand {
#[clap(name = "run", about = "Run the wallet daemon")]
Run,
#[clap(about = "Generate a new key and output the public key")]
CreateKey {
#[clap(long, alias = "key")]
key_index: Option<u64>,
#[clap(long)]
set_active: bool,
#[clap(long, alias = "output", short = 'o')]
output_path: Option<PathBuf>,
},
}
Loading
Loading