stellar_spectrum 1.1.4 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d41ff5a6de38a651fef926df476b73d8bbbc04c91e4305d5ed8d7f7fcd728e25
4
- data.tar.gz: e5e435e16159687d38d399723bf1a8c96fb03f485bd28cde43aa30cff80fb708
3
+ metadata.gz: 9bde5c4526ef6395789a0f36643e1b172f2ee39b27d92783ae33c90f361ccccf
4
+ data.tar.gz: 4fabffb86d4194e6c278c91aabbd57027561101f025e91c0760d01f59ed95c23
5
5
  SHA512:
6
- metadata.gz: 9ba2427f94404372c0a2a4ce4cdfa378d03164befbf4bd2bdb39abc1d6a3b8d7cb90ac701a12bad7f2143722df6785c4a11257fb3b0eafa0cf93a07682869ecf
7
- data.tar.gz: e72181488d54adef9c6c2b44682071f6f35645a33a46b15aaa45e3403101fb4df2c40e1667be97d404eb989bef872b88bc58496c6292bf741d393308f69172c7
6
+ metadata.gz: e59d089d618d4957a4b1c1f853b329f484ccf50289b59c811af883720996fdab88a6d2856318971b5fcaecc1678d164d5e33ef349199cb2be677565ac7f59fa6
7
+ data.tar.gz: 4546b8bd18f5f460d761d687d93a95e8423d5105b2dff88775b0e1bf534b7d353eb16526daefa40ae166522520219225c7bc3db7658e8422872f11dbaecb8054
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.2.0] - 2019-01-18
8
+ ### Added
9
+ - Retry calls to Stellar horizon API regardless of the type of error code it receives.
10
+ - Log, if logger is set, when exceptions occur and payment is retried.
11
+
7
12
  ## [1.1.4] - 2018-12-13
8
13
  ### Fixed
9
14
  - Remove accidentally added puts :/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stellar_spectrum (1.1.4)
4
+ stellar_spectrum (1.2.0)
5
5
  activesupport
6
6
  gem_config
7
7
  light-service
@@ -24,7 +24,7 @@ GEM
24
24
  byebug (10.0.2)
25
25
  citrus (3.0.2)
26
26
  coderay (1.1.2)
27
- concurrent-ruby (1.1.3)
27
+ concurrent-ruby (1.1.4)
28
28
  contracts (0.16.0)
29
29
  crack (0.4.3)
30
30
  safe_yaml (~> 1.0.0)
@@ -40,7 +40,7 @@ GEM
40
40
  faraday_middleware (~> 0.9)
41
41
  faraday_middleware (0.12.2)
42
42
  faraday (>= 0.7.4, < 1.0)
43
- ffi (1.9.25)
43
+ ffi (1.10.0)
44
44
  gem_config (0.3.1)
45
45
  hashdiff (0.3.7)
46
46
  hyperclient (0.9.0)
@@ -50,7 +50,7 @@ GEM
50
50
  faraday_middleware
51
51
  net-http-digest_auth
52
52
  uri_template
53
- i18n (1.2.0)
53
+ i18n (1.5.2)
54
54
  concurrent-ruby (~> 1.0)
55
55
  light-service (0.11.0)
56
56
  activesupport (>= 3.0)
@@ -68,7 +68,7 @@ GEM
68
68
  rake (10.5.0)
69
69
  rbnacl (6.0.0)
70
70
  ffi
71
- redis (4.0.3)
71
+ redis (4.1.0)
72
72
  rspec (3.8.0)
73
73
  rspec-core (~> 3.8.0)
74
74
  rspec-expectations (~> 3.8.0)
@@ -13,10 +13,12 @@ require "stellar_spectrum/services/get_channel_accounts"
13
13
  require "stellar_spectrum/services/get_key_for_address"
14
14
  require "stellar_spectrum/services/get_locked_accounts"
15
15
  require "stellar_spectrum/services/get_sequence_number"
16
+ require "stellar_spectrum/services/get_current_sequence_number"
16
17
  require "stellar_spectrum/services/increment_tries"
17
18
  require "stellar_spectrum/services/init_redis"
18
19
  require "stellar_spectrum/services/init_stellar_client"
19
20
  require "stellar_spectrum/services/lock_channel"
21
+ require "stellar_spectrum/services/log"
20
22
  require "stellar_spectrum/services/pick_channel"
21
23
  require "stellar_spectrum/services/send_payment"
22
24
  require "stellar_spectrum/services/sending_payment/attempt_release_lock"
@@ -4,21 +4,17 @@ module StellarSpectrum
4
4
  attr_accessor :redis_url
5
5
  attr_accessor :seeds
6
6
  attr_accessor :horizon_url
7
- attr_accessor :logger
8
7
 
9
- LOG_TAG = "[StellarSpectrum]"
10
8
  MAX_LOCK_TIME_IN_SECONDS = 120
11
9
 
12
10
  def initialize(
13
11
  redis_url: StellarSpectrum.configuration.redis_url,
14
12
  seeds: StellarSpectrum.configuration.seeds,
15
- horizon_url: StellarSpectrum.configuration.horizon_url,
16
- logger: StellarSpectrum.configuration.logger
13
+ horizon_url: StellarSpectrum.configuration.horizon_url
17
14
  )
18
15
  self.redis_url = redis_url
19
16
  self.seeds = seeds
20
17
  self.horizon_url = horizon_url
21
- self.logger = logger
22
18
  end
23
19
 
24
20
  def send_payment(
@@ -42,10 +38,6 @@ module StellarSpectrum
42
38
  force_lock: false,
43
39
  )
44
40
 
45
- # if result.failure?
46
- # return false
47
- # end
48
-
49
41
  result.send_asset_response
50
42
  end
51
43
  end
@@ -0,0 +1,13 @@
1
+ module StellarSpectrum
2
+ class GetCurrentSequenceNumber
3
+
4
+ def self.execute(stellar_client:, channel_account:)
5
+ account_info = stellar_client.account_info(channel_account)
6
+ account_info.sequence.to_i
7
+ rescue Faraday::ClientError => e
8
+ Log.warn("Retrying GetCurrentSequenceNumber - #{e.inspect}")
9
+ execute(stellar_client: stellar_client, channel_account: channel_account)
10
+ end
11
+
12
+ end
13
+ end
@@ -6,8 +6,10 @@ module StellarSpectrum
6
6
  promises :current_sequence_number, :next_sequence_number
7
7
 
8
8
  executed do |c|
9
- account_info = c.stellar_client.account_info(c.channel_account)
10
- c.current_sequence_number = account_info.sequence.to_i
9
+ c.current_sequence_number = GetCurrentSequenceNumber.execute(
10
+ stellar_client: c.stellar_client,
11
+ channel_account: c.channel_account
12
+ )
11
13
 
12
14
  c.next_sequence_number = c[:force_sequence_number] ||
13
15
  c.current_sequence_number + 1
@@ -0,0 +1,21 @@
1
+ module StellarSpectrum
2
+ class Log
3
+
4
+ TAG = "[StellarSpectrum]".freeze
5
+ LEVELS = [:debug, :warn, :info, :error, :fatal].freeze
6
+
7
+ class << self
8
+ LEVELS.each do |level|
9
+
10
+ define_method level do |message|
11
+ logger = StellarSpectrum.configuration.logger
12
+ if logger
13
+ logger.send(level, "#{TAG}: #{message}")
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -3,7 +3,6 @@ module StellarSpectrum
3
3
  class SendAsset
4
4
 
5
5
  extend LightService::Action
6
- TIMEOUT_CODE = 504.freeze
7
6
 
8
7
  expects *%i[
9
8
  from
@@ -31,27 +30,22 @@ module StellarSpectrum
31
30
  sequence: c.next_sequence_number,
32
31
  )
33
32
  rescue Faraday::ClientError => e
34
- fail if e.response.nil?
35
-
36
- if e.response[:status] == TIMEOUT_CODE
37
- retry_result = Retry.execute(
38
- stellar_client: c.stellar_client,
39
- from: c.from,
40
- to: c.to,
41
- amount: c.amount,
42
- memo: c.memo,
43
- tries: c.tries,
44
- seeds: c.seeds,
45
- horizon_url: c.horizon_url,
46
- redis_url: c.redis_url,
47
- force_transaction_source: c.channel_account,
48
- force_sequence_number: c.next_sequence_number,
49
- force_lock: true,
50
- )
51
- c.send_asset_response = retry_result[:send_asset_response]
52
- else
53
- fail
54
- end
33
+ Log.warn("Retrying SendingPayment::SendAsset - #{e.inspect}")
34
+ retry_result = Retry.execute(
35
+ stellar_client: c.stellar_client,
36
+ from: c.from,
37
+ to: c.to,
38
+ amount: c.amount,
39
+ memo: c.memo,
40
+ tries: c.tries,
41
+ seeds: c.seeds,
42
+ horizon_url: c.horizon_url,
43
+ redis_url: c.redis_url,
44
+ force_transaction_source: c.channel_account,
45
+ force_sequence_number: c.next_sequence_number,
46
+ force_lock: true,
47
+ )
48
+ c.send_asset_response = retry_result[:send_asset_response]
55
49
  end
56
50
 
57
51
  end
@@ -1,3 +1,3 @@
1
1
  module StellarSpectrum
2
- VERSION = "1.1.4"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellar_spectrum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramon Tayag
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-12-13 00:00:00.000000000 Z
12
+ date: 2019-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -178,6 +178,7 @@ files:
178
178
  - lib/stellar_spectrum/services/get_available_channels.rb
179
179
  - lib/stellar_spectrum/services/get_channel_account_info.rb
180
180
  - lib/stellar_spectrum/services/get_channel_accounts.rb
181
+ - lib/stellar_spectrum/services/get_current_sequence_number.rb
181
182
  - lib/stellar_spectrum/services/get_key_for_address.rb
182
183
  - lib/stellar_spectrum/services/get_locked_accounts.rb
183
184
  - lib/stellar_spectrum/services/get_sequence_number.rb
@@ -185,6 +186,7 @@ files:
185
186
  - lib/stellar_spectrum/services/init_redis.rb
186
187
  - lib/stellar_spectrum/services/init_stellar_client.rb
187
188
  - lib/stellar_spectrum/services/lock_channel.rb
189
+ - lib/stellar_spectrum/services/log.rb
188
190
  - lib/stellar_spectrum/services/pick_channel.rb
189
191
  - lib/stellar_spectrum/services/send_payment.rb
190
192
  - lib/stellar_spectrum/services/sending_payment/attempt_release_lock.rb