adequate_crypto_address 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef585fbee4de982f4a6dc07dabb0f1673b55c013b90a8994c734dfbc2bad6c73
4
- data.tar.gz: 891e4cc96c4aa068be0a5d8d5304e47d925b13a0d72f1a246d156ec4bbdfa993
3
+ metadata.gz: 3f7abf6ba909332001fc5fab5db12fd1177aa7d456f4a339fa3e9bda27911cb9
4
+ data.tar.gz: e02c961746fa7768da235cf315a9c381b1b76a82c82343cf39c6fcd290b445f7
5
5
  SHA512:
6
- metadata.gz: b35477ea4b88bf53ba4995760ab6817ec05f9789cb2b952a7778ff590ded8a67f96e6e84f05f65926f4adeda837b3e067ee89af2be3d690178265549259a3265
7
- data.tar.gz: 144c2deec22c1e536a0667e7654c0abfe7eb271e02329b27b849f8277aad29067c12878ae751d95bb8261d2c4ef6163e08cd9bbc946f50132816cb5d3874929d
6
+ metadata.gz: c517de74d9547b1adb25fed8ac499912b2d7d0a289d2404db0b4415b8d17aff6e739149dd035d98a0e65cd72a1c5b13855d9ebd5d7185736d9640cc539eb8561
7
+ data.tar.gz: e68fb7d7efb67f867d01e90a5ffec8d766df845643bb3a938952b229251f55fd9fec0baa84253073d79ae832f304fa7f04fa94ddcad39a24ff2625df6a166fd2
data/README.md CHANGED
@@ -8,9 +8,6 @@
8
8
 
9
9
 
10
10
 
11
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/adequate_crypto_address`. To experiment with that code, run `bin/console` for an interactive prompt.
12
-
13
- TODO: Delete this and the text above, and describe your gem
14
11
 
15
12
  ## Installation
16
13
 
@@ -30,17 +27,42 @@ Or install it yourself as:
30
27
 
31
28
  ## Usage
32
29
 
33
- TODO: Write usage instructions here
30
+ ### Validation
31
+ ``` ruby
32
+ require 'adequate_crypto_address'
33
+ # BTC
34
+ AdequateCryptoAddress.valid?('12QeMLzSrB8XH8FvEzPMVoRxVAzTr5XM2y', 'BTC') #=> true
35
+ AdequateCryptoAddress.valid?('3NJZLcZEEYBpxYEUGewU4knsQRn1WM5Fkt', :bitcoin, :p2sh) #=> true
36
+
37
+ # BCH
38
+ AdequateCryptoAddress.valid?('bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk', :bch) #=> true
39
+ AdequateCryptoAddress.valid?('mmRH4e9WW4ekZUP5HvBScfUyaSUjfQRyvD', :BCH, :P2PKHTestnet) #=> true
40
+ AdequateCryptoAddress.valid?('qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk', :BCH, :bitcoincash) #=> true
41
+
42
+ # ETH
43
+ AdequateCryptoAddress.valid?('0xde709f2102306220921060314715629080e2fb77', :ETH) #=> true
44
+ AdequateCryptoAddress.valid?('de709f2102306220921060314715629080e2fb77', :ethereum) #=> true
45
+ ```
46
+
47
+ ### Normalization
48
+ ``` ruby
49
+ require 'adequate_crypto_address'
34
50
 
35
- ## Development
51
+ # BCH
52
+ AdequateCryptoAddress.address('qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk', 'bch').address #=> "bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk"
53
+ AdequateCryptoAddress.address('mmRH4e9WW4ekZUP5HvBScfUyaSUjfQRyvD', 'bch').cash_address #=> "bchtest:qpqtmmfpw79thzq5z7s0spcd87uhn6d34uqqem83hf"
54
+ AdequateCryptoAddress.address('bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk', 'bch').legacy_address #=> "1LcerwTc1oPsMtByDCNUXFxReZpN1EXHoe"
36
55
 
37
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+ # ETH
57
+ AdequateCryptoAddress.address('D1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', 'eth').address #=> "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"
58
+ ```
59
+
60
+ ## Development
38
61
 
39
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
62
+ Run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
63
 
41
64
  ## Contributing
42
65
 
43
-
44
66
  1. Fork [the repo](https://github.com/vtm9/adequate_crypto_address)
45
67
  2. Grab dependencies: `bundle install`
46
68
  3. Make sure everything is working: `bundle exec rake spec`
@@ -7,7 +7,7 @@ require 'adequate_crypto_address/bch'
7
7
 
8
8
 
9
9
  module AdequateCryptoAddress
10
-
10
+ class UnknownCurrency < StandardError; end
11
11
  module_function
12
12
 
13
13
  def valid?(address, currency, type = nil)
@@ -16,6 +16,8 @@ module AdequateCryptoAddress
16
16
 
17
17
  def address(address, currency)
18
18
  AdequateCryptoAddress.const_get(currency.capitalize).new(address)
19
+ rescue NameError
20
+ raise UnknownCurrency, "Wrong currency #{currency}"
19
21
  end
20
22
 
21
23
  def address_type(address, currency)
@@ -1,3 +1,3 @@
1
1
  module AdequateCryptoAddress
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
@@ -82,17 +82,29 @@ RSpec.describe(AdequateCryptoAddress) do
82
82
  expect(described_class).to be_valid('0x52908400098527886E0F7030069857D2E4169EE7', 'ETH')
83
83
  expect(described_class).to be_valid('0x8617E340B3D01FA5F11F306F4090FD50E238070D', 'ETH')
84
84
  expect(described_class).to be_valid('0xde709f2102306220921060314715629080e2fb77', 'ETH')
85
- expect(described_class).to be_valid('0x27b1fdb04752bbc536007a920d24acb045561c26', 'ETH')
86
- expect(described_class).to be_valid('0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed', 'ETH')
87
- expect(described_class).to be_valid('0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359', 'ETH')
88
- expect(described_class).to be_valid('0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB', 'ETH')
89
- expect(described_class).to be_valid('0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', 'ETH')
85
+ end
86
+ it 'validates without prefixes addresses' do
87
+ expect(described_class).to be_valid('27b1fdb04752bbc536007a920d24acb045561c26', 'ETH')
88
+ expect(described_class).to be_valid('5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed', 'ETH')
89
+ expect(described_class).to be_valid('fB6916095ca1df60bB79Ce92cE3Ea74c37c5d359', 'ETH')
90
+ expect(described_class).to be_valid('dbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB', 'ETH')
91
+ expect(described_class).to be_valid('D1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', 'ETH')
90
92
  end
91
93
 
92
94
  it 'validates wrong addresses' do
93
95
  expect(described_class).not_to be_valid('0xD1110A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', 'ETH')
94
- expect(described_class).not_to be_valid('0xa10354276d2fC74ee91e37D085d35748613f4748', :ethereum)
96
+ expect(described_class).not_to be_valid('a10354276d2fC74ee91e37D085d35748613f4748', :ethereum)
95
97
  end
96
98
  end
97
99
  end
100
+
101
+ describe '.address' do
102
+ it 'returns insance' do
103
+ expect(described_class.address('D1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', 'eth')).to be_kind_of(AdequateCryptoAddress::Eth)
104
+ end
105
+
106
+ it 'raises UnknownCurrency with unknown currency' do
107
+ expect { described_class.address('addr', 'asdf') }.to raise_error(AdequateCryptoAddress::UnknownCurrency, /asdf/)
108
+ end
109
+ end
98
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adequate_crypto_address
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - vtm