Class: Coloredcoins::Multisig
- Inherits:
-
Object
- Object
- Coloredcoins::Multisig
- Defined in:
- lib/coloredcoins/multisig.rb
Instance Attribute Summary collapse
-
#m ⇒ Object
readonly
Returns the value of attribute m.
-
#pub_keys ⇒ Object
readonly
Returns the value of attribute pub_keys.
-
#redeem_script ⇒ Object
Returns the value of attribute redeem_script.
Instance Method Summary collapse
- #address ⇒ Object
-
#initialize(m = nil, pub_keys = nil) ⇒ Multisig
constructor
A new instance of Multisig.
- #sign(tx, key) ⇒ Object
- #valid_sig?(i, script) ⇒ Boolean
Constructor Details
#initialize(m = nil, pub_keys = nil) ⇒ Multisig
Returns a new instance of Multisig.
6 7 8 9 |
# File 'lib/coloredcoins/multisig.rb', line 6 def initialize(m = nil, pub_keys = nil) @m = m @pub_keys = pub_keys end |
Instance Attribute Details
#m ⇒ Object (readonly)
Returns the value of attribute m.
3 4 5 |
# File 'lib/coloredcoins/multisig.rb', line 3 def m @m end |
#pub_keys ⇒ Object (readonly)
Returns the value of attribute pub_keys.
3 4 5 |
# File 'lib/coloredcoins/multisig.rb', line 3 def pub_keys @pub_keys end |
#redeem_script ⇒ Object
Returns the value of attribute redeem_script.
4 5 6 |
# File 'lib/coloredcoins/multisig.rb', line 4 def redeem_script @redeem_script end |
Instance Method Details
#address ⇒ Object
26 27 28 |
# File 'lib/coloredcoins/multisig.rb', line 26 def address @address ||= Bitcoin.hash160_to_p2sh_address(Bitcoin.hash160(redeem_script.hth)) end |
#sign(tx, key) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/coloredcoins/multisig.rb', line 11 def sign(tx, key) key = Coloredcoins::Transaction.build_key(key) tx.inputs.each_with_index do |input, i| sig_hash = tx.signature_hash_for_input(i, redeem_script) sigs = Coloredcoins::Transaction.build_sigs(key, sig_hash) initial = input.script_sig.or(initial_script) input.script_sig = build_script_sig(sigs, sig_hash, initial) end end |
#valid_sig?(i, script) ⇒ Boolean
22 23 24 |
# File 'lib/coloredcoins/multisig.rb', line 22 def valid_sig?(i, script) tx.verify_input_signature(i, script) end |