rubocoin 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -2
- data/lib/rubocoin.rb +0 -1
- data/lib/rubocoin/blockchain/blockchain.rb +29 -1
- data/lib/rubocoin/core_extensions/json_ext.rb +4 -0
- data/lib/rubocoin/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 365ffd4db337c10f99639d7526883d280435da29
|
4
|
+
data.tar.gz: a72276059952d79ec186c80508ea74d31fc53b85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1df1a61ec58b94af660462e0ebb66209e3b4d61922a3c0a4387845259d3894fde1c22a2f5df6082426c74a63eac9b8f527f9176e87f5ad7b13f7e1afe18c8170
|
7
|
+
data.tar.gz: efe627cf10815684d5021bd93a3fc3cabd130aa9e675640b581c6d27dd2f333a3bcc2a6386479107443572d6b56c8e398de62bc1ac749c74d3eefb69fe75c942
|
data/Gemfile.lock
CHANGED
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 (
|
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
|
-
|
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
@@ -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
|
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)
|
data/lib/rubocoin/version.rb
CHANGED