straight-server 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +57 -47
- data/Gemfile.travis +26 -0
- data/README.md +175 -22
- data/Rakefile +7 -0
- data/VERSION +1 -1
- data/benchmark/addons.yml +15 -0
- data/benchmark/config.yml +78 -0
- data/benchmark/default_last_keychain_id +1 -0
- data/benchmark/server_secret +1 -0
- data/bin/goliath.log +6 -0
- data/bin/goliath.log_stdout.log +51 -0
- data/bin/straight-server-benchmark +68 -0
- data/db/migrations/003_add_payment_id_to_orders.rb +13 -0
- data/db/migrations/004_add_description_to_orders.rb +11 -0
- data/db/migrations/005_add_orders_expiration_period_to_gateways.rb +11 -0
- data/db/migrations/006_add_check_order_status_in_db_first_to_gateways.rb +11 -0
- data/db/migrations/007_add_active_switcher_to_gateways.rb +11 -0
- data/db/migrations/008_add_order_counters_to_gateways.rb +11 -0
- data/db/migrations/009_add_hashed_id_to_gateways.rb +18 -0
- data/examples/client/client.dart +5 -0
- data/examples/client/client.html +7 -15
- data/examples/client/client.js +15 -0
- data/lib/straight-server/config.rb +1 -1
- data/lib/straight-server/gateway.rb +241 -59
- data/lib/straight-server/initializer.rb +170 -44
- data/lib/straight-server/logger.rb +1 -1
- data/lib/straight-server/order.rb +74 -9
- data/lib/straight-server/orders_controller.rb +23 -6
- data/lib/straight-server/random_string.rb +18 -0
- data/lib/straight-server/server.rb +44 -17
- data/lib/straight-server/utils/hash_string_to_sym_keys.rb +24 -0
- data/lib/straight-server.rb +6 -3
- data/spec/.straight/config.yml +16 -0
- data/spec/.straight/server_secret +1 -0
- data/spec/fixtures/addons.yml +19 -0
- data/spec/fixtures/test_addon.rb +8 -0
- data/spec/lib/gateway_spec.rb +93 -13
- data/spec/lib/initializer_spec.rb +104 -0
- data/spec/lib/order_spec.rb +59 -0
- data/spec/lib/orders_controller_spec.rb +34 -1
- data/spec/lib/utils/hash_string_to_sym_keys.rb +18 -0
- data/spec/spec_helper.rb +10 -2
- data/straight-server.gemspec +36 -8
- data/templates/addons.yml +15 -0
- data/templates/config.yml +41 -0
- metadata +47 -5
@@ -0,0 +1,51 @@
|
|
1
|
+
|
2
|
+
I, [2015-04-16T04:12:40.115826 #10084] INFO -- : POST /gateways/4989d549e95a757efa02023d12023ef0ffec6088dc0e4a36e630a10e67c25d06/orders
|
3
|
+
{"amount"=>"1"}
|
4
|
+
F, [2015-04-16T04:12:40.116493 #10084] FATAL -- : Sequel::DatabaseDisconnectError: PG::ConnectionBad: PQconsumeInput() SSL connection has been closed unexpectedly
|
5
|
+
|
6
|
+
Backtrace:
|
7
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/adapters/postgres.rb:180:in `async_exec'
|
8
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/adapters/postgres.rb:180:in `block in execute_query'
|
9
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/database/logging.rb:33:in `log_yield'
|
10
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/adapters/postgres.rb:180:in `execute_query'
|
11
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/adapters/postgres.rb:167:in `block in execute'
|
12
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/adapters/postgres.rb:143:in `check_disconnect_errors'
|
13
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/adapters/postgres.rb:167:in `execute'
|
14
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/adapters/postgres.rb:511:in `_execute'
|
15
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/adapters/postgres.rb:335:in `block (2 levels) in execute'
|
16
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/adapters/postgres.rb:532:in `check_database_errors'
|
17
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/adapters/postgres.rb:335:in `block in execute'
|
18
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/database/connecting.rb:250:in `block in synchronize'
|
19
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/connection_pool/threaded.rb:98:in `hold'
|
20
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/database/connecting.rb:250:in `synchronize'
|
21
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/adapters/postgres.rb:335:in `execute'
|
22
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/dataset/actions.rb:911:in `execute'
|
23
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/adapters/postgres.rb:655:in `fetch_rows'
|
24
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/dataset/actions.rb:137:in `each'
|
25
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/dataset/actions.rb:643:in `single_record'
|
26
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/sequel-4.21.0/lib/sequel/dataset/actions.rb:192:in `first'
|
27
|
+
/home/roman/Dropbox/Work/straight/server/lib/straight-server/gateway.rb:233:in `find_by_hashed_id'
|
28
|
+
/home/roman/Dropbox/Work/straight/server/lib/straight-server/orders_controller.rb:85:in `dispatch'
|
29
|
+
/home/roman/Dropbox/Work/straight/server/lib/straight-server/orders_controller.rb:12:in `initialize'
|
30
|
+
/home/roman/Dropbox/Work/straight/server/lib/straight-server/initializer.rb:131:in `new'
|
31
|
+
/home/roman/Dropbox/Work/straight/server/lib/straight-server/initializer.rb:131:in `block in initialize_routes'
|
32
|
+
/home/roman/Dropbox/Work/straight/server/lib/straight-server/server.rb:72:in `call'
|
33
|
+
/home/roman/Dropbox/Work/straight/server/lib/straight-server/server.rb:72:in `block in process_request'
|
34
|
+
/home/roman/Dropbox/Work/straight/server/lib/straight-server/server.rb:71:in `each'
|
35
|
+
/home/roman/Dropbox/Work/straight/server/lib/straight-server/server.rb:71:in `process_request'
|
36
|
+
/home/roman/Dropbox/Work/straight/server/lib/straight-server/server.rb:44:in `block in response'
|
37
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/logmaster-0.1.5/lib/logmaster.rb:54:in `watch_exceptions'
|
38
|
+
/home/roman/Dropbox/Work/straight/server/lib/straight-server/server.rb:37:in `response'
|
39
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/goliath-1.0.4/lib/goliath/api.rb:163:in `call'
|
40
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/faye-websocket-0.9.2/lib/faye/adapters/goliath.rb:28:in `call'
|
41
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/goliath-1.0.4/lib/goliath/rack/params.rb:65:in `block in call'
|
42
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/goliath-1.0.4/lib/goliath/rack/validator.rb:40:in `safely'
|
43
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/goliath-1.0.4/lib/goliath/rack/params.rb:63:in `call'
|
44
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/goliath-1.0.4/lib/goliath/rack/async_middleware.rb:73:in `call'
|
45
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/rack-1.6.0/lib/rack/content_length.rb:15:in `call'
|
46
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/async-rack-0.5.1/lib/async_rack/async_callback.rb:114:in `call'
|
47
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/async-rack-0.5.1/lib/async_rack/async_callback.rb:91:in `block in new'
|
48
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/rack-1.6.0/lib/rack/reloader.rb:44:in `call'
|
49
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/rack-1.6.0/lib/rack/reloader.rb:44:in `call'
|
50
|
+
/home/roman/.rvm/gems/ruby-2.2.0/gems/goliath-1.0.4/lib/goliath/request.rb:166:in `block in process'
|
51
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
# Request example
|
5
|
+
# Simulate 100 users, 10000 requests example (GET)
|
6
|
+
# ab -n 10000 -c 100 http://localhost:9000/
|
7
|
+
|
8
|
+
BENCHMARK_DB_FILE = File.expand_path('benchmark/straight.db')
|
9
|
+
|
10
|
+
def delete_benchmark_db
|
11
|
+
FileUtils.rm_f(BENCHMARK_DB_FILE) if File.exists?(BENCHMARK_DB_FILE)
|
12
|
+
end
|
13
|
+
|
14
|
+
def delete_log_files
|
15
|
+
logs_to_delete = Dir[File.expand_path('benchmark') + "/*.log*"] +
|
16
|
+
Dir[File.expand_path('bin') + "/*.log*"]
|
17
|
+
logs_to_delete.each { |f| FileUtils.rm_f(f) } unless logs_to_delete.empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
if ARGV.empty?
|
21
|
+
print "Enter quantity of requests: "
|
22
|
+
request_qty = gets.strip.to_i
|
23
|
+
|
24
|
+
print "Enter concurrency of the requests: "
|
25
|
+
request_concurrency = gets.strip.to_i
|
26
|
+
|
27
|
+
print "Enter PORT: "
|
28
|
+
port = gets.strip.to_s
|
29
|
+
port = port.empty? ? nil : port
|
30
|
+
|
31
|
+
print "Enter HOST: "
|
32
|
+
host = gets.strip.to_s
|
33
|
+
host = host.empty? ? nil : host
|
34
|
+
else
|
35
|
+
request_qty = ARGV[0]
|
36
|
+
request_concurrency = ARGV[1]
|
37
|
+
host_and_port = ARGV[2]
|
38
|
+
end
|
39
|
+
host_and_port ||= (host ? host : 'http://127.0.0.1') + (port ? ":#{port}" : ':9697')
|
40
|
+
|
41
|
+
delete_benchmark_db
|
42
|
+
delete_log_files
|
43
|
+
|
44
|
+
# Launching Straight server with benchmark configuration
|
45
|
+
system "#{File.expand_path('bin/straight-server')} --config-dir=./benchmark -p " + (port ? "#{port}" : '9697') + " --daemonize --pid #{File.expand_path('benchmark/straight.pid')}"
|
46
|
+
|
47
|
+
# Create order: POST /gateways/1/orders
|
48
|
+
puts "\n\n########## Create order: POST /gateways/1/orders #####################################" +
|
49
|
+
"###############################################################################"
|
50
|
+
puts system "ab -n #{request_qty} -c #{request_concurrency} -T application/x-www-form-urlencoded " + host_and_port + '/gateways/1/orders?amount=1'
|
51
|
+
|
52
|
+
# See order info: GET /gateways/1/orders/1
|
53
|
+
puts "\n\n########## See order info: GET /gateways/1/orders/1 #####################################" +
|
54
|
+
"##############################################################################"
|
55
|
+
puts system "ab -n #{request_qty} -c #{request_concurrency} " + host_and_port + '/gateways/1/orders/1'
|
56
|
+
|
57
|
+
# Subscribe to order status changes via a websocket: GET /gateways/1/orders/1/websocket
|
58
|
+
puts "\n\n########## Subscribe to order status changes via a websocket: GET /gateways/1/orders/1/websocket ##################" +
|
59
|
+
"##############################################################################"
|
60
|
+
puts system "ab -n #{request_qty} -c #{request_concurrency} " + host_and_port + '/gateways/1/orders/1/websocket'
|
61
|
+
|
62
|
+
|
63
|
+
# killing straight server process
|
64
|
+
pid = File.read(File.expand_path('benchmark/straight.pid'))
|
65
|
+
system "kill #{pid}"
|
66
|
+
|
67
|
+
delete_benchmark_db
|
68
|
+
delete_log_files
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
|
3
|
+
up do
|
4
|
+
add_column :gateways, :hashed_id, String
|
5
|
+
add_index :gateways, :hashed_id
|
6
|
+
if defined?(StraightServer)
|
7
|
+
StraightServer.db_connection[:gateways].each do |g|
|
8
|
+
g.update(hashed_id: OpenSSL::HMAC.digest('sha256', StraightServer::Config.server_secret, g[:id].to_s).unpack("H*").first)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
down do
|
14
|
+
remove_index :gateways, :hashed_id
|
15
|
+
remove_column :gateways, :hashed_id
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/examples/client/client.dart
CHANGED
@@ -8,6 +8,11 @@ main() {
|
|
8
8
|
create_order_button.onClick.listen((e) =>
|
9
9
|
create_order().listen((event) {
|
10
10
|
var order = JSON.decode(event.target.responseText);
|
11
|
+
|
12
|
+
// Showing full order info that the server has returned us
|
13
|
+
// in the console.
|
14
|
+
print(order);
|
15
|
+
|
11
16
|
show_pay_order(order);
|
12
17
|
listen_to_order(order);
|
13
18
|
})
|
data/examples/client/client.html
CHANGED
@@ -2,31 +2,23 @@
|
|
2
2
|
|
3
3
|
<head>
|
4
4
|
<title>A Straight client example</title>
|
5
|
-
<script
|
5
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
|
6
|
+
<script src="client.js"></script>
|
6
7
|
</head>
|
7
8
|
|
8
9
|
<body>
|
9
10
|
|
10
|
-
<p><b style="color: red; font-size: 80%;">Attention: this page requires <a href="https://www.dartlang.org/tools/dartium/">Dartium</a> to run properly.</b></p>
|
11
|
-
|
12
11
|
<div id="newOrder">
|
13
|
-
<p>Welcome to the Straight client example.
|
12
|
+
<p>Welcome to the Straight client example. Loading this page from the filesystem won't work since ajax-requests cannot be sent to other domains.</p>
|
14
13
|
|
15
|
-
<p>Clicking the button below will generate a new address for the order and will subscribe you to the websocket, which will automatically notify you when the money arrive to the address. You don't have to refresh this page.</p>
|
14
|
+
<p>Clicking the button below will generate a new address for the order for 1 Satoshi and will subscribe you to the websocket, which will automatically notify you when the money arrive to the address. You don't have to refresh this page.</p>
|
16
15
|
|
17
|
-
<p>Use this
|
16
|
+
<p>Use this form to generate a new order:</p>
|
17
|
+
Gateway id: <input name="gateway_id"/><br/>
|
18
|
+
Amount (in default currency for the gateway, usually in satoshi, but could be USD or EUR): <input name="amount"/>
|
18
19
|
<p><button id="create_order">Create Order</button></p>
|
19
20
|
</div>
|
20
21
|
|
21
|
-
<div id="payOrder" style="display: none;">
|
22
|
-
Order <span class="orderId"></span> created. Please send exactly <b><span class="orderAmount"></span> satoshi(s)</b> to address <span class="orderAddress" style="font-weight: bold;"></span>. This page will be updated as soon as the transaction is made.
|
23
|
-
</div>
|
24
|
-
|
25
|
-
<div id="orderPaid" style="display: none;">
|
26
|
-
The status of your order is now <span class="orderStatus"></span><br/>
|
27
|
-
Transaction id is: <span class="orderTid"></span>
|
28
|
-
</div>
|
29
|
-
|
30
22
|
</body>
|
31
23
|
|
32
24
|
</html>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
jQuery(function($) {
|
2
|
+
|
3
|
+
$("#create_order").click(function() {
|
4
|
+
$.ajax({
|
5
|
+
url: '/gateways/' + $("input[name=gateway_id]").val() + '/orders',
|
6
|
+
type: 'POST',
|
7
|
+
dataType: 'json',
|
8
|
+
data: { amount: $("input[name=amount]").val() },
|
9
|
+
success: function(response) {
|
10
|
+
window.location = '/pay/' + response.payment_id
|
11
|
+
}
|
12
|
+
});
|
13
|
+
});
|
14
|
+
|
15
|
+
});
|
@@ -3,7 +3,7 @@ module StraightServer
|
|
3
3
|
class Config
|
4
4
|
|
5
5
|
class << self
|
6
|
-
attr_accessor :db, :gateways_source, :gateways, :logmaster
|
6
|
+
attr_accessor :db, :gateways_source, :gateways, :logmaster, :server_secret, :count_orders, :environment, :redis, :check_order_status_in_db_first, :port, :blockchain_adapters
|
7
7
|
end
|
8
8
|
|
9
9
|
end
|