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

Add to_custom_script method #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/bitcoin/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,15 @@ def self.to_op_return_script(data = nil)
return buf + pack_pushdata( [data].pack("H*") )
end

# Sometimes you might want to include a script with a custom stack
def self.to_custom_script(data = nil)
if data
[data].pack("H*")
else
[OP_NOP].pack("C")
end
end

# generate input script sig spending a pubkey output with given +signature+ and +pubkey+.
# returns a raw binary script sig of the form:
# <signature> [<pubkey>]
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/bitcoin/script/script_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@ def build_p2sh_multisig_tx(num_to_unlock, *keys)
expect(Bitcoin::Script.to_p2sh_script(hash160))
.to eq(Bitcoin::Script.from_string("OP_HASH160 #{hash160} OP_EQUAL").raw)
end

it 'should generate a custom script' do
script = '6a0400004b5014000000004269747072696d0000000000000f4240'
expect(Bitcoin::Script.to_custom_script(script))
.to eq('6a0400004b5014000000004269747072696d0000000000000f4240'.htb)
end
end

describe 'generate script sigs' do
Expand Down