cryptoruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +111 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cryptoruby.gemspec +36 -0
- data/exe/cryptoruby +3 -0
- data/lib/cryptoruby.rb +5 -0
- data/lib/cryptoruby/block.rb +52 -0
- data/lib/cryptoruby/blockchain.rb +73 -0
- data/lib/cryptoruby/version.rb +3 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 28d197a0c4ebd84e71e8e811d94111ac5cb3eedb
|
4
|
+
data.tar.gz: 2d0cc8cfb0c5d0d92eeebe0d1277e3d9bcda4ebb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eb62301b60fbeb5fef3d3550b8b728180f675c899916b2577fe6968dd55d3aff2f036c1a712dd4a2ab8075d60f5651e0e78c41e558ec7954f90811505e133ae7
|
7
|
+
data.tar.gz: d514b8903ac7f442717385c42154aeabc28b080c26e2292c31c6fcb84698e2bd1ee65cf047ca1b3c7eb0771864e5a3d9920462c624bb488d037f4a727d6f0135
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
cryptoruby
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.4.1
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at ghamdan.eng@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cryptoruby (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
awesome_print (1.8.0)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
rake (10.5.0)
|
12
|
+
rspec (3.7.0)
|
13
|
+
rspec-core (~> 3.7.0)
|
14
|
+
rspec-expectations (~> 3.7.0)
|
15
|
+
rspec-mocks (~> 3.7.0)
|
16
|
+
rspec-core (3.7.0)
|
17
|
+
rspec-support (~> 3.7.0)
|
18
|
+
rspec-expectations (3.7.0)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.7.0)
|
21
|
+
rspec-mocks (3.7.0)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.7.0)
|
24
|
+
rspec-support (3.7.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
awesome_print
|
31
|
+
bundler (~> 1.16)
|
32
|
+
cryptoruby!
|
33
|
+
rake (~> 10.0)
|
34
|
+
rspec (~> 3.0)
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Gabriel Hamdan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# Cryptoruby
|
2
|
+
|
3
|
+
How about to have your own blockchain? This gems allow you application to have it...
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'cryptoruby'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install cryptoruby
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In order to use this gem you'll need to initialize your block first:
|
24
|
+
````ruby
|
25
|
+
blockchain = Cryptoruby::Blockchain.new
|
26
|
+
````
|
27
|
+
|
28
|
+
This will create your blockchain and initiate with and empty first block. The Genesis one.
|
29
|
+
|
30
|
+
After that, all youll need to do is to add some blocks to it:
|
31
|
+
````ruby
|
32
|
+
data = {amount: 3000}
|
33
|
+
blockchain.add_block(data) # or
|
34
|
+
blockchain << data
|
35
|
+
````
|
36
|
+
|
37
|
+
You see... data can be anything. You can store strings, jsons, arrays, even base64 files.
|
38
|
+
|
39
|
+
Then, after adding blocks, you'll need to check if your block is still valid right?
|
40
|
+
````ruby
|
41
|
+
blockchain.is_valid? # returns true or false
|
42
|
+
````
|
43
|
+
Try change something in the blocks and validating again... this works man... for real!
|
44
|
+
|
45
|
+
Ah... almost forgot... you can set the blockchain difficult too...
|
46
|
+
To do so, all you need to do is to change (or instantiate from the beginning) the difficult parameter
|
47
|
+
````ruby
|
48
|
+
blockchain = Cryptoruby::Blockchain.new(3)
|
49
|
+
````
|
50
|
+
The difficult is default to 0, but you can set it for whatever you want. In this example, it was set to 3 zeroes in the start of the hash.
|
51
|
+
|
52
|
+
And, in the end, you'll be able to export everything. How About That?
|
53
|
+
```ruby
|
54
|
+
blockchain.export
|
55
|
+
```
|
56
|
+
|
57
|
+
## Full Usage
|
58
|
+
|
59
|
+
````ruby
|
60
|
+
blockchain = Cryptoruby::Blockchain.new(2) # Difficult of 2 initial zeros
|
61
|
+
#<Cryptoruby::Blockchain:0x007fcb340b5cc8 @blocks=[#<Cryptoruby::Blockchain::Block:0x007fcb340b57f0 @index=0, @previous_hash=nil, @data="Genesis Block", @difficult=2, @blockchain=#<Cryptoruby::Blockchain:0x007fcb340b5cc8 ...>, @timestamp=1513486966, @nonce=6995, @hash="000449121a75ece0e52adbc12cf60bde1f9fe3f7c627f1163c412d58cfc2a41fddcf275814fc8acdbf685b993b07fc3f8bb0d2664294af418a47198c5b7eb90f">], @index=0, @difficult=2>
|
62
|
+
blockchain << { name: 'last night', amount_in_cents: 35000 }
|
63
|
+
[#<Cryptoruby::Blockchain::Block:0x007fcb340b57f0 @index=0, @previous_hash=nil, @data="Genesis Block", @difficult=2, @blockchain=#<Cryptoruby::Blockchain:0x007fcb340b5cc8 @blocks=[...], @index=1, @difficult=2>, @timestamp=1513486966, @nonce=6995, @hash="000449121a75ece0e52adbc12cf60bde1f9fe3f7c627f1163c412d58cfc2a41fddcf275814fc8acdbf685b993b07fc3f8bb0d2664294af418a47198c5b7eb90f">, #<Cryptoruby::Blockchain::Block:0x007fcb358bf080 @index=1, @previous_hash="000449121a75ece0e52adbc12cf60bde1f9fe3f7c627f1163c412d58cfc2a41fddcf275814fc8acdbf685b993b07fc3f8bb0d2664294af418a47198c5b7eb90f", @data={:name=>"last night", :amount_in_cents=>35000}, @difficult=2, @blockchain=#<Cryptoruby::Blockchain:0x007fcb340b5cc8 @blocks=[...], @index=1, @difficult=2>, @timestamp=1513486969, @nonce=4565, @hash="0008767c32faa0bdf72229f1b3d5e55fe590ea7b9dc6791804a831ac4229e074ddc58b1ee9369d7af16d0e89f4f3627df626483a248b720337620f4c26d9e2e7">]
|
64
|
+
blockchain.export
|
65
|
+
{
|
66
|
+
:difficult => 2,
|
67
|
+
:blocks => [
|
68
|
+
[0] {
|
69
|
+
:index => 0,
|
70
|
+
:previous_hash => nil,
|
71
|
+
:data => "Genesis Block",
|
72
|
+
:timestamp => 1513486966,
|
73
|
+
:hash => "000449121a75ece0e52adbc12cf60bde1f9fe3f7c627f1163c412d58cfc2a41fddcf275814fc8acdbf685b993b07fc3f8bb0d2664294af418a47198c5b7eb90f",
|
74
|
+
:difficult => 2,
|
75
|
+
:nonce => 6995
|
76
|
+
},
|
77
|
+
[1] {
|
78
|
+
:index => 1,
|
79
|
+
:previous_hash => "000449121a75ece0e52adbc12cf60bde1f9fe3f7c627f1163c412d58cfc2a41fddcf275814fc8acdbf685b993b07fc3f8bb0d2664294af418a47198c5b7eb90f",
|
80
|
+
:data => {
|
81
|
+
:name => "last night",
|
82
|
+
:amount_in_cents => 35000
|
83
|
+
},
|
84
|
+
:timestamp => 1513486969,
|
85
|
+
:hash => "0008767c32faa0bdf72229f1b3d5e55fe590ea7b9dc6791804a831ac4229e074ddc58b1ee9369d7af16d0e89f4f3627df626483a248b720337620f4c26d9e2e7",
|
86
|
+
:difficult => 2,
|
87
|
+
:nonce => 4565
|
88
|
+
}
|
89
|
+
]
|
90
|
+
}
|
91
|
+
````
|
92
|
+
|
93
|
+
Hope you like it!!
|
94
|
+
|
95
|
+
## Development
|
96
|
+
|
97
|
+
It'll be awesome if you help me to get it better. After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
98
|
+
|
99
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
100
|
+
|
101
|
+
## Contributing
|
102
|
+
|
103
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hamdan85/cryptoruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
104
|
+
|
105
|
+
## License
|
106
|
+
|
107
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
108
|
+
|
109
|
+
## Code of Conduct
|
110
|
+
|
111
|
+
Everyone interacting in the Cryptoruby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hamdan85/cryptoruby/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cryptoruby"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/cryptoruby.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "cryptoruby/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cryptoruby"
|
8
|
+
spec.version = Cryptoruby::VERSION
|
9
|
+
spec.authors = ["Gabriel Hamdan"]
|
10
|
+
spec.email = ["ghamdan.eng@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby's Blockchain}
|
13
|
+
spec.description = %q{Ruby's Blockchain}
|
14
|
+
spec.homepage = "https://github.com/hamdan85/cryptoruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
end
|
data/exe/cryptoruby
ADDED
data/lib/cryptoruby.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
module Cryptoruby
|
5
|
+
class Blockchain
|
6
|
+
class Block
|
7
|
+
attr_reader :blockchain, :index, :previous_hash, :data, :timestamp, :hash, :difficult, :nonce
|
8
|
+
def initialize(args)
|
9
|
+
setup_args(args)
|
10
|
+
@timestamp = Time.now.to_i
|
11
|
+
@difficult = difficult
|
12
|
+
@nonce = 0
|
13
|
+
mine
|
14
|
+
end
|
15
|
+
|
16
|
+
def digest_hash
|
17
|
+
OpenSSL::Digest::SHA512.hexdigest "#{index}#{previous_hash}#{stringfied_data}#{timestamp.to_s}#{nonce}"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def mine
|
23
|
+
loop do
|
24
|
+
@nonce += 1
|
25
|
+
@hash = digest_hash
|
26
|
+
break if @hash[0..@difficult] =~ /^0*$/
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def stringfied_data
|
31
|
+
case @data
|
32
|
+
when String
|
33
|
+
@data
|
34
|
+
when Hash
|
35
|
+
@data.to_json
|
36
|
+
when Array
|
37
|
+
@data.to_json
|
38
|
+
else
|
39
|
+
raise 'Invalid Data'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def setup_args(args)
|
44
|
+
@index = args[:index] || 0
|
45
|
+
@previous_hash = args[:previous_hash] || nil
|
46
|
+
@data = args[:data] || 'Genesis Block'
|
47
|
+
@difficult = args[:difficult] || 0
|
48
|
+
@blockchain = args[:blockchain]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'cryptoruby/block'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Cryptoruby
|
5
|
+
class Blockchain
|
6
|
+
attr_accessor :blocks, :difficult
|
7
|
+
attr_reader :index
|
8
|
+
|
9
|
+
def initialize(difficult = 0)
|
10
|
+
@blocks = []
|
11
|
+
@index = 0
|
12
|
+
@difficult = difficult
|
13
|
+
generate_genesis_block
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_block(data)
|
17
|
+
@index += 1
|
18
|
+
@blocks << Block.new(index: index, previous_hash: last_block.hash, data: data, difficult: @difficult, blockchain: self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def <<(data)
|
22
|
+
add_block(data)
|
23
|
+
end
|
24
|
+
|
25
|
+
def is_valid?
|
26
|
+
blocks[1..-1].sort_by{|block| block.index }.each_with_index do |current_block, index|
|
27
|
+
previous_block = blocks[index]
|
28
|
+
|
29
|
+
if current_block.hash != current_block.digest_hash
|
30
|
+
p 'Hash is different from digest'
|
31
|
+
return false
|
32
|
+
end
|
33
|
+
|
34
|
+
if current_block.index != previous_block.index + 1
|
35
|
+
p 'Index is not sequential'
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
if current_block.previous_hash != previous_block.hash
|
39
|
+
p 'Previous hash doesnt match with the current one'
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
return true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def export
|
47
|
+
{
|
48
|
+
difficult: difficult,
|
49
|
+
blocks: blocks.map{ |block|
|
50
|
+
{
|
51
|
+
index: block.index,
|
52
|
+
previous_hash: block.previous_hash,
|
53
|
+
data: block.data,
|
54
|
+
timestamp: block.timestamp,
|
55
|
+
hash: block.hash,
|
56
|
+
difficult: block.difficult,
|
57
|
+
nonce: block.nonce
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def last_block
|
64
|
+
@blocks.last
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def generate_genesis_block
|
70
|
+
@blocks << Block.new(index: 0, blockchain: self, difficult: @difficult)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cryptoruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gabriel Hamdan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Ruby's Blockchain
|
56
|
+
email:
|
57
|
+
- ghamdan.eng@gmail.com
|
58
|
+
executables:
|
59
|
+
- cryptoruby
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".DS_Store"
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".ruby-gemset"
|
67
|
+
- ".ruby-version"
|
68
|
+
- ".travis.yml"
|
69
|
+
- CODE_OF_CONDUCT.md
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.lock
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- bin/console
|
76
|
+
- bin/setup
|
77
|
+
- cryptoruby.gemspec
|
78
|
+
- exe/cryptoruby
|
79
|
+
- lib/cryptoruby.rb
|
80
|
+
- lib/cryptoruby/block.rb
|
81
|
+
- lib/cryptoruby/blockchain.rb
|
82
|
+
- lib/cryptoruby/version.rb
|
83
|
+
homepage: https://github.com/hamdan85/cryptoruby
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.6.13
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Ruby's Blockchain
|
107
|
+
test_files: []
|