netki 0.0.1 → 0.0.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/lib/netki/netki.rb +57 -32
- data/lib/netki/utilities.rb +51 -0
- data/lib/netki/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 803a57aec11c14749fe4e612378cb0592af844f3
|
4
|
+
data.tar.gz: 6914fbc01f9d1a448651e29a588a6e505dc2af16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a65eb7dea4aa9c7bf6a096f5eeb6eadd1d14c1c28331f41d6fec07b809db269b40c3783a4ffed41f844f41e1fc73c9c7f06550140dd6058c300ce505ca4bfd02
|
7
|
+
data.tar.gz: 35cd36fec85030406ac6890544cca6585585ac90c8eb3593fe96e57e138767ff945c26341ba4d5e7c3febf5e2945f8edf8e38cec50f0ba5e14327e3592b55117
|
data/lib/netki/netki.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'httpclient'
|
4
|
+
require 'json'
|
5
|
+
require_relative 'utilities'
|
5
6
|
|
6
7
|
module Netki
|
7
8
|
|
@@ -13,8 +14,8 @@ module Netki
|
|
13
14
|
# Setup Headers
|
14
15
|
headers = {}
|
15
16
|
headers["Content-Type"] = "application/json"
|
16
|
-
headers["Authorization"] = api_key
|
17
|
-
headers["X-Partner-ID"] = partner_id
|
17
|
+
headers["Authorization"] = api_key if api_key
|
18
|
+
headers["X-Partner-ID"] = partner_id if partner_id
|
18
19
|
|
19
20
|
# Setup Request Options
|
20
21
|
opts = {}
|
@@ -57,36 +58,54 @@ module Netki
|
|
57
58
|
return ret_data
|
58
59
|
end
|
59
60
|
|
61
|
+
# Obtain a WalletName object by querying the Netki Open API.
|
62
|
+
def self.wallet_lookup(uri, currency, api_url='https://api.netki.com')
|
63
|
+
wallet_name = URI.parse(uri).host || uri.to_s
|
64
|
+
|
65
|
+
response = process_request(nil, nil,
|
66
|
+
"#{api_url}/api/wallet_lookup/#{wallet_name}/#{currency.downcase}", 'GET')
|
67
|
+
|
68
|
+
domain_parts = response['wallet_name'].split('.')
|
69
|
+
wallet_name = domain_parts.shift
|
70
|
+
|
71
|
+
parsed = begin
|
72
|
+
parse_bitcoin_uri(response['wallet_address']).merge(
|
73
|
+
{_raw: response['wallet_address']})
|
74
|
+
rescue InvalidURIError => e
|
75
|
+
response['wallet_address']
|
76
|
+
end
|
77
|
+
WalletName.new(
|
78
|
+
domain_parts.join('.'), wallet_name,
|
79
|
+
{ response['currency'] => parsed }
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
60
83
|
##
|
61
84
|
# The WalletName object represents a Netki Wallet Name object.
|
62
85
|
#
|
63
86
|
class WalletName
|
64
87
|
|
65
88
|
##
|
66
|
-
# :args: domain_name, name, wallets, external_id, id
|
67
|
-
def initialize(domain_name, name, wallets={}, external_id
|
68
|
-
@id = id
|
89
|
+
# :args: domain_name, name, wallets, external_id, id,
|
90
|
+
def initialize(domain_name, name, wallets={}, external_id: nil, id: nil)
|
69
91
|
@domain_name = domain_name
|
70
92
|
@name = name
|
71
|
-
|
93
|
+
|
94
|
+
@wallets = wallets.inject({}) do |hsh, (currency, value)|
|
95
|
+
hsh[currency] = value.is_a?(Hash) ? value : { address: value }
|
96
|
+
hsh
|
97
|
+
end
|
72
98
|
@external_id = external_id
|
99
|
+
@id = id
|
73
100
|
end
|
74
101
|
|
75
|
-
|
76
|
-
attr_reader :domain_name
|
77
|
-
attr_reader :name
|
78
|
-
attr_reader :external_id
|
79
|
-
|
80
|
-
attr_writer :id
|
81
|
-
attr_writer :domain_name
|
82
|
-
attr_writer :name
|
83
|
-
attr_writer :external_id
|
102
|
+
attr_accessor :domain_name, :name, :id, :external_id
|
84
103
|
|
85
104
|
# :section: Getters
|
86
105
|
|
87
106
|
# Get Address for Existing Currency
|
88
107
|
def get_address(currency)
|
89
|
-
@wallets[currency]
|
108
|
+
@wallets[currency][:address]
|
90
109
|
end
|
91
110
|
|
92
111
|
# Get Wallet Name Array of Used Currencies
|
@@ -98,7 +117,7 @@ module Netki
|
|
98
117
|
|
99
118
|
# Set the address or URI for the given currency for this wallet name
|
100
119
|
def set_currency_address(currency, address)
|
101
|
-
@wallets[currency] = address
|
120
|
+
@wallets[currency][:address] = address
|
102
121
|
end
|
103
122
|
|
104
123
|
# Remove a used currency from this wallet name
|
@@ -119,18 +138,21 @@ module Netki
|
|
119
138
|
# Save the currency WalletName object to the remote service
|
120
139
|
def save
|
121
140
|
wallet_data = []
|
122
|
-
@wallets.each do |currency,
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
141
|
+
@wallets.each do |currency, wallet|
|
142
|
+
# NOTE: Unsure if remote service supports storing metadata (params/bip70 req)?
|
143
|
+
wallet_data.push(
|
144
|
+
{
|
145
|
+
currency: currency,
|
146
|
+
wallet_address: wallet[:_raw] ? wallet[:_raw] : wallet[:address]
|
147
|
+
}
|
148
|
+
)
|
127
149
|
end
|
128
150
|
|
129
151
|
wn_data = {
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
152
|
+
domain_name: @domain_name,
|
153
|
+
name: @name,
|
154
|
+
wallets: wallet_data,
|
155
|
+
external_id: @external_id || 'null'
|
134
156
|
}
|
135
157
|
|
136
158
|
wn_api_data = {}
|
@@ -286,7 +308,10 @@ module Netki
|
|
286
308
|
# Create a new Wallet Name object using this factory method.
|
287
309
|
# * domain_name -> The pre-configured domain name you would like to add this new wallet name to
|
288
310
|
# * name -> The DNS name that you would like this new wallet name to have (ie.. name.domain_name)
|
289
|
-
# * wallets -> This is a hash where the key is the currency (ie.. btc, ltc, dgc, tusd) and the value is
|
311
|
+
# * wallets -> This is a hash where the key is the currency (ie.. btc, ltc, dgc, tusd) and the value is:
|
312
|
+
# the wallet address OR
|
313
|
+
# URL of the BIP32 / BIP70 address server OR
|
314
|
+
# a hash containing an :address and other metadata
|
290
315
|
# * external_id -> Any unique external ID that you may want to use to track this specific wallet name
|
291
316
|
#
|
292
317
|
def create_new_walletname(domain_name, name, wallets={}, external_id=nil)
|
@@ -323,4 +348,4 @@ module Netki
|
|
323
348
|
wn_list
|
324
349
|
end
|
325
350
|
end
|
326
|
-
end
|
351
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Netki
|
2
|
+
|
3
|
+
KNOWN_PREFIXES = [ 'bitcoin', 'litecoin', 'dogecoin' ]
|
4
|
+
|
5
|
+
class InvalidURIError < StandardError; end
|
6
|
+
|
7
|
+
def self.parse_bitcoin_uri(uri, tolerate_errors: false)
|
8
|
+
parts = uri.split(':', 2)
|
9
|
+
|
10
|
+
unless KNOWN_PREFIXES.include?(parts.shift)
|
11
|
+
raise InvalidURIError.new("unknown URI prefix")
|
12
|
+
end
|
13
|
+
|
14
|
+
# parts => [base58][?[bitcoinparam, [&bitcoinparam, ...]]
|
15
|
+
base58address, query = parts.first.split('?', 2)
|
16
|
+
response = { address: base58address }
|
17
|
+
|
18
|
+
begin
|
19
|
+
response.merge!(_parse_bip_72(query))
|
20
|
+
rescue InvalidURIError => e
|
21
|
+
raise e unless tolerate_errors
|
22
|
+
end
|
23
|
+
|
24
|
+
response
|
25
|
+
end
|
26
|
+
|
27
|
+
# https://github.com/bitcoin/bips/blob/master/bip-0072.mediawiki
|
28
|
+
def self._parse_bip_72(querystring)
|
29
|
+
params = _parse_bip_21(querystring)
|
30
|
+
{ r: params['r'], params: params }
|
31
|
+
end
|
32
|
+
|
33
|
+
# https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
|
34
|
+
def self._parse_bip_21(querystring)
|
35
|
+
|
36
|
+
param_pairs = querystring.split('&') # '&' reserved as separator in bip21
|
37
|
+
|
38
|
+
param_pairs.inject({}) do |hsh, pair|
|
39
|
+
parts = pair.split('=') # '=' reserved as separator in bip21
|
40
|
+
|
41
|
+
raise InvalidURIError.new("unbalanced parameter #{pair}") unless (
|
42
|
+
parts.size == 2 &&
|
43
|
+
parts[0].size > 0 &&
|
44
|
+
parts[1].size > 0)
|
45
|
+
raise InvalidURIError.new("duplicate parameter #{parts[0]}") unless hsh[parts[0]].nil?
|
46
|
+
|
47
|
+
hsh[parts[0]] = parts[1]
|
48
|
+
hsh
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/netki/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt David
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- bin/setup
|
126
126
|
- lib/netki.rb
|
127
127
|
- lib/netki/netki.rb
|
128
|
+
- lib/netki/utilities.rb
|
128
129
|
- lib/netki/version.rb
|
129
130
|
- netki.gemspec
|
130
131
|
homepage: https://github.com/netkicorp/ruby-partner-client
|