blockcypher-ruby 0.2.0 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +31 -2
- data/lib/blockcypher/api.rb +112 -51
- data/lib/blockcypher-ruby.rb +1 -0
- data/spec/blockcypher/api_spec.rb +110 -43
- data/spec/config.yml +2 -0
- data/spec/config.yml.sample +2 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/Asset_API/Asset_Transfer/should_transfer_asset.yml +1349 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/Asset_API/Generate_Asset_Address/should_include_private_public_oap_address_original_address_hashes.yml +51 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/Asset_API/Issue_Asset/should_issue_asset.yml +156 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/_address_final_balance/should_get_the_balance_of_an_address.yml +102 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/_address_generate/should_generate_new_addresses.yml +97 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/_create_forwarding_address/allows_creating_a_payment_forward_with_a_callback.yml +100 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/_create_forwarding_address/allows_creating_a_payment_forward_with_a_callback_and_confirmation_notifications_enabled.yml +101 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/_create_forwarding_address/allows_creating_a_payment_forward_with_options.yml +102 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/_create_forwarding_address/creates_a_payment_forward.yml +99 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/_create_forwarding_address/is_possible_to_use_the_alias_create_payments_forwarding.yml +99 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/_delete_forwarding_address/deletes_all_previously_created_forwarding_addresses.yml +269 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/_faucet/should_fund_a_bcy_test_address_with_the_faucet.yml +96 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/_list_forwarding_addresses/lists_all_forwading_addresses_created_for_a_given_token.yml +119 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/_transaction_new/should_call_the_txs/new_api.yml +187 -0
- data/spec/fixtures/vcr_cassettes/BlockCypher_Api/_transaction_sign_and_send/should_call_txs/send_api.yml +187 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/vcr.rb +10 -0
- metadata +80 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d57bd644ca20b09669708df8ad9ee6bfde407b3ad96ea35a1b92d1fe3e6bb4a7
|
4
|
+
data.tar.gz: 74ea376dd072dddb1f795f625df8d7be4dcbe3163ef933adab48db7a99724d37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f58122d38a6b058b77e27a71ff6f31e2b36eba7207d2f53aa5ca843c82968f3bae2c7ff85bdf63ce28a3dbbdfe5443db8ebfb7926fe6c5774f149185db2391c5
|
7
|
+
data.tar.gz: 8b4c1951d6a66682a45c870c1961296fb4cabdea7e92b9633e4cc764fd152534b3e3019e4942ad53812e2097a37ff06adda382e20a47d72890298229fdac2d08
|
data/README.md
CHANGED
@@ -6,7 +6,31 @@ Simple Ruby client for the [BlockCypher](http://www.blockcypher.com) API.
|
|
6
6
|
|
7
7
|
Simply using rubygems:
|
8
8
|
|
9
|
-
|
9
|
+
gem install blockcypher-ruby
|
10
|
+
|
11
|
+
### For Rails apps
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'blockcypher-ruby', '~> 0.2.7'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ bundle install
|
23
|
+
```
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
```bash
|
28
|
+
$ git clone https://github.com/blockcypher/ruby-client.git
|
29
|
+
$ cd ruby-client
|
30
|
+
$ bundle
|
31
|
+
$ gem build blockcypher-ruby.gemspec
|
32
|
+
$ gem install blockcypher-ruby-0.2.7.gem
|
33
|
+
```
|
10
34
|
|
11
35
|
## Initializing a client
|
12
36
|
|
@@ -18,7 +42,12 @@ If you want to use BTC on the main net, which is normally what you want to do, i
|
|
18
42
|
|
19
43
|
For more information check the API docs at:
|
20
44
|
|
21
|
-
|
45
|
+
https://www.blockcypher.com/dev/bitcoin
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
- Copy `spec/config.yml.sample` to `spec/config.yml` and put your test API token
|
50
|
+
- `rspec spec`
|
22
51
|
|
23
52
|
## Contributors
|
24
53
|
|
data/lib/blockcypher/api.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module BlockCypher
|
3
4
|
V1 = 'v1'
|
4
5
|
|
5
6
|
BTC = 'btc'
|
6
7
|
LTC = 'ltc'
|
7
8
|
DOGE = 'doge'
|
8
|
-
BCY= 'bcy'
|
9
|
+
BCY = 'bcy'
|
10
|
+
ETH = 'eth'
|
9
11
|
|
10
12
|
MAIN_NET = 'main'
|
11
13
|
TEST_NET = 'test'
|
12
14
|
TEST_NET_3 = 'test3'
|
13
15
|
|
14
16
|
class Api
|
15
|
-
|
16
|
-
class Error < RuntimeError ; end
|
17
|
+
class Error < RuntimeError; end
|
17
18
|
|
18
19
|
attr_reader :api_token
|
19
20
|
|
@@ -32,8 +33,8 @@ module BlockCypher
|
|
32
33
|
api_http_get('/txs')
|
33
34
|
end
|
34
35
|
|
35
|
-
def blockchain_transaction(transaction_hash)
|
36
|
-
api_http_get('/txs/' + transaction_hash)
|
36
|
+
def blockchain_transaction(transaction_hash, **params)
|
37
|
+
api_http_get('/txs/' + transaction_hash, query: params)
|
37
38
|
end
|
38
39
|
|
39
40
|
def blockchain_block(block_index, params)
|
@@ -56,9 +57,9 @@ module BlockCypher
|
|
56
57
|
##################
|
57
58
|
# Transaction API
|
58
59
|
##################
|
59
|
-
|
60
|
+
|
60
61
|
def decode_hex(hex)
|
61
|
-
payload = { 'tx' => hex}
|
62
|
+
payload = { 'tx' => hex }
|
62
63
|
api_http_post('/txs/decode', json_payload: payload)
|
63
64
|
end
|
64
65
|
|
@@ -68,10 +69,7 @@ module BlockCypher
|
|
68
69
|
end
|
69
70
|
|
70
71
|
def send_money(from_address, to_address, satoshi_amount, private_key)
|
71
|
-
|
72
|
-
unless to_address.kind_of? Array
|
73
|
-
to_address = [to_address]
|
74
|
-
end
|
72
|
+
to_address = [to_address] unless to_address.is_a? Array
|
75
73
|
|
76
74
|
tx_new = transaction_new([from_address], to_address, satoshi_amount)
|
77
75
|
|
@@ -114,13 +112,13 @@ module BlockCypher
|
|
114
112
|
signatures = []
|
115
113
|
|
116
114
|
tosign.each do |to_sign_hex|
|
117
|
-
to_sign_binary = [to_sign_hex].pack(
|
115
|
+
to_sign_binary = [to_sign_hex].pack('H*')
|
118
116
|
sig_binary = key.sign(to_sign_binary)
|
119
|
-
sig_hex = sig_binary.
|
117
|
+
sig_hex = sig_binary.unpack1('H*')
|
120
118
|
signatures << sig_hex
|
121
119
|
end
|
122
120
|
|
123
|
-
|
121
|
+
signatures
|
124
122
|
end
|
125
123
|
|
126
124
|
def transaction_new_custom(payload)
|
@@ -140,8 +138,8 @@ module BlockCypher
|
|
140
138
|
|
141
139
|
##################
|
142
140
|
# Microtx API
|
143
|
-
##################
|
144
|
-
|
141
|
+
##################
|
142
|
+
|
145
143
|
# This method sends private key to server
|
146
144
|
def microtx_from_priv(private_key, to_address, value_satoshis)
|
147
145
|
payload = {
|
@@ -174,33 +172,58 @@ module BlockCypher
|
|
174
172
|
end
|
175
173
|
|
176
174
|
def address_generate_multi(pubkeys, script_type)
|
177
|
-
payload = { 'pubkeys' => pubkeys, 'script_type' => script_type}
|
175
|
+
payload = { 'pubkeys' => pubkeys, 'script_type' => script_type }
|
178
176
|
api_http_post('/addrs', json_payload: payload)
|
179
177
|
end
|
180
178
|
|
181
|
-
def address_details(address, unspent_only: false
|
182
|
-
|
179
|
+
def address_details(address, unspent_only: false, limit: 50,
|
180
|
+
before: nil, after: nil, confirmations: nil,
|
181
|
+
omit_wallet_addresses: false, include_confidence: false)
|
182
|
+
query = {
|
183
|
+
unspentOnly: unspent_only,
|
184
|
+
limit: limit,
|
185
|
+
omitWalletAddresses: omit_wallet_addresses,
|
186
|
+
includeConfidence: include_confidence
|
187
|
+
}
|
188
|
+
query[:before] = before if before
|
189
|
+
query[:after] = after if after
|
190
|
+
|
191
|
+
api_http_get('/addrs/' + address, query: query)
|
183
192
|
end
|
184
193
|
|
185
|
-
def address_balance(address)
|
186
|
-
|
194
|
+
def address_balance(address, omit_wallet_addresses: false)
|
195
|
+
query = { omitWalletAddresses: omit_wallet_addresses }
|
196
|
+
api_http_get('/addrs/' + address + '/balance', query: query)
|
187
197
|
end
|
188
198
|
|
189
|
-
def address_final_balance(address)
|
190
|
-
details = address_balance(address
|
199
|
+
def address_final_balance(address, omit_wallet_addresses: false)
|
200
|
+
details = address_balance(address,
|
201
|
+
omit_wallet_addresses: omit_wallet_addresses)
|
191
202
|
details['final_balance']
|
192
203
|
end
|
193
204
|
|
194
|
-
def address_full_txs(address, limit: 10
|
195
|
-
|
205
|
+
def address_full_txs(address, limit: 10, before: nil, after: nil,
|
206
|
+
include_hex: false, omit_wallet_addresses: false,
|
207
|
+
include_confidence: false, txlimit: 20)
|
208
|
+
query = {
|
209
|
+
limit: limit,
|
210
|
+
includeHex: include_hex,
|
211
|
+
omitWalletAddresses: omit_wallet_addresses,
|
212
|
+
includeConfidence: include_confidence,
|
213
|
+
txlimit: txlimit
|
214
|
+
}
|
215
|
+
query[:before] = before if before
|
216
|
+
query[:after] = after if after
|
217
|
+
|
218
|
+
api_http_get("/addrs/#{address}/full", query: query)
|
196
219
|
end
|
197
220
|
|
198
221
|
##################
|
199
222
|
# Wallet API
|
200
223
|
##################
|
201
|
-
|
224
|
+
|
202
225
|
def wallet_create(name, addresses)
|
203
|
-
payload = { 'name' => name, 'addresses' => Array(addresses)}
|
226
|
+
payload = { 'name' => name, 'addresses' => Array(addresses) }
|
204
227
|
api_http_post('/wallets', json_payload: payload)
|
205
228
|
end
|
206
229
|
|
@@ -208,9 +231,11 @@ module BlockCypher
|
|
208
231
|
api_http_get('/wallets/' + name)
|
209
232
|
end
|
210
233
|
|
211
|
-
def wallet_add_addr(name, addresses)
|
212
|
-
payload = { 'addresses' => Array(addresses)}
|
213
|
-
|
234
|
+
def wallet_add_addr(name, addresses, omit_wallet_addresses: false)
|
235
|
+
payload = { 'addresses' => Array(addresses) }
|
236
|
+
query = { omitWalletAddresses: omit_wallet_addresses }
|
237
|
+
api_http_post('/wallets/' + name + '/addresses',
|
238
|
+
json_payload: payload, query: query)
|
214
239
|
end
|
215
240
|
|
216
241
|
def wallet_get_addr(name)
|
@@ -218,8 +243,8 @@ module BlockCypher
|
|
218
243
|
end
|
219
244
|
|
220
245
|
def wallet_delete_addr(name, addresses)
|
221
|
-
addrjoin = addresses.join(
|
222
|
-
api_http_delete('/wallets/' + name + '/addresses', query: { address: addrjoin})
|
246
|
+
addrjoin = addresses.join(';')
|
247
|
+
api_http_delete('/wallets/' + name + '/addresses', query: { address: addrjoin })
|
223
248
|
end
|
224
249
|
|
225
250
|
def wallet_gen_addr(name)
|
@@ -234,15 +259,12 @@ module BlockCypher
|
|
234
259
|
# Events API
|
235
260
|
##################
|
236
261
|
|
237
|
-
def event_webhook_subscribe(url, event,
|
262
|
+
def event_webhook_subscribe(url, event, options = {})
|
238
263
|
payload = {
|
239
264
|
url: url,
|
240
|
-
event: event
|
241
|
-
}
|
242
|
-
|
243
|
-
payload[:hash] = hash if hash
|
244
|
-
payload[:script] = script if script
|
245
|
-
payload[:confirmations] = confirmations if confirmations
|
265
|
+
event: event
|
266
|
+
}.merge(options)
|
267
|
+
|
246
268
|
api_http_post('/hooks', json_payload: payload)
|
247
269
|
end
|
248
270
|
|
@@ -262,23 +284,61 @@ module BlockCypher
|
|
262
284
|
# Payments and Forwarding API
|
263
285
|
##################
|
264
286
|
|
265
|
-
def create_forwarding_address(
|
287
|
+
def create_forwarding_address(
|
288
|
+
destination,
|
289
|
+
callback_url: nil,
|
290
|
+
enable_confirmations: false,
|
291
|
+
mining_fees_satoshis: nil
|
292
|
+
)
|
266
293
|
payload = {
|
267
294
|
destination: destination,
|
268
295
|
callback_url: callback_url,
|
269
|
-
enable_confirmations: enable_confirmations
|
296
|
+
enable_confirmations: enable_confirmations,
|
297
|
+
mining_fees_satoshis: mining_fees_satoshis
|
270
298
|
}
|
271
299
|
api_http_post('/payments', json_payload: payload)
|
272
300
|
end
|
273
301
|
|
274
|
-
alias
|
302
|
+
alias create_payments_forwarding create_forwarding_address
|
275
303
|
|
276
304
|
def list_forwarding_addresses
|
277
|
-
api_http_get(
|
305
|
+
api_http_get('/payments')
|
278
306
|
end
|
279
307
|
|
280
308
|
def delete_forwarding_address(id)
|
281
|
-
api_http_delete(
|
309
|
+
api_http_delete('/payments/' + id)
|
310
|
+
end
|
311
|
+
|
312
|
+
#############
|
313
|
+
# Asset API #
|
314
|
+
#############
|
315
|
+
|
316
|
+
def generate_asset_address
|
317
|
+
api_http_post('/oap/addrs')
|
318
|
+
end
|
319
|
+
|
320
|
+
def issue_asset(from_private, to_address, amount)
|
321
|
+
api_http_post('/oap/issue', json_payload: {
|
322
|
+
from_private: from_private,
|
323
|
+
to_address: to_address,
|
324
|
+
amount: amount
|
325
|
+
})
|
326
|
+
end
|
327
|
+
|
328
|
+
def transfer_asset(asset_id, from_private, to_address, amount)
|
329
|
+
api_http_post("/oap/#{asset_id}/transfer", json_payload: {
|
330
|
+
from_private: from_private,
|
331
|
+
to_address: to_address,
|
332
|
+
amount: amount
|
333
|
+
})
|
334
|
+
end
|
335
|
+
|
336
|
+
def asset_txs(asset_id)
|
337
|
+
api_http_get("/oap/#{asset_id}/txs")
|
338
|
+
end
|
339
|
+
|
340
|
+
def asset_address(asset_id, oap_address)
|
341
|
+
api_http_get("/oap/#{asset_id}/addrs/#{oap_address}")
|
282
342
|
end
|
283
343
|
|
284
344
|
private
|
@@ -287,7 +347,7 @@ module BlockCypher
|
|
287
347
|
uri = endpoint_uri(api_path, query)
|
288
348
|
|
289
349
|
# Build the connection
|
290
|
-
http
|
350
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
291
351
|
http.use_ssl = true
|
292
352
|
|
293
353
|
# Build the Request
|
@@ -307,19 +367,20 @@ module BlockCypher
|
|
307
367
|
end
|
308
368
|
|
309
369
|
response = http.request(request)
|
370
|
+
response_code = response.code.to_i
|
310
371
|
|
311
372
|
# Detect errors/return 204 empty body
|
312
|
-
if
|
313
|
-
raise Error
|
314
|
-
elsif
|
373
|
+
if response_code >= 400
|
374
|
+
raise Error, uri.to_s + ' Response:' + response.body
|
375
|
+
elsif response_code == 204
|
315
376
|
return nil
|
316
377
|
end
|
317
378
|
|
318
379
|
# Process the response
|
319
380
|
begin
|
320
381
|
json_response = JSON.parse(response.body)
|
321
|
-
|
322
|
-
rescue => e
|
382
|
+
json_response
|
383
|
+
rescue StandardError => e
|
323
384
|
raise "Unable to parse JSON response #{e.inspect}, #{response.body}"
|
324
385
|
end
|
325
386
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'blockcypher'
|
@@ -1,88 +1,110 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
2
4
|
|
3
5
|
module BlockCypher
|
6
|
+
describe Api, vcr: { record: :once } do
|
7
|
+
let(:api) do
|
8
|
+
BlockCypher::Api.new({
|
9
|
+
api_token: CONFIG[:api_token],
|
10
|
+
currency: BlockCypher::BCY,
|
11
|
+
network: BlockCypher::TEST_NET,
|
12
|
+
version: BlockCypher::V1
|
13
|
+
})
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:addr1) { api.address_generate }
|
17
|
+
let(:addr2) { api.address_generate }
|
18
|
+
context '#address_generate' do
|
19
|
+
it 'should generate new addresses' do
|
20
|
+
expect(addr1['address']).to be_a(String)
|
21
|
+
expect(addr2['address']).to be_a(String)
|
22
|
+
end
|
23
|
+
end
|
4
24
|
|
5
|
-
|
6
|
-
let(:
|
25
|
+
let(:address_1) { addr1['address'].to_s }
|
26
|
+
let(:address_1_private_key) { addr1['private'].to_s }
|
7
27
|
|
8
|
-
let(:
|
9
|
-
let(:
|
28
|
+
let(:address_2) { addr2['address'].to_s }
|
29
|
+
let(:address_2_private_key) { addr2['private'].to_s }
|
10
30
|
|
11
|
-
|
12
|
-
|
31
|
+
context '#faucet' do
|
32
|
+
it 'should fund a bcy test address with the faucet' do
|
33
|
+
res = api.faucet(address_1, 100_000)
|
34
|
+
expect(res['tx_ref']).to be_a(String)
|
35
|
+
end
|
36
|
+
end
|
13
37
|
|
14
38
|
context '#transaction_new' do
|
15
|
-
|
16
39
|
it 'should call the txs/new api' do
|
17
40
|
input_addresses = [address_1]
|
18
41
|
output_addresses = [address_2]
|
19
|
-
satoshi_value =
|
42
|
+
satoshi_value = 20_000
|
20
43
|
res = api.transaction_new(input_addresses, output_addresses, satoshi_value)
|
21
|
-
expect(res[
|
22
|
-
expect(res[
|
44
|
+
expect(res['tx']['hash']).to be_a(String)
|
45
|
+
expect(res['tx']['hash'].length).to be(64)
|
23
46
|
end
|
24
47
|
end
|
25
48
|
|
26
49
|
context '#transaction_sign_and_send' do
|
27
|
-
|
28
50
|
it 'should call txs/send api' do
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
satoshi_value = 10000
|
51
|
+
input_addresses = [address_1]
|
52
|
+
output_addresses = [address_2]
|
53
|
+
satoshi_value = 10_000
|
33
54
|
|
34
55
|
new_tx = api.transaction_new(input_addresses, output_addresses, satoshi_value)
|
35
|
-
res = api.transaction_sign_and_send(new_tx,
|
36
|
-
expect(res[
|
37
|
-
expect(res[
|
56
|
+
res = api.transaction_sign_and_send(new_tx, address_1_private_key)
|
57
|
+
expect(res['tx']['hash']).to be_a(String)
|
58
|
+
expect(res['tx']['hash'].length).to be(64)
|
38
59
|
end
|
39
|
-
|
40
60
|
end
|
41
61
|
|
42
62
|
context '#address_final_balance' do
|
43
|
-
|
44
63
|
it 'should get the balance of an address' do
|
45
64
|
balance = api.address_final_balance(address_1)
|
46
65
|
expect(balance).to be_kind_of Integer
|
47
66
|
expect(balance).to be > 0
|
48
67
|
end
|
49
|
-
|
50
68
|
end
|
51
69
|
|
52
70
|
context '#create_forwarding_address' do
|
53
|
-
|
54
71
|
it 'creates a payment forward' do
|
55
|
-
forward_details = api.create_forwarding_address(address_1
|
56
|
-
expect(forward_details[
|
57
|
-
expect(forward_details[
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'allows creating a payment forward with a callback' do
|
61
|
-
forward_details = api.create_forwarding_address(address_1, "foo", callback_url: "http://test.com/foo")
|
62
|
-
expect(forward_details["callback_url"]).to eql("http://test.com/foo")
|
63
|
-
expect(forward_details["enable_confirmations"]).to be nil
|
72
|
+
forward_details = api.create_forwarding_address(address_1)
|
73
|
+
expect(forward_details['input_address']).to be_a(String)
|
74
|
+
expect(forward_details['input_address'].length).to be(34) # Ok this isn't strictly true but..
|
64
75
|
end
|
65
76
|
|
66
|
-
it 'allows creating a payment forward with
|
67
|
-
forward_details = api.create_forwarding_address(address_1,
|
68
|
-
|
69
|
-
|
77
|
+
it 'allows creating a payment forward with options' do
|
78
|
+
forward_details = api.create_forwarding_address(address_1, {
|
79
|
+
callback_url: 'http://test.com/foo',
|
80
|
+
enable_confirmations: true,
|
81
|
+
mining_fees_satoshis: 20_000
|
82
|
+
})
|
83
|
+
expect(forward_details['callback_url']).to eql('http://test.com/foo')
|
84
|
+
expect(forward_details['enable_confirmations']).to be true
|
85
|
+
expect(forward_details['mining_fees_satoshis']).to be 20_000
|
70
86
|
end
|
71
87
|
|
72
88
|
it 'is possible to use the alias create_payments_forwarding' do
|
73
|
-
forward_details = api.create_payments_forwarding(address_1
|
74
|
-
expect(forward_details[
|
89
|
+
forward_details = api.create_payments_forwarding(address_1)
|
90
|
+
expect(forward_details['input_address']).to be_a(String)
|
75
91
|
end
|
76
|
-
|
77
92
|
end
|
78
93
|
|
79
94
|
context '#list_forwarding_addresses' do
|
80
|
-
|
81
95
|
it 'lists all forwading addresses created for a given token' do
|
82
|
-
forwarding_addresses = api.list_forwarding_addresses
|
83
|
-
expect(forwarding_addresses.first[
|
96
|
+
forwarding_addresses = api.list_forwarding_addresses
|
97
|
+
expect(forwarding_addresses.first['destination']).to eql(address_1)
|
84
98
|
end
|
99
|
+
end
|
85
100
|
|
101
|
+
context '#delete_forwarding_address' do
|
102
|
+
it 'deletes all previously created forwarding addresses' do
|
103
|
+
forwarding_addresses = api.list_forwarding_addresses
|
104
|
+
forwarding_addresses.each { |x| api.delete_forwarding_address(x['id']) }
|
105
|
+
forwarding_addresses = api.list_forwarding_addresses
|
106
|
+
expect(forwarding_addresses.any? == false)
|
107
|
+
end
|
86
108
|
end
|
87
109
|
|
88
110
|
describe '#endpoint_uri' do
|
@@ -98,6 +120,51 @@ module BlockCypher
|
|
98
120
|
end
|
99
121
|
end
|
100
122
|
|
101
|
-
|
123
|
+
describe 'Asset API' do
|
124
|
+
describe 'Generate Asset Address' do
|
125
|
+
it 'should include private, public, oap_address, original_address hashes' do
|
126
|
+
res = api.generate_asset_address
|
127
|
+
expect(res).to include('private', 'public', 'oap_address', 'original_address')
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe 'Issue Asset' do
|
132
|
+
it 'should issue asset' do
|
133
|
+
asset_address = api.generate_asset_address
|
134
|
+
api.faucet(asset_address['original_address'], 1_000_000)
|
135
|
+
res = api.issue_asset(asset_address['private'], asset_address['oap_address'], 1000)
|
136
|
+
|
137
|
+
expect(res).to include(
|
138
|
+
'ver',
|
139
|
+
'assetid',
|
140
|
+
'oap_meta',
|
141
|
+
'hash',
|
142
|
+
'received',
|
143
|
+
'double_spend',
|
144
|
+
'inputs',
|
145
|
+
'outputs'
|
146
|
+
)
|
147
|
+
end
|
148
|
+
end
|
102
149
|
|
150
|
+
describe 'Asset Transfer' do
|
151
|
+
it 'should transfer asset' do
|
152
|
+
asset_address = api.generate_asset_address
|
153
|
+
asset_address_to = api.generate_asset_address
|
154
|
+
api.faucet(asset_address['original_address'], 100_000_000)
|
155
|
+
asset = api.issue_asset(asset_address['private'], asset_address['oap_address'], 1000)
|
156
|
+
|
157
|
+
puts 'waiting asset to been issued'
|
158
|
+
begin
|
159
|
+
printf('|')
|
160
|
+
check_address = api.asset_address(asset['assetid'], asset_address['oap_address'])
|
161
|
+
sleep(1)
|
162
|
+
end while check_address['n_tx'] == 0
|
163
|
+
|
164
|
+
res = api.transfer_asset(asset['assetid'], asset_address['private'], asset_address_to['oap_address'], 100)
|
165
|
+
expect(res).to include('assetid')
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
103
170
|
end
|
data/spec/config.yml
ADDED