Class: CoinSync::Importers::LiskVoting
- Inherits:
-
Base
- Object
- Base
- CoinSync::Importers::LiskVoting
show all
- Defined in:
- lib/coinsync/importers/lisk_voting.rb
Defined Under Namespace
Classes: HistoryEntry
Constant Summary
collapse
- BASE_URL =
"https://explorer.lisk.io/api"
- EPOCH_TIME =
Time.parse('2016-05-24 17:00 UTC')
- LISK =
CryptoCurrency.new('LSK')
Instance Method Summary
collapse
Methods inherited from Base
#can_build?, register_commands, register_importer, registered_commands
Constructor Details
#initialize(config, params = {}) ⇒ LiskVoting
Returns a new instance of LiskVoting.
31
32
33
34
|
# File 'lib/coinsync/importers/lisk_voting.rb', line 31
def initialize(config, params = {})
super
@address = params['address']
end
|
Instance Method Details
#can_import?(type) ⇒ Boolean
36
37
38
|
# File 'lib/coinsync/importers/lisk_voting.rb', line 36
def can_import?(type)
@address && [:balances, :transactions].include?(type)
end
|
#import_balances ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# 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) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# 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) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# 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
|