rippler 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +26 -4
- data/lib/rippler.rb +68 -20
- data/lib/rippler/account.rb +17 -0
- data/lib/rippler/contacts.rb +90 -4
- data/lib/rippler/ledger.rb +11 -0
- data/lib/rippler/money.rb +45 -0
- data/lib/rippler/transaction.rb +21 -27
- data/lib/rippler/utils.rb +19 -0
- data/lib/rippler/version.rb +1 -1
- metadata +6 -2
data/README.md
CHANGED
|
@@ -8,15 +8,37 @@ You need to have Ruby 1.9 (http://www.ruby-lang.org/en/downloads/) installed. On
|
|
|
8
8
|
|
|
9
9
|
$ gem install rippler
|
|
10
10
|
|
|
11
|
+
Alternatively, you can install from source at Github:
|
|
12
|
+
|
|
13
|
+
$ git clone https://github.com/arvicco/rippler.git
|
|
14
|
+
$ cd rippler
|
|
15
|
+
$ bundle install
|
|
16
|
+
|
|
11
17
|
## Usage
|
|
12
18
|
|
|
13
|
-
Rippler supports Ripple API commands (https://ripple.com/wiki/RPC_API). All parameters after command should be given in JSON format, such as:
|
|
19
|
+
Rippler supports Ripple API commands (https://ripple.com/wiki/RPC_API). All parameters after command should be given in commandline JSON format, such as:
|
|
20
|
+
|
|
21
|
+
$ rippler account_info account:rwLYfeQHfucz8wD6tFPY9Ms6ovmMBCCpMd
|
|
22
|
+
|
|
23
|
+
$ rippler account_tx account:rwLYfeQHfucz8wD6tFPY9Ms6ovmMBCCpMd ledger:319841
|
|
24
|
+
|
|
25
|
+
$ rippler account_tx account:evoorhees ledger_min:0 ledger_max:400000
|
|
26
|
+
|
|
27
|
+
Ripple server replies are returned as JSON and printed to stdout. If you want to do some post-processing of the results, get source from Github and modify bin/rippler script.
|
|
28
|
+
|
|
29
|
+
Rippler also provides additional commands print out human-readable output:
|
|
30
|
+
|
|
31
|
+
$ rippler history account:molecular
|
|
32
|
+
|
|
33
|
+
This one prints account history in a human-readable format.
|
|
34
|
+
|
|
35
|
+
$ rippler monitor streams:[ledger,transactions]
|
|
14
36
|
|
|
15
|
-
|
|
37
|
+
This one monitors Ripple transactions in real-time similar to #ripple-watch. Ctrl-C to stop it.
|
|
16
38
|
|
|
17
|
-
|
|
39
|
+
## Contacts database
|
|
18
40
|
|
|
19
|
-
|
|
41
|
+
Contacts database is in lib/rippler/contacts.rb, mostly auto-scraped from Bitcointalk. It may be a bit inaccurate, you can modify/extend it as you see fit.
|
|
20
42
|
|
|
21
43
|
## Contributing
|
|
22
44
|
|
data/lib/rippler.rb
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
require 'eventmachine'
|
|
2
2
|
require 'faye/websocket'
|
|
3
3
|
require "json"
|
|
4
|
+
require 'ostruct'
|
|
5
|
+
|
|
4
6
|
require "rippler/version"
|
|
5
|
-
require 'rippler/transaction'
|
|
6
7
|
require 'rippler/contacts'
|
|
8
|
+
require 'rippler/utils'
|
|
9
|
+
require 'rippler/money'
|
|
10
|
+
require 'rippler/account'
|
|
11
|
+
require 'rippler/ledger'
|
|
12
|
+
require 'rippler/transaction'
|
|
7
13
|
|
|
8
14
|
module Rippler
|
|
15
|
+
extend Rippler::Utils
|
|
16
|
+
|
|
9
17
|
RIPPLE_URI = 'wss://s1.ripple.com:51233'
|
|
10
18
|
MY_ACCT = Rippler::Contacts["arvicco"]
|
|
11
19
|
|
|
@@ -14,20 +22,29 @@ module Rippler
|
|
|
14
22
|
command_line = args.empty? ? ['account_info'] : args.dup
|
|
15
23
|
|
|
16
24
|
command = command_line.shift
|
|
17
|
-
params =
|
|
25
|
+
params = command_line.map {|p| p.split(':')}.flatten. # get json pairs
|
|
26
|
+
map {|p| p =~ /\[.*\]/ ? p.gsub(/\[|\]/,'').split(',') : p} # get arrays
|
|
27
|
+
params = Hash[*params]
|
|
28
|
+
params['account'] = Account(params['account']).address if params['account']
|
|
29
|
+
|
|
18
30
|
# p command, params
|
|
19
31
|
|
|
20
|
-
if
|
|
21
|
-
|
|
32
|
+
if respond_to? command # pre-defined Rippler method
|
|
33
|
+
send command, params
|
|
22
34
|
else # Arbitrary API command
|
|
23
|
-
|
|
35
|
+
request params.merge('command' => command)
|
|
24
36
|
end
|
|
25
37
|
end
|
|
26
38
|
|
|
27
|
-
#
|
|
28
|
-
def self.request params
|
|
39
|
+
# Send a single JSON request to Ripple over Websockets, return a single Ripple reply.
|
|
40
|
+
def self.request params, &block
|
|
29
41
|
reply = ''
|
|
42
|
+
em_request false, params, &(block || lambda {|message| reply = message})
|
|
43
|
+
reply
|
|
44
|
+
end
|
|
30
45
|
|
|
46
|
+
# Send JSON request to Ripple, yields all json-parsed Ripple messages to a given block.
|
|
47
|
+
def self.em_request streaming=false, params, &block
|
|
31
48
|
EM.run {
|
|
32
49
|
ws = Faye::WebSocket::Client.new(RIPPLE_URI)
|
|
33
50
|
|
|
@@ -38,12 +55,16 @@ module Rippler
|
|
|
38
55
|
|
|
39
56
|
ws.onmessage = lambda do |event|
|
|
40
57
|
# p [:message]
|
|
41
|
-
|
|
42
|
-
|
|
58
|
+
message = JSON.parse(event.data)
|
|
59
|
+
check_error message
|
|
60
|
+
yield message
|
|
61
|
+
ws.close unless streaming
|
|
43
62
|
end
|
|
44
63
|
|
|
45
64
|
ws.onerror = lambda do |event|
|
|
46
65
|
# p [:error, event]
|
|
66
|
+
pp event["error"]
|
|
67
|
+
raise "Websocket error"
|
|
47
68
|
end
|
|
48
69
|
|
|
49
70
|
ws.onclose = lambda do |event|
|
|
@@ -52,23 +73,50 @@ module Rippler
|
|
|
52
73
|
EM.stop
|
|
53
74
|
end
|
|
54
75
|
}
|
|
55
|
-
reply
|
|
56
76
|
end
|
|
57
77
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
78
|
+
def self.check_error message
|
|
79
|
+
if message["error"]
|
|
80
|
+
pp message
|
|
81
|
+
raise "Ripple error message"
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Subscribe needs a streaming wrapper
|
|
86
|
+
def self.subscribe params, &block
|
|
87
|
+
em_request( true, {'command' => "subscribe", 'id' => 0, 'streams' => ['ledger']}.
|
|
88
|
+
merge(params), &(block || lambda {|message| pp message}))
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
### These are user-defined methods that post-process Ripple replies
|
|
92
|
+
|
|
93
|
+
# Subscibe to event streams, print events out nicely formatted
|
|
94
|
+
def self.monitor params
|
|
95
|
+
subscribe(params) do |message|
|
|
96
|
+
case message['type']
|
|
97
|
+
when "response"
|
|
98
|
+
puts "#{Ledger.new(message['result'])} starting..."
|
|
99
|
+
when "ledgerClosed"
|
|
100
|
+
ledger = Ledger.new(message)
|
|
101
|
+
puts "#{ledger} active" if ledger.txn_count > 0
|
|
102
|
+
when "transaction"
|
|
103
|
+
pp Transaction.new(message)
|
|
104
|
+
else
|
|
105
|
+
pp message
|
|
106
|
+
end
|
|
107
|
+
end
|
|
61
108
|
end
|
|
62
109
|
|
|
110
|
+
# Retrieve account transactions history, print out nicely formatted transactions
|
|
63
111
|
def self.history params
|
|
64
|
-
reply = request( {command
|
|
65
|
-
account
|
|
66
|
-
ledger_min
|
|
67
|
-
ledger_max
|
|
68
|
-
resume
|
|
69
|
-
sort_asc
|
|
112
|
+
reply = request( {'command' => "account_tx",
|
|
113
|
+
'account' => MY_ACCT,
|
|
114
|
+
'ledger_min' => 0, # 280000, # 312000,
|
|
115
|
+
'ledger_max' => 500000, #329794,
|
|
116
|
+
'resume' => 0,
|
|
117
|
+
'sort_asc' => 1
|
|
70
118
|
}.merge(params) ) #(optional)
|
|
71
119
|
txs = reply["result"]["transactions"]
|
|
72
|
-
txs.reverse.map {|t| Transaction.new(t).to_s}.push("
|
|
120
|
+
txs.reverse.map {|t| Transaction.new(t).to_s}.push("Total transactions: #{txs.size}")
|
|
73
121
|
end
|
|
74
122
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Rippler
|
|
2
|
+
class Account
|
|
3
|
+
include Rippler::Utils
|
|
4
|
+
|
|
5
|
+
attr_accessor :name, :address
|
|
6
|
+
|
|
7
|
+
# String: "evoorhees" or "rpfxDFsjDNtzSBCALKuWoWMkpRp4vxvgrG"
|
|
8
|
+
def initialize name_or_address
|
|
9
|
+
@address = Rippler::Contacts[name_or_address] || name_or_address
|
|
10
|
+
@name = Rippler::Addresses[@address]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def to_s
|
|
14
|
+
@name || @address
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/rippler/contacts.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
module Rippler
|
|
2
2
|
Contacts = Hash[ *%W[
|
|
3
3
|
OpenCoin rJR7gjNe3DpJ7kpB4CHBxjDKfwVMpTKPpj
|
|
4
|
-
|
|
4
|
+
OpenCoin-1 r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV
|
|
5
|
+
ADDRESS_ONE rrrrrrrrrrrrrrrrrrrrBZbvji
|
|
5
6
|
|
|
6
|
-
weex_btc rpvfJ4mR6QQAeogpXEKnuyGBx8mYCSnYZi
|
|
7
7
|
bitstamp rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B
|
|
8
8
|
bitstamp_hotwallet rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1
|
|
9
9
|
weex_btc rpvfJ4mR6QQAeogpXEKnuyGBx8mYCSnYZi
|
|
@@ -11,6 +11,22 @@ module Rippler
|
|
|
11
11
|
weex_cad r47RkFi1Ew3LvCNKT6ufw3ZCyj5AJiLHi9
|
|
12
12
|
weex_usd r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X
|
|
13
13
|
|
|
14
|
+
X.Veirou rhq5LEZSWHWY6H3raiC2KGe8TVeirou4BS
|
|
15
|
+
X.Reya rEyAJhMMi5WNzgdkY67vN7ivfiQnh3itXY
|
|
16
|
+
X.Founder.1 rfbKLd1VLB3o6fpkhCJexckArjoMmBm2wG
|
|
17
|
+
X.9billions rstKSeB2Qx7zrwSkyc7X9Xm5nYTJqtL3iM
|
|
18
|
+
X.77millions rB5TihdPbKgMrkFqrqUC3yLdE8hhv4BdeY
|
|
19
|
+
X.10millions rHrSTVSjMsZKeZMenkpeLgHGvY5svPkRvR
|
|
20
|
+
X.001 rKdtD8YQXCJAnXoXQfmn645FybiaFWVghs
|
|
21
|
+
X.002 ramJoEsBUHc299vFuMvn8NgLrF3Qrt3XV4
|
|
22
|
+
|
|
23
|
+
TTBit rGwUWgN5BEg3QGNY3RX2HfYowjUTZdid3E
|
|
24
|
+
BankOfZed ra88Lr8fyo9cUTuyjVFMTrvTSBU93erjyh
|
|
25
|
+
AlanFromZed rhR5j5LXsujSuwG2bcn1P39utdTA79ceaW
|
|
26
|
+
BobFromZed r4ixnhDRE5VktpgtFkw5L8v1bNGsFusQJS
|
|
27
|
+
ChrisFromZed rPA9PquwamoriknybdishCdWp6N1m2iEF8
|
|
28
|
+
SecondBankOfZed rnqQ7YEStMBBqn6qBP4AYsyGhy1RKfUeRR
|
|
29
|
+
|
|
14
30
|
molecular rpH3zuMch2GrrYX724xGWwbMGwiQ5RbSAU
|
|
15
31
|
Ente rNEtVs4kNeESF5HbWCDZMYcWwKZ5iKwUEr
|
|
16
32
|
herzmeister rUdPvX9YN1NwyniwiJeSW6y3YKZL84gsB6
|
|
@@ -46,10 +62,67 @@ module Rippler
|
|
|
46
62
|
supert rh7eAu9SrFsE2fVfc1PJTs1WYDHGAUde6V
|
|
47
63
|
Evan rfpS692WVbsSXyv6R48K8A2LHCqdvYaS2w
|
|
48
64
|
BBQKorv rrhAmxxwxEchP2iJdGh7nrwwAK4u3BzaLC
|
|
49
|
-
TTBit rGwUWgN5BEg3QGNY3RX2HfYowjUTZdid3E
|
|
50
65
|
Mjbmonetarymetals rNTXjBWitdKUxr6o1zyi4FsjQ8UeP3JCKd
|
|
51
66
|
khal rpUjkUUcbteWbXrPt4aXAMwzotSPzQJHQt
|
|
52
67
|
Trading rNPHozULzm5nKavgXxbq8tcwAcxyhZpTBw
|
|
68
|
+
Schleicher rGGxDC8VZ7zHmVKt6XK6sc7fUziNtvohWC
|
|
69
|
+
ripper234 rhQ7mQ1JJKygoxh7SoCaKNZB4GufdCRiH3
|
|
70
|
+
alexkravets rKQLJpoBagwGiE7LVcY8YfDfE6EUREJjeq
|
|
71
|
+
comboy rLHMoLsuLhg1Q741bHNjv7jhMqr6karoG7
|
|
72
|
+
djbaniel rNnLFDCRrAtuESodmwamAasMBZqCmkqQH9
|
|
73
|
+
wyodude rwJBiKfYKRFX59GykztmGdedUvmV64LpaK
|
|
74
|
+
misterbigg rwLYfeQHfucz8wD6tFPY9Ms6ovmMBCCpMd
|
|
75
|
+
endlesscustoms rN6DeCG5VvmfqjBywwoE24oXQsHzRDUfzh
|
|
76
|
+
avegetable r9MZGmnGc1qo64ZQbxijVFCdcNt741nkYE
|
|
77
|
+
runlinux rsAMwJ4BjuEwb5dkd84XW9WM5KvauxcGAU
|
|
78
|
+
nomnomnom rp3qwd4zb8Ywq8rFrxLgijvyYKMa68FbxW
|
|
79
|
+
nealmcb r3NQyByq6KfvnD1PXu3jwGzdsVGn1HEJNq
|
|
80
|
+
TTBit rGwUWgN5BEg3QGNY3RX2HfYowjUTZdid3E
|
|
81
|
+
plummonkey r3PDtZSa5LiYp1Ysn1vMuMzB59RzV3W9QH
|
|
82
|
+
magnebit rQrUJLNcjnaZJjqMjaiPHxGa7eipzyf7b
|
|
83
|
+
mpfrank rnfLDQaxN7isxzWZuc6BM8jeiCb2WSGpdG
|
|
84
|
+
Bitcoining raW4tvsndX8fkunTqpHWsT8L5BErB5KEJd
|
|
85
|
+
Pteppic rwBYyfufTzk77zUSKEu4MvixfarC35av1J
|
|
86
|
+
Lohoris rDBfeSsYGwDiXWdTARYHsxUtvzAXgARFMu
|
|
87
|
+
MatthewNWright rwTbS9jC9a1Yu57j7ZUwEY5oQTo86o6VXR
|
|
88
|
+
wormbog rLveNTH6EA3tY4BzpdvgkukJ3oTxWk2UHM
|
|
89
|
+
GoWest rszHYGgWBTCwCUQCUjCPwmx6zLinbqXZvT
|
|
90
|
+
VitalikButerin rJ2gXg1xcYW6756fBj393Dd9ZekJP45odZ
|
|
91
|
+
ElectricMucus rpJwZ8dcJLVydewhhfQEgMCQxFyMorH9rG
|
|
92
|
+
RRTaylor-Almanza rE4StrJNLHahqBjpVdz5pj2Zgqtvk1fwuu
|
|
93
|
+
hazek rsQP8f9fLtd58hwjEArJz2evtrKULnCNif
|
|
94
|
+
FlipPro rNSnpURu2o7mD9JPjaLsdUw2HEMx5xHzd
|
|
95
|
+
JoelKatz rHzWtXTBrArrGoLDixQAgcSD2dBisM19fF
|
|
96
|
+
evoorhees rpfxDFsjDNtzSBCALKuWoWMkpRp4vxvgrG
|
|
97
|
+
SunnyKing rKMSa2tRir1kcKW6qrfRBc2fRZLCzVsxxX
|
|
98
|
+
dacoinminster rKj9ngzutnjmuiSJTTkUm3NBBt83v2uc4r
|
|
99
|
+
jimbobway rEMqTpu21XNk62QjTgVXKDig5HUpNnHvij
|
|
100
|
+
nanotube rBJwwXADHqbwsp6yhrqoyt2nmFx9FB83Th
|
|
101
|
+
snapsunny rNuFYAu1aUYbATH3qCs27BjPc5dDHVgY1z
|
|
102
|
+
tbcoin rsvAk3NoSSZwCTv9epzrKtFkAkHLVwEBmw
|
|
103
|
+
Bimmerhead rJzAwqVF3fuKvxRegZMfrFSQQrXJA9Dpms
|
|
104
|
+
MonsterTent r3vaUaLbUgJdg61wuSiX4byD9ofkbPnKVa
|
|
105
|
+
rta rBxi9xHEmvSJHAxrJ21sQNprs9xuENgs1Z
|
|
106
|
+
fimp rGnSAso57ca5hBtSYuXzT5rjCEFQ1RWAec
|
|
107
|
+
intel-core-i7 rsmbvYkXWQ9LH3JHoHPg9rmYhQGi5M7ue4
|
|
108
|
+
btc24 r96WyAeNMykJKpdMi54V5WCqQEqfqhs6oA
|
|
109
|
+
jl2012 rnKhmoH1BFrh7CfDnJ21XW6arPySDXUPFZ
|
|
110
|
+
Prattler rnmB7GYEB9Xz2qBmiU8L6qdpCzd9FdvvJQ
|
|
111
|
+
commonancestor rGguLh5qc15WLntiB7zPfE2XCBdB7HZLdi
|
|
112
|
+
sneef rGQCcCAG2fFmPY7X9zDZEhCnMp5JgAeziS
|
|
113
|
+
zulzedd rJYHWjtcZaHfDTL7P8Dh5zkk1JdZsxiYef
|
|
114
|
+
Snowfire rpVbjBotUFCoi9xPu3BqYXZhTLpgZbQpoZ
|
|
115
|
+
Otoh rKWYoFVMsKjZZhCZMFSagYmasqGZFYkpYu
|
|
116
|
+
Deafboy rUAScykwHVqU2d4rb4twHbpDa7C81p4MSA
|
|
117
|
+
speeder rNzJ6ikJKXAxAaTPMZCcXr2sFkmg9a2GM9
|
|
118
|
+
nelisky rLDDq8ZGhCaVBP8MyYTifhCJzgWPQBjwpt
|
|
119
|
+
mrmx rKishCqMiQG6zhFHPjrFhXztLDjZteNmGP
|
|
120
|
+
drewdtom rsZvcvACPWoTN2Eazzb5radzQX18s3DuK8
|
|
121
|
+
MadSweeney r4pqusLQxgFNQQNByJMcTvQcYG9v1GpBum
|
|
122
|
+
Digigami rHCSeQNZZz7FWbxvLjB2RzF1CrBeUcDj7J
|
|
123
|
+
jking rMpB2AsrDTdbynCB48hg8MwHLD4wtXJfRJ
|
|
124
|
+
justusranvier rnZoz4R1o6GupernFX6bey34uj4g45scLZ
|
|
125
|
+
|
|
53
126
|
|
|
54
127
|
arvicco rnZoUopPFXRSVGdeDkgbqdft8SbXfJxKYh
|
|
55
128
|
paysafecardbitcoin rN4kvobWCZVSzgLmo27B4kMjakAL31pMSr
|
|
@@ -109,7 +182,20 @@ module Rippler
|
|
|
109
182
|
tosku rBs43YZMn5QsYY9jZYcG4C3egEebUfGWh3
|
|
110
183
|
BitcoinG r3CxMDQFX1Atq1vQN5sqVsjm3rawGSwd32
|
|
111
184
|
Gzarcov rEg8hTqY7jhSkeFirfE5Fm7BF72WaaCnrB
|
|
112
|
-
|
|
185
|
+
milly6 rQaxmmRMasgt1edq8pfJKCfbkEiSp5FqXJ
|
|
186
|
+
crazyearner rBcrMMTUKAQJd5tMEsy1zyTGRiy79gY9K3
|
|
187
|
+
elelegzet rBKnNboJeGxTwQM1agrXp28WcVWKtPPQah
|
|
188
|
+
Myrddindc rp2ewp8uH4zi35T2oWkfpETT3rQ4qBBZzt
|
|
189
|
+
Ivica ra6FCgRD4Ye4PNcTRhmiXaSzpJKo1PQEzh
|
|
190
|
+
DrG rQrnuAtfePuz2fsSDTakuDZn594fi9x7dP
|
|
191
|
+
DrG-1 rJEZjBv27ZHCPAoDtTBJb9r82VnUdkRd77
|
|
192
|
+
UnitClick rLKojeESeKi9mdBuPLkiQhCxs4wh8iKy2W
|
|
193
|
+
saddambitcoin rMSEYpzcRtkiA5kkxYEWZtvLr8u3jnn385
|
|
194
|
+
helloworld111 rwGAnUvzT5yrDz6dXxm6MWVhpV9abm39W3
|
|
195
|
+
dykast rQfwn3GVHVEfTpjqU2Y3BoMGAGHrw43XnT
|
|
196
|
+
BurbolGii rDYwnqGbUazEuMfebQwLprCQQXWbYgXTMa
|
|
197
|
+
BC12345 rNy61KXKUYPMFf5fMV6ojo3u98dc5WhiVu
|
|
198
|
+
Eegnylot rPKwrbDS6GC61QF1NuyTCohK926ns2vEG3
|
|
113
199
|
]]
|
|
114
200
|
|
|
115
201
|
Addresses = Contacts.invert
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Rippler
|
|
2
|
+
# Represents a single LedgerClose event
|
|
3
|
+
class Ledger < OpenStruct
|
|
4
|
+
include Rippler::Utils
|
|
5
|
+
|
|
6
|
+
def to_s
|
|
7
|
+
"#{Time(self.ledger_time).strftime("%Y-%m-%d %H:%M:%S")} " +
|
|
8
|
+
"Ledger ##{self.ledger_index}, txn: #{self.txn_count}"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module Rippler
|
|
2
|
+
class Money
|
|
3
|
+
include Rippler::Utils
|
|
4
|
+
|
|
5
|
+
attr_accessor :value, :currency, :issuer
|
|
6
|
+
|
|
7
|
+
# Money comes in in 3 formats:
|
|
8
|
+
# Hash: {'value' => xx, 'currency' => 'XXX', 'issuer' => 'ZZZZZZZ'}
|
|
9
|
+
# String: 'value/currency(/issuer)'
|
|
10
|
+
# Int in a String: XRP amount in drops (x1,000,000)
|
|
11
|
+
def initialize data
|
|
12
|
+
case data
|
|
13
|
+
when Hash
|
|
14
|
+
@value = data['value'].to_f
|
|
15
|
+
@currency = data['currency']
|
|
16
|
+
@issuer = data['issuer']
|
|
17
|
+
when String
|
|
18
|
+
@value, @currency, @issuer = *data.split('/')
|
|
19
|
+
if @currency
|
|
20
|
+
@value = @value.to_f
|
|
21
|
+
else
|
|
22
|
+
@value = @value.to_i/1000000.0
|
|
23
|
+
@currency = "XRP"
|
|
24
|
+
end
|
|
25
|
+
when Int
|
|
26
|
+
@value = data.to_i/1000000.0
|
|
27
|
+
@currency = "XRP"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
@value = @value.to_i if @value.to_i == @value
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def to_s
|
|
34
|
+
if @issuer
|
|
35
|
+
"#{@value}/#{@currency}/#{Account(@issuer)}"
|
|
36
|
+
else
|
|
37
|
+
"#{@value}/#{@currency}"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def to_hash
|
|
42
|
+
{'value' => @value.to_s, 'currency' => @currency, 'issuer' => @issuer}
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/rippler/transaction.rb
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
1
|
-
|
|
2
1
|
module Rippler
|
|
2
|
+
# Represents a single Ripple transaction
|
|
3
3
|
class Transaction
|
|
4
|
-
|
|
5
|
-
@data = data
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def name account
|
|
9
|
-
Rippler::Addresses[account] || account
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def amount money
|
|
13
|
-
if money.is_a? Hash
|
|
14
|
-
"#{money['value']}/#{money['currency']}/#{name(money['issuer'])}"
|
|
15
|
-
else
|
|
16
|
-
"#{money.to_i/1000000.0}/XRP"
|
|
17
|
-
end
|
|
4
|
+
include Rippler::Utils
|
|
18
5
|
|
|
6
|
+
def initialize data # data Hash
|
|
7
|
+
@data = data
|
|
19
8
|
end
|
|
20
9
|
|
|
21
10
|
def to_s
|
|
22
|
-
tx = @data[
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
11
|
+
tx = @data['tx'] || @data['transaction']
|
|
12
|
+
if tx
|
|
13
|
+
"#{Time(tx['date']).strftime("%Y-%m-%d %H:%M:%S")} " +
|
|
14
|
+
case tx["TransactionType"]
|
|
15
|
+
when "Payment"
|
|
16
|
+
"PAY #{Money(tx['Amount'])} #{Account(tx['Account'])} > #{Account(tx['Destination'])}"
|
|
17
|
+
when "OfferCancel"
|
|
18
|
+
"CAN #{Account(tx['Account'])} ##{tx['Sequence']}"
|
|
19
|
+
when "OfferCreate"
|
|
20
|
+
"OFR #{Account(tx['Account'])} ##{tx['Sequence']} offers " +
|
|
21
|
+
"#{Money(tx['TakerGets'])} for #{Money(tx['TakerPays'])}"
|
|
22
|
+
when "TrustSet"
|
|
23
|
+
"TRS #{Money(tx['LimitAmount'])} #{Account(tx['Account'])}"
|
|
24
|
+
else
|
|
25
|
+
tx
|
|
26
|
+
end
|
|
33
27
|
else
|
|
34
|
-
|
|
28
|
+
@data
|
|
35
29
|
end
|
|
36
30
|
end
|
|
37
31
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Rippler
|
|
2
|
+
|
|
3
|
+
# Utility methods to be included
|
|
4
|
+
module Utils
|
|
5
|
+
RIPPLE_TIME_OFFSET = 946684800 # Time.utc(2000,1,1,0,0,0).to_i
|
|
6
|
+
|
|
7
|
+
def Time(ripple_seconds)
|
|
8
|
+
Time.at(RIPPLE_TIME_OFFSET + ripple_seconds.to_i)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def Money(data)
|
|
12
|
+
Rippler::Money.new(data)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def Account(data)
|
|
16
|
+
Rippler::Account.new(data)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/rippler/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rippler
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-03-
|
|
12
|
+
date: 2013-03-08 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: faye-websocket
|
|
@@ -43,8 +43,12 @@ files:
|
|
|
43
43
|
- Rakefile
|
|
44
44
|
- bin/rippler
|
|
45
45
|
- lib/rippler.rb
|
|
46
|
+
- lib/rippler/account.rb
|
|
46
47
|
- lib/rippler/contacts.rb
|
|
48
|
+
- lib/rippler/ledger.rb
|
|
49
|
+
- lib/rippler/money.rb
|
|
47
50
|
- lib/rippler/transaction.rb
|
|
51
|
+
- lib/rippler/utils.rb
|
|
48
52
|
- lib/rippler/version.rb
|
|
49
53
|
- rippler.gemspec
|
|
50
54
|
homepage: ''
|