Comments (7)
For now let's do #[serde(rename)]
.
I think when we're closer to 1.0 we should do a "break the world" serde release (and make very few other changes along the way) and see how much pushback we get over it, and possibly revert it. I'd prefer if we had a cleaner/more principled serde serialization before 1.0 ... but we may be stuck with it ... and in any case I don't want to break serde piecemeal over several versions.
from rust-bitcoin.
"Drop serde
from everything that isn't in Core RPC" feels a little strong. Though I guess almost everything -- WIF keys, xkeys, BIP32 paths, PSBTs, etc., all do appear in the RPC in some place.
As for the use of deny_unknown_fields
, I could go either way on this. I don't want to force people to use bitcoin-core-rpc if they don't have to, but OTOH it's really not difficult to write wrapper structs yourself to handle the output of getrawtransaction
and so on. As long as you only need a couple such structs. I'm tempted to just put deny_unknown_fields
everywhere and accept breakage for people trying to use raw rust-bitcoin types directly with the RPC.
I note that we're already not compatible with Core's RPC for e.g. Transaction
because our input
/output
/etc fields don't match the vin
/vout
fields that the Core RPC uses. So on reflection, I don't know that anybody could possibly be using raw rust-bitcoin types with the RPC. Other than the simple types (e.g. Address) which have uncontroversial string encodings.
For de/serialization from Core RPC I think we should provide an example that uses serde(from)
and serde(into)
to demonstrate making a dummy struct that mirrors the RPC output and letting serde
do the conversion from the dummy struct into Transaction
and vice-versa. And saying that you should probably use bitcoin-core-rpc
crate if you want this done right.
Where does this leave us, serde-wise? I do want to keep the serde feature and have De/Serialize implemented on all the main types, because it's useful for e.g. dumping bitcoin data into json config files or whatever. And we've put a lot of work into e.g. Amount
to make sure that it can be serde-deserialized in the broad range of formats that we see it used in different exchange APIs.
But yes, we need to clarify who our target is and come up with a coherent policy for what we have serde traits for.
from rust-bitcoin.
I note that we're already not compatible with Core's RPC for e.g.
Transaction
because ourinput
/output
/etc fields don't match thevin
/vout
fields that the Core RPC uses. So on reflection, I don't know that anybody could possibly be using raw rust-bitcoin types with the RPC.
Oh, interesting. So we're in a pretty bad situation then. We can't sync them up with Core because that'd break someone and now we have just arbitrary field names. And I have no idea how many users actually use the serde serialization. Honestly maybe we should just change it into hex string/bytes since that format is practically immutable.
simple types (e.g. Address) which have uncontroversial string encodings.
Those I definitely want to keep.
And I fully agree that having serde is useful, great even but if we have weird, unstable serialization format it could be counterproductive.
from rust-bitcoin.
Oh, interesting. So we're in a pretty bad situation then. We can't sync them up with Core because that'd break someone and now we have just arbitrary field names. And I have no idea how many users actually use the serde serialization. Honestly maybe we should just change it into hex string/bytes since that format is practically immutable.
It's tempting, but for example, I'm pretty sure I'm using the existing serialization in some obscure personal tax software (where I'm using the raw transactions, along with merkle proofs, as evidence to be produced in case of audits). Personally it wouldn't be a big deal for me to change this, but if I wasn't a developer of the library I'd be super annoyed.
I think though we should be able to add deny_unused_fields
though because our existing format is ad-hoc, so it's hard to imagine anyone deserializing something in this format that didn't come from this library.
Perhaps we want to go through the library, remove all the derive
Serialize/Deserialize (except maybe for some trivial cases), and move the serialization logic into a single "do not touch this" module. Though maybe the existing serde fixed-vector tests are sufficient for this, if we were to complete them.
from rust-bitcoin.
OK, that sounds good. But what do we do about things like renaming input
to inputs
? Do we put #[serde(rename="input")]
on it or just accept the breakage (because even in format plural looks better). Or do we create some sort of migration module?
from rust-bitcoin.
Sounds good!
from rust-bitcoin.
Though maybe the existing serde fixed-vector tests are sufficient for this, if we were to complete them.
They were complete at the time I did them but by their very nature go stale easily, if we do all this we should try to enforce that regression tests exist on ever serde'd type in CI.
from rust-bitcoin.
Related Issues (20)
- version error PSBT versions greater than 0 are not supported HOT 1
- Principled fix for #2521
- CI: MemorySanitizer is erroring (ASAN job) HOT 12
- units: Audit all types for correct usage of `Ord` vs `ArbitraryOrd` HOT 4
- Inherent functions `to_bytes` / `from_bytes` HOT 6
- Shoosh semver informational part build warning
- CI fails are hard to view HOT 10
- crate labels go stale
- Changes that require updating the lock files do not fail CI HOT 3
- Add `just` command to install githooks HOT 1
- Our current merge policy/script causes excessive delay and work HOT 2
- deserializing network message can request arbitrary sized allocations HOT 6
- Can we sort `rustfmt` out once and for all HOT 5
- Add type data to TxOut HOT 15
- Should `LockTime` types live in `units` HOT 8
- Consider not deriving `serde` impls from `units` types HOT 12
- Is introducing `LockTimeUnit` enum promote redundancy? HOT 3
- Should `Script::witness_version` check if the script `is_witness_program` before it returns the version? HOT 2
- Make sure we mention than 'm/' is not handled in bip32 derivation paths HOT 1
- Use `Message::from` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-bitcoin.