rubocoin 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 23ae9a1bfaaa6ec0518f256d1649f9cba77918ea
4
- data.tar.gz: 858b1365052751d13e841dee809c60a120653493
3
+ metadata.gz: 365ffd4db337c10f99639d7526883d280435da29
4
+ data.tar.gz: a72276059952d79ec186c80508ea74d31fc53b85
5
5
  SHA512:
6
- metadata.gz: 12ca76dcbbb042f28d7e30af56562304afbaa998d440b8de92d411d0628ddf4369a320802e3556f31e75f29ba391aaec806607aef798e2a3735471132924d741
7
- data.tar.gz: e639fafe47e172fc48219b75e03fe5ed22f68d4a2bab778f1075e8b6337c83d78fdf14bf091cd3ebd907c5a25a3fafbf224b5f8449b887e302811ed15d6c8c7c
6
+ metadata.gz: 1df1a61ec58b94af660462e0ebb66209e3b4d61922a3c0a4387845259d3894fde1c22a2f5df6082426c74a63eac9b8f527f9176e87f5ad7b13f7e1afe18c8170
7
+ data.tar.gz: efe627cf10815684d5021bd93a3fc3cabd130aa9e675640b581c6d27dd2f333a3bcc2a6386479107443572d6b56c8e398de62bc1ac749c74d3eefb69fe75c942
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocoin (0.1.0)
4
+ rubocoin (0.1.1)
5
5
  colorize
6
6
  sinatra
7
7
 
data/README.md CHANGED
@@ -7,12 +7,13 @@ This gem is the full node you can run on your machine to mine rubocoin and handl
7
7
  ## Installation
8
8
 
9
9
  You have 2 ways to get the rubocoin node (`rubocoind`). You can grab the source code
10
- or you can download the gem from (RubyGems)[https://rubygems.org].
10
+ or you can download the gem from [RubyGems](https://rubygems.org).
11
11
 
12
12
  #### Installing from source
13
13
 
14
14
  ```
15
15
  $ git clone https://github.com/cbrnrd/RuboCoin
16
+ $ cd RuboCoin
16
17
  $ bundle install
17
18
  $ bundle exec bin/rubocoind
18
19
  ```
@@ -28,7 +29,7 @@ $ rubocoind
28
29
 
29
30
  All you have to do is open port 44856 and run `rubocoind`.
30
31
 
31
- More command line options are coming in the near future.
32
+ You can view the API documentation [here](http://www.rubydoc.info/gems/rubocoin/0.1.0)
32
33
 
33
34
  ## Development
34
35
 
data/lib/rubocoin.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # Gems
2
2
  require 'sinatra'
3
- require 'json'
4
3
  require 'securerandom'
5
4
  require 'optparse'
6
5
 
@@ -45,18 +45,22 @@ class Blockchain
45
45
 
46
46
  #
47
47
  # Register a new node
48
+ # @param addr [String] the ip address of the node to add
48
49
  #
49
50
  def register_node(addr)
50
51
  url = URI.parse(addr)
51
52
  @nodes.add("#{url.host}:#{url.port}")
52
53
  end
53
54
 
54
- # Return the most recent block in our chain
55
+ # Return the most recent block in the chain
55
56
  def last_block
56
57
  @chain[-1]
57
58
  end
58
59
 
60
+ #
59
61
  # Check whether a chain is valid
62
+ # @param chain [Array] the chain to validate
63
+ #
60
64
  def valid_chain(chain)
61
65
  last_block = chain[0]
62
66
  index = 1
@@ -80,6 +84,10 @@ class Blockchain
80
84
  true # If we got here, all blocks are valid; therefore the chain is valid
81
85
  end
82
86
 
87
+ #
88
+ # Resolve conflicts with neighbour nodes. This gets the chain of each of
89
+ # the neighbour nodes and checks it with ours.
90
+ #
83
91
  def resolve_conflicts
84
92
  neighbour_nodes = @nodes
85
93
  new_chain = nil
@@ -113,6 +121,12 @@ class Blockchain
113
121
  return false
114
122
  end
115
123
 
124
+ #
125
+ # Adds a new block to the blockchain
126
+ # @see Blockchain#valid_proof
127
+ # @param proof [Integer] A valid value from the proof of work algorithm
128
+ # @param previous_hash [String] the hash of the previous block in the blockchain
129
+ #
116
130
  def new_block(proof, previous_hash=nil)
117
131
  # Define the block structure
118
132
  block =
@@ -174,11 +188,20 @@ class Blockchain
174
188
  last_block[:index] + 1
175
189
  end
176
190
 
191
+ #
192
+ # Hash the last block in the chain
193
+ # @param last_block [Hash] The last block in the chain
194
+ #
177
195
  def hash(last_block)
178
196
  block_string = last_block.sort.to_h.to_json
179
197
  return Digest::SHA256.hexdigest(block_string)
180
198
  end
181
199
 
200
+ #
201
+ # Iterates through integers until it finds a valid value
202
+ # @see Blockchain#valid_proof
203
+ # @param last_proof [Integer] the value of whatever the last PoW was
204
+ #
182
205
  def proof_of_work(last_proof)
183
206
  proof = -1
184
207
  proof += 1 until valid_proof(last_proof, proof)
@@ -186,6 +209,11 @@ class Blockchain
186
209
  return proof
187
210
  end
188
211
 
212
+ #
213
+ # Checks whether a value is a valid PoW
214
+ # @param last_proof [Integer] the value of whatever the last PoW was
215
+ # @param proof [Integer] the value to check
216
+ #
189
217
  def valid_proof(last_proof, proof)
190
218
  guess = "#{last_proof}#{proof}"
191
219
  guess_hash = Digest::SHA256.hexdigest(guess)
@@ -1,6 +1,10 @@
1
1
  require 'json'
2
2
 
3
3
  module JSON
4
+ #
5
+ # Check whether the given json is valid
6
+ # @param json [String] the JSON to validate
7
+ #
4
8
  def self.is_valid?(json)
5
9
  begin
6
10
  JSON.parse(json)
@@ -1,3 +1,3 @@
1
1
  module Rubocoin
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocoin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - cbrnrd