Class: Counterparty::TxDecode

Inherits:
Object
  • Object
show all
Defined in:
lib/counterparty/tx_decode.rb

Defined Under Namespace

Classes: InvalidOpReturn, InvalidOutput, MultisigUnsupported, UndefinedBehavior

Constant Summary collapse

DEFAULT_PREFIX =
'CNTRPRTY'
OP_RETURN_PARTS =
/^OP_RETURN ([a-z0-9]+)$/
P2PKH_PARTS =
/^OP_DUP OP_HASH160 ([a-z0-9]+) OP_EQUALVERIFY OP_CHECKSIG$/
OP_MULTISIG_PARTS =
/^[12] ([a-z0-9 ]+) ([23]) OP_CHECKMULTISIG$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tx, options = {}) ⇒ TxDecode

Returns a new instance of TxDecode.



20
21
22
23
24
25
26
# File 'lib/counterparty/tx_decode.rb', line 20

def initialize(tx, options = {})
  @prefix = options[:prefix] || DEFAULT_PREFIX
  @decrypt_key = options[:decrypt_key] || [tx.inputs[0].prev_out.reverse_hth].pack('H*')
  
  parse! (tx.respond_to? :outputs) ? 
    tx.outputs.collect{|out| out.parsed_script.to_string } : tx
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



18
19
20
# File 'lib/counterparty/tx_decode.rb', line 18

def data
  @data
end

#decrypt_keyObject

Returns the value of attribute decrypt_key.



18
19
20
# File 'lib/counterparty/tx_decode.rb', line 18

def decrypt_key
  @decrypt_key
end

#prefixObject

Returns the value of attribute prefix.



18
19
20
# File 'lib/counterparty/tx_decode.rb', line 18

def prefix
  @prefix
end

#receiver_addrObject

Returns the value of attribute receiver_addr.



18
19
20
# File 'lib/counterparty/tx_decode.rb', line 18

def receiver_addr
  @receiver_addr
end

#sender_addrObject

Returns the value of attribute sender_addr.



18
19
20
# File 'lib/counterparty/tx_decode.rb', line 18

def sender_addr
  @sender_addr
end

Instance Method Details

#decrypt(chunk) ⇒ Object



28
29
30
# File 'lib/counterparty/tx_decode.rb', line 28

def decrypt(chunk)
  RC4.new(decrypt_key).decrypt chunk
end