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: dev commands to decode and encode notes and invite_code to and from json #4473

Merged
merged 2 commits into from Mar 19, 2024

Conversation

Kodylow
Copy link
Member

@Kodylow Kodylow commented Mar 6, 2024

replaces #4449

Adds dev codes for fedimint-cli to encode/decode to/from json for notes and invite_code

Would it be out of scope to add cashu encoding here? It'd just rename the keys and put the amount in each of the notes then spit out the json

Comment on lines 803 to 804
federation_id_prefix: notes.federation_id_prefix().to_string(),
notes: notes.notes().clone(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I actually liked the previous version of your JSON encoding code which was able to display all OOBNoteData variants. Now we are missing invite codes when provided.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated to use it on OOB notes through .notes_json

#[clap(long = "federation_id_prefix")]
federation_id_prefix: String,
#[clap(long = "notes")]
notes: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be a Vec<_>? Ideally a Vec<SpendableNote>, but due to clap-rs/clap#1704 likely rather a Vec<String>. Maybe supplying the whole vec as JSON is actually more convenient.

Copy link
Member Author

Choose a reason for hiding this comment

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

I originally had it as a vec but it's super tedious to input that way, doing it as Json string you can just wrap the JSON output from the dev decode command with single quotes like '{"notes": stuff}'

Comment on lines 379 to 334
#[clap(long = "url")]
url: SafeUrl,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think if the field name is the same as the long argument name you can just annotate it as #[clap(long)]

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

@elsirion
Copy link
Contributor

elsirion commented Mar 7, 2024

Breaks backwards compat tests, I had to deal with that in #4415, I bet you also have to do some version switching for the command to use for decoding since you changed the CLI.

@Kodylow Kodylow force-pushed the kl/dev-decode-encode branch 4 times, most recently from 8e9eb29 to 9b31257 Compare March 10, 2024 20:13
@@ -346,6 +346,8 @@ pub async fn latency_tests(dev_fed: DevFed, r#type: LatencyTest) -> Result<()> {
}

pub async fn cli_tests(dev_fed: DevFed) -> Result<()> {
let fedimint_cli_version = crate::util::FedimintCli::version_or_default().await;
let version_req = VersionReq::parse(">=0.3.0-alpha")?;
Copy link
Contributor

Choose a reason for hiding this comment

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

If I see correctly, this variable is used only once, and having it here just makes it far from where it's used.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can move it down, was thinking that eventually all the tests will require version matching so define up top but nbd

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough. 👍

But... in that case it might need a longer name.

@@ -154,6 +155,44 @@ impl OOBNotes {
.expect("Invariant violated: OOBNotes does not contain any notes")
}

pub fn notes_json(&self) -> Result<serde_json::Value, serde_json::Error> {
let mut map = serde_json::Map::new();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: map is a meh name for a variable - it doesn't describe the meaning of it in it.

dpc
dpc previously approved these changes Mar 11, 2024
dpc
dpc previously approved these changes Mar 11, 2024
@dpc
Copy link
Contributor

dpc commented Mar 11, 2024

I'd just squash it all at this point, no biggy.

@Kodylow Kodylow force-pushed the kl/dev-decode-encode branch 2 times, most recently from 0b6732f to f48d917 Compare March 14, 2024 18:36
Copy link
Contributor

@dpc dpc left a comment

Choose a reason for hiding this comment

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

LGTM, but really could use a squash.

@dpc
Copy link
Contributor

dpc commented Mar 15, 2024

fix: backwards compatibility tests

fix: fix

fix: test

fix: hold

fix: tests fix

fix: encoding ecash

fix: decode on OOBNotesData

feat: encode dev command for notes and invite-code

feat: decode notes to json

not a good commit message :P

for notes in self.0.iter() {
match notes {
OOBNotesData::Notes(notes) => {
let notes_json = serde_json::to_value(notes).expect("serialization can't fail");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: the other to_value return Result rather than expect, you could do the same here

.await?;

anyhow::ensure!(
encode_invite_output["invite_code"].as_str().unwrap() == invite,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: use expect instead of unwrap

m1sterc001guy
m1sterc001guy previously approved these changes Mar 15, 2024
m1sterc001guy
m1sterc001guy previously approved these changes Mar 15, 2024
dpc
dpc previously approved these changes Mar 15, 2024
@Kodylow Kodylow dismissed stale reviews from dpc and m1sterc001guy via efc6b0c March 16, 2024 04:04
@Kodylow Kodylow force-pushed the kl/dev-decode-encode branch 3 times, most recently from 51cfec1 to 632281d Compare March 18, 2024 17:25
dpc
dpc previously approved these changes Mar 18, 2024
Copy link
Contributor

@dpc dpc left a comment

Choose a reason for hiding this comment

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

But linters not happy

@dpc dpc added this pull request to the merge queue Mar 19, 2024
Merged via the queue into fedimint:master with commit 2befd3c Mar 19, 2024
20 checks passed
Comment on lines +163 to +164
let notes_json = serde_json::to_value(notes)?;
notes_map.insert("notes".to_string(), notes_json);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably assert that insert returns None to avoid confusing ourselves should we ever allow multiple instances of some data type.

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.

None yet

4 participants