-
Notifications
You must be signed in to change notification settings - Fork 15
/
proxycoin_rpc.rb
59 lines (52 loc) · 1.8 KB
/
proxycoin_rpc.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
57
58
59
class ProxycoinRPC
def initialize(btcrpc, coinid)
@btcrpc = btcrpc
@coinid = coinid
@redis = Redis.new
end
def getbalance(accountid = nil, confirms = nil)
#@btcrpc.getgenerate # check online
return @btcrpc.getbalance unless accountid
return @btcrpc.getbalance(accountid, confirms) if accountid == '*'
p [:proxy_getbalance, accountid, confirms]
balancename = "proxycoind:balance:#{@coinid}:#{accountid}"
balance = @redis.get(balancename) || 0
# TODO check confirms
p balance.to_f
balance.to_f
end
def getaddressesbyaccount(accountid)
p [:proxy_getaddressesbyaccount, accountid]
@btcrpc.getaddressesbyaccount(accountid)
end
def getnewaddress(accountid)
p [:proxy_getnewaddress, accountid]
@btcrpc.getnewaddress(accountid)
end
def validateaddress(addr)
p [:proxy_validateaddress, addr]
@btcrpc.validateaddress(addr)
end
def move(accountid, moveto, amount, confirms = 6)
#@btcrpc.getgenerate # check online
p [:proxy_move, accountid, moveto, amount, confirms]
balancename = "proxycoind:balance:#{@coinid}:#{accountid}"
@redis.setnx(balancename, 0.0)
@redis.incrbyfloat(balancename, -amount)
balancename = "proxycoind:balance:#{@coinid}:#{moveto}"
@redis.setnx(balancename, 0.0)
@redis.incrbyfloat(balancename, amount)
@btcrpc.move(accountid, moveto, amount, confirms) # TODO
end
def sendfrom(accountid, payoutto, amount, confirms = 6)
#@btcrpc.getgenerate # check online
p [:proxy_sendfrom, accountid, payoutto, amount]
balancename = "proxycoind:balance:#{@coinid}:#{accountid}"
@redis.setnx(balancename, 0.0)
@redis.incrbyfloat(balancename, -amount)
@btcrpc.sendfrom(accountid, payoutto, amount, confirms) # TODO
end
def listtransactions(accountid)
@btcrpc.listtransactions(accountid) # TODO
end
end