Skip to content

Commit

Permalink
fixup! Include validator avatar in their medatada
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Jan 3, 2024
1 parent f1c247d commit be37c60
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 1 deletion.
22 changes: 22 additions & 0 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2839,6 +2839,7 @@ pub mod args {
pub const ALLOW_DUPLICATE_IP: ArgFlag = flag("allow-duplicate-ip");
pub const AMOUNT: Arg<token::DenominatedAmount> = arg("amount");
pub const ARCHIVE_DIR: ArgOpt<PathBuf> = arg_opt("archive-dir");
pub const AVATAR_OPT: ArgOpt<String> = arg_opt("avatar");
pub const BALANCE_OWNER: ArgOpt<WalletBalanceOwner> = arg_opt("owner");
pub const BASE_DIR: ArgDefault<PathBuf> = arg_default(
"base-dir",
Expand Down Expand Up @@ -4042,6 +4043,7 @@ pub mod args {
description: self.description,
website: self.website,
discord_handle: self.discord_handle,
avatar: self.avatar,
unsafe_dont_encrypt: self.unsafe_dont_encrypt,
tx_code_path: self.tx_code_path.to_path_buf(),
}
Expand All @@ -4064,6 +4066,7 @@ pub mod args {
let description = DESCRIPTION_OPT.parse(matches);
let website = WEBSITE_OPT.parse(matches);
let discord_handle = DISCORD_OPT.parse(matches);
let avatar = AVATAR_OPT.parse(matches);
let unsafe_dont_encrypt = UNSAFE_DONT_ENCRYPT.parse(matches);
let tx_code_path = PathBuf::from(TX_BECOME_VALIDATOR_WASM);
Self {
Expand All @@ -4080,6 +4083,7 @@ pub mod args {
description,
website,
discord_handle,
avatar,
unsafe_dont_encrypt,
tx_code_path,
}
Expand Down Expand Up @@ -4128,6 +4132,7 @@ pub mod args {
.arg(DESCRIPTION_OPT.def().help("The validator's description."))
.arg(WEBSITE_OPT.def().help("The validator's website."))
.arg(DISCORD_OPT.def().help("The validator's discord handle."))
.arg(AVATAR_OPT.def().help("The validator's avatar."))
.arg(VALIDATOR_CODE_PATH.def().help(
"The path to the validity predicate WASM code to be used \
for the validator account. Uses the default validator VP \
Expand Down Expand Up @@ -4163,6 +4168,7 @@ pub mod args {
description: self.description,
website: self.website,
discord_handle: self.discord_handle,
avatar: self.avatar,
validator_vp_code_path: self
.validator_vp_code_path
.to_path_buf(),
Expand Down Expand Up @@ -4193,6 +4199,7 @@ pub mod args {
let description = DESCRIPTION_OPT.parse(matches);
let website = WEBSITE_OPT.parse(matches);
let discord_handle = DISCORD_OPT.parse(matches);
let avatar = AVATAR_OPT.parse(matches);
let validator_vp_code_path = VALIDATOR_CODE_PATH
.parse(matches)
.unwrap_or_else(|| PathBuf::from(VP_USER_WASM));
Expand All @@ -4216,6 +4223,7 @@ pub mod args {
description,
website,
discord_handle,
avatar,
validator_vp_code_path,
unsafe_dont_encrypt,
tx_init_account_code_path,
Expand Down Expand Up @@ -4268,6 +4276,7 @@ pub mod args {
.arg(DESCRIPTION_OPT.def().help("The validator's description."))
.arg(WEBSITE_OPT.def().help("The validator's website."))
.arg(DISCORD_OPT.def().help("The validator's discord handle."))
.arg(AVATAR_OPT.def().help("The validator's avatar."))
.arg(VALIDATOR_CODE_PATH.def().help(
"The path to the validity predicate WASM code to be used \
for the validator account. Uses the default validator VP \
Expand Down Expand Up @@ -5331,6 +5340,7 @@ pub mod args {
description: self.description,
website: self.website,
discord_handle: self.discord_handle,
avatar: self.avatar,
commission_rate: self.commission_rate,
tx_code_path: self.tx_code_path.to_path_buf(),
}
Expand All @@ -5345,6 +5355,7 @@ pub mod args {
let description = DESCRIPTION_OPT.parse(matches);
let website = WEBSITE_OPT.parse(matches);
let discord_handle = DISCORD_OPT.parse(matches);
let avatar = AVATAR_OPT.parse(matches);
let commission_rate = COMMISSION_RATE_OPT.parse(matches);
let tx_code_path = PathBuf::from(TX_CHANGE_METADATA_WASM);
Self {
Expand All @@ -5354,6 +5365,7 @@ pub mod args {
description,
website,
discord_handle,
avatar,
commission_rate,
tx_code_path,
}
Expand Down Expand Up @@ -5382,6 +5394,10 @@ pub mod args {
existing discord handle, pass an empty string to this \
argument.",
))
.arg(AVATAR_OPT.def().help(
"The desired new validator avatar url. To remove the \
existing avatar, pass an empty string to this argument.",
))
.arg(
COMMISSION_RATE_OPT
.def()
Expand Down Expand Up @@ -6707,6 +6723,7 @@ pub mod args {
pub description: Option<String>,
pub website: Option<String>,
pub discord_handle: Option<String>,
pub avatar: Option<String>,
pub address: EstablishedAddress,
pub tx_path: PathBuf,
}
Expand All @@ -6726,6 +6743,7 @@ pub mod args {
let description = DESCRIPTION_OPT.parse(matches);
let website = WEBSITE_OPT.parse(matches);
let discord_handle = DISCORD_OPT.parse(matches);
let avatar = AVATAR_OPT.parse(matches);
let address = RAW_ADDRESS_ESTABLISHED.parse(matches);
let tx_path = PATH.parse(matches);
Self {
Expand All @@ -6740,6 +6758,7 @@ pub mod args {
description,
website,
discord_handle,
avatar,
tx_path,
address,
}
Expand Down Expand Up @@ -6797,6 +6816,9 @@ pub mod args {
"The validator's discord handle. This is an optional \
parameter.",
))
.arg(AVATAR_OPT.def().help(
"The validator's avatar. This is an optional parameter.",
))
}
}

Expand Down
6 changes: 6 additions & 0 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1992,6 +1992,7 @@ pub async fn query_and_print_metadata(
description,
website,
discord_handle,
avatar,
}) => {
display_line!(
context.io(),
Expand All @@ -2018,6 +2019,11 @@ pub async fn query_and_print_metadata(
} else {
display_line!(context.io(), "No discord handle");
}
if let Some(avatar) = avatar {
display_line!(context.io(), "Avatar: {}", avatar);
} else {
display_line!(context.io(), "No avatar");
}
}
None => display_line!(
context.io(),
Expand Down
4 changes: 4 additions & 0 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ pub async fn submit_become_validator(
website,
description,
discord_handle,
avatar,
unsafe_dont_encrypt,
tx_code_path,
}: args::TxBecomeValidator,
Expand Down Expand Up @@ -710,6 +711,7 @@ pub async fn submit_become_validator(
description,
website,
discord_handle,
avatar,
};

// Put together all the PKs that we have to sign with to verify ownership
Expand Down Expand Up @@ -845,6 +847,7 @@ pub async fn submit_init_validator(
website,
description,
discord_handle,
avatar,
validator_vp_code_path,
unsafe_dont_encrypt,
tx_init_account_code_path,
Expand Down Expand Up @@ -896,6 +899,7 @@ pub async fn submit_init_validator(
description,
website,
discord_handle,
avatar,
tx_code_path: tx_become_validator_code_path,
unsafe_dont_encrypt,
},
Expand Down
2 changes: 2 additions & 0 deletions apps/src/lib/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ pub fn init_genesis_validator(
description,
website,
discord_handle,
avatar,
tx_path,
address,
}: args::InitGenesisValidator,
Expand Down Expand Up @@ -884,6 +885,7 @@ pub fn init_genesis_validator(
description,
website,
discord_handle,
avatar,
},
&validator_wallet,
);
Expand Down
1 change: 1 addition & 0 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ pub fn make_dev_genesis(
description: None,
website: None,
discord_handle: None,
avatar: None,
},
net_address: SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
Expand Down
4 changes: 4 additions & 0 deletions apps/src/lib/config/genesis/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub struct GenesisValidatorData {
pub description: Option<String>,
pub website: Option<String>,
pub discord_handle: Option<String>,
pub avatar: Option<String>,
}

/// Panics if given `txs.validator_accounts` is not empty, because validator
Expand Down Expand Up @@ -269,6 +270,7 @@ pub fn init_validator(
description,
website,
discord_handle,
avatar,
}: GenesisValidatorData,
validator_wallet: &ValidatorWallet,
) -> (Address, UnsignedTransactions) {
Expand Down Expand Up @@ -302,6 +304,7 @@ pub fn init_validator(
description,
website,
discord_handle,
avatar,
},
};
let unsigned_validator_addr =
Expand Down Expand Up @@ -613,6 +616,7 @@ impl TxToSign for ValidatorAccountTx<SignedPk> {
description: self.metadata.description.clone(),
website: self.metadata.website.clone(),
discord_handle: self.metadata.discord_handle.clone(),
avatar: self.metadata.avatar.clone(),
},
)
}
Expand Down
2 changes: 2 additions & 0 deletions benches/txs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ fn become_validator(c: &mut Criterion) {
description: None,
website: None,
discord_handle: None,
avatar: None,
};
let tx = shell.generate_tx(
TX_BECOME_VALIDATOR_WASM,
Expand Down Expand Up @@ -722,6 +723,7 @@ fn change_validator_metadata(c: &mut Criterion) {
description: Some("I will change this piece of data".to_string()),
website: None,
discord_handle: None,
avatar: None,
commission_rate: None,
};

Expand Down
4 changes: 4 additions & 0 deletions core/src/types/transaction/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ pub struct MetaDataChange {
pub website: Option<String>,
/// Validator's discord handle
pub discord_handle: Option<String>,
/// Validator's avatar url
pub avatar: Option<String>,
/// Validator's commission rate
pub commission_rate: Option<Dec>,
}
Expand Down Expand Up @@ -270,6 +272,7 @@ pub mod tests {
description in option::of("[a-zA-Z0-9_]*"),
website in option::of("[a-zA-Z0-9_]*"),
discord_handle in option::of("[a-zA-Z0-9_]*"),
avatar in option::of("[a-zA-Z0-9_]*"),
commission_rate in option::of(arb_dec()),
) -> MetaDataChange {
MetaDataChange {
Expand All @@ -278,6 +281,7 @@ pub mod tests {
description,
website,
discord_handle,
avatar,
commission_rate,
}
}
Expand Down
3 changes: 3 additions & 0 deletions light_sdk/src/transaction/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,14 @@ pub struct ChangeMetaData(Tx);

impl ChangeMetaData {
/// Build a raw ChangeMetadata transaction from the given parameters
#[allow(clippy::too_many_arguments)]
pub fn new(
validator: Address,
email: Option<String>,
description: Option<String>,
website: Option<String>,
discord_handle: Option<String>,
avatar: Option<String>,
commission_rate: Option<Dec>,
args: GlobalArgs,
) -> Self {
Expand All @@ -351,6 +353,7 @@ impl ChangeMetaData {
description,
website,
discord_handle,
avatar,
commission_rate,
};

Expand Down
6 changes: 5 additions & 1 deletion proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use crate::storage::{
validator_slashes_handle, validator_state_handle,
validator_total_redelegated_bonded_handle,
validator_total_redelegated_unbonded_handle, write_last_reward_claim_epoch,
write_pos_params, write_validator_address_raw_hash,
write_pos_params, write_validator_address_raw_hash, write_validator_avatar,
write_validator_description, write_validator_discord_handle,
write_validator_email, write_validator_max_commission_rate_change,
write_validator_metadata, write_validator_website,
Expand Down Expand Up @@ -2558,6 +2558,7 @@ pub fn change_validator_metadata<S>(
description: Option<String>,
website: Option<String>,
discord_handle: Option<String>,
avatar: Option<String>,
commission_rate: Option<Dec>,
current_epoch: Epoch,
) -> storage_api::Result<()>
Expand All @@ -2576,6 +2577,9 @@ where
if let Some(discord) = discord_handle {
write_validator_discord_handle(storage, validator, &discord)?;
}
if let Some(avatar) = avatar {
write_validator_avatar(storage, validator, &avatar)?;
}
if let Some(commission_rate) = commission_rate {
change_validator_commission_rate(
storage,
Expand Down
3 changes: 3 additions & 0 deletions proof_of_stake/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,9 @@ where
if let Some(discord) = metadata.discord_handle.as_ref() {
write_validator_discord_handle(storage, validator, discord)?;
}
if let Some(avatar) = metadata.avatar.as_ref() {
write_validator_avatar(storage, validator, avatar)?;
}
Ok(())
}

Expand Down
6 changes: 6 additions & 0 deletions sdk/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,8 @@ pub struct TxBecomeValidator<C: NamadaTypes = SdkTypes> {
pub website: Option<String>,
/// The validator's discord handle
pub discord_handle: Option<String>,
/// The validator's avatar
pub avatar: Option<String>,
/// Path to the TX WASM code file
pub tx_code_path: PathBuf,
/// Don't encrypt the keypair
Expand Down Expand Up @@ -785,6 +787,8 @@ pub struct TxInitValidator<C: NamadaTypes = SdkTypes> {
pub website: Option<String>,
/// The validator's discord handle
pub discord_handle: Option<String>,
/// The validator's avatar
pub avatar: Option<String>,
/// Path to the VP WASM code file
pub validator_vp_code_path: PathBuf,
/// Path to the TX WASM code file
Expand Down Expand Up @@ -1456,6 +1460,8 @@ pub struct MetaDataChange<C: NamadaTypes = SdkTypes> {
pub website: Option<String>,
/// New validator discord handle
pub discord_handle: Option<String>,
/// New validator avatar url
pub avatar: Option<String>,
/// New validator commission rate
pub commission_rate: Option<Dec>,
/// Path to the TX WASM code file
Expand Down
Loading

0 comments on commit be37c60

Please sign in to comment.