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

Implement segwit transaction serialization #25

Merged
merged 1 commit into from
Jan 2, 2018

Conversation

mgpnd
Copy link
Contributor

@mgpnd mgpnd commented Dec 16, 2017

Usage example for spending from 2-of-2 multisig P2SH-P2WSH address.

tx = BTC::SegwitTransaction.new
tx.outputs = outputs
tx.inputs = inputs
tx.inputs.each do |txin|
  txin.signature_script = input_redeem_script.data
  txin.witness =  ["".b, signature1, signature2, input_witness_script.data]
end

@oleganza
Copy link
Owner

oleganza commented Dec 17, 2017

Awesome, thank you.

A few comments:

  1. You can use BTC.hash256() instead of BTC.sha256(BTC.sha256()).
  2. New signature_hash function uses dup on the transaction. But current version of dup does not duplicate witness field. This is not a bug for sighash, but should be addressed as soon as a subclass is introduced. (That is, lets not forget the new field txin.witness.)
  3. I'd recommend not creating a subclass at all. I'd rather extend BTC::Transaction with segwit serialization and sighash options, in the same way BTC::TransactionInput simply adds witness.

I would be glad to help with refactoring this. Maybe lets merge this on a segwit branch in this repo first and then refactor there?

@oleganza oleganza changed the base branch from master to segwit January 2, 2018 23:51
@oleganza oleganza merged commit fa655da into oleganza:segwit Jan 2, 2018
@oleganza
Copy link
Owner

oleganza commented Jan 2, 2018

Merged to a segwit branch to do some design changes before moving to master.

@oleganza oleganza mentioned this pull request Jan 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants