Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source 'https://rubygems.org' do
gem 'straight', '1.0.0' #, path: '../straight-engine'
gem 'straight', '1.0.0' # , path: '../straight-engine'
gem 'satoshi-unit'
gem 'goliath'
gem 'faye-websocket'
Expand All @@ -13,7 +13,7 @@ end

unless ENV['STRAIGHT_SERVER_IGNORE_ADDONS_GEMFILE'] # use this flag when building straight-server.gemspec
addons_gemfile = File.join(ENV['STRAIGHT_SERVER_CONFIG_DIR'] || File.join(ENV['HOME'], '.straight'), 'AddonsGemfile')
eval_gemfile addons_gemfile if File.exists?(addons_gemfile)
eval_gemfile addons_gemfile if File.exist?(addons_gemfile)
end

group :development do
Expand Down
16 changes: 8 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ begin
Bundler.setup(:default, :development, :test)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
$stderr.puts 'Run `bundle install` to install missing gems'
exit e.status_code
end

Expand All @@ -17,13 +17,13 @@ Dir.glob('lib/tasks/*.rake').each { |r| load r }
require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
gem.name = "straight-server"
gem.homepage = "http://github.com/snitko/straight-server"
gem.license = "MIT"
gem.summary = %Q{A Bitcoin payment gateway server: a state server for the stateless Straight library}
gem.description = %Q{Accepts orders via http, returns payment info via http or streams updates via websockets, stores orders in a DB}
gem.email = "roman.snitko@gmail.com"
gem.authors = ["Roman Snitko"]
gem.name = 'straight-server'
gem.homepage = 'http://github.com/snitko/straight-server'
gem.license = 'MIT'
gem.summary = %(A Bitcoin payment gateway server: a state server for the stateless Straight library)
gem.description = %(Accepts orders via http, returns payment info via http or streams updates via websockets, stores orders in a DB)
gem.email = 'roman.snitko@gmail.com'
gem.authors = ['Roman Snitko']
# dependencies defined in Gemfile
end
Jeweler::RubygemsDotOrgTasks.new
Expand Down
37 changes: 18 additions & 19 deletions bin/straight-server-benchmark
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ require 'fileutils'
BENCHMARK_DB_FILE = File.expand_path('benchmark/straight.db')

def delete_benchmark_db
FileUtils.rm_f(BENCHMARK_DB_FILE) if File.exists?(BENCHMARK_DB_FILE)
FileUtils.rm_f(BENCHMARK_DB_FILE) if File.exist?(BENCHMARK_DB_FILE)
end

def delete_log_files
logs_to_delete = Dir[File.expand_path('benchmark') + "/*.log*"] +
Dir[File.expand_path('bin') + "/*.log*"]
logs_to_delete = Dir[File.expand_path('benchmark') + '/*.log*'] +
Dir[File.expand_path('bin') + '/*.log*']
logs_to_delete.each { |f| FileUtils.rm_f(f) } unless logs_to_delete.empty?
end

if ARGV.empty?
print "Enter quantity of requests: "
print 'Enter quantity of requests: '
request_qty = gets.strip.to_i
print "Enter concurrency of the requests: "

print 'Enter concurrency of the requests: '
request_concurrency = gets.strip.to_i
print "Enter PORT: "

print 'Enter PORT: '
port = gets.strip.to_s
port = port.empty? ? nil : port
print "Enter HOST: "

print 'Enter HOST: '
host = gets.strip.to_s
host = host.empty? ? nil : host
else
request_qty = ARGV[0]
request_qty = ARGV[0]
request_concurrency = ARGV[1]
host_and_port = ARGV[2]
end
Expand All @@ -45,24 +45,23 @@ delete_log_files
system "#{File.expand_path('bin/straight-server')} --config-dir=./benchmark -p " + (port ? "#{port}" : '9697') + " --daemonize --pid #{File.expand_path('benchmark/straight.pid')}"

# Create order: POST /gateways/1/orders
puts "\n\n########## Create order: POST /gateways/1/orders #####################################" +
"###############################################################################"
puts "\n\n########## Create order: POST /gateways/1/orders #####################################" \
'###############################################################################'
puts system "ab -n #{request_qty} -c #{request_concurrency} -T application/x-www-form-urlencoded " + host_and_port + '/gateways/1/orders?amount=1'

# See order info: GET /gateways/1/orders/1
puts "\n\n########## See order info: GET /gateways/1/orders/1 #####################################" +
"##############################################################################"
puts "\n\n########## See order info: GET /gateways/1/orders/1 #####################################" \
'##############################################################################'
puts system "ab -n #{request_qty} -c #{request_concurrency} " + host_and_port + '/gateways/1/orders/1'

# Subscribe to order status changes via a websocket: GET /gateways/1/orders/1/websocket
puts "\n\n########## Subscribe to order status changes via a websocket: GET /gateways/1/orders/1/websocket ##################" +
"##############################################################################"
puts "\n\n########## Subscribe to order status changes via a websocket: GET /gateways/1/orders/1/websocket ##################" \
'##############################################################################'
puts system "ab -n #{request_qty} -c #{request_concurrency} " + host_and_port + '/gateways/1/orders/1/websocket'


# killing straight server process
pid = File.read(File.expand_path('benchmark/straight.pid'))
system "kill #{pid}"

delete_benchmark_db
delete_log_files
delete_log_files
14 changes: 6 additions & 8 deletions db/migrations/001_create_orders.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
Sequel.migration do

up do
create_table(:orders) do
primary_key :id
String :address, null: false
String :tid
String :address, null: false
String :tid
Integer :status, null: false, default: 0
Integer :keychain_id, null: false
Bignum :amount, null: false
Integer :gateway_id, null: false
String :data
String :callback_response, text: true
Bignum :amount, null: false
Integer :gateway_id, null: false
String :data
String :callback_response, text: true
DateTime :created_at, null: false
DateTime :updated_at
end
Expand All @@ -22,5 +21,4 @@
down do
drop_table(:orders)
end

end
16 changes: 7 additions & 9 deletions db/migrations/002_create_gateways.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
Sequel.migration do

up do
create_table(:gateways) do
primary_key :id
Integer :confirmations_required, null: false, default: 0
Integer :last_keychain_id, null: false, default: 0
String :pubkey, null: false
String :order_class, null: false
String :secret, null: false
String :name, null: false
String :default_currency, default: 'BTC'
String :callback_url
String :pubkey, null: false
String :order_class, null: false
String :secret, null: false
String :name, null: false
String :default_currency, default: 'BTC'
String :callback_url
Boolean :check_signature, null: false, default: false
String :exchange_rate_adapter_names
String :exchange_rate_adapter_names
DateTime :created_at, null: false
DateTime :updated_at
end
Expand All @@ -24,5 +23,4 @@
down do
drop_table(:gateways)
end

end
4 changes: 1 addition & 3 deletions db/migrations/003_add_payment_id_to_orders.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
Sequel.migration do

up do
add_column :orders, :payment_id, String
add_index :orders, :payment_id, unique: true
end

down do
drop_index :orders, :payment_id
drop_index :orders, :payment_id
drop_column :orders, :payment_id
end

end
2 changes: 0 additions & 2 deletions db/migrations/004_add_description_to_orders.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Sequel.migration do

up do
add_column :orders, :description, String
end

down do
drop_column :orders, :description
end

end
2 changes: 0 additions & 2 deletions db/migrations/005_add_orders_expiration_period_to_gateways.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Sequel.migration do

up do
add_column :gateways, :orders_expiration_period, Integer
end

down do
drop_column :gateways, :orders_expiration_period
end

end
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Sequel.migration do

up do
add_column :gateways, :check_order_status_in_db_first, TrueClass
end

down do
drop_column :gateways, :check_order_status_in_db_first
end

end
2 changes: 0 additions & 2 deletions db/migrations/007_add_active_switcher_to_gateways.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Sequel.migration do

up do
add_column :gateways, :active, TrueClass, default: true
end

down do
drop_column :gateways, :active
end

end
2 changes: 0 additions & 2 deletions db/migrations/008_add_order_counters_to_gateways.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Sequel.migration do

up do
add_column :gateways, :order_counters, String
end

down do
drop_column :gateways, :order_counters
end

end
8 changes: 3 additions & 5 deletions db/migrations/009_add_hashed_id_to_gateways.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
Sequel.migration do

up do
add_column :gateways, :hashed_id, String
add_index :gateways, :hashed_id
add_index :gateways, :hashed_id
if defined?(StraightServer)
StraightServer.db_connection[:gateways].each do |g|
g.update(hashed_id: OpenSSL::HMAC.digest('sha256', StraightServer::Config.server_secret, g[:id].to_s).unpack("H*").first)
g.update(hashed_id: OpenSSL::HMAC.digest('sha256', StraightServer::Config.server_secret, g[:id].to_s).unpack('H*').first)
end
end
end

down do
drop_index :gateways, :hashed_id
drop_index :gateways, :hashed_id
drop_column :gateways, :hashed_id
end

end
12 changes: 5 additions & 7 deletions db/migrations/010_add_address_reusability_orders.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
Sequel.migration do

up do
drop_index :orders, [:keychain_id, :gateway_id]
drop_index :orders, :address
drop_index :orders, [:keychain_id, :gateway_id]
drop_index :orders, :address
add_index :orders, [:keychain_id, :gateway_id]
add_index :orders, :address
add_column :orders, :reused, Integer, default: 0
end

down do
drop_index :orders, [:keychain_id, :gateway_id]
drop_index :orders, :address
drop_column :orders, :reused
drop_index :orders, [:keychain_id, :gateway_id]
drop_index :orders, :address
drop_column :orders, :reused
add_index :orders, [:keychain_id, :gateway_id], unique: true
add_index :orders, :address, unique: true
end

end
2 changes: 0 additions & 2 deletions db/migrations/011_add_callback_data_to_orders.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Sequel.migration do

up do
add_column :orders, :callback_data, String
end

down do
drop_column :orders, :callback_data
end

end
4 changes: 1 addition & 3 deletions db/migrations/012_add_address_provider.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Sequel.migration do

up do
add_column :gateways, :address_provider, String, default: "Bip32"
add_column :gateways, :address_provider, String, default: 'Bip32'
end

down do
drop_column :gateways, :address_provider
end

end
2 changes: 0 additions & 2 deletions db/migrations/013_add_address_derivation_scheme.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Sequel.migration do

up do
add_column :gateways, :address_derivation_scheme, String
end

down do
drop_column :gateways, :address_derivation_scheme
end

end
2 changes: 1 addition & 1 deletion db/migrations/014_pubkey_null_address_provider_not_null.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
change do
alter_table :gateways do
set_column_allow_null :pubkey
set_column_not_null :address_provider
set_column_not_null :address_provider
end
end
end
2 changes: 0 additions & 2 deletions db/migrations/015_add_amount_paid_to_orders.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Sequel.migration do

up do
add_column :orders, :amount_paid, Bignum
end

down do
drop_column :orders, :amount_paid
end

end
2 changes: 0 additions & 2 deletions db/migrations/016_add_new_params_to_orders.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Sequel.migration do

up do
add_column :orders, :callback_url, String
add_column :orders, :title, String
Expand All @@ -9,5 +8,4 @@
drop_column :orders, :callback_url
drop_column :orders, :title
end

end
2 changes: 0 additions & 2 deletions db/migrations/017_add_test_mode_to_gateways.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Sequel.migration do

up do
add_column :gateways, :test_mode, TrueClass, default: false
end

down do
drop_column :gateways, :test_mode
end

end
2 changes: 0 additions & 2 deletions db/migrations/018_add_test_keychain_id_to_gateways.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Sequel.migration do

up do
add_column :gateways, :test_last_keychain_id, Integer, default: 0, null: false
end

down do
drop_column :gateways, :test_last_keychain_id
end

end
Loading