blockchain-node 0.0.3 → 0.0.4

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: 61e4660d85fd214c44a0cd4265d92880e02b9e6f66dc854f43dd88c5b52487d6
4
- data.tar.gz: 72e7791adc00517c1da3441072e60fb32f6b369f4994a92c7448fe4fffa28ab0
3
+ metadata.gz: b783f22fdaaef4c70e77ed848306df99755097442ac07916bb8bcd7482fbd40b
4
+ data.tar.gz: 84bc58e6ad3c4e722879aeb5ee9dafea9c2f3eb443451f7434a7acb8d7a3d15b
5
5
  SHA512:
6
- metadata.gz: bd670cc0168af954ea0c726be2d4cc9df34b5dad9980c7cd4f471e7abe95d1ab21e7e6ffc9fd74475e5cc7b6a76e5deb5a2e894ee6a4d5783fb9dc71bffb9708
7
- data.tar.gz: 2ed1ad1f25fd1c58de1207b7ad6e5456b9b7f0caa0748da774bf7fb62a6b0391610cde88f40a0a454d5a66e32c6d491b78baab4f501de44641446bdb9abe48e2
6
+ metadata.gz: 17599574b46a450e6c65e0a03f92fba493c09e2903ca64b0c14a2bdfdc6e17006414dc7d263f772a8a4070ce7ec2c6629e6cf550008a8d58a42f47d581803882
7
+ data.tar.gz: 5d70c7b73810567ad137e5db0837d17892bf805c28e563eda338f5856e01ec4b278d0ede804acc6c4db1f85c50a500a13017d6f1b3295c7302ca27348158b602
data/README.md CHANGED
@@ -1,12 +1,10 @@
1
1
  # BlockchainNode (BCN) Ruby Client
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/blockchain-node.svg)](https://badge.fury.io/rb/blockchain-node)
4
+
3
5
  This gem is a secure RPC wrapper to connect to nodes launched by
4
6
  [https://blockchainnode.io](https://blockchainnode.io).
5
7
 
6
- Provides a Ruby library to the complete Bitcoin JSON-RPC API. Implements all methods listed
7
- at {https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list}[https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list].
8
- Also supports customizing the host and port number to connect to.
9
-
10
8
  ## Installation and Configuration
11
9
 
12
10
  ```bash
@@ -26,7 +24,7 @@ end
26
24
 
27
25
  **Security Note:**
28
26
  It is recommended that you secure your `CLIENT_ID` and `CLIENT_SECRET` and do not check that into your code repo.
29
- If your `CLIENT_ID` and `CLIENT_SECRET` are comprimised, your wallet will be secure as long as the it is
27
+ If your `CLIENT_ID` and `CLIENT_SECRET` are compromised, your wallet will be secure as long as it is
30
28
  encrypted and not left unlocked.
31
29
 
32
30
 
@@ -40,14 +38,22 @@ node_id = "123ABC"
40
38
  client = BlockchainNode::Client.new(node_id)
41
39
  ```
42
40
 
41
+ Make RPC method calls directly. Pass in parameters as args to the method call.
42
+
43
+ Other helper methods:
44
+
45
+ ```ruby
46
+ # returns a list of nodes you have running on your account
47
+ client.nodes
48
+ ```
49
+
43
50
  ### Bitcoin Example
44
51
 
45
52
 
46
- [Link to RPC Calls](README-RPC-BTC.md)
53
+ [List of Bitcoin RPC Calls](README-RPC-BTC.md)
47
54
 
48
55
  ### Ethereum Example
49
56
 
50
- Make any RPC method call directly. Pass in parameters as args to the method call.
51
57
 
52
58
  Notice, for geth, responses are returned in hex so they have to be converted to an integer.
53
59
 
@@ -64,7 +70,7 @@ resp = client.eth_getBalance("0xf4c2a25fcbaad4e568fb74d6644b164e999d3132", "late
64
70
  Integer(resp[:response]) / 1000000000000000000.0
65
71
  ```
66
72
 
67
- [Link to RPC Calls](README-RPC-ETH.md)
73
+ [List of Ethereum (geth) RPC Calls](README-RPC-ETH.md)
68
74
 
69
75
  ## Contact
70
76
 
@@ -4,10 +4,10 @@ module BlockchainNode
4
4
  @@_auth_token
5
5
  AuthToken = Struct.new(:token, :expires_at)
6
6
 
7
- attr_reader :node_id
7
+ attr_accessor :node_id
8
8
  attr_accessor :configuration
9
9
 
10
- def initialize(node_id)
10
+ def initialize(node_id = nil)
11
11
  @node_id = node_id
12
12
  # allow a different configuration per client instance
13
13
  @configuration = BlockchainNode::Configuration.new
@@ -18,6 +18,10 @@ module BlockchainNode
18
18
  request.get(path: node_index_path, auth_token: auth_token)
19
19
  end
20
20
 
21
+ def details
22
+ request.get(path: nodes_path, auth_token: auth_token)
23
+ end
24
+
21
25
  def auth_token
22
26
  @@_auth_token ||= get_new_auth_token
23
27
  @@_auth_token = get_new_auth_token if auth_token_expired?
@@ -61,6 +65,7 @@ module BlockchainNode
61
65
  end
62
66
 
63
67
  def nodes_path
68
+ raise Errors::ClientNotConfigured.new("Client Needs to be initialized with a node id.") unless @node_id
64
69
  "/api/nodes/#{@node_id}"
65
70
  end
66
71
 
@@ -1,6 +1,7 @@
1
1
  module BlockchainNode
2
2
  module Errors
3
3
  class BadRequest < StandardError; end
4
+ class ClientNotConfigured < StandardError; end
4
5
  class UnAuthorized < StandardError; end
5
6
  class Unknown < StandardError; end
6
7
  end
@@ -2,7 +2,7 @@
2
2
  module BlockchainNode
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 3
5
+ PATCH = 4
6
6
 
7
7
  VERSION = [MAJOR, MINOR, PATCH].join('.').freeze
8
8
  end
@@ -49,6 +49,13 @@ describe BlockchainNode::Configuration do
49
49
  end
50
50
 
51
51
  describe "api calls" do
52
+ it "should return a list of nodes" do
53
+ stub_oauth
54
+ stub_get_nodes
55
+ client = BlockchainNode::Client.new
56
+ resp = client.nodes
57
+ expect(resp["nodes"].first["id"]).to eq(NODE_ID)
58
+ end
52
59
  it "should make a successful API call" do
53
60
  stub_oauth
54
61
  stub_basic_method
@@ -59,4 +66,19 @@ describe BlockchainNode::Configuration do
59
66
  end
60
67
  end
61
68
 
69
+ describe "client instantiation" do
70
+ it "should allow instantiation without a client id" do
71
+ client = BlockchainNode::Client.new
72
+ expect(client.node_id).to be_nil
73
+
74
+ expect{client.details}.to raise_error(BlockchainNode::Errors::ClientNotConfigured)
75
+ client.node_id = NODE_ID
76
+
77
+ stub_oauth
78
+ stub_get_node
79
+ resp = client.details
80
+ expect(resp["id"]).to eq(NODE_ID)
81
+ end
82
+ end
83
+
62
84
  end
@@ -17,10 +17,20 @@ def stub_oauth
17
17
  to_return(status: 200, body: OAUTH_RESPONSE.to_json)
18
18
  end
19
19
 
20
+ def stub_get_node
21
+ stub_request(:get, "#{BlockchainNode::Request::DEFAULT_BASE_URL}/api/nodes/#{NODE_ID}").
22
+ to_return(status: 200, body: "{\"id\":\"#{NODE_ID}\",\"blockchain\":\"bitcoin\",\"network\":\"testnet\",\"status\":\"RUNNING\",\"height\":1454086}" )
23
+ end
24
+
25
+ def stub_get_nodes
26
+ stub_request(:get, "#{BlockchainNode::Request::DEFAULT_BASE_URL}/api/nodes").
27
+ to_return(status: 200, body: "{\"nodes\":[{\"id\":\"#{NODE_ID}\",\"blockchain\":\"bitcoin\",\"network\":\"testnet\",\"status\":\"RUNNING\",\"height\":1454086}]}" )
28
+ end
29
+
20
30
  def stub_basic_method
21
31
  stub_request(:post, "#{BlockchainNode::Request::DEFAULT_BASE_URL}/api/nodes/#{NODE_ID}").
22
32
  with(body: api_method_body('eth_blockNumber')).
23
- to_return(status: 200, body: '0x123A ')
33
+ to_return(status: 200, body: '0x123A')
24
34
  end
25
35
 
26
36
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blockchain-node
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Pestritto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-27 00:00:00.000000000 Z
11
+ date: 2019-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry