forked from poseidon-j/peatio-dogecoin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wallet.rb
57 lines (44 loc) · 1.63 KB
/
wallet.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module Dogecoin
class Wallet < Peatio::Wallet::Abstract
def initialize(settings = {})
@settings = settings
end
def configure(settings = {})
# Clean client state during configure.
@client = nil
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
@wallet = @settings.fetch(:wallet) do
raise Peatio::Wallet::MissingSettingError, :wallet
end.slice(:uri, :address)
@currency = @settings.fetch(:currency) do
raise Peatio::Wallet::MissingSettingError, :currency
end.slice(:id, :base_factor, :options)
end
def create_address!(_options = {})
{ address: client.json_rpc(:getnewaddress) }
rescue Dogecoin::Client::Error => e
raise Peatio::Wallet::ClientError, e
end
def create_transaction!(transaction, options = {})
txid = client.json_rpc_for_withdrawal(:sendtoaddress,
transaction.to_address,
transaction.amount,
# options # subtract fee from transaction amount.
)
transaction.hash = txid
transaction
rescue Dogecoin::Client::Error => e
raise Peatio::Wallet::ClientError, e
end
def load_balance!
client.json_rpc(:getbalance).to_d
rescue Dogecoin::Client::Error => e
raise Peatio::Wallet::ClientError, e
end
private
def client
uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
@client ||= Client.new(uri)
end
end
end