coins_paid_rails 1.1.7 → 1.3.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 +73 -74
- 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 +8 -10
- 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: 2a245456681db498181920344cd14e9535d73f722674653a102d5edac3528a4e
|
4
|
+
data.tar.gz: 942f6799a1ae1784ea09810617c637bafd0745feba909a53779de1e4230ae33d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebb41616c2ae9dfeee509b4c7cbcbd9589950ec0133974b118252081fa68662a2c9c10c8c5c2ea34b946a6b00f3d094e56a1a848dde062f09f07c681ed5aef79
|
7
|
+
data.tar.gz: c08a4d7d308e02fc81d547aa1361da7cbd48bd3cb1801af8890be00218eb3f01e415cfdd3b7ffe100620198c22485f3789c345ccb0a532827b4f3ad4d8bad67c
|
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,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
coins_paid_rails (1.
|
5
|
-
activerecord (
|
4
|
+
coins_paid_rails (1.3.0)
|
5
|
+
activerecord (~> 6.1.4)
|
6
6
|
coins_paid_api (~> 1.0)
|
7
7
|
dry-initializer (~> 3.0)
|
8
8
|
dry-struct (~> 1.0)
|
@@ -10,51 +10,50 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: http://www.rubygems.org/
|
12
12
|
specs:
|
13
|
-
actionpack (
|
14
|
-
actionview (=
|
15
|
-
activesupport (=
|
16
|
-
rack (~> 2.0, >= 2.0.
|
13
|
+
actionpack (6.1.5)
|
14
|
+
actionview (= 6.1.5)
|
15
|
+
activesupport (= 6.1.5)
|
16
|
+
rack (~> 2.0, >= 2.0.9)
|
17
17
|
rack-test (>= 0.6.3)
|
18
18
|
rails-dom-testing (~> 2.0)
|
19
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
20
|
-
actionview (
|
21
|
-
activesupport (=
|
19
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
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
|
-
rails-html-sanitizer (~> 1.
|
26
|
-
activemodel (
|
27
|
-
activesupport (=
|
28
|
-
activerecord (
|
29
|
-
activemodel (=
|
30
|
-
activesupport (=
|
31
|
-
|
32
|
-
activesupport (5.2.4.4)
|
25
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
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)
|
33
32
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
34
|
-
i18n (>=
|
35
|
-
minitest (
|
36
|
-
tzinfo (~>
|
37
|
-
|
33
|
+
i18n (>= 1.6, < 2)
|
34
|
+
minitest (>= 5.1)
|
35
|
+
tzinfo (~> 2.0)
|
36
|
+
zeitwerk (~> 2.3)
|
38
37
|
builder (3.2.4)
|
39
38
|
chunky_png (1.4.0)
|
40
|
-
coins_paid_api (1.0
|
39
|
+
coins_paid_api (1.1.0)
|
41
40
|
dry-struct (~> 1.0)
|
42
41
|
faraday (~> 0.12)
|
43
42
|
faraday_middleware (~> 0.11)
|
44
|
-
concurrent-ruby (1.1.
|
43
|
+
concurrent-ruby (1.1.10)
|
45
44
|
crass (1.0.6)
|
46
|
-
diff-lcs (1.
|
47
|
-
docile (1.
|
48
|
-
dry-configurable (0.
|
45
|
+
diff-lcs (1.5.0)
|
46
|
+
docile (1.4.0)
|
47
|
+
dry-configurable (0.14.0)
|
49
48
|
concurrent-ruby (~> 1.0)
|
50
|
-
dry-core (~> 0.
|
51
|
-
dry-container (0.
|
49
|
+
dry-core (~> 0.6)
|
50
|
+
dry-container (0.9.0)
|
52
51
|
concurrent-ruby (~> 1.0)
|
53
|
-
dry-configurable (~> 0.
|
54
|
-
dry-core (0.
|
52
|
+
dry-configurable (~> 0.13, >= 0.13.0)
|
53
|
+
dry-core (0.7.1)
|
55
54
|
concurrent-ruby (~> 1.0)
|
56
|
-
dry-inflector (0.2.
|
57
|
-
dry-initializer (3.
|
55
|
+
dry-inflector (0.2.1)
|
56
|
+
dry-initializer (3.1.1)
|
58
57
|
dry-logic (1.2.0)
|
59
58
|
concurrent-ruby (~> 1.0)
|
60
59
|
dry-core (~> 0.5, >= 0.5)
|
@@ -69,74 +68,74 @@ GEM
|
|
69
68
|
dry-inflector (~> 0.1, >= 0.1.2)
|
70
69
|
dry-logic (~> 1.0, >= 1.0.2)
|
71
70
|
erubi (1.10.0)
|
72
|
-
faraday (0.17.
|
71
|
+
faraday (0.17.5)
|
73
72
|
multipart-post (>= 1.2, < 3)
|
74
73
|
faraday_middleware (0.14.0)
|
75
74
|
faraday (>= 0.7.4, < 1.0)
|
76
|
-
i18n (1.
|
75
|
+
i18n (1.10.0)
|
77
76
|
concurrent-ruby (~> 1.0)
|
78
77
|
ice_nine (0.11.2)
|
79
|
-
|
80
|
-
loofah (2.8.0)
|
78
|
+
loofah (2.15.0)
|
81
79
|
crass (~> 1.0.2)
|
82
80
|
nokogiri (>= 1.5.9)
|
83
81
|
method_source (1.0.0)
|
84
|
-
mini_portile2 (2.
|
85
|
-
minitest (5.
|
82
|
+
mini_portile2 (2.8.0)
|
83
|
+
minitest (5.15.0)
|
86
84
|
multipart-post (2.1.1)
|
87
|
-
nokogiri (1.
|
88
|
-
mini_portile2 (~> 2.
|
85
|
+
nokogiri (1.13.3)
|
86
|
+
mini_portile2 (~> 2.8.0)
|
89
87
|
racc (~> 1.4)
|
90
|
-
racc (1.
|
88
|
+
racc (1.6.0)
|
91
89
|
rack (2.2.3)
|
92
90
|
rack-test (1.1.0)
|
93
91
|
rack (>= 1.0, < 3)
|
94
92
|
rails-dom-testing (2.0.3)
|
95
93
|
activesupport (>= 4.2.0)
|
96
94
|
nokogiri (>= 1.6)
|
97
|
-
rails-html-sanitizer (1.
|
95
|
+
rails-html-sanitizer (1.4.2)
|
98
96
|
loofah (~> 2.3)
|
99
|
-
railties (
|
100
|
-
actionpack (=
|
101
|
-
activesupport (=
|
97
|
+
railties (6.1.5)
|
98
|
+
actionpack (= 6.1.5)
|
99
|
+
activesupport (= 6.1.5)
|
102
100
|
method_source
|
103
|
-
rake (>=
|
104
|
-
thor (
|
105
|
-
rake (13.0.
|
106
|
-
rqrcode (2.1.
|
101
|
+
rake (>= 12.2)
|
102
|
+
thor (~> 1.0)
|
103
|
+
rake (13.0.6)
|
104
|
+
rqrcode (2.1.1)
|
107
105
|
chunky_png (~> 1.0)
|
108
106
|
rqrcode_core (~> 1.0)
|
109
107
|
rqrcode_core (1.2.0)
|
110
|
-
rspec-core (3.
|
111
|
-
rspec-support (~> 3.
|
112
|
-
rspec-expectations (3.
|
108
|
+
rspec-core (3.11.0)
|
109
|
+
rspec-support (~> 3.11.0)
|
110
|
+
rspec-expectations (3.11.0)
|
113
111
|
diff-lcs (>= 1.2.0, < 2.0)
|
114
|
-
rspec-support (~> 3.
|
112
|
+
rspec-support (~> 3.11.0)
|
115
113
|
rspec-its (1.3.0)
|
116
114
|
rspec-core (>= 3.0.0)
|
117
115
|
rspec-expectations (>= 3.0.0)
|
118
|
-
rspec-mocks (3.
|
116
|
+
rspec-mocks (3.11.0)
|
119
117
|
diff-lcs (>= 1.2.0, < 2.0)
|
120
|
-
rspec-support (~> 3.
|
121
|
-
rspec-rails (
|
122
|
-
actionpack (>=
|
123
|
-
activesupport (>=
|
124
|
-
railties (>=
|
125
|
-
rspec-core (~> 3.
|
126
|
-
rspec-expectations (~> 3.
|
127
|
-
rspec-mocks (~> 3.
|
128
|
-
rspec-support (~> 3.
|
129
|
-
rspec-support (3.
|
130
|
-
simplecov (0.
|
131
|
-
docile (~> 1.1
|
132
|
-
|
133
|
-
|
134
|
-
simplecov-html (0.
|
118
|
+
rspec-support (~> 3.11.0)
|
119
|
+
rspec-rails (5.1.1)
|
120
|
+
actionpack (>= 5.2)
|
121
|
+
activesupport (>= 5.2)
|
122
|
+
railties (>= 5.2)
|
123
|
+
rspec-core (~> 3.10)
|
124
|
+
rspec-expectations (~> 3.10)
|
125
|
+
rspec-mocks (~> 3.10)
|
126
|
+
rspec-support (~> 3.10)
|
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)
|
135
134
|
sqlite3 (1.4.2)
|
136
|
-
thor (1.
|
137
|
-
|
138
|
-
|
139
|
-
|
135
|
+
thor (1.2.1)
|
136
|
+
tzinfo (2.0.4)
|
137
|
+
concurrent-ruby (~> 1.0)
|
138
|
+
zeitwerk (2.5.4)
|
140
139
|
|
141
140
|
PLATFORMS
|
142
141
|
ruby
|
@@ -150,4 +149,4 @@ DEPENDENCIES
|
|
150
149
|
sqlite3
|
151
150
|
|
152
151
|
BUNDLED WITH
|
153
|
-
|
152
|
+
2.2.32
|
data/coins_paid_rails.gemspec
CHANGED
@@ -1,13 +1,13 @@
|
|
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.3.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
9
|
s.add_runtime_dependency 'coins_paid_api', '~> 1.0'
|
10
|
-
s.add_runtime_dependency 'activerecord', '
|
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'
|
13
13
|
s.add_development_dependency 'rspec-rails'
|
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,7 +1,7 @@
|
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Biserov(artembiserov)
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-03-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: coins_paid_api
|
@@ -29,16 +29,16 @@ dependencies:
|
|
29
29
|
name: activerecord
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 6.1.4
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 6.1.4
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: dry-initializer
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- ".circleci/config.yml"
|
91
91
|
- ".gitignore"
|
92
92
|
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
93
94
|
- ".ruby-version"
|
94
95
|
- Gemfile
|
95
96
|
- Gemfile.lock
|
@@ -97,7 +98,6 @@ files:
|
|
97
98
|
- lib/coins_paid.rb
|
98
99
|
- lib/coins_paid/address.rb
|
99
100
|
- lib/coins_paid/coins_paid_address.rb
|
100
|
-
- lib/coins_paid/qr_code.rb
|
101
101
|
- lib/coins_paid_rails.rb
|
102
102
|
- lib/generators/coins_paid/migration_data.rb
|
103
103
|
- lib/generators/coins_paid/migration_generator.rb
|
@@ -105,7 +105,6 @@ files:
|
|
105
105
|
- spec/address_spec.rb
|
106
106
|
- spec/currency_spec.rb
|
107
107
|
- spec/issued_addresses_spec.rb
|
108
|
-
- spec/qr_code_spec.rb
|
109
108
|
- spec/spec_helper.rb
|
110
109
|
- spec/support/database/create_table.rb
|
111
110
|
homepage:
|
@@ -127,8 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
126
|
- !ruby/object:Gem::Version
|
128
127
|
version: '0'
|
129
128
|
requirements: []
|
130
|
-
|
131
|
-
rubygems_version: 2.7.6
|
129
|
+
rubygems_version: 3.1.6
|
132
130
|
signing_key:
|
133
131
|
specification_version: 4
|
134
132
|
summary: CoinsPaid Rails Integration
|
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
|