Giter VIP home page Giter VIP logo

Comments (3)

SimoneBronzini avatar SimoneBronzini commented on June 3, 2024

Imagine you have 3 transactions in the variables tx1, tx2 and tx3. You want to spend output 0 of tx1, output 1 of tx2, output 2 of tx3. You'll go like this:

# create the transaction
unsigned = MutableTransction(version=1,
                             ins=[TxIn(txid=tx1.txid,
                                       txout=0,
                                       script_sig=ScriptSig.empty(),
                                       sequence=Sequence.max()),
                                  TxIn(txid=tx2.txid,
                                       txout=1,
                                       script_sig=ScriptSig.empty(),
                                       sequence=Sequence.max()),
                                  TxIn(txid=tx3.txid,
                                       txout=2,
                                       script_sig=ScriptSig.empty(),
                                       sequence=Sequence.max())],
                              outs=[TxOut(value=100000,
                                          n=0,
                                          script_pubkey=P2pkhScript(pubk))],
                              locktime=Locktime(0))

# create a solver for each input
solver1, solver2, solver3 = ..., ..., ...

# sign the transaction providing the txouts you want to spend and the solver in the respective order
signed = unsigned.spend([tx1.outs[0], tx2.outs[1], tx3.outs[2]], [solver1, solver2, solver3])

from btcpy.

peerchemist avatar peerchemist commented on June 3, 2024

OK I get it now. It's quite complicated workflow overall though.

from btcpy.

SimoneBronzini avatar SimoneBronzini commented on June 3, 2024

A way to slightly improve it would be having the spend method take as input a list of couples instead of two lists (this fix has already been in my personal TODO list for a long time). If you have any other suggestion on how to simplify this workflow it would be more than welcome!

from btcpy.

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.