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 +4 -4
- data/README.md +30 -8
- data/lib/adequate_crypto_address.rb +3 -1
- data/lib/adequate_crypto_address/version.rb +1 -1
- data/spec/adequate_crypto_address_spec.rb +18 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f7abf6ba909332001fc5fab5db12fd1177aa7d456f4a339fa3e9bda27911cb9
|
4
|
+
data.tar.gz: e02c961746fa7768da235cf315a9c381b1b76a82c82343cf39c6fcd290b445f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
|
56
|
+
# ETH
|
57
|
+
AdequateCryptoAddress.address('D1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', 'eth').address #=> "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"
|
58
|
+
```
|
59
|
+
|
60
|
+
## Development
|
38
61
|
|
39
|
-
|
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)
|
@@ -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
|
-
|
86
|
-
|
87
|
-
expect(described_class).to be_valid('
|
88
|
-
expect(described_class).to be_valid('
|
89
|
-
expect(described_class).to be_valid('
|
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('
|
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
|