cryptocoin_payable 1.1.0 → 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
  SHA1:
3
- metadata.gz: 88f7a3d37e5fea6dfc2e08eec657a47c1c21e300
4
- data.tar.gz: e17ae020453e6ccb0fff510f33dd11752f1869c9
3
+ metadata.gz: 7b465403012fd6c2c62f916507601f6a461ec9f6
4
+ data.tar.gz: 660aabdd9e68754853025ca889b5a503b01b0a12
5
5
  SHA512:
6
- metadata.gz: ddcf94b0a53ea8dd77207c4d2827ca277bbd8e952b68bbb41b55ffa31849ff4167b4f2e6d6321ad811c506a0be13ca091e4cb546d02d93f32df13e2987077f5a
7
- data.tar.gz: 1dfe1240bc30c549041c6664785860320330dc1f179408b4383beca9fd4f466efaa225aaa9c644b4eef0900559eae69b8373be05150f7e2e2ba659872333027c
6
+ metadata.gz: 4616fb4173f7ffbfd1893cbc6546b5a69bdd1ee823f9af4b3a8497fa9fd4e987d4b350e4fd427a7c236197bd2f6c723058d687f20bf9b770ef44f1703cda420d
7
+ data.tar.gz: 1903bffd04558bf5b732547e4be3492c9198b587fe068ba701c5300393b48faa86919238b3973755133dfdca8dfcdd46fe81a04c4f8bf18ffe05b677774744f2
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/cryptocoin_payable.svg)](https://badge.fury.io/rb/cryptocoin_payable)
2
- [![Build Status](https://travis-ci.com/mhluska/cryptocoin_payable.svg?branch=master)](https://travis-ci.com/mhluska/cryptocoin_payable)
2
+ [![Build Status](https://travis-ci.com/Sailias/cryptocoin_payable.svg?branch=master)](https://travis-ci.com/Sailias/cryptocoin_payable)
3
3
 
4
4
  # Cryptocoin Payable
5
5
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
1
  require 'bundler/gem_tasks'
2
- require 'rake'
3
- require 'cryptocoin_payable/tasks'
2
+
3
+ import './lib/tasks/delete_currency_conversions.rake'
4
+ import './lib/tasks/process_payments.rake'
5
+ import './lib/tasks/process_prices.rake'
data/bin/console CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
- require 'active_record'
5
4
  require 'cryptocoin_payable'
6
5
 
7
6
  # You can add fixtures and/or initialization code here to make experimenting
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'bundler', '~> 1.15'
25
25
  spec.add_development_dependency 'cucumber', '~> 3.1'
26
26
  spec.add_development_dependency 'database_cleaner', '~> 1.7'
27
+ spec.add_development_dependency 'rails', '>= 4.0.0'
27
28
  spec.add_development_dependency 'rake', '~> 12.3'
28
29
  spec.add_development_dependency 'rspec-rails', '~> 3.7'
29
30
  spec.add_development_dependency 'rubocop', '~> 0.59'
@@ -34,7 +35,6 @@ Gem::Specification.new do |spec|
34
35
  spec.add_dependency 'cash-addr', '~> 0.2'
35
36
  spec.add_dependency 'eth', '0.4.8'
36
37
  spec.add_dependency 'money-tree', '0.10.0'
37
- spec.add_dependency 'rails'
38
38
  spec.add_dependency 'state_machine', '~> 1.2'
39
39
  end
40
40
  # rubocop:enable Metrics/BlockLength
@@ -1,6 +1,4 @@
1
1
  ENV['RAILS_ENV'] ||= 'test'
2
- require File.expand_path('../../spec/dummy/config/environment.rb', __dir__)
3
-
4
2
  ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '../../../spec/dummy'
5
3
 
6
4
  require 'cucumber/rails'
@@ -72,6 +72,10 @@ module CryptocoinPayable
72
72
  @coin_config ||= CryptocoinPayable.configuration.send(self.class.coin_symbol.downcase)
73
73
  end
74
74
 
75
+ def api_adapter_key
76
+ @api_adapter_key ||= coin_config && coin_config.api_adapter_key
77
+ end
78
+
75
79
  def parse_timestamp(timestamp)
76
80
  timestamp.nil? ? nil : DateTime.strptime(timestamp.to_s, '%s')
77
81
  end
@@ -32,8 +32,10 @@ module CryptocoinPayable
32
32
 
33
33
  def parse_total_tx_value_block_explorer(output_transactions, address)
34
34
  output_transactions
35
- .select { |out| out['scriptPubKey']['addresses'].try('include?', address) }
36
- .sum { |out| (out['value'].to_f * self.class.subunit_in_main).to_i }
35
+ .reject { |out| out['scriptPubKey']['addresses'].nil? }
36
+ .select { |out| out['scriptPubKey']['addresses'].include?(address) }
37
+ .map { |out| (out['value'].to_f * self.class.subunit_in_main).to_i }
38
+ .inject(:+)
37
39
  end
38
40
 
39
41
  def fetch_block_explorer_transactions(address)
@@ -52,7 +54,7 @@ module CryptocoinPayable
52
54
  {
53
55
  tx_hash: transaction['txid'],
54
56
  block_hash: transaction['blockhash'],
55
- block_time: transaction['blocktime'].nil? ? nil : parse_timestamp(transaction['blocktime']),
57
+ block_time: parse_timestamp(transaction['blocktime']),
56
58
  estimated_tx_time: parse_timestamp(transaction['time']),
57
59
  estimated_tx_value: parse_total_tx_value_block_explorer(transaction['vout'], address),
58
60
  confirmations: transaction['confirmations']
@@ -61,7 +63,8 @@ module CryptocoinPayable
61
63
 
62
64
  def parse_total_tx_value_block_cypher(output_transactions, address)
63
65
  output_transactions
64
- .sum { |out| out['addresses'].join.eql?(address) ? out['value'] : 0 }
66
+ .map { |out| out['addresses'].join.eql?(address) ? out['value'] : 0 }
67
+ .inject(:+)
65
68
  end
66
69
 
67
70
  def fetch_block_cypher_transactions(address)
@@ -13,7 +13,6 @@ module CryptocoinPayable
13
13
  end
14
14
 
15
15
  def fetch_transactions(address)
16
- api_adapter_key = coin_config.try(:adapter_api_key)
17
16
  url = "https://#{subdomain}.etherscan.io/api?module=account&action=txlist&address=#{address}&tag=latest"
18
17
  url += '?apiKey=' + api_adapter_key if api_adapter_key
19
18
 
@@ -0,0 +1,14 @@
1
+ require 'active_record'
2
+ require 'cryptocoin_payable/coin_payment_transaction'
3
+ require 'cryptocoin_payable/coin_payment'
4
+ require 'cryptocoin_payable/currency_conversion'
5
+ require 'cryptocoin_payable/commands/pricing_processor'
6
+ require 'cryptocoin_payable/commands/payment_processor'
7
+
8
+ module ActiveRecord
9
+ class Base
10
+ def self.has_coin_payments # rubocop:disable Naming/PredicateName
11
+ has_many :coin_payments, class_name: 'CryptocoinPayable::CoinPayment', as: 'payable'
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module CryptocoinPayable
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
@@ -1,18 +1,24 @@
1
- require 'net/http'
1
+ module CryptocoinPayable
2
+ end
3
+
4
+ if defined?(Rails)
5
+ module CryptocoinPayable
6
+ class Railtie < Rails::Railtie
7
+ initializer 'cryptocoin_payable.active_record' do
8
+ ActiveSupport.on_load(:active_record) do
9
+ require 'cryptocoin_payable/orm/activerecord'
10
+ end
11
+ end
12
+
13
+ rake_tasks do
14
+ path = File.expand_path(__dir__)
15
+ Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
16
+ end
17
+ end
18
+ end
19
+ end
2
20
 
3
21
  require 'cryptocoin_payable/config'
4
22
  require 'cryptocoin_payable/errors'
5
23
  require 'cryptocoin_payable/version'
6
- require 'cryptocoin_payable/has_coin_payments'
7
- require 'cryptocoin_payable/tasks'
8
24
  require 'cryptocoin_payable/adapters'
9
- require 'cryptocoin_payable/coin_payment_transaction'
10
- require 'cryptocoin_payable/coin_payment'
11
- require 'cryptocoin_payable/currency_conversion'
12
-
13
- module CryptocoinPayable
14
- end
15
-
16
- ActiveSupport.on_load(:active_record) do
17
- include CryptocoinPayable::Model
18
- end
@@ -0,0 +1,6 @@
1
+ namespace :cryptocoin_payable do
2
+ desc 'Delete old CurrencyConversion data (will delete last month by default)'
3
+ task delete_currency_conversions: :environment do
4
+ CryptocoinPayable::PricingProcessor.delete_currency_conversions(ENV['DELETE_BEFORE'])
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ namespace :cryptocoin_payable do
2
+ desc 'Get transactions from external API and process payments'
3
+ task process_payments: :environment do
4
+ CryptocoinPayable::PaymentProcessor.perform
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ namespace :cryptocoin_payable do
2
+ desc 'Process the prices and update the payments'
3
+ task process_prices: :environment do
4
+ CryptocoinPayable::PricingProcessor.perform
5
+ end
6
+ end
@@ -3,6 +3,7 @@ require File.expand_path('boot', __dir__)
3
3
  require 'rails/all'
4
4
 
5
5
  Bundler.require(*Rails.groups)
6
+
6
7
  require 'cryptocoin_payable'
7
8
 
8
9
  module Dummy
@@ -1,3 +1,5 @@
1
+ require 'state_machine'
2
+
1
3
  module StateMachine
2
4
  module Integrations
3
5
  module ActiveModel
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'vcr'
2
2
  require 'webmock/rspec'
3
+ require 'active_support/time'
3
4
 
4
5
  VCR.configure do |config|
5
6
  config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryptocoin_payable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Salis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-10-14 00:00:00.000000000 Z
12
+ date: 2018-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -67,6 +67,20 @@ dependencies:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '1.7'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rails
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 4.0.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 4.0.0
70
84
  - !ruby/object:Gem::Dependency
71
85
  name: rake
72
86
  requirement: !ruby/object:Gem::Requirement
@@ -193,20 +207,6 @@ dependencies:
193
207
  - - '='
194
208
  - !ruby/object:Gem::Version
195
209
  version: 0.10.0
196
- - !ruby/object:Gem::Dependency
197
- name: rails
198
- requirement: !ruby/object:Gem::Requirement
199
- requirements:
200
- - - ">="
201
- - !ruby/object:Gem::Version
202
- version: '0'
203
- type: :runtime
204
- prerelease: false
205
- version_requirements: !ruby/object:Gem::Requirement
206
- requirements:
207
- - - ">="
208
- - !ruby/object:Gem::Version
209
- version: '0'
210
210
  - !ruby/object:Gem::Dependency
211
211
  name: state_machine
212
212
  requirement: !ruby/object:Gem::Requirement
@@ -264,13 +264,15 @@ files:
264
264
  - lib/cryptocoin_payable/config.rb
265
265
  - lib/cryptocoin_payable/currency_conversion.rb
266
266
  - lib/cryptocoin_payable/errors.rb
267
- - lib/cryptocoin_payable/has_coin_payments.rb
268
- - lib/cryptocoin_payable/tasks.rb
267
+ - lib/cryptocoin_payable/orm/activerecord.rb
269
268
  - lib/cryptocoin_payable/version.rb
270
269
  - lib/generators/cryptocoin_payable/install_generator.rb
271
270
  - lib/generators/cryptocoin_payable/templates/create_coin_payment_transactions.rb
272
271
  - lib/generators/cryptocoin_payable/templates/create_coin_payments.rb
273
272
  - lib/generators/cryptocoin_payable/templates/create_currency_conversions.rb
273
+ - lib/tasks/delete_currency_conversions.rake
274
+ - lib/tasks/process_payments.rake
275
+ - lib/tasks/process_prices.rake
274
276
  - spec/acceptance/adapters/bitcoin_cash_spec.rb
275
277
  - spec/acceptance/adapters/bitcoin_spec.rb
276
278
  - spec/acceptance/adapters/ethereum_spec.rb
@@ -1,15 +0,0 @@
1
- module CryptocoinPayable
2
- module Model
3
- def self.included(base)
4
- base.send :extend, ClassMethods
5
- end
6
-
7
- module ClassMethods
8
- def has_coin_payments(_options = {}) # rubocop:disable Naming/PredicateName
9
- has_many :coin_payments, -> { order(:id) },
10
- class_name: 'CryptocoinPayable::CoinPayment',
11
- as: 'payable'
12
- end
13
- end
14
- end
15
- end
@@ -1,20 +0,0 @@
1
- require 'rake'
2
- require 'cryptocoin_payable/commands/pricing_processor'
3
- require 'cryptocoin_payable/commands/payment_processor'
4
-
5
- namespace :cryptocoin_payable do
6
- desc 'Process the prices and update the payments'
7
- task process_prices: :environment do
8
- CryptocoinPayable::PricingProcessor.perform
9
- end
10
-
11
- desc 'Delete old CurrencyConversion data (will delete last month by default)'
12
- task delete_currency_conversions: :environment do
13
- CryptocoinPayable::PricingProcessor.delete_currency_conversions(ENV['DELETE_BEFORE'])
14
- end
15
-
16
- desc 'Get transactions from external API and process payments'
17
- task process_payments: :environment do
18
- CryptocoinPayable::PaymentProcessor.perform
19
- end
20
- end