Skip to content

Instantly share code, notes, and snippets.

@ysv
Last active April 29, 2020 10:00
Show Gist options
  • Select an option

  • Save ysv/48520526424fb1935a22a3693396e21d to your computer and use it in GitHub Desktop.

Select an option

Save ysv/48520526424fb1935a22a3693396e21d to your computer and use it in GitHub Desktop.
module Ethereum
class Blockchain < Peatio::Blockchain::Abstract
def build_erc20_transactions(txn_receipt)
# Build invalid transaction for failed withdrawals
if transaction_status(txn_receipt) == 'fail' && txn_receipt.fetch('logs').blank?
return build_invalid_erc20_transaction(txn_receipt)
end
txn_receipt.fetch('logs').each_with_object([]) do |log, formatted_txs|
next if log.fetch('topics').blank? || log.fetch('topics')[0] != TOKEN_EVENT_IDENTIFIER
# Skip if ERC20 contract address doesn't match.
currencies = @erc20.select { |c| c.dig(:options, :erc20_contract_address) == log.fetch('address') }
next if currencies.blank?
destination_address = normalize_address('0x' + log.fetch('topics').last[-40..-1])
currencies.each do |currency|
will_raise = begin
log["logIndex"].to_i(16)
false
rescue ArgumentError
true
end
if will_raise
pp "================================================================"
pp log
pp "================================================================"
end
formatted_txs << { hash: normalize_txid(txn_receipt.fetch('transactionHash')),
amount: convert_from_base_unit(log.fetch('data').hex, currency),
to_address: destination_address,
txout: log['logIndex'].to_i(16),
block_number: txn_receipt.fetch('blockNumber').to_i(16),
currency_id: currency.fetch(:id),
status: transaction_status(txn_receipt) }
end
end
end
end
end
bc = Blockchain.find_by(key: "eth-mainnet")
Workers::Daemons::Blockchain.new.process(bc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment