-
Notifications
You must be signed in to change notification settings - Fork 11
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
base: master
Are you sure you want to change the base?
add upsert-permissioned-candidates smart-contracts node command #382
Conversation
ae8424b
to
22d7042
Compare
#[clap(flatten)] | ||
common_arguments: crate::CommonArguments, | ||
#[arg(long)] | ||
permissioned_candidates_file: String, |
There was a problem hiding this comment.
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?
There was a problem hiding this 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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)?; |
There was a problem hiding this comment.
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':') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
5fac2c6
to
bec8813
Compare
bec8813
to
cc3d60b
Compare
use sidechain_domain::PermissionedCandidateData; | ||
use sidechain_domain::SidechainPublicKey; | ||
use sidechain_domain::UtxoId; | ||
use std::fs::read_to_string; |
There was a problem hiding this comment.
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); | ||
} |
There was a problem hiding this comment.
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))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.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() { |
There was a problem hiding this comment.
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.
Description
Add your description here, if it fixes a particular issue please provide a
link
to the issue.
Checklist
changelog.md
for affected crateNote 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.