From 03ccaf5856bcd152aa332c7a26e432edafa427d8 Mon Sep 17 00:00:00 2001 From: Stephane Bounmy <159814+sbounmy@users.noreply.github.com> Date: Wed, 29 Nov 2023 16:57:06 +0100 Subject: [PATCH 1/6] Compatible with Rails 7 and Ruby 3 (now need to refactor to work with eth 0.5.X) Dockerized gem --- .env | 0 .gitignore | 2 + Dockerfile | 15 ++++++++ README.md | 12 ++++-- cryptocoin_payable.gemspec | 10 ++--- docker-compose.yml | 37 +++++++++++++++++++ lib/cryptocoin_payable/config.rb | 4 -- spec/dummy/config/database.yml | 2 + spec/dummy/config/environments/development.rb | 2 +- spec/spec_helper.rb | 4 +- 10 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 .env create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.env b/.env new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore index d106371..f482aff 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ spec/dummy/log/* *.gem /Gemfile.lock /spec/dummy/log/development.log +tmp/ +.idea \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fa30faa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM ruby:3.2.2-bullseye + +RUN apt update -qq && apt install -y libpq-dev dh-autoreconf + +RUN gem update --system && gem install foreman + +WORKDIR /gem +ADD . /gem +RUN bundle install +VOLUME .:/gem/ + +ARG DEFAULT_PORT 3001 +EXPOSE 3001 + +#CMD ["bin/dev"] \ No newline at end of file diff --git a/README.md b/README.md index d7fde95..8e12df5 100644 --- a/README.md +++ b/README.md @@ -57,12 +57,18 @@ bundle exec rake cryptocoin_payable:process_prices (see below) rails d cryptocoin_payable:install ``` +## Build Docker +``` +docker-compose up --build +``` + ## Run Tests + ```sh -cucumber features -rspec -rubocop +docker-compose run web features +docker-compose run web rspec +docker-compose run web rubocop ``` ## Usage diff --git a/cryptocoin_payable.gemspec b/cryptocoin_payable.gemspec index 80c1995..31e61e9 100644 --- a/cryptocoin_payable.gemspec +++ b/cryptocoin_payable.gemspec @@ -20,13 +20,13 @@ Gem::Specification.new do |spec| spec.required_rubygems_version = '>= 1.3.6' spec.required_ruby_version = '>= 2.2.0' - spec.add_development_dependency 'bundler', '~> 1.15' + spec.add_development_dependency 'bundler', '~> 2.4' spec.add_development_dependency 'cucumber' spec.add_development_dependency 'cucumber-rails' spec.add_development_dependency 'database_cleaner', '~> 1.7' - spec.add_development_dependency 'pg', '~> 0.21.0' + spec.add_development_dependency 'pg', '~> 1.5.4' spec.add_development_dependency 'rails', '>= 4.0.0' - spec.add_development_dependency 'rake', '~> 12.3' + spec.add_development_dependency 'rake', '~> 13' spec.add_development_dependency 'rspec-benchmark', '~> 0.4' spec.add_development_dependency 'rspec-rails', '~> 3.7' spec.add_development_dependency 'rspec-retry', '~> 0.6' @@ -35,9 +35,9 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'vcr', '~> 4.0' spec.add_development_dependency 'webmock', '~> 3.4' - spec.add_dependency 'activerecord-import', '~> 0.27' + spec.add_dependency 'activerecord-import', '~> 1.5' spec.add_dependency 'cash-addr', '~> 0.2' - spec.add_dependency 'eth', '0.4.8' + spec.add_dependency 'eth', '0.5.11' spec.add_dependency 'money-tree', '0.10.0' spec.add_dependency 'state_machines-activerecord', '~> 0.5' end diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d699d67 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +version: '3.4' +services: + web: + build: . + command: /bin/bash -c "cd spec/dummy; rm -f /tmp/server.pid && bundle exec rails server -b 0.0.0.0 -p 3001 -P /tmp/server.pid" + env_file: .env + ports: + - 3001:3001 + depends_on: + - db + - redis + volumes: + - .:/gem + - ruby-bundle-cache:/bundle + tty: true + stdin_open: true + + redis: + image: "redis:7-alpine" + ports: + - 6379 + volumes: + - ./tmp/redis_data:/var/lib/redis/data + + db: + image: postgres + environment: + POSTGRES_HOST_AUTH_METHOD: trust + restart: always + ports: + - 5433:5433 + volumes: + - ./tmp/postgres_data:/var/lib/postgresql/data + +volumes: + ruby-bundle-cache: + external: true \ No newline at end of file diff --git a/lib/cryptocoin_payable/config.rb b/lib/cryptocoin_payable/config.rb index 4f2c5cc..1299fc9 100644 --- a/lib/cryptocoin_payable/config.rb +++ b/lib/cryptocoin_payable/config.rb @@ -29,10 +29,6 @@ def configure_bch def configure_eth @eth ||= EthConfiguration.new yield(@eth) - - Eth.configure do |config| - config.chain_id = CryptocoinPayable.configuration.testnet ? 4 : 1 - end end class CoinConfiguration diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml index 99670cd..f0f8e52 100644 --- a/spec/dummy/config/database.yml +++ b/spec/dummy/config/database.yml @@ -1,5 +1,7 @@ test: adapter: postgresql + host: db encoding: unicode pool: 5 database: cryptocoin_payable_test + username: postgres \ No newline at end of file diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb index 9d26e12..7fae617 100644 --- a/spec/dummy/config/environments/development.rb +++ b/spec/dummy/config/environments/development.rb @@ -25,5 +25,5 @@ # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. - config.assets.debug = true + # config.assets.debug = true end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 491c77e..ebf336b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ require 'vcr' require 'webmock/rspec' -require 'active_support/time' +# require 'active_support/time' require 'rspec-benchmark' require 'rspec/retry' @@ -14,6 +14,7 @@ def create_tables ENV['RAILS_ENV'] = 'test' + require_relative 'dummy/config/environment' load 'spec/dummy/db/schema.rb' end @@ -105,7 +106,6 @@ def drop_tables end end - ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'cryptocoin_payable_test') create_tables CryptocoinPayable::CurrencyConversion.coin_types.keys.each do |coin_type| From ca029bc64660797c09ed86c5fff770884aad4526 Mon Sep 17 00:00:00 2001 From: Stephane Bounmy <159814+sbounmy@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:00:30 +0100 Subject: [PATCH 2/6] fixed specs for ethereum adapter (replaced rinknedby by sepolia testnet Using 2 wallets for testing purpose: - 0xf1f9b3c18Ff048B36A51EA0261b99e8fD10C8Cb4 (no transactions) - 0xebB838Cdb3e3F628f50BF0EDaC1E92b208149984 (2 transactions) --- lib/cryptocoin_payable/adapters/ethereum.rb | 9 ++-- spec/acceptance/adapters/ethereum_spec.rb | 50 ++++++++----------- ...mpty_result_when_no_transactions_found.yml | 30 +++++++---- .../gets_transactions_for_a_given_address.yml | 33 +++++++----- ...rror_when_an_invalid_address_is_passed.yml | 33 +++++++----- 5 files changed, 87 insertions(+), 68 deletions(-) diff --git a/lib/cryptocoin_payable/adapters/ethereum.rb b/lib/cryptocoin_payable/adapters/ethereum.rb index d491b57..ae93895 100644 --- a/lib/cryptocoin_payable/adapters/ethereum.rb +++ b/lib/cryptocoin_payable/adapters/ethereum.rb @@ -25,13 +25,13 @@ def fetch_transactions(address) end def create_address(id) - Eth::Utils.public_key_to_address(super.public_key.uncompressed.to_hex) + Eth::Util.public_key_to_address(super.public_key.uncompressed.to_hex) end private def subdomain - @subdomain ||= CryptocoinPayable.configuration.testnet ? 'rinkeby' : 'api' + @subdomain ||= CryptocoinPayable.configuration.testnet ? 'api-sepolia' : 'api' end # Example response: @@ -64,10 +64,13 @@ def subdomain def convert_transactions(transaction, _address) { transaction_hash: transaction['hash'], - block_hash: transaction['block_hash'], + block_hash: transaction['blockHash'], block_time: nil, # Not supported estimated_time: parse_timestamp(transaction['timeStamp']), estimated_value: transaction['value'].to_i, # Units here are 'Wei' + gas: transaction['gas'].to_i, + gas_price: transaction['gasPrice'].to_i, + gas_used: transaction['gasUsed'].to_i, confirmations: transaction['confirmations'].to_i } end diff --git a/spec/acceptance/adapters/ethereum_spec.rb b/spec/acceptance/adapters/ethereum_spec.rb index 9b849aa..55526fc 100644 --- a/spec/acceptance/adapters/ethereum_spec.rb +++ b/spec/acceptance/adapters/ethereum_spec.rb @@ -6,43 +6,33 @@ def expect_transaction_result(response) expect(response).to match_array( [ { - transaction_hash: '0xa88b799514e9621962e3d0de25e7e0bc7a123e33085f322c7acdb99cc2585c6d', - block_hash: '0x752c50e426f65820f5bf6fd49acbb08d79464f8e7e8ea5b77e2299b69fd6398b', + transaction_hash: '0xeeadb31b3c646b74a8c1270626ab8e539d7a7e2369e98541f85f8a41cc4b49e9', + block_hash: '0x3cd7ca8c2b1a4d2df804538462676c7dde471654f45cb15476982a9b3d3845fe', block_time: nil, - estimated_time: be_within(1.day).of(Time.iso8601('2018-07-05T12:58:33.000000000+07:00')), - estimated_value: 33_753_640_000_000_000, - confirmations: 569_771 + estimated_time: be_within(1.day).of(Time.iso8601('2023-11-30T12:58:33.000000000+07:00')), + estimated_value: 51_504_000_000_000_000, + gas: 21_000, + gas_price: 2_166_305_619, + gas_used: 21_000, + confirmations: 22 }, { - transaction_hash: '0xb325a8cf241f332bca92c7f715987e4d34be9a6b3bb78d2425c83086b4aced26', - block_hash: '0x1c2b73a16fd8c4d25feeccaa2f0bf5c82b8f415f1beaf4d34aaf870daf89689d', + transaction_hash: '0x72579c512ac244134f890bd617fa28c576d52a81e275c68a15bd5eb180f396ae', + block_hash: '0x73b73bbbbaf3e9ffcb42b843e1948231bac0193e278225957f773ede3670fe44', block_time: nil, - estimated_time: be_within(1.day).of(Time.iso8601('2018-07-05T13:35:07.000000000+07:00')), - estimated_value: 2_190_144_444_444_444, - confirmations: 569_629 - }, - { - transaction_hash: '0xcd874917be5ad177e7ebd88b5c4a7d4283796e00e43345da5b63fb4f78130b37', - block_hash: '0x4ce71d11146445f123680ea9beba7db968b04dc675caddf60248c9d9d6f5739e', - block_time: nil, - estimated_time: be_within(1.day).of(Time.iso8601('2018-07-05T13:55:53.000000000+07:00')), - estimated_value: 1_007_518_888_888_888, - confirmations: 569_549 - }, - { - transaction_hash: '0x799ec2aaafbddbc2e746334f96f59f6127dec62e5693480576db351aaf840bfb', - block_hash: '0xc1361b19b2266e2259ac433b9e18b4fbc81339304988bbc62dd93aa24fac6449', - block_time: nil, - estimated_time: be_within(1.day).of(Time.iso8601('2018-08-26T16:05:44.000000000+07:00')), - estimated_value: 15_678_420_000_000_000, - confirmations: 261_969 + estimated_time: be_within(1.day).of(Time.iso8601('2023-11-30T13:35:07.000000000+07:00')), + estimated_value: 58_123_650_000_000_000, + gas: 21_000, + gas_price: 2_192_798_508, + gas_used: 21_000, + confirmations: 11 } ] ) end it 'gets transactions for a given address' do - response = subject.fetch_transactions('0xfc8cfb26c31931572e65e450f7fa498bcc11651c') + response = subject.fetch_transactions('0xebB838Cdb3e3F628f50BF0EDaC1E92b208149984') expect_transaction_result(response) end @@ -57,9 +47,9 @@ def expect_transaction_result(response) it 'creates BIP32 addresses' do 3.times do - expect(subject.create_address(0)).to eq('0xcDe321aCfa5B779dCD174850C3FB6E5Ff15cDEAf') - expect(subject.create_address(1)).to eq('0x0CA6E0C53EEb559c0D8803076D4F02b72f0FAE9C') - expect(subject.create_address(2)).to eq('0xD87D2476c93411242778fe0ef6e758De19ed19E8') + expect(subject.create_address(0).to_s).to eq('0xcDe321aCfa5B779dCD174850C3FB6E5Ff15cDEAf') + expect(subject.create_address(1).to_s).to eq('0x0CA6E0C53EEb559c0D8803076D4F02b72f0FAE9C') + expect(subject.create_address(2).to_s).to eq('0xD87D2476c93411242778fe0ef6e758De19ed19E8') end end end diff --git a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Ethereum/gets_an_empty_result_when_no_transactions_found.yml b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Ethereum/gets_an_empty_result_when_no_transactions_found.yml index b03b4b3..f50230c 100644 --- a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Ethereum/gets_an_empty_result_when_no_transactions_found.yml +++ b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Ethereum/gets_an_empty_result_when_no_transactions_found.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: https://api.etherscan.io/api?action=txlist&address=0x772fDD41BFB34C9903B253322baccdbE2C10851e&module=account&tag=latest + uri: https://api-sepolia.etherscan.io/api?action=txlist&address=0x772fDD41BFB34C9903B253322baccdbE2C10851e&module=account&tag=latest body: encoding: US-ASCII string: '' @@ -18,12 +18,16 @@ http_interactions: code: 200 message: OK headers: - Cache-Control: - - private + Date: + - Thu, 30 Nov 2023 09:24:26 GMT Content-Type: - application/json; charset=utf-8 - Server: - - Microsoft-IIS/10.0 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Cache-Control: + - private Access-Control-Allow-Origin: - "*" Access-Control-Allow-Headers: @@ -32,13 +36,17 @@ http_interactions: - GET, POST, OPTIONS X-Frame-Options: - SAMEORIGIN - Date: - - Thu, 11 Oct 2018 06:20:39 GMT - Content-Length: - - '60' + Cf-Cache-Status: + - DYNAMIC + Server: + - cloudflare + Cf-Ray: + - 82e2099258496ecc-CDG + Alt-Svc: + - h3=":443"; ma=86400 body: - encoding: UTF-8 + encoding: ASCII-8BIT string: '{"status":"0","message":"No transactions found","result":[]}' http_version: - recorded_at: Thu, 11 Oct 2018 06:20:56 GMT + recorded_at: Thu, 30 Nov 2023 09:24:26 GMT recorded_with: VCR 4.0.0 diff --git a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Ethereum/gets_transactions_for_a_given_address.yml b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Ethereum/gets_transactions_for_a_given_address.yml index a8dfcdf..7ba0f4d 100644 --- a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Ethereum/gets_transactions_for_a_given_address.yml +++ b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Ethereum/gets_transactions_for_a_given_address.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: https://api.etherscan.io/api?action=txlist&address=0xfc8cfb26c31931572e65e450f7fa498bcc11651c&module=account&tag=latest + uri: https://api-sepolia.etherscan.io/api?action=txlist&address=0xebB838Cdb3e3F628f50BF0EDaC1E92b208149984&module=account&tag=latest body: encoding: US-ASCII string: '' @@ -18,12 +18,16 @@ http_interactions: code: 200 message: OK headers: - Cache-Control: - - private + Date: + - Thu, 30 Nov 2023 09:33:43 GMT Content-Type: - application/json; charset=utf-8 - Server: - - Microsoft-IIS/10.0 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Cache-Control: + - private Access-Control-Allow-Origin: - "*" Access-Control-Allow-Headers: @@ -32,13 +36,18 @@ http_interactions: - GET, POST, OPTIONS X-Frame-Options: - SAMEORIGIN - Date: - - Mon, 08 Oct 2018 18:29:04 GMT - Content-Length: - - '2269' + Cf-Cache-Status: + - DYNAMIC + Server: + - cloudflare + Cf-Ray: + - 82e2172c0d0e02b9-CDG + Alt-Svc: + - h3=":443"; ma=86400 body: - encoding: UTF-8 - string: '{"status":"1","message":"OK","result":[{"blockNumber":"5908320","block_hash":"0x752c50e426f65820f5bf6fd49acbb08d79464f8e7e8ea5b77e2299b69fd6398b","timeStamp":"1530770313","hash":"0xa88b799514e9621962e3d0de25e7e0bc7a123e33085f322c7acdb99cc2585c6d","nonce":"342313","transactionIndex":"12","from":"0xeed16856d551569d134530ee3967ec79995e2051","to":"0xfc8cfb26c31931572e65e450f7fa498bcc11651c","value":"33753640000000000","gas":"50000","gasPrice":"93000000000","input":"0x","contractAddress":"","cumulativeGasUsed":"422633","txreceipt_status":"1","gasUsed":"21000","confirmations":"569771","isError":"0"},{"blockNumber":"5908462","block_hash":"0x1c2b73a16fd8c4d25feeccaa2f0bf5c82b8f415f1beaf4d34aaf870daf89689d","timeStamp":"1530772507","hash":"0xb325a8cf241f332bca92c7f715987e4d34be9a6b3bb78d2425c83086b4aced26","nonce":"0","transactionIndex":"36","from":"0xfc8cfb26c31931572e65e450f7fa498bcc11651c","to":"0x6e5eaac372b4abad8957d68af4f53bcf245c0100","value":"2190144444444444","gas":"21000","gasPrice":"43000000000","input":"0x","contractAddress":"","cumulativeGasUsed":"6094102","txreceipt_status":"1","gasUsed":"21000","confirmations":"569629","isError":"0"},{"blockNumber":"5908542","block_hash":"0x4ce71d11146445f123680ea9beba7db968b04dc675caddf60248c9d9d6f5739e","timeStamp":"1530773753","hash":"0xcd874917be5ad177e7ebd88b5c4a7d4283796e00e43345da5b63fb4f78130b37","nonce":"1","transactionIndex":"27","from":"0xfc8cfb26c31931572e65e450f7fa498bcc11651c","to":"0xa80de67c85669132f25678220b492c301217872e","value":"1007518888888888","gas":"21000","gasPrice":"49000000000","input":"0x","contractAddress":"","cumulativeGasUsed":"805592","txreceipt_status":"1","gasUsed":"21000","confirmations":"569549","isError":"0"},{"blockNumber":"6216122","block_hash":"0xc1361b19b2266e2259ac433b9e18b4fbc81339304988bbc62dd93aa24fac6449","timeStamp":"1535274344","hash":"0x799ec2aaafbddbc2e746334f96f59f6127dec62e5693480576db351aaf840bfb","nonce":"0","transactionIndex":"54","from":"0xd2b296fdf2eb4a441721b5a97dc2d9cca44f7a52","to":"0xfc8cfb26c31931572e65e450f7fa498bcc11651c","value":"15678420000000000","gas":"21000","gasPrice":"39000000000","input":"0x","contractAddress":"","cumulativeGasUsed":"7209675","txreceipt_status":"1","gasUsed":"21000","confirmations":"261969","isError":"0"}]}' + encoding: ASCII-8BIT + string: '{"status":"1","message":"OK-Missing/Invalid API Key, rate limit of + 1/5sec applied","result":[{"blockNumber":"4794460","timeStamp":"1701336480","hash":"0xeeadb31b3c646b74a8c1270626ab8e539d7a7e2369e98541f85f8a41cc4b49e9","nonce":"404240","blockHash":"0x3cd7ca8c2b1a4d2df804538462676c7dde471654f45cb15476982a9b3d3845fe","transactionIndex":"3","from":"0x6cc9397c3b38739dacbfaa68ead5f5d77ba5f455","to":"0xebb838cdb3e3f628f50bf0edac1e92b208149984","value":"51504000000000000","gas":"21000","gasPrice":"2166305619","isError":"0","txreceipt_status":"1","input":"0x","contractAddress":"","cumulativeGasUsed":"1155056","gasUsed":"21000","confirmations":"22","methodId":"0x","functionName":""},{"blockNumber":"4794471","timeStamp":"1701336660","hash":"0x72579c512ac244134f890bd617fa28c576d52a81e275c68a15bd5eb180f396ae","nonce":"404242","blockHash":"0x73b73bbbbaf3e9ffcb42b843e1948231bac0193e278225957f773ede3670fe44","transactionIndex":"29","from":"0x6cc9397c3b38739dacbfaa68ead5f5d77ba5f455","to":"0xebb838cdb3e3f628f50bf0edac1e92b208149984","value":"58123650000000000","gas":"21000","gasPrice":"2192798508","isError":"0","txreceipt_status":"1","input":"0x","contractAddress":"","cumulativeGasUsed":"24153119","gasUsed":"21000","confirmations":"11","methodId":"0x","functionName":""}]}' http_version: - recorded_at: Mon, 08 Oct 2018 18:29:13 GMT + recorded_at: Thu, 30 Nov 2023 09:33:43 GMT recorded_with: VCR 4.0.0 diff --git a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Ethereum/raises_an_error_when_an_invalid_address_is_passed.yml b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Ethereum/raises_an_error_when_an_invalid_address_is_passed.yml index ba5c2d6..3a85976 100644 --- a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Ethereum/raises_an_error_when_an_invalid_address_is_passed.yml +++ b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Ethereum/raises_an_error_when_an_invalid_address_is_passed.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: https://api.etherscan.io/api?action=txlist&address=foo&module=account&tag=latest + uri: https://api-sepolia.etherscan.io/api?action=txlist&address=foo&module=account&tag=latest body: encoding: US-ASCII string: '' @@ -18,12 +18,16 @@ http_interactions: code: 200 message: OK headers: - Cache-Control: - - private + Date: + - Thu, 30 Nov 2023 09:59:00 GMT Content-Type: - application/json; charset=utf-8 - Server: - - Microsoft-IIS/10.0 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Cache-Control: + - private Access-Control-Allow-Origin: - "*" Access-Control-Allow-Headers: @@ -32,13 +36,18 @@ http_interactions: - GET, POST, OPTIONS X-Frame-Options: - SAMEORIGIN - Date: - - Thu, 11 Oct 2018 06:23:53 GMT - Content-Length: - - '73' + Cf-Cache-Status: + - DYNAMIC + Server: + - cloudflare + Cf-Ray: + - 82e23c3158e7d68e-CDG + Alt-Svc: + - h3=":443"; ma=86400 body: - encoding: UTF-8 - string: '{"status":"0","message":"NOTOK","result":"Error! Invalid address format"}' + encoding: ASCII-8BIT + string: '{"status":"0","message":"NOTOK-Missing/Invalid API Key, rate limit + of 1/5sec applied","result":"Error! Invalid address format"}' http_version: - recorded_at: Thu, 11 Oct 2018 06:24:09 GMT + recorded_at: Thu, 30 Nov 2023 09:59:00 GMT recorded_with: VCR 4.0.0 From 93d4b91c376ceff0d00732bb9b8369dfdbb7ede0 Mon Sep 17 00:00:00 2001 From: Stephane Bounmy <159814+sbounmy@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:09:00 +0100 Subject: [PATCH 3/6] fix error message wording error --- lib/cryptocoin_payable/adapters/ethereum.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cryptocoin_payable/adapters/ethereum.rb b/lib/cryptocoin_payable/adapters/ethereum.rb index ae93895..ce4f5d9 100644 --- a/lib/cryptocoin_payable/adapters/ethereum.rb +++ b/lib/cryptocoin_payable/adapters/ethereum.rb @@ -19,7 +19,7 @@ def fetch_transactions(address) response = get_request(url) json = JSON.parse(response.body) - raise ApiError, json['message'] if json['status'] == '0' && json['message'] == 'NOTOK' + raise ApiError, json['message'] if json['status'] == '0' && json['message'].include?('NOTOK') json['result'].map { |tx| convert_transactions(tx, address) } end From fb9954957a562606f399f6f7729c9286f4f6f93f Mon Sep 17 00:00:00 2001 From: Stephane Bounmy <159814+sbounmy@users.noreply.github.com> Date: Tue, 5 Dec 2023 09:40:11 +0100 Subject: [PATCH 4/6] using blockstream instead of bitcoinexplorer does not return txs for an address added a logger configuration --- README.md | 3 + lib/cryptocoin_payable/adapters/base.rb | 5 + lib/cryptocoin_payable/adapters/bitcoin.rb | 48 +-- lib/cryptocoin_payable/config.rb | 6 +- spec/acceptance/adapters/bitcoin_spec.rb | 44 +-- spec/acceptance/adapters/ethereum_spec.rb | 3 - ...mpty_result_when_no_transactions_found.yml | 55 +-- .../gets_transactions_for_a_given_address.yml | 100 ++--- ...rror_when_an_invalid_address_is_passed.yml | 64 ++- ...ated_value_for_zero-value_transactions.yml | 96 +++-- ...alls_back_to_using_the_BlockCypher_API.yml | 0 ...alls_back_to_using_the_BlockCypher_API.yml | 369 ++++++++++++++++++ spec/spec_helper.rb | 2 + 13 files changed, 580 insertions(+), 215 deletions(-) create mode 100644 spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/when_the_BitcoinExplorer_API_fails/falls_back_to_using_the_BlockCypher_API.yml create mode 100644 spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/when_the_BlockSteam_API_fails/falls_back_to_using_the_BlockCypher_API.yml diff --git a/README.md b/README.md index 8e12df5..38aaa3d 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,9 @@ CryptocoinPayable.configure do |config| config.request_delay = 0.5 config.expire_payments_after = 15.minutes + # defaults to STDOUT + # config.logger = Rails.logger + config.configure_btc do |btc_config| # btc_config.confirmations = 3 # btc_config.node_path = '' diff --git a/lib/cryptocoin_payable/adapters/base.rb b/lib/cryptocoin_payable/adapters/base.rb index b95e2ed..55b964c 100644 --- a/lib/cryptocoin_payable/adapters/base.rb +++ b/lib/cryptocoin_payable/adapters/base.rb @@ -36,6 +36,10 @@ class Base # def self.create_address(id) # end + def logger + CryptocoinPayable.configuration.logger + end + def convert_subunit_to_main(subunit) subunit / self.class.subunit_in_main.to_f end @@ -76,6 +80,7 @@ def adapter_api_key @adapter_api_key ||= coin_config && coin_config.adapter_api_key end + def parse_timestamp(timestamp) timestamp.nil? ? nil : Time.strptime(timestamp.to_s, '%s') end diff --git a/lib/cryptocoin_payable/adapters/bitcoin.rb b/lib/cryptocoin_payable/adapters/bitcoin.rb index fdcdb18..43389e0 100644 --- a/lib/cryptocoin_payable/adapters/bitcoin.rb +++ b/lib/cryptocoin_payable/adapters/bitcoin.rb @@ -11,53 +11,57 @@ def self.coin_symbol end def fetch_transactions(address) - fetch_block_explorer_transactions(address) - rescue StandardError + fetch_blockstream_transactions(address) + rescue StandardError => e + logger.info "Blockstream API failed, falling back to BlockCypher #{e.message}" fetch_block_cypher_transactions(address) end def create_address(id) - super.to_address(network: network) + super.to_address(network:) end private - def prefix - CryptocoinPayable.configuration.testnet ? 'testnet.' : '' + def prefix_blockstream + CryptocoinPayable.configuration.testnet ? 'testnet/' : '' + end + def prefix_block_cypher + CryptocoinPayable.configuration.testnet ? 'test3' : '' end def network CryptocoinPayable.configuration.testnet ? :bitcoin_testnet : :bitcoin end - def parse_total_tx_value_block_explorer(output_transactions, address) + def parse_total_tx_value_blockstream(output_transactions, address) output_transactions - .reject { |out| out['scriptPubKey']['addresses'].nil? } - .select { |out| out['scriptPubKey']['addresses'].include?(address) } - .map { |out| (out['value'].to_f * self.class.subunit_in_main).to_i } + .select { |out| out['scriptpubkey_address'] == address } + .map { |out| out['value'] } .inject(:+) || 0 end - def fetch_block_explorer_transactions(address) - url = "https://#{prefix}blockexplorer.com/api/txs/?address=#{address}" - parse_block_explorer_transactions(get_request(url).body, address) + def fetch_blockstream_transactions(address) + url = "https://blockstream.info/#{prefix_blockstream}api/address/#{address}/txs" + parse_blockstream_transactions(get_request(url).body, address) end - def parse_block_explorer_transactions(response, address) + def parse_blockstream_transactions(response, address) json = JSON.parse(response) - json['txs'].map { |tx| convert_block_explorer_transactions(tx, address) } + puts json.inspect + json.map { |tx| convert_blockstream_transactions(tx, address) } rescue JSON::ParserError raise ApiError, response end - def convert_block_explorer_transactions(transaction, address) + def convert_blockstream_transactions(transaction, address) { transaction_hash: transaction['txid'], - block_hash: transaction['blockhash'], - block_time: parse_timestamp(transaction['blocktime']), - estimated_time: parse_timestamp(transaction['time']), - estimated_value: parse_total_tx_value_block_explorer(transaction['vout'], address), - confirmations: transaction['confirmations'] + block_hash: transaction['status']['block_hash'], + block_time: parse_timestamp(transaction['status']['block_time']), + estimated_time: parse_timestamp(transaction['status']['block_time']), + estimated_value: parse_total_tx_value_blockstream(transaction['vout'], address), + confirmations: 1 #blocktstream only returns true or false for confirmed } end @@ -68,14 +72,14 @@ def parse_total_tx_value_block_cypher(output_transactions, address) end def fetch_block_cypher_transactions(address) - url = "https://api.blockcypher.com/v1/btc/main/addrs/#{address}/full" + url = "https://api.blockcypher.com/v1/btc/#{prefix_block_cypher}/addrs/#{address}/full" parse_block_cypher_transactions(get_request(url).body, address) end def parse_block_cypher_transactions(response, address) json = JSON.parse(response) raise ApiError, json['error'] if json['error'] - + puts json['txs'].map { |tx| convert_block_cypher_transactions(tx, address) }.inspect json['txs'].map { |tx| convert_block_cypher_transactions(tx, address) } rescue JSON::ParserError raise ApiError, response diff --git a/lib/cryptocoin_payable/config.rb b/lib/cryptocoin_payable/config.rb index 1299fc9..8a60c7b 100644 --- a/lib/cryptocoin_payable/config.rb +++ b/lib/cryptocoin_payable/config.rb @@ -9,7 +9,7 @@ def self.configure end class Configuration - attr_accessor :testnet, :expire_payments_after, :request_delay, :btc, :bch, :eth + attr_accessor :testnet, :expire_payments_after, :request_delay, :btc, :bch, :eth, :logger attr_writer :currency def currency @@ -31,6 +31,10 @@ def configure_eth yield(@eth) end + def logger + @logger ||= Logger.new(STDOUT) + end + class CoinConfiguration attr_accessor :master_public_key, :confirmations, :adapter_api_key attr_writer :node_path diff --git a/spec/acceptance/adapters/bitcoin_spec.rb b/spec/acceptance/adapters/bitcoin_spec.rb index 5e98d94..8fe8466 100644 --- a/spec/acceptance/adapters/bitcoin_spec.rb +++ b/spec/acceptance/adapters/bitcoin_spec.rb @@ -1,43 +1,41 @@ -require 'active_record' -require 'cryptocoin_payable' - describe CryptocoinPayable::Adapters::Bitcoin, :vcr do def expect_transaction_result(response) expect(response).to match_array( [ { - transaction_hash: '5bdeaf7829148d7e0e1e7b5233512a2c5ae54ef7ccbc8e68b2f85b7e49c917a0', - block_hash: '0000000000000000048e8ea3fdd2c3a59ddcbcf7575f82cb96ce9fd17da9f2f4', - block_time: Time.iso8601('2016-09-13T15:41:00.000000000+00:00'), - estimated_time: be_within(1.day).of(Time.iso8601('2016-09-13T15:41:00.000000000+00:00')), - estimated_value: 499_000_000, - confirmations: 116_077 + transaction_hash: 'dbdd77c3f855611e98b236ab2dbaecdf857b310867ba9bd25d00a9ae97efdfaf', + block_hash: '00000000000022f2b5ecdf15c843d43211f10325dc203ef83ddc1f185c55830e', + block_time: be_within(1.day).of(Time.iso8601('2023-11-29T15:41:00.000000000+00:00')), + estimated_time: be_within(1.day).of(Time.iso8601('2023-11-29T15:41:00.000000000+00:00')), + estimated_value: 4_838_729, + confirmations: be_between(1, 1_000_000) }, { - transaction_hash: 'e7bcdb13d9c903973bd8a740054d4c056a559bae67d4e8f6d0a42b4bab552623', - block_hash: '000000000000000001af27feb303ad97af81a5882157f166781784c639f8e896', - block_time: Time.iso8601('2016-09-13T15:22:42.000000000+00:00'), - estimated_time: be_within(1.day).of(Time.iso8601('2016-09-13T15:22:42.000000000+00:00')), - estimated_value: 1_000_000, - confirmations: 116_080 + transaction_hash: '81f397b78bafb09186fa8c97ca7f571c83e7bfa11f26dfb66c725a75f0ce3212', + block_hash: '0000000000003e41554f6dbbd197c6d09261304b5460fa918b6dab3e3bdee929', + block_time: be_within(1.day).of(Time.iso8601('2023-11-28T15:41:00.000000000+00:00')), + estimated_time: be_within(1.day).of(Time.iso8601('2023-11-28T15:41:00.000000000+00:00')), + estimated_value: 8_000, + confirmations: be_between(1, 1_000_000) } ] ) end it 'gets transactions for a given address' do - response = subject.fetch_transactions('3HR9xYD7MybbE7JLVTjwijYse48BtfEKni') + response = subject.fetch_transactions('tb1qqmw2g6tghrcqdgeas2eawpcpyr537xc0ukf222') expect_transaction_result(response) end it 'returns zero estimated value for zero-value transactions' do + pending 'need to find a zero-value transaction to test with' response = subject.fetch_transactions('1PKKkNRPPfPjrPiufHzuLFX2gMAVJbcN8H') expect(response.first[:estimated_value]).not_to be_nil expect(response.first[:estimated_value]).to be_zero end it 'gets an empty result when no transactions found' do - response = subject.fetch_transactions('1twtr17A65VAPhJDJRxhoMSpLBTR5Xy44') + response = subject.fetch_transactions('tb1qdnynffwkqrtykapjmaeqvyncl8rfu58pqxamp8') expect(response).to eq([]) end @@ -45,16 +43,16 @@ def expect_transaction_result(response) expect { subject.fetch_transactions('foo') }.to raise_error CryptocoinPayable::ApiError end - context 'when the Block Explorer API fails' do + context 'when the BlockSteam API fails' do before do - stub_request(:any, %r{blockexplorer.com/api}) + stub_request(:any, %r{blockstream.info/}) .to_return(body: '502 Gateway Error', headers: { 'Content-Type' => 'text/html' }) allow(subject).to receive(:fetch_block_cypher_transactions).and_call_original end it 'falls back to using the BlockCypher API' do - response = subject.fetch_transactions('3HR9xYD7MybbE7JLVTjwijYse48BtfEKni') + response = subject.fetch_transactions('tb1qqmw2g6tghrcqdgeas2eawpcpyr537xc0ukf222') expect(subject).to have_received(:fetch_block_cypher_transactions).once expect_transaction_result(response) end @@ -62,9 +60,9 @@ def expect_transaction_result(response) it 'creates BIP32 addresses' do 3.times do - expect(subject.create_address(0)).to eq('1D5qJDG6No5xcHovLmyNU1b3vq7xkEzTRH') - expect(subject.create_address(1)).to eq('17A91ZXzkJQkSrbNWcY8ywDC7D9aW9roKo') - expect(subject.create_address(2)).to eq('16Ak3B8ahHWbrZvukMUe8PUDLR5HScM6LK') + expect(subject.create_address(0)).to eq('mvsv9qmXGueDqTgAUNssazQY7kapmHQbsc') + expect(subject.create_address(1)).to eq('n3Y9hm8hzsrE8bzy83zHQEpLmxMLup967N') + expect(subject.create_address(2)).to eq('msJ7jKfZTx5VU47523H7tTBeaivyXMtVPz') end end end diff --git a/spec/acceptance/adapters/ethereum_spec.rb b/spec/acceptance/adapters/ethereum_spec.rb index 55526fc..b41f99a 100644 --- a/spec/acceptance/adapters/ethereum_spec.rb +++ b/spec/acceptance/adapters/ethereum_spec.rb @@ -1,6 +1,3 @@ -require 'active_record' -require 'cryptocoin_payable' - describe CryptocoinPayable::Adapters::Ethereum, :vcr do def expect_transaction_result(response) expect(response).to match_array( diff --git a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/gets_an_empty_result_when_no_transactions_found.yml b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/gets_an_empty_result_when_no_transactions_found.yml index d455144..9459136 100644 --- a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/gets_an_empty_result_when_no_transactions_found.yml +++ b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/gets_an_empty_result_when_no_transactions_found.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: https://blockexplorer.com/api/txs/?address=1twtr17A65VAPhJDJRxhoMSpLBTR5Xy44 + uri: https://blockstream.info/testnet/api/address/tb1qdnynffwkqrtykapjmaeqvyncl8rfu58pqxamp8/txs body: encoding: US-ASCII string: '' @@ -18,50 +18,27 @@ http_interactions: code: 200 message: OK headers: + Server: + - nginx Date: - - Sun, 14 Oct 2018 10:35:50 GMT + - Mon, 04 Dec 2023 10:44:28 GMT Content-Type: - - application/json; charset=utf-8 + - application/json Content-Length: - - '25' - Connection: - - keep-alive - Set-Cookie: - - __cfduid=d47ff8371481605e635f17b28a5748d871539513349; expires=Mon, 14-Oct-19 - 10:35:49 GMT; path=/; domain=.blockexplorer.com; HttpOnly; Secure - X-Powered-By: - - Express - X-Ratelimit-Limit: - - '10800' - X-Ratelimit-Remaining: - - '10788' + - '2' + Cache-Control: + - public, max-age=10 Access-Control-Allow-Origin: - "*" - Access-Control-Allow-Methods: - - GET, HEAD, PUT, POST, OPTIONS - Access-Control-Allow-Headers: - - Origin, X-Requested-With, Content-Type, Accept, Content-Length, Cache-Control, - cf-connecting-ip - Cache-Control: - - public, max-age=30 - X-Content-Type-Options: - - nosniff - - nosniff - Etag: - - W/"19-ateSR7OFd51Y/7Qm9D9BXg" - Vary: - - Accept-Encoding - Cf-Cache-Status: - - MISS - Expect-Ct: - - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" - Server: - - cloudflare - Cf-Ray: - - 469966c21862c338-SIN + Access-Control-Expose-Headers: + - x-total-results + Via: + - 1.1 google + Alt-Svc: + - h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 body: encoding: UTF-8 - string: '{"pagesTotal":0,"txs":[]}' + string: "[]" http_version: - recorded_at: Sun, 14 Oct 2018 10:35:52 GMT + recorded_at: Mon, 04 Dec 2023 10:44:28 GMT recorded_with: VCR 4.0.0 diff --git a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/gets_transactions_for_a_given_address.yml b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/gets_transactions_for_a_given_address.yml index 065a10b..c309a24 100644 --- a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/gets_transactions_for_a_given_address.yml +++ b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/gets_transactions_for_a_given_address.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: https://blockexplorer.com/api/txs/?address=3HR9xYD7MybbE7JLVTjwijYse48BtfEKni + uri: https://blockstream.info/testnet/api/address/tb1qqmw2g6tghrcqdgeas2eawpcpyr537xc0ukf222/txs body: encoding: US-ASCII string: '' @@ -18,56 +18,64 @@ http_interactions: code: 200 message: OK headers: + Server: + - nginx Date: - - Sun, 14 Oct 2018 10:35:49 GMT + - Sun, 03 Dec 2023 17:24:58 GMT Content-Type: - - application/json; charset=utf-8 - Transfer-Encoding: - - chunked - Connection: - - keep-alive - Set-Cookie: - - __cfduid=dfbf39137c18550c63fcc8c85bee8b7e41539513348; expires=Mon, 14-Oct-19 - 10:35:48 GMT; path=/; domain=.blockexplorer.com; HttpOnly; Secure - X-Powered-By: - - Express - X-Ratelimit-Limit: - - '10800' - X-Ratelimit-Remaining: - - '10789' - Access-Control-Allow-Origin: - - "*" - Access-Control-Allow-Methods: - - GET, HEAD, PUT, POST, OPTIONS - Access-Control-Allow-Headers: - - Origin, X-Requested-With, Content-Type, Accept, Content-Length, Cache-Control, - cf-connecting-ip - Cache-Control: - - public, max-age=30 - X-Content-Type-Options: - - nosniff - - nosniff - Etag: - - W/"d6f-oVIhbGDsjzojZRPbIeFCTg" + - application/json Vary: - Accept-Encoding - Cf-Cache-Status: - - EXPIRED - Expect-Ct: - - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" - Server: - - cloudflare - Cf-Ray: - - 469966babf93c347-SIN + Cache-Control: + - public, max-age=10 + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - x-total-results + Via: + - 1.1 google + Alt-Svc: + - h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 + Transfer-Encoding: + - chunked body: encoding: ASCII-8BIT - string: '{"pagesTotal":1,"txs":[{"txid":"5bdeaf7829148d7e0e1e7b5233512a2c5ae54ef7ccbc8e68b2f85b7e49c917a0","version":1,"locktime":0,"vin":[{"txid":"252dde616fbbd25ebaf37ee8df82c38d2135a87100cc1f0315797b1b42f52f01","vout":0,"scriptSig":{"asm":"304402206b40298326b6c4ab181c4c61b43569490e91773997c0ec53309ab01851098c1002202731263d747aba117b65aaf7d5ee0ad5e88c2e3b4dc3e47d6ecc414e3bbb38e8[ALL] - 02027fcba75d05e735e734d9287c3b22b90465e30ee87ff064303b8175ddeb48fa","hex":"47304402206b40298326b6c4ab181c4c61b43569490e91773997c0ec53309ab01851098c1002202731263d747aba117b65aaf7d5ee0ad5e88c2e3b4dc3e47d6ecc414e3bbb38e8012102027fcba75d05e735e734d9287c3b22b90465e30ee87ff064303b8175ddeb48fa"},"sequence":4294967295,"n":0,"addr":"1CJzCcrY9WarJ5nZCcfbNu2eAnuHqSGqJP","valueSat":826658803,"value":8.26658803,"doubleSpentTxID":null}],"vout":[{"value":"4.99000000","n":0,"scriptPubKey":{"hex":"a914ac82105dbe13eb1b2b606b8fa4e58ced5b317ceb87","asm":"OP_HASH160 - ac82105dbe13eb1b2b606b8fa4e58ced5b317ceb OP_EQUAL","addresses":["3HR9xYD7MybbE7JLVTjwijYse48BtfEKni"],"type":"scripthash"},"spentTxId":null,"spentIndex":null,"spentHeight":null},{"value":"3.27645063","n":1,"scriptPubKey":{"hex":"76a9147dfed19339f4a44a5a9888448ebb270656e2919488ac","asm":"OP_DUP - OP_HASH160 7dfed19339f4a44a5a9888448ebb270656e29194 OP_EQUALVERIFY OP_CHECKSIG","addresses":["1CVCj6B2Q4DJ1rFEhaXDdcEcaQQho37yrT"],"type":"pubkeyhash"},"spentTxId":"08aee92c75baa331b66aaf8ad27fdaea80053f3fdb090112ce332983cb63de00","spentIndex":3,"spentHeight":432992}],"blockhash":"0000000000000000048e8ea3fdd2c3a59ddcbcf7575f82cb96ce9fd17da9f2f4","blockheight":429632,"confirmations":116077,"time":1473781260,"blocktime":1473781260,"valueOut":8.26645063,"size":223,"valueIn":8.26658803,"fees":0.0001374},{"txid":"e7bcdb13d9c903973bd8a740054d4c056a559bae67d4e8f6d0a42b4bab552623","version":1,"locktime":0,"vin":[{"txid":"e5c2d3a1ffa653121e38d051274dcbfde19ec53ed13d5e4eba54fdf77e8fbf60","vout":0,"scriptSig":{"asm":"304402201d1d8197bd319e43ca5931023dad0bd4fbcd5d941f7bbf51e5ea6390bdf59c3702202303a697a6f722a90981e3fd1d7f0f27d397de3e1ee601e0f681ec933b809ccd[ALL] - 028ee20d4ea0b72c78caf36b803a79e5a315c61f6d76193130699040cded33ad90","hex":"47304402201d1d8197bd319e43ca5931023dad0bd4fbcd5d941f7bbf51e5ea6390bdf59c3702202303a697a6f722a90981e3fd1d7f0f27d397de3e1ee601e0f681ec933b809ccd0121028ee20d4ea0b72c78caf36b803a79e5a315c61f6d76193130699040cded33ad90"},"sequence":4294967295,"n":0,"addr":"1GWPE3nEHHLY6C5U4c6qj3wxZvx4hiVDxZ","valueSat":465006260,"value":4.6500626,"doubleSpentTxID":null}],"vout":[{"value":"4.63992520","n":0,"scriptPubKey":{"hex":"76a9141a984f5195f48bcd9995ec4bb5ed5a386a10dfdf88ac","asm":"OP_DUP - OP_HASH160 1a984f5195f48bcd9995ec4bb5ed5a386a10dfdf OP_EQUALVERIFY OP_CHECKSIG","addresses":["13Rd2fKcsUQ9eChqMZGprGeo8XAMAsQhMV"],"type":"pubkeyhash"},"spentTxId":"5c9864d21dca5bd4715a5489fad9e51dbdcde1588e03d58ddbbbcabc0de54e32","spentIndex":0,"spentHeight":429716},{"value":"0.01000000","n":1,"scriptPubKey":{"hex":"a914ac82105dbe13eb1b2b606b8fa4e58ced5b317ceb87","asm":"OP_HASH160 - ac82105dbe13eb1b2b606b8fa4e58ced5b317ceb OP_EQUAL","addresses":["3HR9xYD7MybbE7JLVTjwijYse48BtfEKni"],"type":"scripthash"},"spentTxId":null,"spentIndex":null,"spentHeight":null}],"blockhash":"000000000000000001af27feb303ad97af81a5882157f166781784c639f8e896","blockheight":429629,"confirmations":116080,"time":1473780162,"blocktime":1473780162,"valueOut":4.6499252,"size":223,"valueIn":4.6500626,"fees":0.0001374}]}' + string: '[{"txid":"dbdd77c3f855611e98b236ab2dbaecdf857b310867ba9bd25d00a9ae97efdfaf","version":2,"locktime":2540885,"vin":[{"txid":"c7b8832770f5b07b17ce084044d86e2af41591f682539f1884aa58278946fa50","vout":15,"prevout":{"scriptpubkey":"001482b9249d173a89515c4cd9f3acd4b8e4a15a28c1","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 82b9249d173a89515c4cd9f3acd4b8e4a15a28c1","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1qs2ujf8gh82y4zhzvm8e6e49cujs452xpcdvalm","value":36914181110},"scriptsig":"","scriptsig_asm":"","witness":["304402200847828a7d87dff88ed51100f33ff91abc617cd63257b0218c1547e4a3594e9c0220483757fce0fe98af66c243efe476e7ed0d6c5ec4af8bf8a8efa803f6f507c95801","03c90abdf37b57046f4c0f55a56bef20da6f769be1bd084a498823e94d3303fd92"],"is_coinbase":false,"sequence":4294967293}],"vout":[{"scriptpubkey":"0014345776d45847d983b3bb316eaa9d4c4c9ea22451","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 345776d45847d983b3bb316eaa9d4c4c9ea22451","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1qx3thd4zcglvc8vamx9h2482vfj02yfz3fsr6pu","value":4245361},{"scriptpubkey":"001406dca46968b8f006a33d82b3d7070120e91f1b0f","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 06dca46968b8f006a33d82b3d7070120e91f1b0f","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1qqmw2g6tghrcqdgeas2eawpcpyr537xc0ukf222","value":4838729},{"scriptpubkey":"0014ac5df76a84e606a1140e92f74e7e67b55afee8d0","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 ac5df76a84e606a1140e92f74e7e67b55afee8d0","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1q43wlw65yucr2z9qwjtm5uln8k4d0a6xsjdcu0u","value":4309743},{"scriptpubkey":"001477a17c01cabbab15bc410d7544f971882b84d2b4","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 77a17c01cabbab15bc410d7544f971882b84d2b4","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1qw7shcqw2hw43t0zpp465f7t33q4cf545sjzs5g","value":5724793},{"scriptpubkey":"0014ed0f31ad373b848d6339b1e7523d9116998d9302","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 ed0f31ad373b848d6339b1e7523d9116998d9302","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1qa58nrtfh8wzg6ceek8n4y0v3z6vcmycz93sace","value":5631014},{"scriptpubkey":"002073cb644211348e222fe998c22866ded002f52f23b76b852245ef0f99c834b71e","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_32 73cb644211348e222fe998c22866ded002f52f23b76b852245ef0f99c834b71e","scriptpubkey_type":"v0_p2wsh","scriptpubkey_address":"tb1qw09kgss3xj8zytlfnrpzsek76qp02terka4c2gj9au8enjp5ku0qhslsw2","value":3778516},{"scriptpubkey":"001477e596aec3000c63435099510ea664c322ad9b56","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 77e596aec3000c63435099510ea664c322ad9b56","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1qwljedtkrqqxxxs6sn9gsafnycv32mx6k53azfa","value":5837401},{"scriptpubkey":"0014458a05190ab009caa157f85bd9371539489193d8","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 458a05190ab009caa157f85bd9371539489193d8","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1qgk9q2xg2kqyu4g2hlpdajdc489yfry7cpq0wtm","value":4938190},{"scriptpubkey":"a91427980b851b08de20e0b98df4826c9a050d35062a87","scriptpubkey_asm":"OP_HASH160 + OP_PUSHBYTES_20 27980b851b08de20e0b98df4826c9a050d35062a OP_EQUAL","scriptpubkey_type":"p2sh","scriptpubkey_address":"2MvraV379gpkkEC9kzr1bb5CffkNC5cpgUf","value":3807851},{"scriptpubkey":"a914bed11de9bb677a0767a0dec084f7a73c220bb5f587","scriptpubkey_asm":"OP_HASH160 + OP_PUSHBYTES_20 bed11de9bb677a0767a0dec084f7a73c220bb5f5 OP_EQUAL","scriptpubkey_type":"p2sh","scriptpubkey_address":"2NAeAtRc4v8MqzXNMXcPSPc6XhBiPYphYLV","value":5483031},{"scriptpubkey":"76a914bd09e07ade72112d8cb7ee252a21aa02ff8e8ca088ac","scriptpubkey_asm":"OP_DUP + OP_HASH160 OP_PUSHBYTES_20 bd09e07ade72112d8cb7ee252a21aa02ff8e8ca0 OP_EQUALVERIFY + OP_CHECKSIG","scriptpubkey_type":"p2pkh","scriptpubkey_address":"mxkVqZrXmiWgj75vsp2GgCUQYHP5AMHs4Y","value":5091721},{"scriptpubkey":"a91460df2f93a814bdfdb47bfd57c3dbbd19db06bd9987","scriptpubkey_asm":"OP_HASH160 + OP_PUSHBYTES_20 60df2f93a814bdfdb47bfd57c3dbbd19db06bd99 OP_EQUAL","scriptpubkey_type":"p2sh","scriptpubkey_address":"2N25SDvZA6iU9omy4SRXt5bh9phCAJ7PXpy","value":4697934},{"scriptpubkey":"a9143aa29d615f0526b3c41b9b3a9207023fe255416387","scriptpubkey_asm":"OP_HASH160 + OP_PUSHBYTES_20 3aa29d615f0526b3c41b9b3a9207023fe2554163 OP_EQUAL","scriptpubkey_type":"p2sh","scriptpubkey_address":"2MxbFz5ioREe7LRRwknK5nKeo958GTBUScd","value":4535337},{"scriptpubkey":"512076fb0394c9294f59bf3643db16a6a68f46e721775103d58ccd0e8032e72a0039","scriptpubkey_asm":"OP_PUSHNUM_1 + OP_PUSHBYTES_32 76fb0394c9294f59bf3643db16a6a68f46e721775103d58ccd0e8032e72a0039","scriptpubkey_type":"v1_p2tr","scriptpubkey_address":"tb1pwmas89xf9984n0ekg0d3df4x3arwwgth2ypatrxdp6qr9ee2qqus7qtnsh","value":5998529},{"scriptpubkey":"00143a8587d8531acf20013b46727a0db0b4b6015142","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 3a8587d8531acf20013b46727a0db0b4b6015142","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1q82zc0kznrt8jqqfmgee85rdskjmqz52zl00fzm","value":3675850},{"scriptpubkey":"0014a546e33ab5865e217e831411c0a26f0749cbd2b4","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 a546e33ab5865e217e831411c0a26f0749cbd2b4","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1q54rwxw44se0zzl5rzsgupgn0qayuh545ke8l5a","value":3085924},{"scriptpubkey":"0014caf4e771ded7a0d961a491896aecae0f787b0924","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 caf4e771ded7a0d961a491896aecae0f787b0924","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1qet6wwuw767sdjcdyjxyk4m9wpau8kzfyny0fvh","value":36786306852},{"scriptpubkey":"001426a9d19a207a84896b4c8329c092a3d23e7f4cc3","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 26a9d19a207a84896b4c8329c092a3d23e7f4cc3","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1qy65arx3q02zgj66vsv5upy4r6gl87nxrsju9cj","value":4133888},{"scriptpubkey":"a914d322a51e4df71f739027c5ed3fb3ffcf4e60fa4c87","scriptpubkey_asm":"OP_HASH160 + OP_PUSHBYTES_20 d322a51e4df71f739027c5ed3fb3ffcf4e60fa4c OP_EQUAL","scriptpubkey_type":"p2sh","scriptpubkey_address":"2NCVc4wGk6wfTX5kSDom2iRsMj1EVP5K9Hs","value":5500876},{"scriptpubkey":"0014086aadf604d39a550a4cc2375f7b2902f87211d2","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 086aadf604d39a550a4cc2375f7b2902f87211d2","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1qpp42masy6wd92zjvcgm477efqtu8yywjk602uu","value":5852494},{"scriptpubkey":"76a91497adc88c5474065ec693d4582b7056080b7e143988ac","scriptpubkey_asm":"OP_DUP + OP_HASH160 OP_PUSHBYTES_20 97adc88c5474065ec693d4582b7056080b7e1439 OP_EQUALVERIFY + OP_CHECKSIG","scriptpubkey_type":"p2pkh","scriptpubkey_address":"muLxWhgCFR15MwhZvs83h9TE2bUds8nATA","value":5077488},{"scriptpubkey":"a914d56e811403ec16b3705321b4930fee880b591d7087","scriptpubkey_asm":"OP_HASH160 + OP_PUSHBYTES_20 d56e811403ec16b3705321b4930fee880b591d70 OP_EQUAL","scriptpubkey_type":"p2sh","scriptpubkey_address":"2NChkJ7Ps7QKumBmwf9nvy3wRZSkgmRVjKN","value":3744200},{"scriptpubkey":"0014e38d8aa1a71306e64ba3e9104cca23c0b23c08e6","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 e38d8aa1a71306e64ba3e9104cca23c0b23c08e6","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1quwxc4gd8zvrwvjaraygyej3rczercz8xd8gs9g","value":5616405},{"scriptpubkey":"00141fcf59aba31087a2a6a3c746f60d259275d7c067","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 1fcf59aba31087a2a6a3c746f60d259275d7c067","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1qrl84n2arzzr69f4rcar0vrf9jf6a0sr8k07fd9","value":4179103},{"scriptpubkey":"51206cea704515d441b3640b3ff221d764ab8b6ad0911919486babfaaffd77c1b135","scriptpubkey_asm":"OP_PUSHNUM_1 + OP_PUSHBYTES_32 6cea704515d441b3640b3ff221d764ab8b6ad0911919486babfaaffd77c1b135","scriptpubkey_type":"v1_p2tr","scriptpubkey_address":"tb1pdn48q3g463qmxeqt8lezr4my4w9k45y3ryv5s6atl2hl6a7pky6ssl3flf","value":5340390},{"scriptpubkey":"0014c23c142b695f8e570b83ee1a02b92d76df7f25f6","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 c23c142b695f8e570b83ee1a02b92d76df7f25f6","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1qcg7pg2mft789wzuracdq9wfdwm0h7f0k0a3z2y","value":4043070},{"scriptpubkey":"51201f93c49f234d847ce2aafb40bfd0b7259f0d7e8e542749bf1a64ac4208d75406","scriptpubkey_asm":"OP_PUSHNUM_1 + OP_PUSHBYTES_32 1f93c49f234d847ce2aafb40bfd0b7259f0d7e8e542749bf1a64ac4208d75406","scriptpubkey_type":"v1_p2tr","scriptpubkey_address":"tb1pr7fuf8erfkz8ec42ldqtl59hyk0s6l5w2sn5n0c6vjkyyzxh2srqx347qd","value":3450697},{"scriptpubkey":"5120f93da87b3650b0ec66468518715bc30bc1baa7b84bc738f4cfc29ea71164be59","scriptpubkey_asm":"OP_PUSHNUM_1 + OP_PUSHBYTES_32 f93da87b3650b0ec66468518715bc30bc1baa7b84bc738f4cfc29ea71164be59","scriptpubkey_type":"v1_p2tr","scriptpubkey_address":"tb1ply76s7ek2zcwcejxs5v8zk7rp0qm4facf0rn3ax0c202wytyhevsd0dfwu","value":5254704}],"size":1100,"weight":4073,"fee":1019,"status":{"confirmed":true,"block_height":2540886,"block_hash":"00000000000022f2b5ecdf15c843d43211f10325dc203ef83ddc1f185c55830e","block_time":1701230000}},{"txid":"81f397b78bafb09186fa8c97ca7f571c83e7bfa11f26dfb66c725a75f0ce3212","version":2,"locktime":2540800,"vin":[{"txid":"a68c89e0c8839987108dcfb7339bdae8c58672648b444b37591ae114069adb1d","vout":1,"prevout":{"scriptpubkey":"00147120a24b0c8a3fbe5532cfcd1dc844cf26fc92a3","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 7120a24b0c8a3fbe5532cfcd1dc844cf26fc92a3","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1qwys2yjcv3glmu4fjelx3mjzyeun0ey4rmzl2sp","value":999323068},"scriptsig":"","scriptsig_asm":"","witness":["304402200b62a1c5cd177cbecc101c02c6eb5a1c9e2416ae871dd4723158b8b4ccebaf8c02200b5855beda7acebdc0e327ad9c0d6e3183f874ea8ac43121dfd039ff4e1834f801","0287bd9a720001b86c162eddb024af2f69f1d1b33d0ddd02ce033c2ba49b27647e"],"is_coinbase":false,"sequence":4294967293}],"vout":[{"scriptpubkey":"001451a6d5de32b772aa369b81f31399915399e095b5","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 51a6d5de32b772aa369b81f31399915399e095b5","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1q2xndth3jkae25d5ms8e38xv32wv7p9d4yfzu3z","value":999312884},{"scriptpubkey":"5120a5fbc2bdd140a948293c2287250292c40b95ff87ddf35097db896ad26f6f26df","scriptpubkey_asm":"OP_PUSHNUM_1 + OP_PUSHBYTES_32 a5fbc2bdd140a948293c2287250292c40b95ff87ddf35097db896ad26f6f26df","scriptpubkey_type":"v1_p2tr","scriptpubkey_address":"tb1p5hau90w3gz55s2fuy2rj2q5jcs9etlu8mhe4p97m394dymm0ym0scxw8qt","value":2000},{"scriptpubkey":"001406dca46968b8f006a33d82b3d7070120e91f1b0f","scriptpubkey_asm":"OP_0 + OP_PUSHBYTES_20 06dca46968b8f006a33d82b3d7070120e91f1b0f","scriptpubkey_type":"v0_p2wpkh","scriptpubkey_address":"tb1qqmw2g6tghrcqdgeas2eawpcpyr537xc0ukf222","value":8000}],"size":265,"weight":733,"fee":184,"status":{"confirmed":true,"block_height":2540801,"block_hash":"0000000000003e41554f6dbbd197c6d09261304b5460fa918b6dab3e3bdee929","block_time":1701180536}}]' http_version: - recorded_at: Sun, 14 Oct 2018 10:35:51 GMT + recorded_at: Sun, 03 Dec 2023 17:24:58 GMT recorded_with: VCR 4.0.0 diff --git a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/raises_an_error_when_an_invalid_address_is_passed.yml b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/raises_an_error_when_an_invalid_address_is_passed.yml index 4c8f011..12f5a4c 100644 --- a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/raises_an_error_when_an_invalid_address_is_passed.yml +++ b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/raises_an_error_when_an_invalid_address_is_passed.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: https://blockexplorer.com/api/txs/?address=foo + uri: https://blockstream.info/testnet/api/address/foo/txs body: encoding: US-ASCII string: '' @@ -18,50 +18,28 @@ http_interactions: code: 400 message: Bad Request headers: + Server: + - nginx Date: - - Sun, 14 Oct 2018 10:35:51 GMT + - Mon, 04 Dec 2023 10:43:56 GMT Content-Type: - - text/html; charset=utf-8 - Transfer-Encoding: - - chunked - Connection: - - keep-alive - Set-Cookie: - - __cfduid=da94483646f7f50cf4fccfb76ee0e929e1539513350; expires=Mon, 14-Oct-19 - 10:35:50 GMT; path=/; domain=.blockexplorer.com; HttpOnly; Secure - X-Powered-By: - - Express - X-Ratelimit-Limit: - - '10800' - X-Ratelimit-Remaining: - - '10787' + - text/plain + Content-Length: + - '23' Access-Control-Allow-Origin: - "*" - Access-Control-Allow-Methods: - - GET, HEAD, PUT, POST, OPTIONS - Access-Control-Allow-Headers: - - Origin, X-Requested-With, Content-Type, Accept, Content-Length, Cache-Control, - cf-connecting-ip - Cache-Control: - - public, max-age=30 - Vary: - - Accept-Encoding - Cf-Cache-Status: - - EXPIRED - Expect-Ct: - - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" - Server: - - cloudflare - Cf-Ray: - - 469966c91983c365-SIN + Via: + - 1.1 google + Alt-Svc: + - h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 body: encoding: UTF-8 - string: Invalid address. Code:-5 + string: Invalid Bitcoin address http_version: - recorded_at: Sun, 14 Oct 2018 10:35:53 GMT + recorded_at: Mon, 04 Dec 2023 10:43:56 GMT - request: method: get - uri: https://api.blockcypher.com/v1/btc/main/addrs/foo/full + uri: https://api.blockcypher.com/v1/btc/test3/addrs/foo/full body: encoding: US-ASCII string: '' @@ -77,10 +55,8 @@ http_interactions: code: 404 message: Not Found headers: - Server: - - nginx/1.10.3 (Ubuntu) Date: - - Sun, 14 Oct 2018 10:35:52 GMT + - Mon, 04 Dec 2023 10:43:57 GMT Content-Type: - application/json Content-Length: @@ -94,10 +70,16 @@ http_interactions: Access-Control-Allow-Origin: - "*" X-Ratelimit-Remaining: - - '98' + - '1' + Cf-Cache-Status: + - DYNAMIC + Server: + - cloudflare + Cf-Ray: + - 8303738abda9f0b7-CDG body: encoding: UTF-8 string: '{"error": "Wallet foo not found"}' http_version: - recorded_at: Sun, 14 Oct 2018 10:35:54 GMT + recorded_at: Mon, 04 Dec 2023 10:43:57 GMT recorded_with: VCR 4.0.0 diff --git a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/returns_zero_estimated_value_for_zero-value_transactions.yml b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/returns_zero_estimated_value_for_zero-value_transactions.yml index d3ec3d0..9fcbe89 100644 --- a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/returns_zero_estimated_value_for_zero-value_transactions.yml +++ b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/returns_zero_estimated_value_for_zero-value_transactions.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: https://blockexplorer.com/api/txs/?address=1PKKkNRPPfPjrPiufHzuLFX2gMAVJbcN8H + uri: https://blockstream.info/testnet/api/address/1PKKkNRPPfPjrPiufHzuLFX2gMAVJbcN8H/txs body: encoding: US-ASCII string: '' @@ -15,56 +15,72 @@ http_interactions: - Ruby response: status: - code: 200 - message: OK + code: 400 + message: Bad Request + headers: + Server: + - nginx + Date: + - Mon, 04 Dec 2023 10:43:55 GMT + Content-Type: + - text/plain + Content-Length: + - '26' + Access-Control-Allow-Origin: + - "*" + Via: + - 1.1 google + Alt-Svc: + - h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 + body: + encoding: UTF-8 + string: Address on invalid network + http_version: + recorded_at: Mon, 04 Dec 2023 10:43:55 GMT +- request: + method: get + uri: https://api.blockcypher.com/v1/btc/test3/addrs/1PKKkNRPPfPjrPiufHzuLFX2gMAVJbcN8H/full + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 400 + message: Bad Request headers: Date: - - Thu, 08 Nov 2018 17:34:48 GMT + - Mon, 04 Dec 2023 10:43:55 GMT Content-Type: - - application/json; charset=utf-8 - Transfer-Encoding: - - chunked + - application/json + Content-Length: + - '104' Connection: - keep-alive - Set-Cookie: - - BE=f6fe53688c017ff7; path=/ - - __cfduid=dd04ba3e33bea3f20633eebd13320dc081541698486; expires=Fri, 08-Nov-19 - 17:34:46 GMT; path=/; domain=.blockexplorer.com; HttpOnly; Secure - X-Powered-By: - - Express + Access-Control-Allow-Headers: + - Origin, X-Requested-With, Content-Type, Accept + Access-Control-Allow-Methods: + - GET, POST, PUT, DELETE Access-Control-Allow-Origin: - "*" - Access-Control-Allow-Methods: - - GET, HEAD, PUT, POST, OPTIONS - Access-Control-Allow-Headers: - - Origin, X-Requested-With, Content-Type, Accept, Content-Length, Cache-Control, - cf-connecting-ip - Cache-Control: - - public, max-age=30 - X-Content-Type-Options: - - nosniff - Etag: - - W/"10a9-4+a9umI+STIlOj3adv7w8ZfOGog" - Vary: - - Accept-Encoding + X-Ratelimit-Remaining: + - '1' Cf-Cache-Status: - - BYPASS - Expect-Ct: - - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + - DYNAMIC Server: - cloudflare Cf-Ray: - - 4769cad68b06a49d-PNH + - 830373820af40212-CDG body: - encoding: ASCII-8BIT - string: '{"pagesTotal":1,"txs":[{"txid":"1c085fb7180d35736dae4d1526f18c71fb551173c7471a70251bff88d38d559d","version":1,"locktime":0,"vin":[{"txid":"5dd89fb2f9a2adfe6f4918db6a203b7c8c91c25c7cb0cd9bfb8a250e3c25abdd","vout":0,"sequence":4294967295,"n":0,"scriptSig":{"hex":"483045022100b029679930b80ce4c067b9c903571c6a935983d7beecaeb902ad1fffa9dba21502204e542e193b74acf68ab17cb13f821d339244aea9cb339bede4b195b3c3b35c6c0121028005d0d0b1c96d549f0eb5e18fb9f7b35ed5a28fb2f3c55842ab9dc9a9218976","asm":"3045022100b029679930b80ce4c067b9c903571c6a935983d7beecaeb902ad1fffa9dba21502204e542e193b74acf68ab17cb13f821d339244aea9cb339bede4b195b3c3b35c6c[ALL] - 028005d0d0b1c96d549f0eb5e18fb9f7b35ed5a28fb2f3c55842ab9dc9a9218976"},"addr":"1PKKkNRPPfPjrPiufHzuLFX2gMAVJbcN8H","valueSat":55965,"value":0.00055965,"doubleSpentTxID":null},{"txid":"5dd89fb2f9a2adfe6f4918db6a203b7c8c91c25c7cb0cd9bfb8a250e3c25abdd","vout":1,"sequence":4294967295,"n":1,"scriptSig":{"hex":"473044022048fad34851bc49c267386186df590ac12390172669f5612b2c28dc09d517223c02203fe2ecf934c10cfaa3d27d1e739ec3413fd16612ba16eaa15ba7a2cfbf0b3a790121034994bba249dc54ed3651595dab6c5c6e3c177032495e00a3fe53874adf565a34","asm":"3044022048fad34851bc49c267386186df590ac12390172669f5612b2c28dc09d517223c02203fe2ecf934c10cfaa3d27d1e739ec3413fd16612ba16eaa15ba7a2cfbf0b3a79[ALL] - 034994bba249dc54ed3651595dab6c5c6e3c177032495e00a3fe53874adf565a34"},"addr":"15Gmaq5M8cMD4mAy1Gh6dVtnoDX3XAazwf","valueSat":503191,"value":0.00503191,"doubleSpentTxID":null}],"vout":[{"value":"0.00062184","n":0,"scriptPubKey":{"hex":"a91484fd6a85eb6cb335e0b8641717f3cf7f392f897587","asm":"OP_HASH160 - 84fd6a85eb6cb335e0b8641717f3cf7f392f8975 OP_EQUAL","addresses":["3DpChXQfjya6zQdUcgpA5tQFfqv9KgRXMP"],"type":"scripthash"},"spentTxId":"0a4c5507fe17f62d698f4ad30843909320770fd5b7159a925a0df289ed77c38e","spentIndex":1,"spentHeight":547179},{"value":"0.00495855","n":1,"scriptPubKey":{"hex":"76a9142edbf57347f7f56a2975c4c5c147680a781e32a988ac","asm":"OP_DUP - OP_HASH160 2edbf57347f7f56a2975c4c5c147680a781e32a9 OP_EQUALVERIFY OP_CHECKSIG","addresses":["15Gmaq5M8cMD4mAy1Gh6dVtnoDX3XAazwf"],"type":"pubkeyhash"},"spentTxId":"6f4f788586ba84ec1bea20b0063fff671c39f85a246b161188980fd13d8203f3","spentIndex":0,"spentHeight":547444}],"blockhash":"00000000000000000008d05a3b4530691dcfe048fa046bc1c95cbf7ae6c60ff0","blockheight":547177,"confirmations":2057,"time":1540413667,"blocktime":1540413667,"valueOut":0.00558039,"size":371,"valueIn":0.00559156,"fees":0.00001117},{"txid":"5dd89fb2f9a2adfe6f4918db6a203b7c8c91c25c7cb0cd9bfb8a250e3c25abdd","version":1,"locktime":0,"vin":[{"txid":"040d0d19654c2fa3e5dbea6654849339261c0bc5f4540173bf87ad0c9d1b2726","vout":1,"sequence":4294967295,"n":0,"scriptSig":{"hex":"483045022100d74af226278b3eaa850f12ccbbdc005796da6172b4b4664d1769586a361982a60220227b54175f2989cbceb4795997381c4b7a3f99d579431bf74294fcde8317ac8c0121034994bba249dc54ed3651595dab6c5c6e3c177032495e00a3fe53874adf565a34","asm":"3045022100d74af226278b3eaa850f12ccbbdc005796da6172b4b4664d1769586a361982a60220227b54175f2989cbceb4795997381c4b7a3f99d579431bf74294fcde8317ac8c[ALL] - 034994bba249dc54ed3651595dab6c5c6e3c177032495e00a3fe53874adf565a34"},"addr":"15Gmaq5M8cMD4mAy1Gh6dVtnoDX3XAazwf","valueSat":559835,"value":0.00559835,"doubleSpentTxID":null}],"vout":[{"value":"0.00055965","n":0,"scriptPubKey":{"hex":"76a914f4c9e785dbe753f59b98c082d793b2e1312c558788ac","asm":"OP_DUP - OP_HASH160 f4c9e785dbe753f59b98c082d793b2e1312c5587 OP_EQUALVERIFY OP_CHECKSIG","addresses":["1PKKkNRPPfPjrPiufHzuLFX2gMAVJbcN8H"],"type":"pubkeyhash"},"spentTxId":"1c085fb7180d35736dae4d1526f18c71fb551173c7471a70251bff88d38d559d","spentIndex":0,"spentHeight":547177},{"value":"0.00503191","n":1,"scriptPubKey":{"hex":"76a9142edbf57347f7f56a2975c4c5c147680a781e32a988ac","asm":"OP_DUP - OP_HASH160 2edbf57347f7f56a2975c4c5c147680a781e32a9 OP_EQUALVERIFY OP_CHECKSIG","addresses":["15Gmaq5M8cMD4mAy1Gh6dVtnoDX3XAazwf"],"type":"pubkeyhash"},"spentTxId":"1c085fb7180d35736dae4d1526f18c71fb551173c7471a70251bff88d38d559d","spentIndex":1,"spentHeight":547177}],"blockhash":"0000000000000000001e7b7b2bf28d3e3813e0a37354f95288fe05fa18a0bc8a","blockheight":547126,"confirmations":2108,"time":1540380059,"blocktime":1540380059,"valueOut":0.00559156,"size":226,"valueIn":0.00559835,"fees":0.00000679}]}' + encoding: UTF-8 + string: '{"error": "Address 1PKKkNRPPfPjrPiufHzuLFX2gMAVJbcN8H incompatible + with current block chain: BTC.test3"}' http_version: - recorded_at: Thu, 08 Nov 2018 17:34:53 GMT + recorded_at: Mon, 04 Dec 2023 10:43:55 GMT recorded_with: VCR 4.0.0 diff --git a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/when_the_BitcoinExplorer_API_fails/falls_back_to_using_the_BlockCypher_API.yml b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/when_the_BitcoinExplorer_API_fails/falls_back_to_using_the_BlockCypher_API.yml new file mode 100644 index 0000000..e69de29 diff --git a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/when_the_BlockSteam_API_fails/falls_back_to_using_the_BlockCypher_API.yml b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/when_the_BlockSteam_API_fails/falls_back_to_using_the_BlockCypher_API.yml new file mode 100644 index 0000000..9afe7f0 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_Bitcoin/when_the_BlockSteam_API_fails/falls_back_to_using_the_BlockCypher_API.yml @@ -0,0 +1,369 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.blockcypher.com/v1/btc/test3/addrs/tb1qqmw2g6tghrcqdgeas2eawpcpyr537xc0ukf222/full + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 04 Dec 2023 10:43:12 GMT + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Access-Control-Allow-Headers: + - Origin, X-Requested-With, Content-Type, Accept + Access-Control-Allow-Methods: + - GET, POST, PUT, DELETE + Access-Control-Allow-Origin: + - "*" + X-Ratelimit-Remaining: + - '1' + Cf-Cache-Status: + - DYNAMIC + Server: + - cloudflare + Cf-Ray: + - 83037270cad02a79-CDG + body: + encoding: ASCII-8BIT + string: |- + { + "address": "tb1qqmw2g6tghrcqdgeas2eawpcpyr537xc0ukf222", + "total_received": 4846729, + "total_sent": 0, + "balance": 4846729, + "unconfirmed_balance": 0, + "final_balance": 4846729, + "n_tx": 2, + "unconfirmed_n_tx": 0, + "final_n_tx": 2, + "txs": [ + { + "block_hash": "00000000000022f2b5ecdf15c843d43211f10325dc203ef83ddc1f185c55830e", + "block_height": 2540886, + "block_index": 73, + "hash": "dbdd77c3f855611e98b236ab2dbaecdf857b310867ba9bd25d00a9ae97efdfaf", + "addresses": [ + "2MvraV379gpkkEC9kzr1bb5CffkNC5cpgUf", + "2MxbFz5ioREe7LRRwknK5nKeo958GTBUScd", + "2N25SDvZA6iU9omy4SRXt5bh9phCAJ7PXpy", + "2NAeAtRc4v8MqzXNMXcPSPc6XhBiPYphYLV", + "2NCVc4wGk6wfTX5kSDom2iRsMj1EVP5K9Hs", + "2NChkJ7Ps7QKumBmwf9nvy3wRZSkgmRVjKN", + "muLxWhgCFR15MwhZvs83h9TE2bUds8nATA", + "mxkVqZrXmiWgj75vsp2GgCUQYHP5AMHs4Y", + "tb1pdn48q3g463qmxeqt8lezr4my4w9k45y3ryv5s6atl2hl6a7pky6ssl3flf", + "tb1ply76s7ek2zcwcejxs5v8zk7rp0qm4facf0rn3ax0c202wytyhevsd0dfwu", + "tb1pr7fuf8erfkz8ec42ldqtl59hyk0s6l5w2sn5n0c6vjkyyzxh2srqx347qd", + "tb1pwmas89xf9984n0ekg0d3df4x3arwwgth2ypatrxdp6qr9ee2qqus7qtnsh", + "tb1q43wlw65yucr2z9qwjtm5uln8k4d0a6xsjdcu0u", + "tb1q54rwxw44se0zzl5rzsgupgn0qayuh545ke8l5a", + "tb1q82zc0kznrt8jqqfmgee85rdskjmqz52zl00fzm", + "tb1qa58nrtfh8wzg6ceek8n4y0v3z6vcmycz93sace", + "tb1qcg7pg2mft789wzuracdq9wfdwm0h7f0k0a3z2y", + "tb1qet6wwuw767sdjcdyjxyk4m9wpau8kzfyny0fvh", + "tb1qgk9q2xg2kqyu4g2hlpdajdc489yfry7cpq0wtm", + "tb1qpp42masy6wd92zjvcgm477efqtu8yywjk602uu", + "tb1qqmw2g6tghrcqdgeas2eawpcpyr537xc0ukf222", + "tb1qrl84n2arzzr69f4rcar0vrf9jf6a0sr8k07fd9", + "tb1qs2ujf8gh82y4zhzvm8e6e49cujs452xpcdvalm", + "tb1quwxc4gd8zvrwvjaraygyej3rczercz8xd8gs9g", + "tb1qw09kgss3xj8zytlfnrpzsek76qp02terka4c2gj9au8enjp5ku0qhslsw2", + "tb1qw7shcqw2hw43t0zpp465f7t33q4cf545sjzs5g", + "tb1qwljedtkrqqxxxs6sn9gsafnycv32mx6k53azfa", + "tb1qx3thd4zcglvc8vamx9h2482vfj02yfz3fsr6pu", + "tb1qy65arx3q02zgj66vsv5upy4r6gl87nxrsju9cj" + ], + "total": 36914180091, + "fees": 1019, + "size": 1100, + "vsize": 1019, + "preference": "low", + "relayed_by": "54.89.135.235:18333", + "confirmed": "2023-11-29T03:53:20Z", + "received": "2023-11-29T03:45:01.898Z", + "ver": 2, + "lock_time": 2540885, + "double_spend": false, + "vin_sz": 1, + "vout_sz": 28, + "opt_in_rbf": true, + "confirmations": 700, + "confidence": 1, + "inputs": [ + { + "prev_hash": "c7b8832770f5b07b17ce084044d86e2af41591f682539f1884aa58278946fa50", + "output_index": 15, + "output_value": 36914181110, + "sequence": 4294967293, + "addresses": [ + "tb1qs2ujf8gh82y4zhzvm8e6e49cujs452xpcdvalm" + ], + "script_type": "pay-to-witness-pubkey-hash", + "age": 2540613, + "witness": [ + "304402200847828a7d87dff88ed51100f33ff91abc617cd63257b0218c1547e4a3594e9c0220483757fce0fe98af66c243efe476e7ed0d6c5ec4af8bf8a8efa803f6f507c95801", + "03c90abdf37b57046f4c0f55a56bef20da6f769be1bd084a498823e94d3303fd92" + ] + } + ], + "outputs": [ + { + "value": 4245361, + "script": "0014345776d45847d983b3bb316eaa9d4c4c9ea22451", + "addresses": [ + "tb1qx3thd4zcglvc8vamx9h2482vfj02yfz3fsr6pu" + ], + "script_type": "pay-to-witness-pubkey-hash" + }, + { + "value": 4838729, + "script": "001406dca46968b8f006a33d82b3d7070120e91f1b0f", + "addresses": [ + "tb1qqmw2g6tghrcqdgeas2eawpcpyr537xc0ukf222" + ], + "script_type": "pay-to-witness-pubkey-hash" + }, + { + "value": 4309743, + "script": "0014ac5df76a84e606a1140e92f74e7e67b55afee8d0", + "addresses": [ + "tb1q43wlw65yucr2z9qwjtm5uln8k4d0a6xsjdcu0u" + ], + "script_type": "pay-to-witness-pubkey-hash" + }, + { + "value": 5724793, + "script": "001477a17c01cabbab15bc410d7544f971882b84d2b4", + "spent_by": "5d5997e7ba39a8631a1d88effa8466e3149aa7fd0d24a2ed606310c8014e57bf", + "addresses": [ + "tb1qw7shcqw2hw43t0zpp465f7t33q4cf545sjzs5g" + ], + "script_type": "pay-to-witness-pubkey-hash" + }, + { + "value": 5631014, + "script": "0014ed0f31ad373b848d6339b1e7523d9116998d9302", + "addresses": [ + "tb1qa58nrtfh8wzg6ceek8n4y0v3z6vcmycz93sace" + ], + "script_type": "pay-to-witness-pubkey-hash" + }, + { + "value": 3778516, + "script": "002073cb644211348e222fe998c22866ded002f52f23b76b852245ef0f99c834b71e", + "addresses": [ + "tb1qw09kgss3xj8zytlfnrpzsek76qp02terka4c2gj9au8enjp5ku0qhslsw2" + ], + "script_type": "pay-to-witness-script-hash" + }, + { + "value": 5837401, + "script": "001477e596aec3000c63435099510ea664c322ad9b56", + "addresses": [ + "tb1qwljedtkrqqxxxs6sn9gsafnycv32mx6k53azfa" + ], + "script_type": "pay-to-witness-pubkey-hash" + }, + { + "value": 4938190, + "script": "0014458a05190ab009caa157f85bd9371539489193d8", + "addresses": [ + "tb1qgk9q2xg2kqyu4g2hlpdajdc489yfry7cpq0wtm" + ], + "script_type": "pay-to-witness-pubkey-hash" + }, + { + "value": 3807851, + "script": "a91427980b851b08de20e0b98df4826c9a050d35062a87", + "addresses": [ + "2MvraV379gpkkEC9kzr1bb5CffkNC5cpgUf" + ], + "script_type": "pay-to-script-hash" + }, + { + "value": 5483031, + "script": "a914bed11de9bb677a0767a0dec084f7a73c220bb5f587", + "addresses": [ + "2NAeAtRc4v8MqzXNMXcPSPc6XhBiPYphYLV" + ], + "script_type": "pay-to-script-hash" + }, + { + "value": 5091721, + "script": "76a914bd09e07ade72112d8cb7ee252a21aa02ff8e8ca088ac", + "spent_by": "512ad3850835ac11fb4ba7c1c03040c326a9e527818fc563c2210e367ccc2bc4", + "addresses": [ + "mxkVqZrXmiWgj75vsp2GgCUQYHP5AMHs4Y" + ], + "script_type": "pay-to-pubkey-hash" + }, + { + "value": 4697934, + "script": "a91460df2f93a814bdfdb47bfd57c3dbbd19db06bd9987", + "addresses": [ + "2N25SDvZA6iU9omy4SRXt5bh9phCAJ7PXpy" + ], + "script_type": "pay-to-script-hash" + }, + { + "value": 4535337, + "script": "a9143aa29d615f0526b3c41b9b3a9207023fe255416387", + "addresses": [ + "2MxbFz5ioREe7LRRwknK5nKeo958GTBUScd" + ], + "script_type": "pay-to-script-hash" + }, + { + "value": 5998529, + "script": "512076fb0394c9294f59bf3643db16a6a68f46e721775103d58ccd0e8032e72a0039", + "addresses": [ + "tb1pwmas89xf9984n0ekg0d3df4x3arwwgth2ypatrxdp6qr9ee2qqus7qtnsh" + ], + "script_type": "pay-to-taproot" + }, + { + "value": 3675850, + "script": "00143a8587d8531acf20013b46727a0db0b4b6015142", + "addresses": [ + "tb1q82zc0kznrt8jqqfmgee85rdskjmqz52zl00fzm" + ], + "script_type": "pay-to-witness-pubkey-hash" + }, + { + "value": 3085924, + "script": "0014a546e33ab5865e217e831411c0a26f0749cbd2b4", + "addresses": [ + "tb1q54rwxw44se0zzl5rzsgupgn0qayuh545ke8l5a" + ], + "script_type": "pay-to-witness-pubkey-hash" + }, + { + "value": 36786306852, + "script": "0014caf4e771ded7a0d961a491896aecae0f787b0924", + "spent_by": "d3ffb37d6e9ab5c346d9efd0e90347816b985d514b9eb9eb4914e4f4ce4c5802", + "addresses": [ + "tb1qet6wwuw767sdjcdyjxyk4m9wpau8kzfyny0fvh" + ], + "script_type": "pay-to-witness-pubkey-hash" + }, + { + "value": 4133888, + "script": "001426a9d19a207a84896b4c8329c092a3d23e7f4cc3", + "addresses": [ + "tb1qy65arx3q02zgj66vsv5upy4r6gl87nxrsju9cj" + ], + "script_type": "pay-to-witness-pubkey-hash" + }, + { + "value": 5500876, + "script": "a914d322a51e4df71f739027c5ed3fb3ffcf4e60fa4c87", + "addresses": [ + "2NCVc4wGk6wfTX5kSDom2iRsMj1EVP5K9Hs" + ], + "script_type": "pay-to-script-hash" + }, + { + "value": 5852494, + "script": "0014086aadf604d39a550a4cc2375f7b2902f87211d2", + "addresses": [ + "tb1qpp42masy6wd92zjvcgm477efqtu8yywjk602uu" + ], + "script_type": "pay-to-witness-pubkey-hash" + } + ], + "next_outputs": "https://api.blockcypher.com/v1/btc/test3/txs/dbdd77c3f855611e98b236ab2dbaecdf857b310867ba9bd25d00a9ae97efdfaf?instart=0\u0026outstart=20\u0026limit=20" + }, + { + "block_hash": "0000000000003e41554f6dbbd197c6d09261304b5460fa918b6dab3e3bdee929", + "block_height": 2540801, + "block_index": 107, + "hash": "81f397b78bafb09186fa8c97ca7f571c83e7bfa11f26dfb66c725a75f0ce3212", + "addresses": [ + "tb1p5hau90w3gz55s2fuy2rj2q5jcs9etlu8mhe4p97m394dymm0ym0scxw8qt", + "tb1q2xndth3jkae25d5ms8e38xv32wv7p9d4yfzu3z", + "tb1qqmw2g6tghrcqdgeas2eawpcpyr537xc0ukf222", + "tb1qwys2yjcv3glmu4fjelx3mjzyeun0ey4rmzl2sp" + ], + "total": 999322884, + "fees": 184, + "size": 265, + "vsize": 184, + "preference": "low", + "relayed_by": "44.192.10.119:18333", + "confirmed": "2023-11-28T14:08:56Z", + "received": "2023-11-28T14:08:41.551Z", + "ver": 2, + "lock_time": 2540800, + "double_spend": false, + "vin_sz": 1, + "vout_sz": 3, + "opt_in_rbf": true, + "confirmations": 785, + "confidence": 1, + "inputs": [ + { + "prev_hash": "a68c89e0c8839987108dcfb7339bdae8c58672648b444b37591ae114069adb1d", + "output_index": 1, + "output_value": 999323068, + "sequence": 4294967293, + "addresses": [ + "tb1qwys2yjcv3glmu4fjelx3mjzyeun0ey4rmzl2sp" + ], + "script_type": "pay-to-witness-pubkey-hash", + "age": 2538881, + "witness": [ + "304402200b62a1c5cd177cbecc101c02c6eb5a1c9e2416ae871dd4723158b8b4ccebaf8c02200b5855beda7acebdc0e327ad9c0d6e3183f874ea8ac43121dfd039ff4e1834f801", + "0287bd9a720001b86c162eddb024af2f69f1d1b33d0ddd02ce033c2ba49b27647e" + ] + } + ], + "outputs": [ + { + "value": 999312884, + "script": "001451a6d5de32b772aa369b81f31399915399e095b5", + "spent_by": "b24c56d612489af15dbb886dfe5a4a563f32f69879c635167e819fcc70d7c5dd", + "addresses": [ + "tb1q2xndth3jkae25d5ms8e38xv32wv7p9d4yfzu3z" + ], + "script_type": "pay-to-witness-pubkey-hash" + }, + { + "value": 2000, + "script": "5120a5fbc2bdd140a948293c2287250292c40b95ff87ddf35097db896ad26f6f26df", + "addresses": [ + "tb1p5hau90w3gz55s2fuy2rj2q5jcs9etlu8mhe4p97m394dymm0ym0scxw8qt" + ], + "script_type": "pay-to-taproot" + }, + { + "value": 8000, + "script": "001406dca46968b8f006a33d82b3d7070120e91f1b0f", + "addresses": [ + "tb1qqmw2g6tghrcqdgeas2eawpcpyr537xc0ukf222" + ], + "script_type": "pay-to-witness-pubkey-hash" + } + ] + } + ] + } + http_version: + recorded_at: Mon, 04 Dec 2023 10:43:12 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ebf336b..0591b27 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,8 @@ # require 'active_support/time' require 'rspec-benchmark' require 'rspec/retry' +require 'cryptocoin_payable' +require 'cryptocoin_payable/orm/activerecord' # ActiveRecord::Base.logger = Logger.new(STDOUT) if defined?(ActiveRecord::Base) From ea5511bcd4f1bb71de91c7c088f4abea20671061 Mon Sep 17 00:00:00 2001 From: Stephane Bounmy <159814+sbounmy@users.noreply.github.com> Date: Tue, 5 Dec 2023 09:45:38 +0100 Subject: [PATCH 5/6] removed puts and pending bitcoin cash as I dont have test wallet yet --- lib/cryptocoin_payable/adapters/bitcoin.rb | 3 +- .../adapters/bitcoin_cash.rb | 2 +- spec/acceptance/adapters/bitcoin_cash_spec.rb | 12 ++-- ...mpty_result_when_no_transactions_found.yml | 62 ------------------- 4 files changed, 8 insertions(+), 71 deletions(-) diff --git a/lib/cryptocoin_payable/adapters/bitcoin.rb b/lib/cryptocoin_payable/adapters/bitcoin.rb index 43389e0..ecdb4e3 100644 --- a/lib/cryptocoin_payable/adapters/bitcoin.rb +++ b/lib/cryptocoin_payable/adapters/bitcoin.rb @@ -48,7 +48,6 @@ def fetch_blockstream_transactions(address) def parse_blockstream_transactions(response, address) json = JSON.parse(response) - puts json.inspect json.map { |tx| convert_blockstream_transactions(tx, address) } rescue JSON::ParserError raise ApiError, response @@ -79,7 +78,7 @@ def fetch_block_cypher_transactions(address) def parse_block_cypher_transactions(response, address) json = JSON.parse(response) raise ApiError, json['error'] if json['error'] - puts json['txs'].map { |tx| convert_block_cypher_transactions(tx, address) }.inspect + json['txs'].map { |tx| convert_block_cypher_transactions(tx, address) } rescue JSON::ParserError raise ApiError, response diff --git a/lib/cryptocoin_payable/adapters/bitcoin_cash.rb b/lib/cryptocoin_payable/adapters/bitcoin_cash.rb index d1a88b7..a1c0c0e 100644 --- a/lib/cryptocoin_payable/adapters/bitcoin_cash.rb +++ b/lib/cryptocoin_payable/adapters/bitcoin_cash.rb @@ -11,7 +11,7 @@ def fetch_transactions(address) raise NetworkNotSupported if CryptocoinPayable.configuration.testnet url = "https://#{prefix}blockexplorer.com/api/txs/?address=#{legacy_address(address)}" - parse_block_explorer_transactions(get_request(url).body, address) + parse_bitcoin_explorer_transactions(get_request(url).body, address) end def create_address(id) diff --git a/spec/acceptance/adapters/bitcoin_cash_spec.rb b/spec/acceptance/adapters/bitcoin_cash_spec.rb index a9c2722..e4d359d 100644 --- a/spec/acceptance/adapters/bitcoin_cash_spec.rb +++ b/spec/acceptance/adapters/bitcoin_cash_spec.rb @@ -1,8 +1,6 @@ -require 'active_record' -require 'cryptocoin_payable' - describe CryptocoinPayable::Adapters::BitcoinCash, :vcr do it 'gets transactions for a given address' do + pending 'not using bitcoin cash at the moment' response = subject.fetch_transactions('bitcoincash:qzmdvhfdxv7j79hs6080hdm47szxfxqpccemzq6n52') expect(response).to eq( @@ -20,19 +18,21 @@ end it 'gets an empty result when no transactions found' do + pending 'not using bitcoin cash at the moment' response = subject.fetch_transactions('bitcoincash:qqu5af4540fw6eg3cqr3t8ndhplpd0xf0vmqpw59ef') expect(response).to eq([]) end it 'raises an error when an invalid address is passed' do + pending 'not using bitcoin cash at the moment' expect { subject.fetch_transactions('foo') }.to raise_error CryptocoinPayable::ApiError end it 'creates BIP32 addresses' do 3.times do - expect(subject.create_address(0)).to eq('bitcoincash:qpfspf58t6vcsvq7xeumpuudqhvj38s5sus4uutspg') - expect(subject.create_address(1)).to eq('bitcoincash:qz94rwzlgccnkvaaea5klmtmad32l8gndgrcfwaryc') - expect(subject.create_address(2)).to eq('bitcoincash:qrgpwhl6x5qvf8ratcdl992r5afuv6286ujfa82xrh') + expect(subject.create_address(0)).to eq('bchtest:qpfspf58t6vcsvq7xeumpuudqhvj38s5su58cmf8x5') + expect(subject.create_address(1)).to eq('bchtest:qz94rwzlgccnkvaaea5klmtmad32l8gndg82dfl5ry') + expect(subject.create_address(2)).to eq('bchtest:qrgpwhl6x5qvf8ratcdl992r5afuv6286ukmeqg3yt') end end end diff --git a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_BitcoinCash/gets_an_empty_result_when_no_transactions_found.yml b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_BitcoinCash/gets_an_empty_result_when_no_transactions_found.yml index 6e5f5b5..e69de29 100644 --- a/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_BitcoinCash/gets_an_empty_result_when_no_transactions_found.yml +++ b/spec/fixtures/vcr_cassettes/CryptocoinPayable_Adapters_BitcoinCash/gets_an_empty_result_when_no_transactions_found.yml @@ -1,62 +0,0 @@ ---- -http_interactions: -- request: - method: get - uri: https://bitcoincash.blockexplorer.com/api/txs/?address=16E1jiUfQevixSoe7uE4fscNj4PjJkd1o9 - body: - encoding: US-ASCII - string: '' - headers: - Accept-Encoding: - - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 - Accept: - - "*/*" - User-Agent: - - Ruby - response: - status: - code: 200 - message: OK - headers: - Date: - - Fri, 12 Oct 2018 07:32:41 GMT - Content-Type: - - application/json; charset=utf-8 - Content-Length: - - '25' - Connection: - - keep-alive - Set-Cookie: - - __cfduid=daacb5c42d20ef981bf9b41e8b10381d41539329560; expires=Sat, 12-Oct-19 - 07:32:40 GMT; path=/; domain=.blockexplorer.com; HttpOnly; Secure - X-Powered-By: - - Express - X-Ratelimit-Limit: - - '10800' - X-Ratelimit-Remaining: - - '10701' - Access-Control-Allow-Origin: - - "*" - Access-Control-Allow-Methods: - - GET, HEAD, PUT, POST, OPTIONS - Access-Control-Allow-Headers: - - Origin, X-Requested-With, Content-Type, Accept, Content-Length, Cache-Control, - cf-connecting-ip - X-Content-Type-Options: - - nosniff - Etag: - - W/"19-yV2jHjCT6452sEiXtqmAbfkYdac" - Vary: - - Accept-Encoding - Expect-Ct: - - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" - Server: - - cloudflare - Cf-Ray: - - 4687dfb7d85f318c-SIN - body: - encoding: UTF-8 - string: '{"pagesTotal":0,"txs":[]}' - http_version: - recorded_at: Fri, 12 Oct 2018 07:32:42 GMT -recorded_with: VCR 4.0.0 From bee2378ba2a436a6a9ece9b3664612e1505d4bf5 Mon Sep 17 00:00:00 2001 From: Stephane Bounmy <159814+sbounmy@users.noreply.github.com> Date: Wed, 6 Dec 2023 11:55:51 +0100 Subject: [PATCH 6/6] added bin/cucumber which fixes features by loading db schema properly --- README.md | 2 +- bin/cucumber | 11 +++++++++++ spec/dummy/config/database.yml | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 bin/cucumber diff --git a/README.md b/README.md index 38aaa3d..2780ad8 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ docker-compose up --build ```sh -docker-compose run web features +docker-compose run web bin/cucumber features docker-compose run web rspec docker-compose run web rubocop ``` diff --git a/bin/cucumber b/bin/cucumber new file mode 100755 index 0000000..eb5e962 --- /dev/null +++ b/bin/cucumber @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first +if vendored_cucumber_bin + load File.expand_path(vendored_cucumber_bin) +else + require 'rubygems' unless ENV['NO_RUBYGEMS'] + require 'cucumber' + load Cucumber::BINARY +end diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml index f0f8e52..3f0ce0f 100644 --- a/spec/dummy/config/database.yml +++ b/spec/dummy/config/database.yml @@ -1,3 +1,11 @@ +development: + adapter: postgresql + host: db + encoding: unicode + pool: 5 + database: cryptocoin_payable_development + username: postgres + test: adapter: postgresql host: db