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

add upsert-permissioned-candidates smart-contracts node command #382

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jankun4
Copy link
Contributor

@jankun4 jankun4 commented Jan 14, 2025

Description

Add your description here, if it fixes a particular issue please provide a
link
to the issue.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages.
  • New tests are added if needed and existing tests are updated.
  • Relevant logging and metrics added
  • CI passes. See note on CI.
  • Any changes are noted in the changelog.md for affected crate
  • Self-reviewed the diff

Note on CI

If your PR is from a fork, the necessary CI jobs won't trigger automatically for security reasons.
You will need to get someone with write privileges. Please contact IOG Partner Chains developers to do this
for you.

@jankun4 jankun4 requested a review from AmbientTea January 14, 2025 13:21
@jankun4 jankun4 force-pushed the ETCM-9053-upsert-permissioned-candidate-cli-command branch from ae8424b to 22d7042 Compare January 14, 2025 13:24
#[clap(flatten)]
common_arguments: crate::CommonArguments,
#[arg(long)]
permissioned_candidates_file: String,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Help is missing here. How is user supposed to know it should be colon separated CSV?

Copy link
Contributor

@LGLO LGLO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command has accepted file that was just:

aaaa:bbbb

Error handling in this code is totally missing

let record = result?;

let permissioned_candidate = PermissionedCandidateData {
sidechain_public_key: SidechainPublicKey::from_hex_unsafe(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use unsafe in user facing code. This is used for user input, not for tests or values that were earlier validated in some way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW in this crate there is function: parse_partnerchain_public_keys that could be used and then we don't need CSV dependency.


let mut reader = csv::ReaderBuilder::new()
.delimiter(b':')
.from_path(&self.permissioned_candidates_file)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap error somehow, so error message to user points that it's about permissioned candidates file

let payment_key = self.payment_key_file.read_key()?;

let mut reader = csv::ReaderBuilder::new()
.delimiter(b':')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you share a file that you have tested this with? I tried a CSV that seems valid, but I get empty result.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With 1 entry file this code reads 0 records, with 3 entries in file it reads 2 records.

@jankun4 jankun4 force-pushed the ETCM-9053-upsert-permissioned-candidate-cli-command branch 3 times, most recently from 5fac2c6 to bec8813 Compare January 15, 2025 12:48
@jankun4 jankun4 requested a review from LGLO January 15, 2025 12:48
@jankun4 jankun4 force-pushed the ETCM-9053-upsert-permissioned-candidate-cli-command branch from bec8813 to cc3d60b Compare January 15, 2025 13:58
use sidechain_domain::PermissionedCandidateData;
use sidechain_domain::SidechainPublicKey;
use sidechain_domain::UtxoId;
use std::fs::read_to_string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clean up, 36% of these imports are unused

let permissioned_candidate = parse_partnerchain_public_keys(line)
.map_err(|e| format!("Failed to parse permissioned candidate: {}", e))?;
permissioned_candidates.push(permissioned_candidate);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./partner-chains-node smart-contracts upsert-permissioned-candidates -c f8fbe7316561e57de9ecd1c86ee8f8b512a314ba86499ba9a584bfa8fe2edc8d#0 -k funded_address.skey --permissioned-candidates-file oneentry.csv
Error: Application("Failed to parse permissioned candidate: Failed to parse partner chain public keys.")

Just because I have \n after the last key in the file. This will surely come back to us.


for line in read_to_string(&self.permissioned_candidates_file).unwrap().lines() {
let permissioned_candidate = parse_partnerchain_public_keys(line)
.map_err(|e| format!("Failed to parse permissioned candidate: {}", e))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.map_err(|e| format!("Failed to parse permissioned candidate: {}", e))?;
.map_err(|e| format!("Failed to parse permissioned candidate: '{}', because of {}", line, e))?;


let mut permissioned_candidates = Vec::new();

for line in read_to_string(&self.permissioned_candidates_file).unwrap().lines() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of unwrap, please map it to a message that points user what file is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants