lian / bitcoin-ruby

bitcoin utils and protocol in ruby.
Other
922 stars 322 forks source link

cant sign raw transaction with Bitcoin::ExtKey #235

Closed SFzxc closed 6 years ago

SFzxc commented 6 years ago

i tried to sig a raw transaction as below code

require 'bitcoin'
require 'open-uri'

Bitcoin.network = :testnet3

include Bitcoin::Builder

key = Bitcoin::ExtKey.from_base58('xprvA3obhRGRcLrQ5Ed3rgv2g1t9imv74Fe7bigt45fQd1AuEfA5KuqHuApfw14gnZSrmu9a7Qm9uJoFKi7Etv5w6CnAkgBNBVp6QVFQip9G8ui')
prev_tx = Bitcoin::P::Tx.new('0100000001ff44091d6bf7006d31f94295db566d14219bc67b19847feca4e30391de70dfbd010000006a4730440220250fbcef786a3efc76bdeb92cb4d83c27dc483437dc7b7ff64e0fb832bca245902204fcb6b6e3de225b1bf8aed4935ad93ea662d3da3b543c7bfdb0d6ceb75936082012102e2399effc745f767ba5e9abb10178b62b2efcb89298e37caf9e60a85ab034b30ffffffff0240420f00000000001976a914e122c87b1a057e1a138b1c5911fdc2a679fd66f888acc0c37303000000001976a91450a336b13b17aa77b61b7691320331b750df6a2b88ac00000000'.htb)
prev_out_index = 0

new_tx = build_tx do |t|
  t.input do |i|
    i.prev_out prev_tx
    i.prev_out_index prev_out_index
    i.signature_key key
  end

  t.output do |o|
    o.value 04000000
    o.script {|s| s.recipient "moSppkA1cSjqHkrpRtuwuxQQft8fUjAchp" }
  end
end

puts new_tx.to_json

but i got error

bitcoin/builder.rb:426:insign': undefined method sign' for #<Bitcoin::ExtKey:0x007ff6c29fc138> (NoMethodError)