straight-server 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8610bd49c87e428c82c658ecdc0a1f0e2299bfb
4
- data.tar.gz: e046d7b179cafead65d803e4fb30e52d11a8bc11
3
+ metadata.gz: 833d00355a560e1e82ce97ef09a53b0f96bdd0b0
4
+ data.tar.gz: 96c715dbdd8718aaaded9810738df8ce64e8b13c
5
5
  SHA512:
6
- metadata.gz: 0fda4cd1ecb67821380631da86fd6c2d4864c57ed5f0200b1b6d45508190a07b06e8c66e5e72a1b501df477b8da6c7f385ad4c7b059d50c51ce1f1176e570ef8
7
- data.tar.gz: edb15d2d84f5de98901a3d0d3e18f7a2fb5279c6a9ed19418c9c8b400a9e6b006a3cf5b9d9d42cbcd82a7ae32861a32644048e2e0e851f32a0c09a5d71b79bae
6
+ metadata.gz: 7b3a8d3401e5d2116f35692996dc188bbc8adcbaad4b79d5b22ba2fcd862b3610f8a62ac5dbc022add0f1880bd5babd31a804f088060731a8ccdbcadee7a94ba
7
+ data.tar.gz: 1d611882cc686cb3d5e6905630ef3ec2fd708712bcaaa1dcbbacb83eca37965ff39f29570ad4000ab0a5aa14e2f1f5a66626238b074b5a215e53bf4deab2b4f9
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "straight"
3
+ gem "straight", "0.2.2"
4
4
  gem "satoshi-unit"
5
5
  gem "goliath"
6
6
  gem "faye-websocket"
data/Gemfile.lock CHANGED
@@ -115,7 +115,7 @@ GEM
115
115
  satoshi-unit (0.1.7)
116
116
  sequel (4.22.0)
117
117
  sqlite3 (1.3.10)
118
- straight (0.1.0)
118
+ straight (0.2.2)
119
119
  httparty
120
120
  money-tree
121
121
  satoshi-unit
@@ -145,4 +145,4 @@ DEPENDENCIES
145
145
  satoshi-unit
146
146
  sequel
147
147
  sqlite3
148
- straight
148
+ straight (= 0.2.2)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -3,7 +3,18 @@ module StraightServer
3
3
  class Config
4
4
 
5
5
  class << self
6
- attr_accessor :db, :gateways_source, :gateways, :logmaster, :server_secret, :count_orders, :environment, :redis, :check_order_status_in_db_first, :port, :blockchain_adapters
6
+ attr_accessor :db,
7
+ :gateways_source,
8
+ :gateways,
9
+ :logmaster,
10
+ :server_secret,
11
+ :count_orders,
12
+ :environment,
13
+ :redis,
14
+ :check_order_status_in_db_first,
15
+ :port,
16
+ :blockchain_adapters,
17
+ :expiration_overtime
7
18
  end
8
19
 
9
20
  end
@@ -9,7 +9,7 @@ module StraightServer
9
9
  @@websockets = {}
10
10
 
11
11
  def fetch_transactions_for(address)
12
- try_adapters(@blockchain_adapters) { |b| b.fetch_transactions_for(address) }
12
+ try_adapters(@blockchain_adapters, type: 'blockchain') { |b| b.fetch_transactions_for(address) }
13
13
  end
14
14
 
15
15
  class InvalidSignature < Exception; end
@@ -52,7 +52,7 @@ module StraightServer
52
52
  #
53
53
  def initialize_exchange_rate_adapters
54
54
  @exchange_rate_adapters ||= []
55
- if self.exchange_rate_adapter_names
55
+ if self.exchange_rate_adapter_names.kind_of?(Array) && self.exchange_rate_adapter_names
56
56
  self.exchange_rate_adapter_names.each do |adapter|
57
57
  begin
58
58
  @exchange_rate_adapters << Straight::ExchangeRate.const_get("#{adapter}Adapter").instance
@@ -68,7 +68,8 @@ module StraightServer
68
68
 
69
69
  def validate
70
70
  super # calling Sequel::Model validator
71
- errors.add(:amount, "is invalid") if !amount.kind_of?(Numeric) || amount <= 0
71
+ errors.add(:amount, "is not numeric") if !amount.kind_of?(Numeric)
72
+ errors.add(:amount, "should be more than 0") if amount && amount <= 0
72
73
  errors.add(:gateway_id, "is invalid") if !gateway_id.kind_of?(Numeric) || gateway_id <= 0
73
74
  errors.add(:description, "should be shorter than 255 charachters") if description.kind_of?(String) && description.length > 255
74
75
  errors.add(:gateway, "is inactive, cannot create order for inactive gateway") unless gateway.active
@@ -104,8 +105,8 @@ module StraightServer
104
105
  # Order#created_at into account now, so that we don't start checking on
105
106
  # an order that is already expired. Or, if it's not expired yet,
106
107
  # we make sure to stop all checks as soon as it expires, but not later.
107
- def start_periodic_status_check(duration: gateway.orders_expiration_period)
108
- StraightServer.logger.info "Starting periodic status checks of order #{self.id}"
108
+ def start_periodic_status_check(duration: nil)
109
+ StraightServer.logger.info "Starting periodic status checks of order #{self.id} (expires in #{duration} seconds)"
109
110
  if (t = time_left_before_expiration) > 0
110
111
  check_status_on_schedule(duration: t)
111
112
  end
@@ -117,9 +118,9 @@ module StraightServer
117
118
  super
118
119
  end
119
120
 
120
- def time_left_before_expiration(duration: gateway.orders_expiration_period)
121
+ def time_left_before_expiration
121
122
  time_passed_after_creation = (Time.now - created_at).to_i
122
- gateway.orders_expiration_period-time_passed_after_creation
123
+ gateway.orders_expiration_period+(StraightServer::Config.expiration_overtime || 0) - time_passed_after_creation
123
124
  end
124
125
 
125
126
  end
@@ -20,20 +20,29 @@ module StraightServer
20
20
  end
21
21
 
22
22
  begin
23
- order = @gateway.create_order(
23
+ order_data = {
24
24
  amount: @params['amount'], # this is satoshi
25
25
  currency: @params['currency'],
26
26
  btc_denomination: @params['btc_denomination'],
27
27
  id: @params['order_id'],
28
28
  signature: @params['signature'],
29
29
  data: @params['data']
30
- )
30
+ }
31
+ order = @gateway.create_order(order_data)
31
32
  StraightServer::Thread.new do
32
- order.start_periodic_status_check
33
+ # Because this is a new thread, we have to wrap the code inside in #watch_exceptions
34
+ # once again. Otherwise, not watching is done. Oh, threads!
35
+ StraightServer.logger.watch_exceptions do
36
+ order.start_periodic_status_check
37
+ end
33
38
  end
34
39
  [200, {}, order.to_json ]
35
40
  rescue Sequel::ValidationFailed => e
36
- StraightServer.logger.warn "validation errors in order, cannot create it."
41
+ StraightServer.logger.warn(
42
+ "VALIDATION ERRORS in order, cannot create it:\n" +
43
+ "#{e.message.split(",").each_with_index.map { |e,i| "#{i+1}. #{e.lstrip}"}.join("\n") }\n" +
44
+ "Order data: #{order_data.inspect}\n"
45
+ )
37
46
  [409, {}, "Invalid order: #{e.message}" ]
38
47
  rescue StraightServer::GatewayModule::InvalidSignature
39
48
  [409, {}, "Invalid signature for id: #{@params['order_id']}" ]
@@ -3,6 +3,7 @@
3
3
  gateways_source: config
4
4
  environment: test
5
5
  count_orders: true
6
+ expiration_overtime: 0
6
7
 
7
8
  gateways:
8
9
 
@@ -54,12 +54,6 @@ RSpec.describe StraightServer::Initializer do
54
54
  end
55
55
  end
56
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
57
  it "connects to the database" do
64
58
  StraightServer::Config.db = {
65
59
  adapter: 'sqlite',
@@ -21,7 +21,7 @@ RSpec.describe StraightServer::OrdersController do
21
21
  it "renders 409 error when an order cannot be created due to some validation errors" do
22
22
  send_request "POST", '/gateways/2/orders', amount: 0
23
23
  expect(response[0]).to eq(409)
24
- expect(response[2]).to eq("Invalid order: amount is invalid")
24
+ expect(response[2]).to eq("Invalid order: amount should be more than 0")
25
25
  end
26
26
 
27
27
  it "starts tracking the order status in a separate thread" do
data/spec/spec_helper.rb CHANGED
@@ -63,6 +63,9 @@ RSpec.configure do |config|
63
63
  [:debug, :info, :warn, :fatal, :unknown, :blank_lines].each do |e|
64
64
  allow(logger_mock).to receive(e)
65
65
  end
66
+
67
+ allow(logger_mock).to receive(:watch_exceptions).and_yield
68
+
66
69
  StraightServer.logger = logger_mock
67
70
  StraightServer::GatewayOnConfig.class_variable_get(:@@gateways).each do |g|
68
71
  g.last_keychain_id = 0
@@ -2,16 +2,16 @@
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.2.0 ruby lib
5
+ # stub: straight-server 0.2.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "straight-server"
9
- s.version = "0.2.0"
9
+ s.version = "0.2.1"
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-05-05"
14
+ s.date = "2015-05-07"
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
17
  s.executables = ["goliath.log", "goliath.log_stdout.log", "straight-console", "straight-server", "straight-server-benchmark"]
@@ -87,7 +87,7 @@ Gem::Specification.new do |s|
87
87
  s.specification_version = 4
88
88
 
89
89
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
90
- s.add_runtime_dependency(%q<straight>, [">= 0"])
90
+ s.add_runtime_dependency(%q<straight>, ["= 0.2.2"])
91
91
  s.add_runtime_dependency(%q<satoshi-unit>, [">= 0"])
92
92
  s.add_runtime_dependency(%q<goliath>, [">= 0"])
93
93
  s.add_runtime_dependency(%q<faye-websocket>, [">= 0"])
@@ -99,7 +99,7 @@ Gem::Specification.new do |s|
99
99
  s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
100
100
  s.add_development_dependency(%q<github_api>, ["= 0.11.3"])
101
101
  else
102
- s.add_dependency(%q<straight>, [">= 0"])
102
+ s.add_dependency(%q<straight>, ["= 0.2.2"])
103
103
  s.add_dependency(%q<satoshi-unit>, [">= 0"])
104
104
  s.add_dependency(%q<goliath>, [">= 0"])
105
105
  s.add_dependency(%q<faye-websocket>, [">= 0"])
@@ -112,7 +112,7 @@ Gem::Specification.new do |s|
112
112
  s.add_dependency(%q<github_api>, ["= 0.11.3"])
113
113
  end
114
114
  else
115
- s.add_dependency(%q<straight>, [">= 0"])
115
+ s.add_dependency(%q<straight>, ["= 0.2.2"])
116
116
  s.add_dependency(%q<satoshi-unit>, [">= 0"])
117
117
  s.add_dependency(%q<goliath>, [">= 0"])
118
118
  s.add_dependency(%q<faye-websocket>, [">= 0"])
data/templates/config.yml CHANGED
@@ -9,6 +9,13 @@ environment: development
9
9
  # redis-server connection details below.
10
10
  count_orders: false
11
11
 
12
+ # When you display a payment window to a user, he has some time to pay. But what if a
13
+ # transaction has been made in the last seconds and Straight didn't have time to detect it?
14
+ # This just adds a little bit more time to each expiration period.
15
+ # So technically, you can tell your customer he's got 900 seconds to pay, yet wait additional
16
+ # 30 seconds (default value) to be able to detect a late transaction
17
+ expiration_overtime: 30
18
+
12
19
  # Uncomment this if you want to use Gateway's order counters feature
13
20
  # It requires redis.
14
21
  #redis:
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: straight-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
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-05-05 00:00:00.000000000 Z
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: straight
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.2.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.2.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: satoshi-unit
29
29
  requirement: !ruby/object:Gem::Requirement