coins_paid_rails 1.1.8 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +22 -33
- data/.rubocop.yml +64 -0
- data/.ruby-version +1 -1
- data/Gemfile.lock +54 -54
- data/coins_paid_rails.gemspec +2 -2
- data/lib/coins_paid/address.rb +2 -1
- data/lib/coins_paid.rb +3 -23
- data/lib/generators/coins_paid/migration_data.rb +13 -12
- data/lib/generators/coins_paid/migration_generator.rb +1 -1
- data/spec/address_spec.rb +67 -28
- data/spec/issued_addresses_spec.rb +5 -5
- data/spec/spec_helper.rb +1 -1
- metadata +20 -16
- data/lib/coins_paid/qr_code.rb +0 -44
- data/spec/qr_code_spec.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f346670118262abe7f87249bad43d50553c3f5b0fd593ca90239efd02af7af7a
|
4
|
+
data.tar.gz: 73502131a9b21c5804b1a11a1a90a99d2cc0698d36123982541ed5ce5c702600
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3eb5405ca21db8b6a0079bb9fe3e13d070eded4c4c07192d3a4bfe4e1193ad9774a68d57bdac74f7dff5e55488f2ce790ff36eac222e1cecfb2897909932fea1
|
7
|
+
data.tar.gz: 2d9d9d06890a6e7ef02ac602cb616ac147830e30b506c87c2305d33cdaf591156e48b57bb528d7650db31367d1d3719cb0534ac686f7286eeda217a8772d78e9
|
data/.circleci/config.yml
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
version: 2.0
|
2
|
+
|
2
3
|
defaults: &defaults
|
3
4
|
docker:
|
4
|
-
- image:
|
5
|
-
working_directory: ~/
|
5
|
+
- image: cimg/ruby:2.7-node
|
6
|
+
working_directory: ~/project
|
6
7
|
|
7
8
|
jobs:
|
8
9
|
checkout_code:
|
@@ -10,10 +11,10 @@ jobs:
|
|
10
11
|
steps:
|
11
12
|
- checkout
|
12
13
|
- run: mkdir log
|
13
|
-
-
|
14
|
-
|
14
|
+
- persist_to_workspace:
|
15
|
+
root: ~/project
|
15
16
|
paths:
|
16
|
-
-
|
17
|
+
- ./
|
17
18
|
|
18
19
|
download_cc_reporter:
|
19
20
|
<<: *defaults
|
@@ -25,45 +26,45 @@ jobs:
|
|
25
26
|
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc/cc-test-reporter
|
26
27
|
chmod +x ./cc/cc-test-reporter
|
27
28
|
- persist_to_workspace:
|
28
|
-
root: ~/
|
29
|
+
root: ~/project
|
29
30
|
paths:
|
30
31
|
- cc/cc-test-reporter
|
31
32
|
|
32
33
|
run_bundler:
|
33
34
|
<<: *defaults
|
34
35
|
steps:
|
36
|
+
- attach_workspace:
|
37
|
+
at: ~/project
|
35
38
|
- restore_cache:
|
36
|
-
key:
|
37
|
-
- restore_cache:
|
38
|
-
key: v4-bundle-{{ checksum "Gemfile.lock" }}
|
39
|
+
key: v1-bundle-{{ checksum "Gemfile.lock" }}
|
39
40
|
- run: echo "export rvm_ignore_gemsets_flag=1" >> ~/.rvmrc
|
40
41
|
- run: sudo apt-get update && sudo apt-get install -y libsodium-dev
|
41
|
-
- run: bundle
|
42
|
+
- run: bundle config set --local path 'vendor/bundle'
|
43
|
+
- run: bundle check || bundle install --path=vendor/bundle --jobs=4 --retry=3
|
42
44
|
- save_cache:
|
43
|
-
key:
|
45
|
+
key: v1-bundle-{{ checksum "Gemfile.lock" }}
|
44
46
|
paths:
|
45
|
-
- ~/
|
47
|
+
- ~/project/vendor/bundle
|
46
48
|
|
47
49
|
run_rspec_tests:
|
48
50
|
<<: *defaults
|
49
51
|
docker:
|
50
|
-
- image:
|
52
|
+
- image: cimg/ruby:2.7-node
|
51
53
|
environment:
|
52
54
|
RACK_ENV: "test"
|
53
55
|
CIRCLE_ARTIFACTS: "./tmp"
|
54
56
|
steps:
|
55
|
-
- restore_cache:
|
56
|
-
key: v4-repo-{{ .Environment.CIRCLE_SHA1 }}
|
57
|
-
- restore_cache:
|
58
|
-
key: v4-bundle-{{ checksum "Gemfile.lock" }}
|
59
57
|
- attach_workspace:
|
60
|
-
at: ~/
|
58
|
+
at: ~/project
|
59
|
+
- restore_cache:
|
60
|
+
key: v1-bundle-{{ checksum "Gemfile.lock" }}
|
61
61
|
- run: sudo apt-get update && sudo apt-get install -y libsodium-dev
|
62
|
-
- run: bundle
|
62
|
+
- run: bundle config set --local path 'vendor/bundle'
|
63
|
+
- run: bundle check
|
63
64
|
- run: bundle exec rspec spec
|
64
65
|
- run: ./cc/cc-test-reporter format-coverage -t simplecov -o cc/codeclimate.rspec.json tmp/coverage/.resultset.json
|
65
66
|
- persist_to_workspace:
|
66
|
-
root: ~/
|
67
|
+
root: ~/project
|
67
68
|
paths:
|
68
69
|
- cc/codeclimate.rspec.json
|
69
70
|
|
@@ -71,24 +72,12 @@ jobs:
|
|
71
72
|
<<: *defaults
|
72
73
|
steps:
|
73
74
|
- attach_workspace:
|
74
|
-
at: ~/
|
75
|
+
at: ~/project
|
75
76
|
- run:
|
76
77
|
name: Upload coverage results to Code Climate
|
77
78
|
command: |
|
78
79
|
./cc/cc-test-reporter upload-coverage -i cc/codeclimate.rspec.json
|
79
80
|
|
80
|
-
deploy:
|
81
|
-
<<: *defaults
|
82
|
-
steps:
|
83
|
-
- restore_cache:
|
84
|
-
key: v4-repo-{{ .Environment.CIRCLE_SHA1 }}
|
85
|
-
- restore_cache:
|
86
|
-
key: v4-bundle-{{ checksum "Gemfile.lock" }}
|
87
|
-
- run: mkdir -p ~/.ssh && ssh-keyscan -H github.com >> ~/.ssh/known_hosts
|
88
|
-
- run: sudo apt-get update && sudo apt-get install -y libsodium-dev
|
89
|
-
- run: bundle check --path vendor/bundle
|
90
|
-
- run: bundle exec rake deploy:branch_or_label
|
91
|
-
|
92
81
|
workflows:
|
93
82
|
version: 2
|
94
83
|
build_test_deploy:
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rails
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.7
|
6
|
+
NewCops: enable
|
7
|
+
SuggestExtensions: false
|
8
|
+
|
9
|
+
Naming/MethodParameterName:
|
10
|
+
MinNameLength: 1
|
11
|
+
Naming/VariableNumber:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Lint/MissingCopEnableDirective:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Layout/EmptyLineAfterMagicComment:
|
18
|
+
Enabled: false
|
19
|
+
Layout/LineLength:
|
20
|
+
Max: 120
|
21
|
+
Layout/MultilineOperationIndentation:
|
22
|
+
Enabled: false
|
23
|
+
Layout/MultilineMethodCallIndentation:
|
24
|
+
EnforcedStyle: indented_relative_to_receiver
|
25
|
+
|
26
|
+
Style/AsciiComments:
|
27
|
+
Enabled: false
|
28
|
+
Style/ClassAndModuleChildren:
|
29
|
+
Enabled: false
|
30
|
+
Style/Documentation:
|
31
|
+
Enabled: false
|
32
|
+
Style/FormatStringToken:
|
33
|
+
Enabled: false
|
34
|
+
Style/Lambda:
|
35
|
+
Enabled: false
|
36
|
+
Style/LambdaCall:
|
37
|
+
Enabled: false
|
38
|
+
Style/ModuleFunction:
|
39
|
+
Enabled: false
|
40
|
+
Style/PercentLiteralDelimiters:
|
41
|
+
PreferredDelimiters:
|
42
|
+
'%i': '()'
|
43
|
+
'%I': '()'
|
44
|
+
'%r': '{}'
|
45
|
+
'%w': '()'
|
46
|
+
'%W': '()'
|
47
|
+
Style/SignalException:
|
48
|
+
EnforcedStyle: 'only_raise'
|
49
|
+
|
50
|
+
Metrics/AbcSize:
|
51
|
+
Exclude:
|
52
|
+
- 'config/**/*'
|
53
|
+
- 'db/**/*'
|
54
|
+
- 'spec/**/*'
|
55
|
+
Metrics/BlockLength:
|
56
|
+
Exclude:
|
57
|
+
- 'config/**/*'
|
58
|
+
- 'db/**/*'
|
59
|
+
- 'spec/**/*'
|
60
|
+
Metrics/MethodLength:
|
61
|
+
Exclude:
|
62
|
+
- 'config/**/*'
|
63
|
+
- 'db/**/*'
|
64
|
+
- 'spec/**/*'
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.5
|
1
|
+
2.7.5
|
data/Gemfile.lock
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
coins_paid_rails (1.
|
4
|
+
coins_paid_rails (1.3.0)
|
5
5
|
activerecord (~> 6.1.4)
|
6
|
-
coins_paid_api (
|
6
|
+
coins_paid_api (>= 1.2.0, < 2.0)
|
7
7
|
dry-initializer (~> 3.0)
|
8
8
|
dry-struct (~> 1.0)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: http://www.rubygems.org/
|
12
12
|
specs:
|
13
|
-
actionpack (6.1.
|
14
|
-
actionview (= 6.1.
|
15
|
-
activesupport (= 6.1.
|
13
|
+
actionpack (6.1.5)
|
14
|
+
actionview (= 6.1.5)
|
15
|
+
activesupport (= 6.1.5)
|
16
16
|
rack (~> 2.0, >= 2.0.9)
|
17
17
|
rack-test (>= 0.6.3)
|
18
18
|
rails-dom-testing (~> 2.0)
|
19
19
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
20
|
-
actionview (6.1.
|
21
|
-
activesupport (= 6.1.
|
20
|
+
actionview (6.1.5)
|
21
|
+
activesupport (= 6.1.5)
|
22
22
|
builder (~> 3.1)
|
23
23
|
erubi (~> 1.4)
|
24
24
|
rails-dom-testing (~> 2.0)
|
25
25
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
26
|
-
activemodel (6.1.
|
27
|
-
activesupport (= 6.1.
|
28
|
-
activerecord (6.1.
|
29
|
-
activemodel (= 6.1.
|
30
|
-
activesupport (= 6.1.
|
31
|
-
activesupport (6.1.
|
26
|
+
activemodel (6.1.5)
|
27
|
+
activesupport (= 6.1.5)
|
28
|
+
activerecord (6.1.5)
|
29
|
+
activemodel (= 6.1.5)
|
30
|
+
activesupport (= 6.1.5)
|
31
|
+
activesupport (6.1.5)
|
32
32
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
33
33
|
i18n (>= 1.6, < 2)
|
34
34
|
minitest (>= 5.1)
|
@@ -36,24 +36,24 @@ GEM
|
|
36
36
|
zeitwerk (~> 2.3)
|
37
37
|
builder (3.2.4)
|
38
38
|
chunky_png (1.4.0)
|
39
|
-
coins_paid_api (1.0
|
39
|
+
coins_paid_api (1.2.0)
|
40
40
|
dry-struct (~> 1.0)
|
41
41
|
faraday (~> 0.12)
|
42
42
|
faraday_middleware (~> 0.11)
|
43
|
-
concurrent-ruby (1.1.
|
43
|
+
concurrent-ruby (1.1.10)
|
44
44
|
crass (1.0.6)
|
45
|
-
diff-lcs (1.
|
46
|
-
docile (1.
|
47
|
-
dry-configurable (0.
|
45
|
+
diff-lcs (1.5.0)
|
46
|
+
docile (1.4.0)
|
47
|
+
dry-configurable (0.14.0)
|
48
48
|
concurrent-ruby (~> 1.0)
|
49
|
-
dry-core (~> 0.
|
50
|
-
dry-container (0.
|
49
|
+
dry-core (~> 0.6)
|
50
|
+
dry-container (0.9.0)
|
51
51
|
concurrent-ruby (~> 1.0)
|
52
|
-
dry-configurable (~> 0.
|
53
|
-
dry-core (0.
|
52
|
+
dry-configurable (~> 0.13, >= 0.13.0)
|
53
|
+
dry-core (0.7.1)
|
54
54
|
concurrent-ruby (~> 1.0)
|
55
|
-
dry-inflector (0.2.
|
56
|
-
dry-initializer (3.
|
55
|
+
dry-inflector (0.2.1)
|
56
|
+
dry-initializer (3.1.1)
|
57
57
|
dry-logic (1.2.0)
|
58
58
|
concurrent-ruby (~> 1.0)
|
59
59
|
dry-core (~> 0.5, >= 0.5)
|
@@ -68,25 +68,24 @@ GEM
|
|
68
68
|
dry-inflector (~> 0.1, >= 0.1.2)
|
69
69
|
dry-logic (~> 1.0, >= 1.0.2)
|
70
70
|
erubi (1.10.0)
|
71
|
-
faraday (0.17.
|
71
|
+
faraday (0.17.5)
|
72
72
|
multipart-post (>= 1.2, < 3)
|
73
73
|
faraday_middleware (0.14.0)
|
74
74
|
faraday (>= 0.7.4, < 1.0)
|
75
|
-
i18n (1.
|
75
|
+
i18n (1.10.0)
|
76
76
|
concurrent-ruby (~> 1.0)
|
77
77
|
ice_nine (0.11.2)
|
78
|
-
|
79
|
-
loofah (2.12.0)
|
78
|
+
loofah (2.15.0)
|
80
79
|
crass (~> 1.0.2)
|
81
80
|
nokogiri (>= 1.5.9)
|
82
81
|
method_source (1.0.0)
|
83
|
-
mini_portile2 (2.
|
84
|
-
minitest (5.
|
82
|
+
mini_portile2 (2.8.0)
|
83
|
+
minitest (5.15.0)
|
85
84
|
multipart-post (2.1.1)
|
86
|
-
nokogiri (1.
|
87
|
-
mini_portile2 (~> 2.
|
85
|
+
nokogiri (1.13.3)
|
86
|
+
mini_portile2 (~> 2.8.0)
|
88
87
|
racc (~> 1.4)
|
89
|
-
racc (1.
|
88
|
+
racc (1.6.0)
|
90
89
|
rack (2.2.3)
|
91
90
|
rack-test (1.1.0)
|
92
91
|
rack (>= 1.0, < 3)
|
@@ -95,29 +94,29 @@ GEM
|
|
95
94
|
nokogiri (>= 1.6)
|
96
95
|
rails-html-sanitizer (1.4.2)
|
97
96
|
loofah (~> 2.3)
|
98
|
-
railties (6.1.
|
99
|
-
actionpack (= 6.1.
|
100
|
-
activesupport (= 6.1.
|
97
|
+
railties (6.1.5)
|
98
|
+
actionpack (= 6.1.5)
|
99
|
+
activesupport (= 6.1.5)
|
101
100
|
method_source
|
102
|
-
rake (>=
|
101
|
+
rake (>= 12.2)
|
103
102
|
thor (~> 1.0)
|
104
103
|
rake (13.0.6)
|
105
|
-
rqrcode (2.1.
|
104
|
+
rqrcode (2.1.1)
|
106
105
|
chunky_png (~> 1.0)
|
107
106
|
rqrcode_core (~> 1.0)
|
108
107
|
rqrcode_core (1.2.0)
|
109
|
-
rspec-core (3.
|
110
|
-
rspec-support (~> 3.
|
111
|
-
rspec-expectations (3.
|
108
|
+
rspec-core (3.11.0)
|
109
|
+
rspec-support (~> 3.11.0)
|
110
|
+
rspec-expectations (3.11.0)
|
112
111
|
diff-lcs (>= 1.2.0, < 2.0)
|
113
|
-
rspec-support (~> 3.
|
112
|
+
rspec-support (~> 3.11.0)
|
114
113
|
rspec-its (1.3.0)
|
115
114
|
rspec-core (>= 3.0.0)
|
116
115
|
rspec-expectations (>= 3.0.0)
|
117
|
-
rspec-mocks (3.
|
116
|
+
rspec-mocks (3.11.0)
|
118
117
|
diff-lcs (>= 1.2.0, < 2.0)
|
119
|
-
rspec-support (~> 3.
|
120
|
-
rspec-rails (5.
|
118
|
+
rspec-support (~> 3.11.0)
|
119
|
+
rspec-rails (5.1.1)
|
121
120
|
actionpack (>= 5.2)
|
122
121
|
activesupport (>= 5.2)
|
123
122
|
railties (>= 5.2)
|
@@ -125,17 +124,18 @@ GEM
|
|
125
124
|
rspec-expectations (~> 3.10)
|
126
125
|
rspec-mocks (~> 3.10)
|
127
126
|
rspec-support (~> 3.10)
|
128
|
-
rspec-support (3.
|
129
|
-
simplecov (0.
|
130
|
-
docile (~> 1.1
|
131
|
-
|
132
|
-
|
133
|
-
simplecov-html (0.
|
127
|
+
rspec-support (3.11.0)
|
128
|
+
simplecov (0.21.2)
|
129
|
+
docile (~> 1.1)
|
130
|
+
simplecov-html (~> 0.11)
|
131
|
+
simplecov_json_formatter (~> 0.1)
|
132
|
+
simplecov-html (0.12.3)
|
133
|
+
simplecov_json_formatter (0.1.4)
|
134
134
|
sqlite3 (1.4.2)
|
135
|
-
thor (1.1
|
135
|
+
thor (1.2.1)
|
136
136
|
tzinfo (2.0.4)
|
137
137
|
concurrent-ruby (~> 1.0)
|
138
|
-
zeitwerk (2.4
|
138
|
+
zeitwerk (2.5.4)
|
139
139
|
|
140
140
|
PLATFORMS
|
141
141
|
ruby
|
@@ -149,4 +149,4 @@ DEPENDENCIES
|
|
149
149
|
sqlite3
|
150
150
|
|
151
151
|
BUNDLED WITH
|
152
|
-
|
152
|
+
2.2.32
|
data/coins_paid_rails.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'coins_paid_rails'
|
3
3
|
s.authors = ['Artem Biserov(artembiserov)', 'Oleg Ivanov(morhekil)']
|
4
|
-
s.version = '1.
|
4
|
+
s.version = '1.4.0'
|
5
5
|
s.files = `git ls-files`.split("\n")
|
6
6
|
s.summary = 'CoinsPaid Rails Integration'
|
7
7
|
s.license = 'MIT'
|
8
8
|
|
9
|
-
s.add_runtime_dependency 'coins_paid_api', '
|
9
|
+
s.add_runtime_dependency 'coins_paid_api', '>= 1.2.0', '<2.0'
|
10
10
|
s.add_runtime_dependency 'activerecord', '~> 6.1.4'
|
11
11
|
s.add_runtime_dependency 'dry-initializer', '~> 3.0'
|
12
12
|
s.add_runtime_dependency 'dry-struct', '~> 1.0'
|
data/lib/coins_paid/address.rb
CHANGED
@@ -18,7 +18,8 @@ module CoinsPaid
|
|
18
18
|
|
19
19
|
def call
|
20
20
|
ActiveRecord::Base.transaction do
|
21
|
-
|
21
|
+
lookup_attrs = request_data.attributes.slice(:foreign_id, :convert_to, :currency)
|
22
|
+
CoinsPaidAddress.lock.find_or_create_by!(lookup_attrs) do |address|
|
22
23
|
response = CoinsPaid::API.take_address(request_data.attributes)
|
23
24
|
address.assign_attributes(response.attributes)
|
24
25
|
end
|
data/lib/coins_paid.rb
CHANGED
@@ -3,34 +3,14 @@ require 'dry-struct'
|
|
3
3
|
require 'dry-initializer'
|
4
4
|
require_relative 'coins_paid/address'
|
5
5
|
require_relative 'coins_paid/coins_paid_address'
|
6
|
-
require_relative 'coins_paid/qr_code'
|
7
6
|
|
8
7
|
module CoinsPaid
|
9
8
|
module_function
|
10
9
|
|
11
10
|
UnknownCurrency = Class.new RuntimeError
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
ADDRESS_PREFIXES = {
|
16
|
-
'BTC' => 'bitcoin',
|
17
|
-
'BCH' => 'bitcoincash',
|
18
|
-
'DOGE' => 'doge',
|
19
|
-
'ETH' => 'ethereum',
|
20
|
-
'EURTE' => 'ethereum',
|
21
|
-
'LTC' => 'litecoin',
|
22
|
-
'USDT' => 'bitcoin',
|
23
|
-
'USDTE' => 'ethereum',
|
24
|
-
'TRX' => 'tron',
|
25
|
-
'USDTT' => 'tron'
|
26
|
-
}.freeze
|
27
|
-
|
28
|
-
def address(foreign_id, currency:)
|
29
|
-
Address.new(foreign_id: foreign_id, currency: currency, convert_to: DEFAULT_CONVERT_TO).call
|
30
|
-
end
|
31
|
-
|
32
|
-
def qr_code(player_id, currency:, label:, message:)
|
33
|
-
QrCode.new(player_id, currency: currency, label: label, message: message)
|
12
|
+
def address(foreign_id, currency:, convert_to: currency)
|
13
|
+
Address.new(foreign_id: foreign_id, currency: currency, convert_to: convert_to).call
|
34
14
|
end
|
35
15
|
|
36
16
|
def currency(name)
|
@@ -38,6 +18,6 @@ module CoinsPaid
|
|
38
18
|
end
|
39
19
|
|
40
20
|
def issued_addresses(foreign_id)
|
41
|
-
CoinsPaidAddress.where(foreign_id: foreign_id).order(:currency)
|
21
|
+
CoinsPaidAddress.where(foreign_id: foreign_id).order(:currency, :convert_to)
|
42
22
|
end
|
43
23
|
end
|
@@ -5,18 +5,19 @@ module CoinsPaid
|
|
5
5
|
module_function
|
6
6
|
|
7
7
|
def get
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
<<~RUBY
|
9
|
+
create_table :coins_paid_addresses do |t|
|
10
|
+
t.string :foreign_id, null: false
|
11
|
+
t.string :currency, null: false
|
12
|
+
t.string :convert_to, null: false
|
13
|
+
t.string :address, null: false
|
14
|
+
t.string :tag
|
15
|
+
t.integer :external_id, null: false
|
16
|
+
|
17
|
+
t.timestamps
|
18
|
+
t.index [:foreign_id, :currency, :convert_to], name: :address_currencies, unique: true
|
19
|
+
end
|
20
|
+
RUBY
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -6,7 +6,7 @@ module CoinsPaid
|
|
6
6
|
module Generators
|
7
7
|
class MigrationGenerator < ActiveRecord::Generators::Base
|
8
8
|
argument :name, default: 'create_coins_paid_addresses'
|
9
|
-
source_root File.expand_path(
|
9
|
+
source_root File.expand_path('templates', __dir__)
|
10
10
|
|
11
11
|
def copy_coins_paid_migration
|
12
12
|
migration_template 'migration.rb', "#{db_migrate_path}/#{file_name}.rb"
|
data/spec/address_spec.rb
CHANGED
@@ -1,56 +1,95 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe CoinsPaid, '.address' do
|
4
|
-
let(:
|
4
|
+
let(:foreign_id) { 'user-id:2048' }
|
5
5
|
let(:currency) { 'BTC' }
|
6
|
-
let(:
|
7
|
-
{
|
8
|
-
foreign_id: foreign_key,
|
9
|
-
currency: currency
|
10
|
-
}.merge(address_attributes)
|
11
|
-
end
|
6
|
+
let(:convert_to) { 'EUR' }
|
12
7
|
let(:address_attributes) do
|
13
8
|
{
|
14
9
|
external_id: 1,
|
15
10
|
address: '12983h13ro1hrt24it432t',
|
16
|
-
tag: 'tag-123'
|
11
|
+
tag: 'tag-123'
|
17
12
|
}
|
18
13
|
end
|
19
|
-
|
14
|
+
let(:api_request_args) { { foreign_id: foreign_id, currency: currency, convert_to: convert_to } }
|
15
|
+
|
16
|
+
subject(:take_address) { described_class.address(foreign_id, currency: currency, convert_to: convert_to) }
|
20
17
|
|
21
|
-
context 'when there is
|
22
|
-
let
|
23
|
-
|
18
|
+
context 'when there is a previously stored address record' do
|
19
|
+
let(:stored_address_attributes) do
|
20
|
+
address_attributes.merge(
|
21
|
+
foreign_id: foreign_id,
|
22
|
+
currency: currency,
|
23
|
+
convert_to: recorded_convert_to
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
let!(:stored_address) do
|
28
|
+
CoinsPaid::CoinsPaidAddress.create!(stored_address_attributes)
|
24
29
|
end
|
25
30
|
|
26
31
|
before do
|
27
|
-
allow(CoinsPaid::API).to receive(:take_address)
|
32
|
+
allow(CoinsPaid::API).to receive(:take_address).and_return(
|
33
|
+
CoinsPaid::API::TakeAddress::Response.new(address_attributes)
|
34
|
+
)
|
28
35
|
end
|
29
36
|
|
30
|
-
|
31
|
-
|
37
|
+
context 'with the same convert_to value' do
|
38
|
+
let(:recorded_convert_to) { convert_to }
|
32
39
|
|
33
|
-
|
40
|
+
it 'returns existing record' do
|
41
|
+
expect do
|
42
|
+
expect(take_address).to eq stored_address
|
43
|
+
end.to_not change(CoinsPaid::CoinsPaidAddress, :count)
|
44
|
+
expect(CoinsPaid::API).not_to have_received(:take_address)
|
45
|
+
end
|
34
46
|
end
|
35
|
-
end
|
36
47
|
|
37
|
-
|
38
|
-
|
39
|
-
allow(CoinsPaid::API).to receive(:take_address).and_raise(CoinsPaid::API::Error)
|
40
|
-
end
|
48
|
+
context 'with a different convert_to value' do
|
49
|
+
let(:recorded_convert_to) { 'DOGE' }
|
41
50
|
|
42
|
-
|
43
|
-
|
51
|
+
it 'requests and records new address' do
|
52
|
+
expect do
|
53
|
+
new_address_attrs = stored_address_attributes.merge(convert_to: convert_to)
|
54
|
+
expect(take_address).to have_attributes(new_address_attrs)
|
55
|
+
end.to change(CoinsPaid::CoinsPaidAddress, :count).by(1)
|
56
|
+
expect(CoinsPaid::API).to have_received(:take_address).with(api_request_args)
|
57
|
+
end
|
44
58
|
end
|
45
59
|
end
|
46
60
|
|
47
|
-
context 'when
|
48
|
-
|
49
|
-
|
61
|
+
context 'when there is no recorded address' do
|
62
|
+
context 'and coins paid api responds with error' do
|
63
|
+
before do
|
64
|
+
allow(CoinsPaid::API).to receive(:take_address).and_raise(CoinsPaid::API::Error)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'raises error' do
|
68
|
+
expect { take_address }.to raise_error(CoinsPaid::API::Error)
|
69
|
+
end
|
50
70
|
end
|
51
71
|
|
52
|
-
|
53
|
-
|
72
|
+
context 'and coins paid returns valid response' do
|
73
|
+
before do
|
74
|
+
allow(CoinsPaid::API).to receive(:take_address).and_return(
|
75
|
+
CoinsPaid::API::TakeAddress::Response.new(address_attributes)
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
let(:new_address_attrs) do
|
80
|
+
address_attributes.merge(
|
81
|
+
foreign_id: foreign_id,
|
82
|
+
currency: currency,
|
83
|
+
convert_to: convert_to
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'creates new address' do
|
88
|
+
expect do
|
89
|
+
expect(take_address).to have_attributes(new_address_attrs)
|
90
|
+
end.to change(CoinsPaid::CoinsPaidAddress, :count).by(1)
|
91
|
+
expect(CoinsPaid::API).to have_received(:take_address).with(api_request_args)
|
92
|
+
end
|
54
93
|
end
|
55
94
|
end
|
56
95
|
end
|
@@ -6,15 +6,15 @@ describe CoinsPaid, '.issued_addresses' do
|
|
6
6
|
it 'returns addresses with requested foreign_id ordered by currency' do
|
7
7
|
attrs = {
|
8
8
|
foreign_id: foreign_id,
|
9
|
-
currency: 'BTC',
|
10
9
|
address: 'addr',
|
11
10
|
external_id: 1
|
12
11
|
}
|
13
12
|
|
14
|
-
addr1 = CoinsPaid::CoinsPaidAddress.create!(attrs)
|
15
|
-
addr2 = CoinsPaid::CoinsPaidAddress.create!(attrs.merge(currency: 'ETH'))
|
16
|
-
CoinsPaid::CoinsPaidAddress.create!(attrs.merge(
|
13
|
+
addr1 = CoinsPaid::CoinsPaidAddress.create!(attrs.merge(currency: 'BTC', convert_to: 'EUR'))
|
14
|
+
addr2 = CoinsPaid::CoinsPaidAddress.create!(attrs.merge(currency: 'ETH', convert_to: 'EUR'))
|
15
|
+
addr3 = CoinsPaid::CoinsPaidAddress.create!(attrs.merge(currency: 'ETH', convert_to: 'ETH'))
|
16
|
+
CoinsPaid::CoinsPaidAddress.create!(attrs.merge(currency: 'BTC', convert_to: 'EUR', foreign_id: 555))
|
17
17
|
|
18
|
-
expect(CoinsPaid.issued_addresses(foreign_id)).to eq [addr1, addr2]
|
18
|
+
expect(CoinsPaid.issued_addresses(foreign_id)).to eq [addr1, addr3, addr2]
|
19
19
|
end
|
20
20
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,30 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coins_paid_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Biserov(artembiserov)
|
8
8
|
- Oleg Ivanov(morhekil)
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-03-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: coins_paid_api
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 1.2.0
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '2.0'
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
|
-
- - "
|
28
|
+
- - ">="
|
26
29
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
30
|
+
version: 1.2.0
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
28
34
|
- !ruby/object:Gem::Dependency
|
29
35
|
name: activerecord
|
30
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,8 +87,8 @@ dependencies:
|
|
81
87
|
- - ">="
|
82
88
|
- !ruby/object:Gem::Version
|
83
89
|
version: '0'
|
84
|
-
description:
|
85
|
-
email:
|
90
|
+
description:
|
91
|
+
email:
|
86
92
|
executables: []
|
87
93
|
extensions: []
|
88
94
|
extra_rdoc_files: []
|
@@ -90,6 +96,7 @@ files:
|
|
90
96
|
- ".circleci/config.yml"
|
91
97
|
- ".gitignore"
|
92
98
|
- ".rspec"
|
99
|
+
- ".rubocop.yml"
|
93
100
|
- ".ruby-version"
|
94
101
|
- Gemfile
|
95
102
|
- Gemfile.lock
|
@@ -97,7 +104,6 @@ files:
|
|
97
104
|
- lib/coins_paid.rb
|
98
105
|
- lib/coins_paid/address.rb
|
99
106
|
- lib/coins_paid/coins_paid_address.rb
|
100
|
-
- lib/coins_paid/qr_code.rb
|
101
107
|
- lib/coins_paid_rails.rb
|
102
108
|
- lib/generators/coins_paid/migration_data.rb
|
103
109
|
- lib/generators/coins_paid/migration_generator.rb
|
@@ -105,14 +111,13 @@ files:
|
|
105
111
|
- spec/address_spec.rb
|
106
112
|
- spec/currency_spec.rb
|
107
113
|
- spec/issued_addresses_spec.rb
|
108
|
-
- spec/qr_code_spec.rb
|
109
114
|
- spec/spec_helper.rb
|
110
115
|
- spec/support/database/create_table.rb
|
111
|
-
homepage:
|
116
|
+
homepage:
|
112
117
|
licenses:
|
113
118
|
- MIT
|
114
119
|
metadata: {}
|
115
|
-
post_install_message:
|
120
|
+
post_install_message:
|
116
121
|
rdoc_options: []
|
117
122
|
require_paths:
|
118
123
|
- lib
|
@@ -127,9 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
132
|
- !ruby/object:Gem::Version
|
128
133
|
version: '0'
|
129
134
|
requirements: []
|
130
|
-
|
131
|
-
|
132
|
-
signing_key:
|
135
|
+
rubygems_version: 3.1.6
|
136
|
+
signing_key:
|
133
137
|
specification_version: 4
|
134
138
|
summary: CoinsPaid Rails Integration
|
135
139
|
test_files: []
|
data/lib/coins_paid/qr_code.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module CoinsPaid
|
4
|
-
class QrCode
|
5
|
-
include Dry::Initializer.define -> do
|
6
|
-
param :player_id
|
7
|
-
option :currency
|
8
|
-
option :label
|
9
|
-
option :message
|
10
|
-
end
|
11
|
-
|
12
|
-
def url
|
13
|
-
known_url? ? "#{token_type}:#{address.address}?label=#{encode(label)}&message=#{encode(message)}" : nil
|
14
|
-
end
|
15
|
-
|
16
|
-
def address
|
17
|
-
@address ||= CoinsPaid.address(player_id, currency: currency)
|
18
|
-
end
|
19
|
-
|
20
|
-
def svg
|
21
|
-
RQRCode::QRCode.new(url || address.address).as_svg(
|
22
|
-
offset: 0,
|
23
|
-
color: '000',
|
24
|
-
shape_rendering: 'crispEdges',
|
25
|
-
module_size: 3,
|
26
|
-
standalone: true
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def token_type
|
33
|
-
ADDRESS_PREFIXES[currency]
|
34
|
-
end
|
35
|
-
|
36
|
-
def encode(string)
|
37
|
-
URI.encode_www_form_component(string)
|
38
|
-
end
|
39
|
-
|
40
|
-
def known_url?
|
41
|
-
token_type.present?
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/spec/qr_code_spec.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe CoinsPaid, '.qr_code' do
|
4
|
-
let(:foreign_id) { 123 }
|
5
|
-
let(:currency) { 'BTC' }
|
6
|
-
let(:address) { 'abc123' }
|
7
|
-
let(:coins_paid_address) do
|
8
|
-
instance_double CoinsPaid::CoinsPaidAddress,
|
9
|
-
currency: currency,
|
10
|
-
address: address
|
11
|
-
end
|
12
|
-
subject(:qr_code) do
|
13
|
-
described_class.qr_code(
|
14
|
-
foreign_id,
|
15
|
-
currency: currency,
|
16
|
-
label: 'RedStar deposit',
|
17
|
-
message: 'Make a deposit to RedStar'
|
18
|
-
)
|
19
|
-
end
|
20
|
-
|
21
|
-
before do
|
22
|
-
allow(CoinsPaid).to receive(:address).with(foreign_id, currency: currency).and_return(coins_paid_address)
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'it is known how to build payment url for the currency' do
|
26
|
-
let(:currency) { 'BTC' }
|
27
|
-
let(:url) { "bitcoin:#{address}?label=RedStar+deposit&message=Make+a+deposit+to+RedStar" }
|
28
|
-
|
29
|
-
describe '#url' do
|
30
|
-
its(:url) { is_expected.to eq url }
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#svg' do
|
34
|
-
it 'encodes payment url' do
|
35
|
-
expect(RQRCode::QRCode).to receive(:new).with(url).and_call_original
|
36
|
-
qr_code.svg
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'it is not known how to build payment url for the currency' do
|
42
|
-
let(:currency) { 'BNB' }
|
43
|
-
|
44
|
-
describe '#url' do
|
45
|
-
its(:url) { is_expected.to be_nil }
|
46
|
-
end
|
47
|
-
|
48
|
-
describe '#svg' do
|
49
|
-
it 'encodes payment address' do
|
50
|
-
expect(RQRCode::QRCode).to receive(:new).with(address).and_call_original
|
51
|
-
qr_code.svg
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context '#address' do
|
57
|
-
its(:address) { is_expected.to eq coins_paid_address }
|
58
|
-
end
|
59
|
-
end
|