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 +4 -4
- data/README.md +1 -1
- data/Rakefile +4 -2
- data/bin/console +0 -1
- data/cryptocoin_payable.gemspec +1 -1
- data/features/support/env.rb +0 -2
- data/lib/cryptocoin_payable/adapters/base.rb +4 -0
- data/lib/cryptocoin_payable/adapters/bitcoin.rb +7 -4
- data/lib/cryptocoin_payable/adapters/ethereum.rb +0 -1
- data/lib/cryptocoin_payable/orm/activerecord.rb +14 -0
- data/lib/cryptocoin_payable/version.rb +1 -1
- data/lib/cryptocoin_payable.rb +19 -13
- data/lib/tasks/delete_currency_conversions.rake +6 -0
- data/lib/tasks/process_payments.rake +6 -0
- data/lib/tasks/process_prices.rake +6 -0
- data/spec/dummy/config/application.rb +1 -0
- data/spec/dummy/config/initializers/state_machine.rb +2 -0
- data/spec/spec_helper.rb +1 -0
- metadata +20 -18
- data/lib/cryptocoin_payable/has_coin_payments.rb +0 -15
- data/lib/cryptocoin_payable/tasks.rb +0 -20
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7b465403012fd6c2c62f916507601f6a461ec9f6
         | 
| 4 | 
            +
              data.tar.gz: 660aabdd9e68754853025ca889b5a503b01b0a12
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 4616fb4173f7ffbfd1893cbc6546b5a69bdd1ee823f9af4b3a8497fa9fd4e987d4b350e4fd427a7c236197bd2f6c723058d687f20bf9b770ef44f1703cda420d
         | 
| 7 | 
            +
              data.tar.gz: 1903bffd04558bf5b732547e4be3492c9198b587fe068ba701c5300393b48faa86919238b3973755133dfdca8dfcdd46fe81a04c4f8bf18ffe05b677774744f2
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,5 +1,5 @@ | |
| 1 1 | 
             
            [](https://badge.fury.io/rb/cryptocoin_payable)
         | 
| 2 | 
            -
            [](https://travis-ci.com/Sailias/cryptocoin_payable)
         | 
| 3 3 |  | 
| 4 4 | 
             
            # Cryptocoin Payable
         | 
| 5 5 |  | 
    
        data/Rakefile
    CHANGED
    
    
    
        data/bin/console
    CHANGED
    
    
    
        data/cryptocoin_payable.gemspec
    CHANGED
    
    | @@ -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
         | 
    
        data/features/support/env.rb
    CHANGED
    
    
| @@ -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 | 
            -
                      . | 
| 36 | 
            -
                      . | 
| 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:  | 
| 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 | 
            -
                      . | 
| 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
         | 
    
        data/lib/cryptocoin_payable.rb
    CHANGED
    
    | @@ -1,18 +1,24 @@ | |
| 1 | 
            -
             | 
| 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
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        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. | 
| 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- | 
| 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/ | 
| 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
         |