bitcoin-3rd-party-apis 0.2.0 → 0.3.0

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.
@@ -1,3 +1,7 @@
1
+ ## v0.3.0
2
+
3
+ * Added BlockchainInfo.multiaddr call.
4
+
1
5
  ## v0.2.0
2
6
 
3
7
  * Added http://blockchain.info call, BlockchainInfo.getreceivedbyaddress.
data/Guardfile CHANGED
@@ -1,7 +1,7 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
- guard 'rspec', :version => 2, :cli => "--color --format nested --fail-fast" do
4
+ guard 'rspec', :version => 2, :cli => "--color --format nested" do
5
5
  watch(%r{^lib/(.+)\.rb$}) { "spec" }
6
6
  end
7
7
 
@@ -1,3 +1,3 @@
1
1
  module Bitcoin3rdPartyApis
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,6 +1,15 @@
1
1
  class BlockchainInfo
2
2
  module BlockChain
3
3
 
4
+ def multiaddr(addresses)
5
+ if addresses.is_a?(String)
6
+ addresses = [addresses]
7
+ end
8
+
9
+ url = "#{multiaddr_url}?active=#{addresses.join('|')}"
10
+ JSON.parse(open(URI.encode(url)).read)
11
+ end
12
+
4
13
  def getreceivedbyaddress(address, minconf = 0)
5
14
  if minconf > 0
6
15
  url = "#{getreceivedbyaddress_url}/#{address}?confirmations=#{minconf}"
@@ -21,6 +30,10 @@ class BlockchainInfo
21
30
  "#{domain}/q/getreceivedbyaddress"
22
31
  end
23
32
 
33
+ def multiaddr_url
34
+ "#{domain}/multiaddr"
35
+ end
36
+
24
37
  def get_json(url)
25
38
  JSON.parse open(url).read
26
39
  end
@@ -20,6 +20,33 @@ describe BlockchainInfo do
20
20
  BlockchainInfo.getreceivedbyaddress(addressA, 120).should == BigDecimal("0.1")
21
21
  end
22
22
  end
23
+ end
24
+
25
+ context '#multiaddr' do
26
+ context 'getting transactions for one address' do
27
+ use_vcr_cassette
28
+
29
+ let(:transactions) { BlockchainInfo.multiaddr(addressA)['txs'] }
30
+
31
+ it "returns 2 transactions" do
32
+ transactions.length.should == 2
33
+ end
34
+
35
+ it "wraps the transactions in JSON" do
36
+ transactions[1]['hash'].should == "6c5067ee83752022110fafefefcbbba9f006c2c90bce0d7cba4c28258831e0af"
37
+ transactions[1]['out'][0]['value'].should == 10000000
38
+ end
39
+ end
40
+
41
+ context 'getting transactions for 2 addresses' do
42
+ use_vcr_cassette
43
+
44
+ let(:dummy) { '1abcdef' }
23
45
 
46
+ it "returns addressA transactions" do
47
+ BlockchainInfo.multiaddr([addressA, dummy])['txs'] == BlockchainInfo.multiaddr([addressA, dummy])['txs']
48
+ end
49
+ end
24
50
  end
51
+
25
52
  end
@@ -0,0 +1,81 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://blockchain.info/multiaddr?active=1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs%7C1abcdef
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Server:
20
+ - Apache-Coyote/1.1
21
+ Set-Cookie:
22
+ - SID=b63bd142-d643-4f46-acc1-d9c17f7e9d07; Expires=Fri, 03-Aug-2012 23:29:35
23
+ GMT; Path=/
24
+ Content-Type:
25
+ - application/json;charset=UTF-8
26
+ Content-Length:
27
+ - '1849'
28
+ Date:
29
+ - Fri, 06 Jul 2012 23:29:35 GMT
30
+ body:
31
+ encoding: US-ASCII
32
+ string: ! "\n\n{\n\n\t\"info\": {\n\t\t\n\t\t\"conversion\":100000000,\n\t\t\"nconnected\":274,\n\t\t\"symbol_local\":{\"code\"
33
+ : \"USD\", \"symbol\" : \"$\", \"name\" : \"U.S. dollar\", \"conversion\"
34
+ : 14880996, \"symbolAppearsAfter\" : false}\n\t\t, \"latest_block\" : { \n\t\t\t\"height\":187864,\n\t\t\t\"block_index\":243230,\n\t\t\t\"hash\":\"0000000000000728cb6fd5d75bdcd886315d4cbdd7130a6fc24c97f228519fea\",\n\t\t\t\"time\":1341617277\n\t\t},
35
+ \"error\" : \"You have an invalid bitcoin address\"\n\t}\n\t,\"wallet\": {\n\t\t\"n_tx\":2,\n\t\t\"n_tx_filtered\":2,\n\t\t\"total_received\":10000000,\n\t\t\"total_sent\":10000000,\n\t\t\"final_balance\":0\n\t},\n\t\"addresses\":[\n\t\n\t{\n\t\t\"address\":\"1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs\",\n\t\t\"n_tx\":2,\n\t\t\"total_received\":10000000,\n\t\t\"total_sent\":10000000,\n\t\t\"final_balance\":0\n\t}\n\t\n\t],\t\t\t\n\t\"txs\":[\n\t\n\t\n\t\n\t\n\t\n\t\n{\n\t\"hash\":\"21dd59c14dc771550b78dbfb3fd57386ad21bb02ad8c8989c7e6bbd8a2e85418\",\n\t\"ver\":1,\n\t\"vin_sz\":1,\n\t\"vout_sz\":1,\n\t\"size\":223,\n\t\"relayed_by\":\"199.188.194.36\",\n\t\"tx_index\":2597766,\"result\":-10000000,\"balance\":0,\n\t\"time\":1330114726,\"block_height\":166328,\n\t\"inputs\":[\n\t\t\t{\n\t\t\t\t\n\t\t\t\t\"prev_out\":{\n\t\t\t\t\t\"type\":0,\n\t\t\t\t\t\"addr\":\"1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs\",
36
+ \ \n\t\t\t\t\t\"value\":10000000,\n\t\t\t\t\t\"tx_index\":2361741,\n\t\t\t\t\t\"n\":1\n\t\t\t\t}\n\t\t\t}\n\t\t],\n\t\"out\":[\n\t\t\t{\n\t\t\t\t\"addr\":\"1Eqr3DVzC1c2n85WkffznhXTp2dmUY6RLm\",
37
+ \ \n\t\t\t\t\"value\":10000000, \n\t\t\t\t\"type\":0\n\t\t\t}\n\t\t]\n},\n\t\n\t\n\t\n\t\n\t\n\t\n{\n\t\"hash\":\"6c5067ee83752022110fafefefcbbba9f006c2c90bce0d7cba4c28258831e0af\",\n\t\"ver\":1,\n\t\"vin_sz\":1,\n\t\"vout_sz\":2,\n\t\"size\":257,\n\t\"relayed_by\":\"199.188.194.36\",\n\t\"tx_index\":2361741,\"result\":10000000,\"balance\":10000000,\n\t\"time\":1330114726,\"block_height\":161186,\n\t\"inputs\":[\n\t\t\t{\n\t\t\t\t\n\t\t\t\t\"prev_out\":{\n\t\t\t\t\t\"type\":0,\n\t\t\t\t\t\"addr\":\"1McjPsUHS7ifNwSnRDrvKud7h3o4aCs5Pu\",
38
+ \ \n\t\t\t\t\t\"value\":26200000,\n\t\t\t\t\t\"tx_index\":976849,\n\t\t\t\t\t\"n\":1\n\t\t\t\t}\n\t\t\t}\n\t\t],\n\t\"out\":[\n\t\t\t{\n\t\t\t\t\"addr\":\"1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs\",
39
+ \ \n\t\t\t\t\"value\":10000000, \n\t\t\t\t\"type\":0\n\t\t\t}\n\t\t]\n}]\n\t\n}"
40
+ http_version:
41
+ recorded_at: Fri, 06 Jul 2012 23:29:35 GMT
42
+ - request:
43
+ method: get
44
+ uri: https://blockchain.info/multiaddr?active=1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs%7C1abcdef
45
+ body:
46
+ encoding: US-ASCII
47
+ string: ''
48
+ headers:
49
+ Accept:
50
+ - ! '*/*'
51
+ User-Agent:
52
+ - Ruby
53
+ response:
54
+ status:
55
+ code: 200
56
+ message: OK
57
+ headers:
58
+ Server:
59
+ - Apache-Coyote/1.1
60
+ Set-Cookie:
61
+ - SID=778d143b-a737-4a60-9515-b7cf54246cb6; Expires=Fri, 03-Aug-2012 23:29:36
62
+ GMT; Path=/
63
+ Content-Type:
64
+ - application/json;charset=UTF-8
65
+ Content-Length:
66
+ - '1849'
67
+ Date:
68
+ - Fri, 06 Jul 2012 23:29:35 GMT
69
+ body:
70
+ encoding: US-ASCII
71
+ string: ! "\n\n{\n\n\t\"info\": {\n\t\t\n\t\t\"conversion\":100000000,\n\t\t\"nconnected\":274,\n\t\t\"symbol_local\":{\"code\"
72
+ : \"USD\", \"symbol\" : \"$\", \"name\" : \"U.S. dollar\", \"conversion\"
73
+ : 14880996, \"symbolAppearsAfter\" : false}\n\t\t, \"latest_block\" : { \n\t\t\t\"height\":187864,\n\t\t\t\"block_index\":243230,\n\t\t\t\"hash\":\"0000000000000728cb6fd5d75bdcd886315d4cbdd7130a6fc24c97f228519fea\",\n\t\t\t\"time\":1341617277\n\t\t},
74
+ \"error\" : \"You have an invalid bitcoin address\"\n\t}\n\t,\"wallet\": {\n\t\t\"n_tx\":2,\n\t\t\"n_tx_filtered\":2,\n\t\t\"total_received\":10000000,\n\t\t\"total_sent\":10000000,\n\t\t\"final_balance\":0\n\t},\n\t\"addresses\":[\n\t\n\t{\n\t\t\"address\":\"1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs\",\n\t\t\"n_tx\":2,\n\t\t\"total_received\":10000000,\n\t\t\"total_sent\":10000000,\n\t\t\"final_balance\":0\n\t}\n\t\n\t],\t\t\t\n\t\"txs\":[\n\t\n\t\n\t\n\t\n\t\n\t\n{\n\t\"hash\":\"21dd59c14dc771550b78dbfb3fd57386ad21bb02ad8c8989c7e6bbd8a2e85418\",\n\t\"ver\":1,\n\t\"vin_sz\":1,\n\t\"vout_sz\":1,\n\t\"size\":223,\n\t\"relayed_by\":\"199.188.194.36\",\n\t\"tx_index\":2597766,\"result\":-10000000,\"balance\":0,\n\t\"time\":1330114726,\"block_height\":166328,\n\t\"inputs\":[\n\t\t\t{\n\t\t\t\t\n\t\t\t\t\"prev_out\":{\n\t\t\t\t\t\"type\":0,\n\t\t\t\t\t\"addr\":\"1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs\",
75
+ \ \n\t\t\t\t\t\"value\":10000000,\n\t\t\t\t\t\"tx_index\":2361741,\n\t\t\t\t\t\"n\":1\n\t\t\t\t}\n\t\t\t}\n\t\t],\n\t\"out\":[\n\t\t\t{\n\t\t\t\t\"addr\":\"1Eqr3DVzC1c2n85WkffznhXTp2dmUY6RLm\",
76
+ \ \n\t\t\t\t\"value\":10000000, \n\t\t\t\t\"type\":0\n\t\t\t}\n\t\t]\n},\n\t\n\t\n\t\n\t\n\t\n\t\n{\n\t\"hash\":\"6c5067ee83752022110fafefefcbbba9f006c2c90bce0d7cba4c28258831e0af\",\n\t\"ver\":1,\n\t\"vin_sz\":1,\n\t\"vout_sz\":2,\n\t\"size\":257,\n\t\"relayed_by\":\"199.188.194.36\",\n\t\"tx_index\":2361741,\"result\":10000000,\"balance\":10000000,\n\t\"time\":1330114726,\"block_height\":161186,\n\t\"inputs\":[\n\t\t\t{\n\t\t\t\t\n\t\t\t\t\"prev_out\":{\n\t\t\t\t\t\"type\":0,\n\t\t\t\t\t\"addr\":\"1McjPsUHS7ifNwSnRDrvKud7h3o4aCs5Pu\",
77
+ \ \n\t\t\t\t\t\"value\":26200000,\n\t\t\t\t\t\"tx_index\":976849,\n\t\t\t\t\t\"n\":1\n\t\t\t\t}\n\t\t\t}\n\t\t],\n\t\"out\":[\n\t\t\t{\n\t\t\t\t\"addr\":\"1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs\",
78
+ \ \n\t\t\t\t\"value\":10000000, \n\t\t\t\t\"type\":0\n\t\t\t}\n\t\t]\n}]\n\t\n}"
79
+ http_version:
80
+ recorded_at: Fri, 06 Jul 2012 23:29:36 GMT
81
+ recorded_with: VCR 2.2.1
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://blockchain.info/multiaddr?active=1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Server:
20
+ - Apache-Coyote/1.1
21
+ Set-Cookie:
22
+ - SID=f0f08091-52f0-4554-a78f-9fd679fa6cd8; Expires=Fri, 03-Aug-2012 23:29:34
23
+ GMT; Path=/
24
+ Content-Type:
25
+ - application/json;charset=UTF-8
26
+ Content-Length:
27
+ - '1800'
28
+ Date:
29
+ - Fri, 06 Jul 2012 23:29:33 GMT
30
+ body:
31
+ encoding: US-ASCII
32
+ string: ! "\n\n{\n\n\t\"info\": {\n\t\t\n\t\t\"conversion\":100000000,\n\t\t\"nconnected\":274,\n\t\t\"symbol_local\":{\"code\"
33
+ : \"USD\", \"symbol\" : \"$\", \"name\" : \"U.S. dollar\", \"conversion\"
34
+ : 14880996, \"symbolAppearsAfter\" : false}\n\t\t, \"latest_block\" : { \n\t\t\t\"height\":187864,\n\t\t\t\"block_index\":243230,\n\t\t\t\"hash\":\"0000000000000728cb6fd5d75bdcd886315d4cbdd7130a6fc24c97f228519fea\",\n\t\t\t\"time\":1341617277\n\t\t}\n\t}\n\t,\"wallet\":
35
+ {\n\t\t\"n_tx\":2,\n\t\t\"n_tx_filtered\":2,\n\t\t\"total_received\":10000000,\n\t\t\"total_sent\":10000000,\n\t\t\"final_balance\":0\n\t},\n\t\"addresses\":[\n\t\n\t{\n\t\t\"address\":\"1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs\",\n\t\t\"n_tx\":2,\n\t\t\"total_received\":10000000,\n\t\t\"total_sent\":10000000,\n\t\t\"final_balance\":0\n\t}\n\t\n\t],\t\t\t\n\t\"txs\":[\n\t\n\t\n\t\n\t\n\t\n\t\n{\n\t\"hash\":\"21dd59c14dc771550b78dbfb3fd57386ad21bb02ad8c8989c7e6bbd8a2e85418\",\n\t\"ver\":1,\n\t\"vin_sz\":1,\n\t\"vout_sz\":1,\n\t\"size\":223,\n\t\"relayed_by\":\"199.188.194.36\",\n\t\"tx_index\":2597766,\"result\":-10000000,\"balance\":0,\n\t\"time\":1330114726,\"block_height\":166328,\n\t\"inputs\":[\n\t\t\t{\n\t\t\t\t\n\t\t\t\t\"prev_out\":{\n\t\t\t\t\t\"type\":0,\n\t\t\t\t\t\"addr\":\"1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs\",
36
+ \ \n\t\t\t\t\t\"value\":10000000,\n\t\t\t\t\t\"tx_index\":2361741,\n\t\t\t\t\t\"n\":1\n\t\t\t\t}\n\t\t\t}\n\t\t],\n\t\"out\":[\n\t\t\t{\n\t\t\t\t\"addr\":\"1Eqr3DVzC1c2n85WkffznhXTp2dmUY6RLm\",
37
+ \ \n\t\t\t\t\"value\":10000000, \n\t\t\t\t\"type\":0\n\t\t\t}\n\t\t]\n},\n\t\n\t\n\t\n\t\n\t\n\t\n{\n\t\"hash\":\"6c5067ee83752022110fafefefcbbba9f006c2c90bce0d7cba4c28258831e0af\",\n\t\"ver\":1,\n\t\"vin_sz\":1,\n\t\"vout_sz\":2,\n\t\"size\":257,\n\t\"relayed_by\":\"199.188.194.36\",\n\t\"tx_index\":2361741,\"result\":10000000,\"balance\":10000000,\n\t\"time\":1330114726,\"block_height\":161186,\n\t\"inputs\":[\n\t\t\t{\n\t\t\t\t\n\t\t\t\t\"prev_out\":{\n\t\t\t\t\t\"type\":0,\n\t\t\t\t\t\"addr\":\"1McjPsUHS7ifNwSnRDrvKud7h3o4aCs5Pu\",
38
+ \ \n\t\t\t\t\t\"value\":26200000,\n\t\t\t\t\t\"tx_index\":976849,\n\t\t\t\t\t\"n\":1\n\t\t\t\t}\n\t\t\t}\n\t\t],\n\t\"out\":[\n\t\t\t{\n\t\t\t\t\"addr\":\"1JDfUiJHZ6pDY6wWYTx86RYjDCW7QxCofs\",
39
+ \ \n\t\t\t\t\"value\":10000000, \n\t\t\t\t\"type\":0\n\t\t\t}\n\t\t]\n}]\n\t\n}"
40
+ http_version:
41
+ recorded_at: Fri, 06 Jul 2012 23:29:35 GMT
42
+ recorded_with: VCR 2.2.1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitcoin-3rd-party-apis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-18 00:00:00.000000000 Z
12
+ date: 2012-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70255676113420 !ruby/object:Gem::Requirement
16
+ requirement: &70316423310800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70255676113420
24
+ version_requirements: *70316423310800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: vcr
27
- requirement: &70255675997220 !ruby/object:Gem::Requirement
27
+ requirement: &70316423310200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70255675997220
35
+ version_requirements: *70316423310200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ir_b
38
- requirement: &70255675850020 !ruby/object:Gem::Requirement
38
+ requirement: &70316423309400 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70255675850020
46
+ version_requirements: *70316423309400
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-rspec
49
- requirement: &70255675283360 !ruby/object:Gem::Requirement
49
+ requirement: &70316423308980 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70255675283360
57
+ version_requirements: *70316423308980
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: webmock
60
- requirement: &70255675361500 !ruby/object:Gem::Requirement
60
+ requirement: &70316423308560 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70255675361500
68
+ version_requirements: *70316423308560
69
69
  description: Ruby wrapper for Block Explorer and Blockchain.info. Plan to add additional
70
70
  3rd-party bitcoin APIs
71
71
  email:
@@ -96,6 +96,8 @@ files:
96
96
  - spec/cassettes/BlockExplorer/_mytransactions/getting_transactions_for_one_address.yml
97
97
  - spec/cassettes/BlockchainInfo/_getreceivedbyaddress/minconf.yml
98
98
  - spec/cassettes/BlockchainInfo/_getreceivedbyaddress/without_minconf.yml
99
+ - spec/cassettes/BlockchainInfo/_multiaddr/getting_transactions_for_2_addresses.yml
100
+ - spec/cassettes/BlockchainInfo/_multiaddr/getting_transactions_for_one_address.yml
99
101
  - spec/spec_helper.rb
100
102
  homepage: https://github.com/matholroyd/bitcoin-3rd-party-apis
101
103
  licenses: []
@@ -130,4 +132,6 @@ test_files:
130
132
  - spec/cassettes/BlockExplorer/_mytransactions/getting_transactions_for_one_address.yml
131
133
  - spec/cassettes/BlockchainInfo/_getreceivedbyaddress/minconf.yml
132
134
  - spec/cassettes/BlockchainInfo/_getreceivedbyaddress/without_minconf.yml
135
+ - spec/cassettes/BlockchainInfo/_multiaddr/getting_transactions_for_2_addresses.yml
136
+ - spec/cassettes/BlockchainInfo/_multiaddr/getting_transactions_for_one_address.yml
133
137
  - spec/spec_helper.rb