GithubHelp home page GithubHelp logo

Comments (12)

tcharding avatar tcharding commented on June 27, 2024 1

We have that usecase covered already, one can do:

struct GetTransactionInfo {
    ...
    #[serde(with = "bitcoin::amount::serde::as_sat")]
    pub fee: Amount,
    ...
}

I haven't thought it through for other unit types but we want to provide some way to be able to derive them too.

from rust-bitcoin.

apoelstra avatar apoelstra commented on June 27, 2024

I don't understand. Right now we have e.g. the amount::serde module which lets them choose between sats and BTC. We should definitely keep that.

For the locktime types things are less clear (should we have serde on Height/Time or just on LockTime).

from rust-bitcoin.

tcharding avatar tcharding commented on June 27, 2024

You were too quick. I've updated the issue

from rust-bitcoin.

sanket1729 avatar sanket1729 commented on June 27, 2024

Having an implementation is definitely valuable for auto-derive users. I can imagine something like

struct GetTransactionInfo {
    pub reciever: Address, 
    pub fee: Amount,
    pub sent_amount: Amount,
}

requiring an auto-derive.

from rust-bitcoin.

tcharding avatar tcharding commented on June 27, 2024

I just had a play and if we remove the serde imples it is annoying to not be able to do

#[derive(Debug, Serialize, Deserialize)]
struct Foo {
    height: absolute::Height,
    time: absolute::Time,
}

And it is surprising that

#[derive(Debug, Serialize, Deserialize)]
struct Bar {
    lt: absolute::LockTime
}

is fine but using Height and Time is not (if we remove the impls).

Do we gain anything by not allowing Foo to be defined like that? Seems to me like we will just be annoying users.

from rust-bitcoin.

sanket1729 avatar sanket1729 commented on June 27, 2024

Amount is probably the most important one. If we have that covered, I am okay dropping the serde requirement from units. Users dealing with Height and Time are advanced users that can do their own serde.

from rust-bitcoin.

apoelstra avatar apoelstra commented on June 27, 2024

Agreed. I do not think we should change Amount. We spent forever implementing it, many people are using it (including me) and we have covered the multiple natural ways to implement it.

Meanwhile Height and Time have no natural ways to implement serde because they basically just exist to compensate for Rusts' lack of privacy on enum internals, and their serde implementations are confusingly inconsistent with that for LockTime.

I'm fine keeping them, but they are a weird bit of API surface that if we commit to, we're stuck with forever.

You were too quick. I've updated the issue

It still seems to imply that we should get rid of serde entirely in the units crate.

from rust-bitcoin.

15IITian avatar 15IITian commented on June 27, 2024

But It is possible that some users can just use Height struct for simply representing the height of a block -> so will require its serde implementation.

from rust-bitcoin.

tcharding avatar tcharding commented on June 27, 2024

It still seems to imply that we should get rid of serde entirely in the units crate.

I re-edited the description, third time lucky.

from rust-bitcoin.

tcharding avatar tcharding commented on June 27, 2024

But It is possible that some users can just use Height struct for simply representing the height of a block -> so will require its serde implementation.

I agree, absolute::Height seems totally likely to be put into a struct that wants to derive serde traits.

from rust-bitcoin.

tcharding avatar tcharding commented on June 27, 2024

Closing, this does not seem to be going anywhere. We can re-visit this at a later time if needed.

from rust-bitcoin.

tcharding avatar tcharding commented on June 27, 2024

Note at this stage we do have serde traits implemented and the bug that started this conversation is fixed by: #2582

from rust-bitcoin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.