class CryptocoinPayable::Adapters::Ethereum

Public Class Methods

coin_symbol() click to toggle source
# File lib/cryptocoin_payable/adapters/ethereum.rb, line 11
def self.coin_symbol
  'ETH'
end
subunit_in_main() click to toggle source

Wei in Ether

# File lib/cryptocoin_payable/adapters/ethereum.rb, line 7
def self.subunit_in_main
  1_000_000_000_000_000_000
end

Public Instance Methods

create_address(id) click to toggle source
# File lib/cryptocoin_payable/adapters/ethereum.rb, line 27
def create_address(id)
  Eth::Utils.public_key_to_address(super.public_key.uncompressed.to_hex)
end
fetch_transactions(address) click to toggle source
# File lib/cryptocoin_payable/adapters/ethereum.rb, line 15
def fetch_transactions(address)
  url = "https://#{subdomain}.etherscan.io/api?module=account&action=txlist&address=#{address}&tag=latest"
  url += '?apiKey=' + adapter_api_key if adapter_api_key

  response = get_request(url)
  json = JSON.parse(response.body)

  raise ApiError, json['message'] if json['status'] == '0' && json['message'] == 'NOTOK'

  json['result'].map { |tx| convert_transactions(tx, address) }
end

Private Instance Methods

convert_transactions(transaction, _address) click to toggle source

Example response: {

status: "1",
message: "OK",
result: [
  {
    blockNumber: "4790248",
    timeStamp: "1514144760",
    hash: "0x52345400e42a15ba883fb0e314d050a7e7e376a30fc59dfcd7b841007d5d710c",
    nonce: "215964",
    block_hash: "0xe6ed0d98586cae04be57e515ca7773c020b441de60a467cd2773877a8996916f",
    transactionIndex: "4",
    from: "0xd24400ae8bfebb18ca49be86258a3c749cf46853",
    to: "0x911f9d574d1ca099cae5ab606aa9207fe238579f",
    value: "10000000000000000",
    gas: "90000",
    gasPrice: "28000000000",
    isError: "0",
    txreceipt_status: "1",
    input: "0x",
    contractAddress: "",
    cumulativeGasUsed: "156270",
    gasUsed: "21000",
    confirmations: "154"
  }
]

}

# File lib/cryptocoin_payable/adapters/ethereum.rb, line 64
def convert_transactions(transaction, _address)
  {
    transaction_hash: transaction['hash'],
    block_hash: transaction['block_hash'],
    block_time: nil, # Not supported
    estimated_time: parse_timestamp(transaction['timeStamp']),
    estimated_value: transaction['value'].to_i, # Units here are 'Wei'
    confirmations: transaction['confirmations'].to_i
  }
end
subdomain() click to toggle source
# File lib/cryptocoin_payable/adapters/ethereum.rb, line 33
def subdomain
  @subdomain ||= CryptocoinPayable.configuration.testnet ? 'rinkeby' : 'api'
end