[英]Why I can't sign a Bitcoin transaction in Ruby?
What is wrong with my code (I'm using this gem )? 我的代码有什么问题(我正在使用这个宝石 )?
require 'bitcoin'
include Bitcoin::Builder
key = Bitcoin::Key.from_base58('...')
txn = build_tx do |tx|
tx.input do |i|
i.prev_out(Bitcoin::P::Tx.from_hash(...))
i.prev_out_index(0)
i.signature_key(Bitcoin::Key.from_base58(...))
end
tx.output do |o|
o.value(50000)
o.to('1GzqkR2zNQUzHLpE7PLPjVNJ51FHC3bpDH')
end
end
I'm getting: 我越来越:
RuntimeError: Script type must be hash160, pubkey, p2wpkh or multisig
/Users/yegor/.rvm/gems/ruby-2.6.0/gems/bitcoin-ruby-0.0.19/lib/bitcoin/builder.rb:239:in `sig_hash_and_all_keys_exist?'
/Users/yegor/.rvm/gems/ruby-2.6.0/gems/bitcoin-ruby-0.0.19/lib/bitcoin/builder.rb:308:in `sign_input'
/Users/yegor/.rvm/gems/ruby-2.6.0/gems/bitcoin-ruby-0.0.19/lib/bitcoin/builder.rb:208:in `block in tx'
/Users/yegor/.rvm/gems/ruby-2.6.0/gems/bitcoin-ruby-0.0.19/lib/bitcoin/builder.rb:207:in `each'
/Users/yegor/.rvm/gems/ruby-2.6.0/gems/bitcoin-ruby-0.0.19/lib/bitcoin/builder.rb:207:in `each_with_index'
/Users/yegor/.rvm/gems/ruby-2.6.0/gems/bitcoin-ruby-0.0.19/lib/bitcoin/builder.rb:207:in `tx'
/Users/yegor/.rvm/gems/ruby-2.6.0/gems/bitcoin-ruby-0.0.19/lib/bitcoin/builder.rb:21:in `build_tx'
What am I doing wrong? 我究竟做错了什么? BTW, no matter what private key I provide to the
signature_key
I get the same error. 顺便说一句,无论我为
signature_key
提供什么私钥,我都会得到同样的错误。 If I remove the line with singature_key
, I get no error. 如果我用
singature_key
删除该行,我没有错误。
I submitted a ticket to their repo too: https://github.com/lian/bitcoin-ruby/issues/287 我也向他们的回购提交了一张票: https : //github.com/lian/bitcoin-ruby/issues/287
The problem was with the format of the script. 问题在于脚本的格式。 This code works:
此代码有效:
utxo = # coming from https://www.blockchain.info/api/unspent
builder.input do |i|
i.prev_out(utxo['tx_hash_big_endian'])
i.prev_out_index(utxo['tx_output_n'])
i.prev_out_script = [utxo['script']].pack('H*')
i.signature_key(key)
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.