class CoinSync::Importers::LiskVoting
Constants
- BASE_URL
- EPOCH_TIME
- LISK
Public Class Methods
new(config, params = {})
click to toggle source
Calls superclass method
CoinSync::Importers::Base::new
# File lib/coinsync/importers/lisk_voting.rb, line 31 def initialize(config, params = {}) super @address = params['address'] end
Public Instance Methods
can_import?(type)
click to toggle source
# File lib/coinsync/importers/lisk_voting.rb, line 36 def can_import?(type) @address && [:balances, :transactions].include?(type) end
import_balances()
click to toggle source
# File lib/coinsync/importers/lisk_voting.rb, line 61 def import_balances response = make_request('/getAccount', address: @address) case response when Net::HTTPSuccess json = JSON.parse(response.body) if json['success'] != true || !json['balance'] raise "Lisk importer: Invalid response: #{response.body}" end [Balance.new(LISK, available: BigDecimal.new(json['balance']) / 100_000_000)] when Net::HTTPBadRequest raise "Lisk importer: Bad request: #{response}" else raise "Lisk importer: Bad response: #{response}" end end
import_transactions(filename)
click to toggle source
# File lib/coinsync/importers/lisk_voting.rb, line 40 def import_transactions(filename) response = make_request('/getTransactionsByAddress', address: @address, limit: 1000) case response when Net::HTTPSuccess json = JSON.parse(response.body) if json['success'] != true || !json['transactions'] raise "Lisk importer: Invalid response: #{response.body}" end rewards = json['transactions'].select { |tx| tx['senderDelegate'] } File.write(filename, JSON.pretty_generate(rewards) + "\n") when Net::HTTPBadRequest raise "Lisk importer: Bad request: #{response}" else raise "Lisk importer: Bad response: #{response}" end end
read_transaction_list(source)
click to toggle source
# File lib/coinsync/importers/lisk_voting.rb, line 80 def read_transaction_list(source) json = JSON.parse(source.read) transactions = [] json.each do |hash| entry = HistoryEntry.new(hash) transactions << Transaction.new( exchange: 'Lisk voting', time: entry.timestamp, bought_amount: entry.amount, bought_currency: LISK, sold_amount: BigDecimal.new(0), sold_currency: FiatCurrency.new(nil) ) end transactions.reverse end
Private Instance Methods
make_request(path, params = {})
click to toggle source
# File lib/coinsync/importers/lisk_voting.rb, line 102 def make_request(path, params = {}) url = URI(BASE_URL + path) url.query = URI.encode_www_form(params) Request.get(url) end