Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction with several utxos #18

Closed
caqs opened this issue Feb 7, 2018 · 4 comments
Closed

Transaction with several utxos #18

caqs opened this issue Feb 7, 2018 · 4 comments
Assignees

Comments

@caqs
Copy link

caqs commented Feb 7, 2018

Hi everyone!

I'm trying to make a Transaction from an address that has several utxos. If I build an array of Inputs, and then make the Transaction it fails:

############# Balance=1BTC / utxo1[value]=0.5BTC / utxo2[value]=0.5BTC #############
inp1 = Input(prev_hash='xxxxx',output_index=0,keys=pubkey.public(), network='testnet') #from utxo1
inp2 = Input(prev_hash='yyyy',output_index=0,keys=pubkey.public(), network='testnet') #from utxo2
out = Output(100000000, address=addr_to, network='testnet')

t = Transaction(inputs=[inp1,inp2],outputs=[out], network='testnet')
t.sign(private)
t.verify() # False

But if I try to make a Transaction only using the information from one utxo, it's completed ok:

############# Balance=1BTC / utxo1[value]=0.5BTC / utxo2[value]=0.5BTC #############
inp1 = Input(prev_hash='xxxxx',output_index=0,keys=pubkey.public(), network='testnet') #from utxo1
out = Output(50000000, address=addr_to, network='testnet')

t = Transaction(inputs=[inp1],outputs=[out], network='testnet')
t.sign(private)
t.verify() # True

Is there any way to build a Transaction from several utxo's?

@mccwdev mccwdev self-assigned this Feb 9, 2018
@mccwdev mccwdev added the bug label Feb 9, 2018
@mccwdev
Copy link
Member

mccwdev commented Feb 9, 2018

Yes there seems to be a problem in the verify method, will take a look into it.

@mccwdev
Copy link
Member

mccwdev commented Feb 9, 2018

It's the sign method, it doesn't sign the second input because it uses the same key.
You can sign it like this to workaround this issue:
t.sign(private, tid=0)
t.sign(private, tid=1)

@mccwdev mccwdev added enhancement and removed bug labels Feb 9, 2018
@mccwdev
Copy link
Member

mccwdev commented Feb 10, 2018

Your code should work as expected after this branch is merged:
https://github.com/1200wd/bitcoinlib/tree/fix-duplicate-key-inputs

@caqs
Copy link
Author

caqs commented Feb 12, 2018

Thanks a lot! I'm trying this way before going to another branch.

Regards!

@caqs caqs closed this as completed Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants