GithubHelp home page GithubHelp logo

Comments (4)

apoelstra avatar apoelstra commented on July 20, 2024

Agree with the prioritization and high-level observations. Can you say more about:

  • What AsRawTransaction would do? (Maybe this is not the issue for it.)
  • What features we'd want from Hash trait ideally. Somewhere I recall we came to a rough consensus that our 1.0 MSRV would be 1.6x or thereabouts.

from rust-bitcoin.

Kixunil avatar Kixunil commented on July 20, 2024

What AsRawTransaction would do?

Effectively a copy of AsTransaction from #2347 with only modification being use of raw types (integers, byte slices) to resolve the dependency loop. It'd be considered an implementation detail and only stay there as long as other crates are unstable. Once stable, the implementation would change and the trait would get removed.

Basically what we want:

// in internals
pub struct TransactionEncoder<'a, T>(TransactionEncoderState<'a, T>);

impl<'a, T: AsRawTransaction> TransactionEncoder<'a, T> {
    pub fn new(transaction: &'a T) -> Self { /* ... */ }
}

impl<'a, T: AsRawTransaction> Encoder for TransactionEncoder<'a, T> { /* ... */ }

// in primitives:

pub fn txid(&self) -> Txid {
    struct Wrapper<'a>(&'a Transaction);
    impl<'a> AsRawTransaction for Wrapper<'a> { /* ...*/ }
    let mut encoder = TransactionEncoder::new(&Wrapper(self));
    let mut engine = sha256::engine();
    while !encoder.encoded_chunk().is_empty() {
        engine.input(encoder.encoded_chunk());
        if !encoder.next() { break }
    }
    Txid(engine.finalize())
}
  • What features we'd want from Hash trait ideally. Somewhere I recall we came to a rough consensus that our 1.0 MSRV would be 1.6x or thereabouts.

Allow writing fn to_byte_array(self) -> [u8; Self::LEN], though IIRC it may require the feature that is not even in stable and is somewhat broken in nightly too. (I might be confusing this with something else.) But from what I can observe so far: both GAT and weak dependencies will be a must when fully stable, so 1.65 IIRC. But the leaf crates don't need this. Actually that's what I wanted to mention above and forgot.

from rust-bitcoin.

apoelstra avatar apoelstra commented on July 20, 2024

I think we should try the to_byte_array thing. It doesn't look like it needs GATs, just regular ATs, which have been around for a long time.

The AsRawTransaction thing makes sense, thanks. Though I wonder if we want to make this a permanent part of the API (and have a corresponding Raw type for some other types, notably Block and BlockHeader). It seems like it may be useful in some obscure low-level usecases.

OTOH it would be easy to add (or expose) post-1.0 so this isn't a decision we need to make now.

from rust-bitcoin.

Kixunil avatar Kixunil commented on July 20, 2024

I don't see when it'd be useful. Script is already freely convertible, so only Witness is a bit obscure type. We could do something about that too. I was already thinking of having unsized Witness for zero-copy deserialization however it'd loose the index which is non issue when serializing but can be a problem when accessing.

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.