-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_ripple_lib.rb
149 lines (133 loc) · 3.82 KB
/
test_ripple_lib.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#require 'ripple'
require './lib/ripple'
ripple = Ripple.client(
endpoint: "http://s1.ripple.com:51234/",
client_account: "r4LADqzmqQUMhgSyBLTtPMG4pAzrMDx7Yj",
client_secret: "ssm5HPoeEZYJWvkJvQW9ro6e6hW9m"
)
# # Send XRP
# tx_hash = ripple.send_basic_transaction({destination: "rfGKu3tSxwMFZ5mQ6bUcxWrxahACxABqKc",currency: "XRP",amount: "1"})
# # Send IOU
# tx_hash = ripple.send_basic_transaction({destination: "rfGKu3tSxwMFZ5mQ6bUcxWrxahACxABqKc",currency: "USD",amount: "0.00001"})
# # XRP Balance
# balance = ripple.xrp_balance
# # Verify tx_hash
# begin
# if ripple.transaction_suceeded?("84062717735DD0E6255F3A64750F543020D7DA05AA344012EFF1FEFB8213F735")
# puts "Transaction complete"
# else
# puts "Transaction Pending"
# end
# rescue Ripple::InvalidTxHash
# puts "Invalid transaction"
# end
# # Send and confirm with error checking
# success = false
# failed = false
# begin
# puts "Sending transaction"
# tx_hash = ripple.send_basic_transaction({destination: "rfGKu3tSxwMFZ5mQ6bUcxWrxahACxABqKc",currency: "USD",amount: "0.00001"})
# success = true
# rescue Ripple::SubmitFailed => e
# puts "Transaction failed: " + e.message
# failed = true
# rescue Ripple::ServerUnavailable
# puts "Server Unavailable"
# rescue Ripple::Timedout
# puts "Request timed out"
# end while not success and not failed
# if success
# # Verify transaction
# complete = false
# begin
# puts "Checking transaction status"
# complete = ripple.transaction_suceeded?(tx_hash)
# if not complete
# # Sleep for small amount of time before checking again
# sleep 1
# end
# rescue Ripple::InvalidTxHash
# puts "Invalid Tx Hash"
# rescue Ripple::ServerUnavailable
# puts "Server Unavailable"
# rescue Ripple::Timedout
# puts "Request timed out"
# end while not complete
# puts "Transaction complete"
# end
# Send and confirm complex send with error checking
# 1. Find path
success = false
begin
puts "Finding Path"
path = ripple.new_path(
source_currency: 'USD',
destination_account: "r44SfjdwtQMpzyAML3vJkssHBiQspdMBw9",
destination_amount: ripple.new_amount(
value: '1',
currency: 'XRP',
#issuer: 'r44SfjdwtQMpzyAML3vJkssHBiQspdMBw9'
)
)
transaction = ripple.find_transaction_path(path)
success = true
rescue Ripple::ServerUnavailable
puts "Server Unavailable"
rescue Ripple::Timedout
puts "Request timed out"
end while not success
# 2. Sign transaction
if success
success = false
failed = false
begin
puts "Signing transaction"
#transaction.print_path_info
transaction = ripple.sign_transaction(transaction)
success = true
rescue Ripple::SubmitFailed => e
puts "Signing failed: " + e.message
failed = true
rescue Ripple::ServerUnavailable
puts "Server Unavailable"
rescue Ripple::Timedout
puts "Request timed out"
end while not success and not failed
end
# 3. Submit transaction
if success
success = false
failed = false
begin
puts "Submitting transaction"
transaction.print_path_info
tx_hash = ripple.submit_transaction(transaction)
success = true
rescue Ripple::SubmitFailed => e
puts "Transaction failed: " + e.message
failed = true
rescue Ripple::ServerUnavailable
puts "Server Unavailable"
rescue Ripple::Timedout
puts "Request timed out"
end while not success and not failed
end
# 4. Verify transaction
if success
complete = false
begin
puts "Checking transaction status"
complete = ripple.transaction_suceeded?(tx_hash)
if not complete
# Sleep for small amount of time before checking again
sleep 1
end
rescue Ripple::InvalidTxHash
puts "Invalid Tx Hash"
rescue Ripple::ServerUnavailable
puts "Server Unavailable"
rescue Ripple::Timedout
puts "Request timed out"
end while not complete
puts "Transaction complete"
end