Code Monkey home page Code Monkey logo

Comments (8)

mhanne avatar mhanne commented on September 26, 2024

Hah, I just pushed a change that allows you to do this: mhanne@5366a03

Now you can give it just the prev_out_hash, index and pk_script to create an input:
i.prev_out(prev_out.get_tx.hash, prev_out.tx_idx, prev_out.pk_script)

from bitcoin-ruby.

sidazhang avatar sidazhang commented on September 26, 2024

@mhanne thanks, just to be clear, do they take plain hex string arugments? (or do they require objects / binary strings?)

For example, would the following work?

# https://blockchain.info/tx/108cb6bc3c8607a707dde49fceb10ad7bbe037260a6fd9e1b0e2f30e73180481/0
i.prev_out("108cb6bc3c8607a707dde49fceb10ad7bbe037260a6fd9e1b0e2f30e73180481", 0, "76a914419fb60d29b320764ed2ae6e77a16648a4e1853c88ac")

from bitcoin-ruby.

mhanne avatar mhanne commented on September 26, 2024

Ugh.. I see how this can be confusing, actually the hash is hex-encoded, but the pk_script is expected as a raw binary string... It's not consistent in itself, but it's the format that usually comes out of the other helpers so I figured it was the most intuitive. Should add more documentation about it though.

from bitcoin-ruby.

sidazhang avatar sidazhang commented on September 26, 2024

Yeah it would be nice to have a bit more consistency but I think for now this should be fine:

It does seem a little bit jenky haha

i.prev_out("108cb6bc3c8607a707dde49fceb10ad7bbe037260a6fd9e1b0e2f30e73180481", 0, ["76a914419fb60d29b320764ed2ae6e77a16648a4e1853c88ac"].pack("H*"))

Thank you very much for this commit. Do you have plans to add documentations for this?

I can also do it if you don't plan to add change the interface which is i.prev_out(hex_string, integer, binary_string)

As for what is intuitive, I feel that a lot of developers might not run a full node with bitcoin-ruby. I personally use an API (which outputs hex strings) and use bitcoin ruby to handle the protocol. So binary string is a bit harder to work with.

from bitcoin-ruby.

mhanne avatar mhanne commented on September 26, 2024

Hmm, to be honest, I still think it makes more sense this way... It's awkward in your case, because you are getting the tx from blockchain.info. But if you get it from bitcoin-ruby, these are the formats you have at hand for the tx hash / pk script and they are used like this everywhere else.

The deeper reason for the difference is that the pk_script is deserialized from the binary tx payload received from the network, but the tx hash is computed from that data. Transforming the pk_script into hex every time (and back at some point) would be a huge performance hit. And always having to convert the hash would be a huge inconvenience, since everyone only uses the hex form for it (since it's not actually included in the blockchain and therefore not that space-critical).

I think I will change the interface to also make it accept a single TxOut object. But I don't know when I'll get to it, and since these particular parameters won't change and still be awkward from your perspective, it would be great if you could add some comments about it :)

from bitcoin-ruby.

sidazhang avatar sidazhang commented on September 26, 2024

Thanks for the explaination, in this case I think this makes sense. Let's keep the interface this way then.

I am happy to add some documentation for i.prev_out(hex_string, integer, binary_string) and will make a pull request in a separate issue

from bitcoin-ruby.

sidazhang avatar sidazhang commented on September 26, 2024

@mhanne do you have plans to deploy this latest to rubygems anytime soon?

from bitcoin-ruby.

mhanne avatar mhanne commented on September 26, 2024

The gem is mostly a fallback, the suggested way to use bitcoin-ruby is to enter the git repo in your Gemfile or clone/build it yourself. The lian/master branch should always be stable, and I try to keep mine that way too (albeit with less success). Usually @lian only updates the gem when there are important bugfixes (which there are now... ;)

from bitcoin-ruby.

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.