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
Conversation
fedimint-cli/src/lib.rs
Outdated
federation_id_prefix: notes.federation_id_prefix().to_string(), | ||
notes: notes.notes().clone(), |
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.
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.
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.
updated to use it on OOB notes through .notes_json
fedimint-cli/src/lib.rs
Outdated
#[clap(long = "federation_id_prefix")] | ||
federation_id_prefix: String, | ||
#[clap(long = "notes")] | ||
notes: 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.
Shouldn't this be a Maybe supplying the whole vec as JSON is actually more convenient.Vec<_>
? Ideally a Vec<SpendableNote>
, but due to clap-rs/clap#1704 likely rather a Vec<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.
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}'
fedimint-cli/src/lib.rs
Outdated
#[clap(long = "url")] | ||
url: SafeUrl, |
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.
I think if the field name is the same as the long argument name you can just annotate it as #[clap(long)]
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.
updated
ef0ae5b
to
0ac21f9
Compare
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. |
8e9eb29
to
9b31257
Compare
devimint/src/tests.rs
Outdated
@@ -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")?; |
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.
If I see correctly, this variable is used only once, and having it here just makes it far from where it's used.
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.
I can move it down, was thinking that eventually all the tests will require version matching so define up top but nbd
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.
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(); |
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.
Nit: map
is a meh name for a variable - it doesn't describe the meaning of it in it.
eabc220
to
504638f
Compare
I'd just squash it all at this point, no biggy. |
0b6732f
to
f48d917
Compare
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.
LGTM, but really could use a squash.
not a good commit message :P |
b446279
to
776ff93
Compare
for notes in self.0.iter() { | ||
match notes { | ||
OOBNotesData::Notes(notes) => { | ||
let notes_json = serde_json::to_value(notes).expect("serialization can't fail"); |
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.
Nit: the other to_value
return Result
rather than expect
, you could do the same here
devimint/src/tests.rs
Outdated
.await?; | ||
|
||
anyhow::ensure!( | ||
encode_invite_output["invite_code"].as_str().unwrap() == invite, |
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.
Nit: use expect
instead of unwrap
4b61bd9
to
49addcc
Compare
51cfec1
to
632281d
Compare
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.
But linters not happy
632281d
to
5d01f70
Compare
5d01f70
to
c7d12ab
Compare
let notes_json = serde_json::to_value(notes)?; | ||
notes_map.insert("notes".to_string(), notes_json); |
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.
We should probably assert that insert returns None
to avoid confusing ourselves should we ever allow multiple instances of some data type.
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