straight-server 0.1.2 → 0.2.0
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.
- 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,104 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require_relative '../../lib/straight-server'
|
3
|
+
|
4
|
+
RSpec.describe StraightServer::Initializer do
|
5
|
+
|
6
|
+
class StraightServer::TestInitializerClass
|
7
|
+
include StraightServer::Initializer
|
8
|
+
include StraightServer::Initializer::ConfigDir
|
9
|
+
end
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
# redefining Kernel #puts and #print, to get rid of outputs/noise while running specs
|
13
|
+
module Kernel
|
14
|
+
alias :original_puts :puts
|
15
|
+
alias :original_print :print
|
16
|
+
def puts(s); end
|
17
|
+
def print(s); end
|
18
|
+
end
|
19
|
+
remove_tmp_dir
|
20
|
+
@templates_dir = File.expand_path('../../templates', File.dirname(__FILE__))
|
21
|
+
ENV['HOME'] = File.expand_path('../tmp', File.dirname(__FILE__))
|
22
|
+
@initializer = StraightServer::TestInitializerClass.new
|
23
|
+
StraightServer::Initializer::ConfigDir.set!
|
24
|
+
end
|
25
|
+
|
26
|
+
after(:each) do
|
27
|
+
# reverting redefinition of Kernel #puts and #print made in before block
|
28
|
+
module Kernel
|
29
|
+
alias :puts :original_puts
|
30
|
+
alias :print :original_print
|
31
|
+
end
|
32
|
+
remove_tmp_dir
|
33
|
+
end
|
34
|
+
|
35
|
+
# as #create_config_files method contains #exit method we need to rescue SystemExix: exit() error
|
36
|
+
# and at the same time its good to assert that method execution went well, which we do in rescue
|
37
|
+
let(:create_config_files) do
|
38
|
+
begin
|
39
|
+
@initializer.create_config_files
|
40
|
+
rescue Exception => e
|
41
|
+
expect(e.status).to eq 0
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "creates config files" do
|
46
|
+
create_config_files
|
47
|
+
expect(File.exist?(StraightServer::Initializer::ConfigDir.path)).to eq true
|
48
|
+
created_config_files = Dir.glob(File.join(File.expand_path('../tmp', File.dirname(__FILE__)), '**', '*'), File::FNM_DOTMATCH).select { |f| File.file? f }
|
49
|
+
expect(created_config_files.size).to eq 3
|
50
|
+
created_config_files.each do |file|
|
51
|
+
expect(File.read(file)).to eq File.read(@templates_dir + '/addons.yml') if file.match(/.*\.straight\/addons.yml\Z/)
|
52
|
+
expect(File.read(file)).to eq File.read(@templates_dir + '/config.yml') if file.match(/.*\.straight\/config.yml\Z/)
|
53
|
+
expect(File.read(file).scan(/\w+/).join.size).to eq 16 if file.match(/.*\.straight\/server_secret\Z/)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "reads config" do
|
58
|
+
create_config_files
|
59
|
+
@initializer.read_config_file
|
60
|
+
expect(StraightServer::Config.blockchain_adapters).to eq(["BlockchainInfo", "Mycelium"])
|
61
|
+
end
|
62
|
+
|
63
|
+
it "connects to the database" do
|
64
|
+
StraightServer::Config.db = {
|
65
|
+
adapter: 'sqlite',
|
66
|
+
name: 'straight.db',
|
67
|
+
}
|
68
|
+
create_config_files
|
69
|
+
@initializer.connect_to_db
|
70
|
+
expect(StraightServer.db_connection.test_connection).to be true
|
71
|
+
end
|
72
|
+
|
73
|
+
it "creates logger" do
|
74
|
+
StraightServer::Config.logmaster = { 'log_level' => 'WARN', 'file' => 'straight.log' }
|
75
|
+
create_config_files
|
76
|
+
expect(@initializer.create_logger).to be_kind_of(StraightServer::Logger)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "runs migrations"
|
80
|
+
|
81
|
+
it "loads addons" do
|
82
|
+
create_config_files
|
83
|
+
FileUtils.ln_sf(File.expand_path(File.join(ENV['HOME'], '../fixtures/addons.yml')), File.expand_path(File.join(ENV['HOME'], '../tmp/.straight/addons.yml')))
|
84
|
+
FileUtils.ln_sf(File.expand_path(File.join(ENV['HOME'], '../fixtures')), File.expand_path(File.join(ENV['HOME'], '../tmp/.straight/addons')))
|
85
|
+
disable_logger_noise
|
86
|
+
@initializer.load_addons
|
87
|
+
expect(@initializer).to respond_to(:test_addon_method)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Stubing logger with empty string to remove its noise while test run
|
91
|
+
def disable_logger_noise
|
92
|
+
StraightServer::Config.logmaster = { 'log_level' => 'INFO', 'file' => 'straight.log' }
|
93
|
+
@initializer.create_logger
|
94
|
+
expect(StraightServer.logger).to receive(:info).and_return ''
|
95
|
+
end
|
96
|
+
|
97
|
+
# Cleans up files created by #create_config_files defined in let:
|
98
|
+
def remove_tmp_dir
|
99
|
+
if Dir.exist?(File.expand_path('../tmp/', File.dirname(__FILE__)))
|
100
|
+
FileUtils.rm_r(File.expand_path('../tmp/', File.dirname(__FILE__)))
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
data/spec/lib/order_spec.rb
CHANGED
@@ -7,10 +7,23 @@ RSpec.describe StraightServer::Order do
|
|
7
7
|
DB.run("DELETE FROM orders")
|
8
8
|
@gateway = double("Straight Gateway mock")
|
9
9
|
allow(@gateway).to receive(:id).and_return(1)
|
10
|
+
allow(@gateway).to receive(:active).and_return(true)
|
11
|
+
allow(@gateway).to receive(:order_status_changed)
|
12
|
+
allow(@gateway).to receive(:save)
|
13
|
+
allow(@gateway).to receive(:increment_order_counter!)
|
14
|
+
allow(@gateway).to receive(:current_exchange_rate).and_return(111)
|
15
|
+
allow(@gateway).to receive(:default_currency).and_return('USD')
|
10
16
|
@order = create(:order, gateway_id: @gateway.id)
|
11
17
|
allow(@gateway).to receive(:fetch_transactions_for).with(anything).and_return([])
|
12
18
|
allow(@gateway).to receive(:order_status_changed).with(anything)
|
19
|
+
allow(@gateway).to receive(:sign_with_secret).with(anything).and_return("1", "2", "3")
|
13
20
|
allow(StraightServer::Gateway).to receive(:find_by_id).and_return(@gateway)
|
21
|
+
|
22
|
+
websockets = {}
|
23
|
+
StraightServer::GatewayOnConfig.class_variable_get(:@@gateways).each do |g|
|
24
|
+
websockets[g.id] = {}
|
25
|
+
end
|
26
|
+
StraightServer::GatewayModule.class_variable_set(:@@websockets, websockets)
|
14
27
|
end
|
15
28
|
|
16
29
|
it "prepares data as http params" do
|
@@ -18,6 +31,47 @@ RSpec.describe StraightServer::Order do
|
|
18
31
|
expect(@order.to_http_params).to eq("order_id=#{@order.id}&amount=10&status=#{@order.status}&address=#{@order.address}&tid=tid1")
|
19
32
|
end
|
20
33
|
|
34
|
+
it "generates a payment_id" do
|
35
|
+
expect(@order.payment_id).to eq(@order.gateway.sign_with_secret("#{@order.id}#{@order.amount}#{@order.created_at}"))
|
36
|
+
end
|
37
|
+
|
38
|
+
it "starts a periodic status check but subtracts the time passed from order creation from the duration of the check" do
|
39
|
+
expect(@order).to receive(:check_status_on_schedule).with(duration: 900)
|
40
|
+
@order.start_periodic_status_check
|
41
|
+
|
42
|
+
@order.created_at = (Time.now - 100)
|
43
|
+
expect(@order).to receive(:check_status_on_schedule).with(duration: 800)
|
44
|
+
@order.start_periodic_status_check
|
45
|
+
end
|
46
|
+
|
47
|
+
it "checks DB for a status update first if the respective option for the gateway is turned on" do
|
48
|
+
allow(@order).to receive(:transaction).and_raise("Shouldn't ever be happening!")
|
49
|
+
StraightServer::Config.check_order_status_in_db_first = true
|
50
|
+
StraightServer::Order.where(id: @order.id).update(status: 2)
|
51
|
+
allow(@order.gateway).to receive(:order_status_changed)
|
52
|
+
expect(@order.status(reload: false)).to eq(0)
|
53
|
+
expect(@order.status(reload: true)).to eq(2)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "updates order status when the time in which it expires passes (periodic status checks finish)" do
|
57
|
+
allow(@order).to receive(:status=) do
|
58
|
+
expect(@order).to receive(:status_changed?).and_return(true)
|
59
|
+
expect(@order).to receive(:save)
|
60
|
+
end
|
61
|
+
allow(@order).to receive(:check_status_on_schedule).with(duration: 900) { @order.status = 5 }
|
62
|
+
@order.start_periodic_status_check
|
63
|
+
end
|
64
|
+
|
65
|
+
it "doesn't allow to create an order for inactive gateway" do
|
66
|
+
allow(@gateway).to receive(:active).and_return(false)
|
67
|
+
expect( -> { create(:order, gateway_id: @gateway.id) }).to raise_exception(Sequel::ValidationFailed, "gateway is inactive, cannot create order for inactive gateway")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "adds exchange rate at the moment of purchase to the data hash" do
|
71
|
+
order = create(:order, gateway_id: @gateway.id)
|
72
|
+
expect(order.data[:exchange_rate]).to eq({ price: 111, currency: 'USD' })
|
73
|
+
end
|
74
|
+
|
21
75
|
describe "DB interaction" do
|
22
76
|
|
23
77
|
it "saves a new order into the database" do
|
@@ -25,6 +79,7 @@ RSpec.describe StraightServer::Order do
|
|
25
79
|
end
|
26
80
|
|
27
81
|
it "updates an existing order" do
|
82
|
+
allow(@order).to receive(:gateway).and_return(@gateway)
|
28
83
|
expect(DB[:orders][:keychain_id => @order.id][:status]).to eq(0)
|
29
84
|
@order.status = 1
|
30
85
|
@order.save
|
@@ -75,6 +130,10 @@ RSpec.describe StraightServer::Order do
|
|
75
130
|
expect( -> { create(:order, gateway_id: 0) }).to raise_error()
|
76
131
|
end
|
77
132
|
|
133
|
+
it "doesn't save order if description is too long" do
|
134
|
+
expect( -> { create(:order, description: ("text" * 100)) }).to raise_error()
|
135
|
+
end
|
136
|
+
|
78
137
|
end
|
79
138
|
|
80
139
|
end
|
@@ -32,6 +32,24 @@ RSpec.describe StraightServer::OrdersController do
|
|
32
32
|
send_request "POST", '/gateways/2/orders', amount: 10
|
33
33
|
end
|
34
34
|
|
35
|
+
it "passes data param to Order which then saves it serialized" do
|
36
|
+
allow(StraightServer::Thread).to receive(:new) # ignore periodic status checks, we're not testing it here
|
37
|
+
send_request "POST", '/gateways/2/orders', amount: 10, data: { hello: 'world' }
|
38
|
+
expect(StraightServer::Order.last.data.hello).to eq('world')
|
39
|
+
end
|
40
|
+
|
41
|
+
it "renders 503 page when the gateway is inactive" do
|
42
|
+
@gateway.active = false
|
43
|
+
send_request "POST", '/gateways/2/orders', amount: 1
|
44
|
+
expect(response[0]).to eq(503)
|
45
|
+
expect(response[2]).to eq("The gateway is inactive, you cannot create order with it")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "finds gateway using hashed_id" do
|
49
|
+
allow(StraightServer::Thread).to receive(:new)
|
50
|
+
send_request "POST", "/gateways/#{@gateway.id}/orders", amount: 10
|
51
|
+
end
|
52
|
+
|
35
53
|
end
|
36
54
|
|
37
55
|
describe "show action" do
|
@@ -63,12 +81,20 @@ RSpec.describe StraightServer::OrdersController do
|
|
63
81
|
expect(response).to eq([404, {}, "GET /gateways/2/orders/1 Not found"])
|
64
82
|
end
|
65
83
|
|
84
|
+
it "finds order by payment_id" do
|
85
|
+
allow(@order_mock).to receive(:status_changed?).and_return(false)
|
86
|
+
expect(StraightServer::Order).to receive(:[]).with('payment_id').and_return(nil)
|
87
|
+
expect(StraightServer::Order).to receive(:[]).with(:payment_id => 'payment_id').and_return(@order_mock)
|
88
|
+
send_request "GET", '/gateways/2/orders/payment_id'
|
89
|
+
expect(response).to eq([200, {}, "order json mock"])
|
90
|
+
end
|
91
|
+
|
66
92
|
end
|
67
93
|
|
68
94
|
describe "websocket action" do
|
69
95
|
|
70
96
|
before(:each) do
|
71
|
-
|
97
|
+
StraightServer::GatewayModule.class_variable_set(:@@websockets, { @gateway.id => {} })
|
72
98
|
@ws_mock = double("websocket mock")
|
73
99
|
@order_mock = double("order mock")
|
74
100
|
allow(@ws_mock).to receive(:rack_response).and_return("ws rack response")
|
@@ -99,6 +125,13 @@ RSpec.describe StraightServer::OrdersController do
|
|
99
125
|
expect(response).to eq([403, {}, "You cannot listen to this order because it is completed (status > 1)"])
|
100
126
|
end
|
101
127
|
|
128
|
+
it "finds order by payment_id" do
|
129
|
+
allow(@order_mock).to receive(:status).and_return(0)
|
130
|
+
expect(StraightServer::Order).to receive(:[]).with(:payment_id => 'payment_id').and_return(@order_mock)
|
131
|
+
send_request "GET", '/gateways/2/orders/payment_id/websocket'
|
132
|
+
expect(response).to eq("ws rack response")
|
133
|
+
end
|
134
|
+
|
102
135
|
end
|
103
136
|
|
104
137
|
def send_request(method, path, params={})
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative "../../../lib/straight-server/utils/hash_string_to_sym_keys"
|
2
|
+
|
3
|
+
describe Hash do
|
4
|
+
|
5
|
+
it "converts string keys to symbols in a hash" do
|
6
|
+
hash = { 'hello' => 'world', 'hello?' => 'world!' }
|
7
|
+
hash.keys_to_sym!
|
8
|
+
expect(hash).to include(hello: 'world', :hello? => 'world!')
|
9
|
+
expect(hash).not_to include('hello' => 'world', 'hello?' => 'world!')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "doesn't convert string keys that have spaces or other unintended chars in them" do
|
13
|
+
hash = { 'hello' => 'world', 'hello hi' => 'world planet' }
|
14
|
+
hash.keys_to_sym!
|
15
|
+
expect(hash).to include(hello: 'world', 'hello hi' => 'world planet')
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,9 +21,11 @@ ENV['HOME'] = File.expand_path(File.dirname(__FILE__))
|
|
21
21
|
# 3.2 Actually load the initializer
|
22
22
|
require_relative "../lib/straight-server/config"
|
23
23
|
require_relative "../lib/straight-server/initializer"
|
24
|
+
require_relative "../lib/straight-server/utils/hash_string_to_sym_keys"
|
24
25
|
include StraightServer::Initializer
|
25
|
-
|
26
|
+
StraightServer::Initializer::ConfigDir.set!
|
26
27
|
read_config_file
|
28
|
+
setup_redis_connection
|
27
29
|
|
28
30
|
# 4. Load the rest of the files, including models, which are now ready
|
29
31
|
# to be used as intended and will follow all the previous configuration.
|
@@ -66,10 +68,16 @@ RSpec.configure do |config|
|
|
66
68
|
g.last_keychain_id = 0
|
67
69
|
g.save
|
68
70
|
end
|
71
|
+
|
72
|
+
# Clear Gateway's order counters in Redis
|
73
|
+
Redis.current.keys("#{StraightServer::Config.redis[:prefix]}*").each do |k|
|
74
|
+
Redis.current.del k
|
75
|
+
end
|
76
|
+
|
69
77
|
end
|
70
78
|
|
71
79
|
config.after(:all) do
|
72
|
-
["default_last_keychain_id", "second_gateway_last_keychain_id"].each do |f|
|
80
|
+
["default_last_keychain_id", "second_gateway_last_keychain_id", "default_order_counters.yml"].each do |f|
|
73
81
|
FileUtils.rm "#{ENV['HOME']}/.straight/#{f}" if File.exists?("#{ENV['HOME']}/.straight/#{f}")
|
74
82
|
end
|
75
83
|
end
|
data/straight-server.gemspec
CHANGED
@@ -2,19 +2,19 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: straight-server 0.
|
5
|
+
# stub: straight-server 0.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "straight-server"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Roman Snitko"]
|
14
|
-
s.date = "2015-
|
14
|
+
s.date = "2015-05-05"
|
15
15
|
s.description = "Accepts orders via http, returns payment info via http or streams updates via websockets, stores orders in a DB"
|
16
16
|
s.email = "roman.snitko@gmail.com"
|
17
|
-
s.executables = ["straight-console", "straight-server"]
|
17
|
+
s.executables = ["goliath.log", "goliath.log_stdout.log", "straight-console", "straight-server", "straight-server-benchmark"]
|
18
18
|
s.extra_rdoc_files = [
|
19
19
|
"LICENSE.txt",
|
20
20
|
"README.md"
|
@@ -22,18 +22,35 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.files = [
|
23
23
|
".document",
|
24
24
|
".rspec",
|
25
|
+
".travis.yml",
|
25
26
|
"Gemfile",
|
26
27
|
"Gemfile.lock",
|
28
|
+
"Gemfile.travis",
|
27
29
|
"LICENSE.txt",
|
28
30
|
"README.md",
|
29
31
|
"Rakefile",
|
30
32
|
"VERSION",
|
33
|
+
"benchmark/addons.yml",
|
34
|
+
"benchmark/config.yml",
|
35
|
+
"benchmark/default_last_keychain_id",
|
36
|
+
"benchmark/server_secret",
|
37
|
+
"bin/goliath.log",
|
38
|
+
"bin/goliath.log_stdout.log",
|
31
39
|
"bin/straight-console",
|
32
40
|
"bin/straight-server",
|
41
|
+
"bin/straight-server-benchmark",
|
33
42
|
"db/migrations/001_create_orders.rb",
|
34
43
|
"db/migrations/002_create_gateways.rb",
|
44
|
+
"db/migrations/003_add_payment_id_to_orders.rb",
|
45
|
+
"db/migrations/004_add_description_to_orders.rb",
|
46
|
+
"db/migrations/005_add_orders_expiration_period_to_gateways.rb",
|
47
|
+
"db/migrations/006_add_check_order_status_in_db_first_to_gateways.rb",
|
48
|
+
"db/migrations/007_add_active_switcher_to_gateways.rb",
|
49
|
+
"db/migrations/008_add_order_counters_to_gateways.rb",
|
50
|
+
"db/migrations/009_add_hashed_id_to_gateways.rb",
|
35
51
|
"examples/client/client.dart",
|
36
52
|
"examples/client/client.html",
|
53
|
+
"examples/client/client.js",
|
37
54
|
"lib/straight-server.rb",
|
38
55
|
"lib/straight-server/config.rb",
|
39
56
|
"lib/straight-server/gateway.rb",
|
@@ -41,21 +58,29 @@ Gem::Specification.new do |s|
|
|
41
58
|
"lib/straight-server/logger.rb",
|
42
59
|
"lib/straight-server/order.rb",
|
43
60
|
"lib/straight-server/orders_controller.rb",
|
61
|
+
"lib/straight-server/random_string.rb",
|
44
62
|
"lib/straight-server/server.rb",
|
45
63
|
"lib/straight-server/thread.rb",
|
64
|
+
"lib/straight-server/utils/hash_string_to_sym_keys.rb",
|
46
65
|
"spec/.straight/config.yml",
|
66
|
+
"spec/.straight/server_secret",
|
47
67
|
"spec/factories.rb",
|
68
|
+
"spec/fixtures/addons.yml",
|
69
|
+
"spec/fixtures/test_addon.rb",
|
48
70
|
"spec/lib/gateway_spec.rb",
|
71
|
+
"spec/lib/initializer_spec.rb",
|
49
72
|
"spec/lib/order_spec.rb",
|
50
73
|
"spec/lib/orders_controller_spec.rb",
|
74
|
+
"spec/lib/utils/hash_string_to_sym_keys.rb",
|
51
75
|
"spec/spec_helper.rb",
|
52
76
|
"spec/support/custom_matchers.rb",
|
53
77
|
"straight-server.gemspec",
|
78
|
+
"templates/addons.yml",
|
54
79
|
"templates/config.yml"
|
55
80
|
]
|
56
81
|
s.homepage = "http://github.com/snitko/straight-server"
|
57
82
|
s.licenses = ["MIT"]
|
58
|
-
s.rubygems_version = "2.
|
83
|
+
s.rubygems_version = "2.4.5"
|
59
84
|
s.summary = "A Bitcoin payment gateway server: a state server for the stateless Straight library"
|
60
85
|
|
61
86
|
if s.respond_to? :specification_version then
|
@@ -67,8 +92,9 @@ Gem::Specification.new do |s|
|
|
67
92
|
s.add_runtime_dependency(%q<goliath>, [">= 0"])
|
68
93
|
s.add_runtime_dependency(%q<faye-websocket>, [">= 0"])
|
69
94
|
s.add_runtime_dependency(%q<sequel>, [">= 0"])
|
70
|
-
s.add_runtime_dependency(%q<logmaster>, ["= 0.1.
|
95
|
+
s.add_runtime_dependency(%q<logmaster>, ["= 0.1.5"])
|
71
96
|
s.add_runtime_dependency(%q<ruby-hmac>, [">= 0"])
|
97
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
72
98
|
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
73
99
|
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
74
100
|
s.add_development_dependency(%q<github_api>, ["= 0.11.3"])
|
@@ -78,8 +104,9 @@ Gem::Specification.new do |s|
|
|
78
104
|
s.add_dependency(%q<goliath>, [">= 0"])
|
79
105
|
s.add_dependency(%q<faye-websocket>, [">= 0"])
|
80
106
|
s.add_dependency(%q<sequel>, [">= 0"])
|
81
|
-
s.add_dependency(%q<logmaster>, ["= 0.1.
|
107
|
+
s.add_dependency(%q<logmaster>, ["= 0.1.5"])
|
82
108
|
s.add_dependency(%q<ruby-hmac>, [">= 0"])
|
109
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
83
110
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
84
111
|
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
85
112
|
s.add_dependency(%q<github_api>, ["= 0.11.3"])
|
@@ -90,8 +117,9 @@ Gem::Specification.new do |s|
|
|
90
117
|
s.add_dependency(%q<goliath>, [">= 0"])
|
91
118
|
s.add_dependency(%q<faye-websocket>, [">= 0"])
|
92
119
|
s.add_dependency(%q<sequel>, [">= 0"])
|
93
|
-
s.add_dependency(%q<logmaster>, ["= 0.1.
|
120
|
+
s.add_dependency(%q<logmaster>, ["= 0.1.5"])
|
94
121
|
s.add_dependency(%q<ruby-hmac>, [">= 0"])
|
122
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
95
123
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
96
124
|
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
97
125
|
s.add_dependency(%q<github_api>, ["= 0.11.3"])
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This is where you put info about your addons.
|
2
|
+
#
|
3
|
+
# Addons are just modules that extend the StraightServer::Server module.
|
4
|
+
#
|
5
|
+
# Addon modules can be both rubygems or files under ~/.straight/addons/.
|
6
|
+
# If ~/.straight/addons.yml contains a 'path' key for a particular addon, then it means
|
7
|
+
# the addon is placed under the ~/.straight/addons/. If not, it is assumed it is
|
8
|
+
# already in the LOAD_PATH somehow, with rubygems for example.
|
9
|
+
#
|
10
|
+
#
|
11
|
+
# Example:
|
12
|
+
#
|
13
|
+
# payment_ui: # <- name doesn't affect anything, just shows up in the log file
|
14
|
+
# path: addons/payment_ui # <- This is unnecessary if addon is already in the LOAD_PATH
|
15
|
+
# module: PaymentUI # <- actual module should be a submodule of StraightServer::Addon
|
data/templates/config.yml
CHANGED
@@ -2,6 +2,21 @@
|
|
2
2
|
# useful when your run many gateways on the same server.
|
3
3
|
gateways_source: config
|
4
4
|
|
5
|
+
environment: development
|
6
|
+
|
7
|
+
# This enabled order counting using Redis. Please see he README file for details.
|
8
|
+
# You're gonna need to install redis-server and redis rubygem on your system and provide
|
9
|
+
# redis-server connection details below.
|
10
|
+
count_orders: false
|
11
|
+
|
12
|
+
# Uncomment this if you want to use Gateway's order counters feature
|
13
|
+
# It requires redis.
|
14
|
+
#redis:
|
15
|
+
#host: localhost
|
16
|
+
#port: 6380
|
17
|
+
#db: null # change to 1, 2, 3 etc. or leave as is
|
18
|
+
#password: null # if no password is needed, leave as is
|
19
|
+
|
5
20
|
gateways:
|
6
21
|
default:
|
7
22
|
pubkey: xpub-xxx # <- TODO: change this to your BIP32 pubkey
|
@@ -11,6 +26,18 @@ gateways:
|
|
11
26
|
check_signature: false
|
12
27
|
callback_url: 'http://localhost:3000/my_app/payment_callback'
|
13
28
|
default_currency: 'BTC'
|
29
|
+
orders_expiration_period: 600 # seconds
|
30
|
+
|
31
|
+
# This options decides whether we should also check the DB for status updates first
|
32
|
+
# when we check order status. That is, if we're tracking an order and this option
|
33
|
+
# is set to true, it first fetches the fields from the local DB, sees if the status has changed there,
|
34
|
+
# and if it did - we no longer need to query the blockchain.
|
35
|
+
#
|
36
|
+
# Usecase? Currently mostly debugging (so set it to false for production). For example,
|
37
|
+
# when testing payments, you don't actually want to pay, you can just run the server console,
|
38
|
+
# change order status in the DB and see how your client picks it up, showing you that your
|
39
|
+
# order has been paid for.
|
40
|
+
check_order_status_in_db_first: true # Consider changing to `false` in production.
|
14
41
|
|
15
42
|
# The order matters here, we check for prices with the first adapter,
|
16
43
|
# if it fails, move on to the next
|
@@ -19,6 +46,20 @@ gateways:
|
|
19
46
|
- Coinbase
|
20
47
|
- Bitstamp
|
21
48
|
|
49
|
+
# This affects whether it is possible to create a new order with the gateway.
|
50
|
+
# If it's set to false, then it won't be possible to create a new order, but
|
51
|
+
# it will keep checking on the existing ones.
|
52
|
+
active: true
|
53
|
+
|
54
|
+
# These adapters are used to query the blockchain. If the first one fails, the second one is tried and
|
55
|
+
# so on. The adapters are generally looked up as subclasses of Straight::Blockchain::Adapter
|
56
|
+
# but you are free to create your own and put a fully qualified class name below. The order is,
|
57
|
+
# of course, important.
|
58
|
+
blockchain_adapters:
|
59
|
+
- BlockchainInfo # uses Straight::Blockchain::BlockchainInfoAdapter
|
60
|
+
- Mycelium # uses Straight::Blockchain::MyceliumAdapter
|
61
|
+
# - MyCustomClass::MyCustomBlockchainAdapter
|
62
|
+
|
22
63
|
logmaster:
|
23
64
|
log_level: INFO # Wise to change to WARN for production
|
24
65
|
file: straight.log
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: straight-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Snitko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: straight
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.1.
|
89
|
+
version: 0.1.5
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.1.
|
96
|
+
version: 0.1.5
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: ruby-hmac
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: httparty
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: bundler
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,8 +168,11 @@ description: Accepts orders via http, returns payment info via http or streams u
|
|
154
168
|
via websockets, stores orders in a DB
|
155
169
|
email: roman.snitko@gmail.com
|
156
170
|
executables:
|
171
|
+
- goliath.log
|
172
|
+
- goliath.log_stdout.log
|
157
173
|
- straight-console
|
158
174
|
- straight-server
|
175
|
+
- straight-server-benchmark
|
159
176
|
extensions: []
|
160
177
|
extra_rdoc_files:
|
161
178
|
- LICENSE.txt
|
@@ -163,18 +180,35 @@ extra_rdoc_files:
|
|
163
180
|
files:
|
164
181
|
- ".document"
|
165
182
|
- ".rspec"
|
183
|
+
- ".travis.yml"
|
166
184
|
- Gemfile
|
167
185
|
- Gemfile.lock
|
186
|
+
- Gemfile.travis
|
168
187
|
- LICENSE.txt
|
169
188
|
- README.md
|
170
189
|
- Rakefile
|
171
190
|
- VERSION
|
191
|
+
- benchmark/addons.yml
|
192
|
+
- benchmark/config.yml
|
193
|
+
- benchmark/default_last_keychain_id
|
194
|
+
- benchmark/server_secret
|
195
|
+
- bin/goliath.log
|
196
|
+
- bin/goliath.log_stdout.log
|
172
197
|
- bin/straight-console
|
173
198
|
- bin/straight-server
|
199
|
+
- bin/straight-server-benchmark
|
174
200
|
- db/migrations/001_create_orders.rb
|
175
201
|
- db/migrations/002_create_gateways.rb
|
202
|
+
- db/migrations/003_add_payment_id_to_orders.rb
|
203
|
+
- db/migrations/004_add_description_to_orders.rb
|
204
|
+
- db/migrations/005_add_orders_expiration_period_to_gateways.rb
|
205
|
+
- db/migrations/006_add_check_order_status_in_db_first_to_gateways.rb
|
206
|
+
- db/migrations/007_add_active_switcher_to_gateways.rb
|
207
|
+
- db/migrations/008_add_order_counters_to_gateways.rb
|
208
|
+
- db/migrations/009_add_hashed_id_to_gateways.rb
|
176
209
|
- examples/client/client.dart
|
177
210
|
- examples/client/client.html
|
211
|
+
- examples/client/client.js
|
178
212
|
- lib/straight-server.rb
|
179
213
|
- lib/straight-server/config.rb
|
180
214
|
- lib/straight-server/gateway.rb
|
@@ -182,16 +216,24 @@ files:
|
|
182
216
|
- lib/straight-server/logger.rb
|
183
217
|
- lib/straight-server/order.rb
|
184
218
|
- lib/straight-server/orders_controller.rb
|
219
|
+
- lib/straight-server/random_string.rb
|
185
220
|
- lib/straight-server/server.rb
|
186
221
|
- lib/straight-server/thread.rb
|
222
|
+
- lib/straight-server/utils/hash_string_to_sym_keys.rb
|
187
223
|
- spec/.straight/config.yml
|
224
|
+
- spec/.straight/server_secret
|
188
225
|
- spec/factories.rb
|
226
|
+
- spec/fixtures/addons.yml
|
227
|
+
- spec/fixtures/test_addon.rb
|
189
228
|
- spec/lib/gateway_spec.rb
|
229
|
+
- spec/lib/initializer_spec.rb
|
190
230
|
- spec/lib/order_spec.rb
|
191
231
|
- spec/lib/orders_controller_spec.rb
|
232
|
+
- spec/lib/utils/hash_string_to_sym_keys.rb
|
192
233
|
- spec/spec_helper.rb
|
193
234
|
- spec/support/custom_matchers.rb
|
194
235
|
- straight-server.gemspec
|
236
|
+
- templates/addons.yml
|
195
237
|
- templates/config.yml
|
196
238
|
homepage: http://github.com/snitko/straight-server
|
197
239
|
licenses:
|
@@ -213,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
255
|
version: '0'
|
214
256
|
requirements: []
|
215
257
|
rubyforge_project:
|
216
|
-
rubygems_version: 2.
|
258
|
+
rubygems_version: 2.4.5
|
217
259
|
signing_key:
|
218
260
|
specification_version: 4
|
219
261
|
summary: 'A Bitcoin payment gateway server: a state server for the stateless Straight
|