Commit d9971b74475fe5ee2e07189f8dc345c0b3d0d2b9

Authored by Marius Hanne
Committed by Julian Langschaedel
1 parent f3b4147130

make sure script data elements are strings

fixes error with testnet tx 1ff8d1e58922816f28e62b2db2666c933e6f31c83c8a44fe066d2ecd1aa08bf6 which has a script of "OP_RETURN OP_CHECKSIG"

Showing 2 changed files with 7 additions and 4 deletions Side-by-side Diff

lib/bitcoin/script.rb
... ... @@ -486,7 +486,7 @@
486 486 # is this a pubkey script
487 487 def is_pubkey?
488 488 return false if @chunks.size != 2
489   - (@chunks[1] == OP_CHECKSIG) && @chunks[0].size > 1
  489 + (@chunks[1] == OP_CHECKSIG) && @chunks[0].is_a?(String) && @chunks[0].size > 1
490 490 end
491 491 alias :is_send_to_ip? :is_pubkey?
492 492  
... ... @@ -506,7 +506,7 @@
506 506  
507 507 # is this an op_return script
508 508 def is_op_return?
509   - @chunks[0] == OP_RETURN && @chunks.size <= 2
  509 + @chunks[0] == OP_RETURN && (!@chunks[1] || @chunks[1].is_a?(String)) &&@chunks.size <= 2
510 510 end
511 511  
512 512 # get type of this tx
spec/bitcoin/script/script_spec.rb
... ... @@ -205,6 +205,8 @@
205 205 Script.new(SCRIPT[6]).get_op_return_data.should == "deadbeef"
206 206 Script.new(SCRIPT[1]).get_op_return_data.should == nil
207 207 Script.from_string("OP_RETURN").get_op_return_data.should == nil
  208 + Script.from_string("OP_RETURN dead beef").get_op_return_data.should == nil
  209 + Script.from_string("OP_RETURN OP_CHECKSIG").get_op_return_data.should == nil
208 210 end
209 211  
210 212 end
... ... @@ -270,8 +272,8 @@
270 272 Script.new(SCRIPT[4]).is_op_return?.should == false
271 273 Script.new(SCRIPT[5]).is_op_return?.should == false
272 274 Script.new(SCRIPT[6]).is_op_return?.should == true
273   - script = Script.from_string("OP_RETURN dead beef")
274   - script.is_op_return?.should == false
  275 + Script.from_string("OP_RETURN dead beef").is_op_return?.should == false
  276 + Script.from_string("OP_RETURN OP_CHECKSIG").is_op_return?.should == false
275 277 end
276 278  
277 279 it "#type" do
... ... @@ -282,6 +284,7 @@
282 284 Script.new(SCRIPT[4]).type.should == :multisig
283 285 Script.new(SCRIPT[5]).type.should == :p2sh
284 286 Script.new(SCRIPT[6]).type.should == :op_return
  287 + Script.from_string("OP_RETURN OP_CHECKSIG").type.should == :unknown
285 288 end
286 289  
287 290 end