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

asset/btc/electrum: make floatString work for float and string float #2770

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ukane-philemon
Copy link
Contributor

This PR improves the UnmarshalJSON method of type floatString.

@ukane-philemon ukane-philemon changed the title asset/btc/electrum: make floatString work for floats and `strings asset/btc/electrum: make floatString work for floats and strings May 12, 2024
Copy link
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

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

Could you add a test that confirms it does what it should? I don't know exactly what we want to parse, like "1.31" and 0?

@ukane-philemon
Copy link
Contributor Author

like "1.31" and 0

Yes, floatString should do both, master code parses only the former. This PR enables parsing both.

@buck54321
Copy link
Member

Please provide some reasoning for why this change is needed.

@ukane-philemon
Copy link
Contributor Author

Please provide some reasoning for why this change is needed.

I intend to use this in #2769, as a shared code since we deal with floatString there too, suggesting this as a smaller change to make floatString compatible with cases where the same fields could be represented as floats and strings depending on the asset. In other cases where we'd need this, we would simply add a type.

- remove unused type ntfn in btc/electrum/jsonrpcs.go

Signed-off-by: Philemon Ukane <[email protected]>
@ukane-philemon ukane-philemon changed the title asset/btc/electrum: make floatString work for floats and strings asset/btc/electrum: make floatString work for float and string float Jun 27, 2024
client/asset/btc/electrum/jsonrpc_test.go Outdated Show resolved Hide resolved
@buck54321
Copy link
Member

cases where the same fields could be represented as floats and strings depending on the asset

Sorry to keep pushing on this, but can you provide an example of a response from #2769 where the type varies depending on the asset. I have never run into an api response where a single field might be different types. floatString itself might have been unnecessary to begin with, because you can e.g.

type A struct {
    AA float64 `json:"aa,string"`
}

@buck54321
Copy link
Member

Wait. This is for electrum? What does #2769 have to do with electrum?

@ukane-philemon
Copy link
Contributor Author

Sorry to keep pushing on this, but can you provide an example of a response from #2769 where the type varies depending on the asset. I have never run into an api response where a single field might be different types.

At one point I intended to use average_transaction_fee_24h but eventually went with suggested_transaction_fee_gwei_options that has predictable type.

The fields circled in red are not the same for other assets, I think only eth uses strings (because of the large number) and

Screenshot 2024-07-09 at 1 14 58 PM

Wait. This is for electrum? What does #2769 have to do with electrum?

I won't be using changes in this PR for #2769 anymore as I have moved on with other options available (suggested_transaction_fee_gwei_options) but I assumed the concept of floatString should handle both cases of "24.0" and 24.0.

In that note, you can proceed to close this PR if the changes are entirely not desirable or to remove floatString entirely.

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.

3 participants