Class: Katapaty::TxDecode

Inherits:
Object
  • Object
show all
Defined in:
lib/katapaty/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.



22
23
24
25
26
27
28
# File 'lib/katapaty/tx_decode.rb', line 22

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.



20
21
22
# File 'lib/katapaty/tx_decode.rb', line 20

def data
  @data
end

#decrypt_keyObject

Returns the value of attribute decrypt_key.



20
21
22
# File 'lib/katapaty/tx_decode.rb', line 20

def decrypt_key
  @decrypt_key
end

#prefixObject

Returns the value of attribute prefix.



20
21
22
# File 'lib/katapaty/tx_decode.rb', line 20

def prefix
  @prefix
end

#receiver_addrObject

Returns the value of attribute receiver_addr.



20
21
22
# File 'lib/katapaty/tx_decode.rb', line 20

def receiver_addr
  @receiver_addr
end

#sender_addrObject

Returns the value of attribute sender_addr.



20
21
22
# File 'lib/katapaty/tx_decode.rb', line 20

def sender_addr
  @sender_addr
end

Instance Method Details

#decrypt(chunk) ⇒ Object



30
31
32
# File 'lib/katapaty/tx_decode.rb', line 30

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