osbc 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -3
  3. data/README.md +24 -10
  4. data/app/controllers/api/v1/application_controller.rb +67 -0
  5. data/app/controllers/api/v1/block_confirmations_controller.rb +19 -38
  6. data/app/controllers/api/v1/ticket_manager_controller.rb +65 -0
  7. data/app/workers/create_ticket_worker.rb +1 -0
  8. data/config/initializers/sidekiq.rb +1 -0
  9. data/config/routes/api.rb +1 -1
  10. data/lib/osbc/osbc.rb +1 -1
  11. data/mining_concept.ipynb +2 -2
  12. metadata +6 -36
  13. data/coverage/.last_run.json +0 -5
  14. data/coverage/.resultset.json +0 -1746
  15. data/coverage/.resultset.json.lock +0 -0
  16. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc.png +0 -0
  17. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc_disabled.png +0 -0
  18. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_both.png +0 -0
  19. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc.png +0 -0
  20. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc_disabled.png +0 -0
  21. data/coverage/assets/0.12.3/application.css +0 -1
  22. data/coverage/assets/0.12.3/application.js +0 -7
  23. data/coverage/assets/0.12.3/colorbox/border.png +0 -0
  24. data/coverage/assets/0.12.3/colorbox/controls.png +0 -0
  25. data/coverage/assets/0.12.3/colorbox/loading.gif +0 -0
  26. data/coverage/assets/0.12.3/colorbox/loading_background.png +0 -0
  27. data/coverage/assets/0.12.3/favicon_green.png +0 -0
  28. data/coverage/assets/0.12.3/favicon_red.png +0 -0
  29. data/coverage/assets/0.12.3/favicon_yellow.png +0 -0
  30. data/coverage/assets/0.12.3/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  31. data/coverage/assets/0.12.3/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  32. data/coverage/assets/0.12.3/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  33. data/coverage/assets/0.12.3/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  34. data/coverage/assets/0.12.3/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  35. data/coverage/assets/0.12.3/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  36. data/coverage/assets/0.12.3/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  37. data/coverage/assets/0.12.3/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  38. data/coverage/assets/0.12.3/images/ui-icons_222222_256x240.png +0 -0
  39. data/coverage/assets/0.12.3/images/ui-icons_2e83ff_256x240.png +0 -0
  40. data/coverage/assets/0.12.3/images/ui-icons_454545_256x240.png +0 -0
  41. data/coverage/assets/0.12.3/images/ui-icons_888888_256x240.png +0 -0
  42. data/coverage/assets/0.12.3/images/ui-icons_cd0a0a_256x240.png +0 -0
  43. data/coverage/assets/0.12.3/loading.gif +0 -0
  44. data/coverage/assets/0.12.3/magnify.png +0 -0
  45. data/coverage/index.html +0 -20466
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd1d73f028ec3088b5eaeb186edaeaa6cb1251e93c68810e1dffc520ab4a2d37
4
- data.tar.gz: 11cd22644ea8bf53f2428b415550e61092214a7c1dd299a47526f5d3dbaaee72
3
+ metadata.gz: 34b4e07aede46460687f931e6c170bfa6cd32b96eec1022db4dc0edd20c8b4f4
4
+ data.tar.gz: e15914a8d36c5c60561109915cc2acdd9fe0517d2f767f02e5a118e7684f0f08
5
5
  SHA512:
6
- metadata.gz: 2de4088d38539c8054ac620b7fbaa8655d8607af1555dec37a4c5b1ca2e8ab002d47fcd0078da39e41203078713d6d92ceedc1a30a01663d87b3aaf62ee0911b
7
- data.tar.gz: '0688ddf35ac525fe9a584f12a1831ef35f5967dba4f5eec2686a9430edfe453d218c4c9b3ce9faa7d283d3a56a10b4a5611466a3a72025025a724247a6a7bafd'
6
+ metadata.gz: 4db75d9e4e3dbc1889e205ffe3e802e7956be058b7f93519d064297ad46d6bc0ab2fad3b27fb95a309bc3e7abd77aa9689f304fd34b6240eca9430ab0dec1568
7
+ data.tar.gz: b1f5afc4c7016ed067b8520d5e7d81324dc393eda418e3a0fbef8a87257f78ab5883daeb601aed694fe05b414028020cb1c13546da59e962c613670ed2ac63eb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2022-10-18
4
-
5
- - Initial release
3
+ ## [0.1.5]
4
+ ### Added
5
+ - Initial Version
6
+ ## [0.1.6]
7
+ ### Added
8
+ - Docker Compose Installation Recognition
9
+ - Refactored some tests
10
+ - Added lib tasks helper to created rake tasks for blockchain
data/README.md CHANGED
@@ -12,6 +12,22 @@
12
12
 
13
13
  #### Rspec is used to test the blockchain.
14
14
 
15
+ ## Build Version: 0.1.7
16
+ ### Last Update:
17
+ #### Added Open Ticket Api Methods
18
+ #### Reafactored some methods and tests
19
+ #### Removed coverage folder github repo
20
+ ##### TODO
21
+ ###### Add more tests
22
+ ###### Add more features
23
+ ###### Include pagination
24
+ ###### Create Queries Folder
25
+ ###### Test in kubernetes
26
+ ###### Add more documentation
27
+ ###### Add NFT Generator
28
+ ###### Increase the environment variables for autoconfig
29
+ ###### Add features to autogeneration of blockchain for better configuration
30
+
15
31
  ## System dependencies
16
32
  1. Docker
17
33
  2. Postgresql
@@ -159,18 +175,16 @@ The mine will depend of the contract signatures that will be formed by the serve
159
175
  2. The server will send a message to the user to start mining if the POOL is open
160
176
  3. The users will load the RANDOM WORD LIST provided by the server API
161
177
  4. The user have to use 1 common word, 1 symbol sequence and 1 number sequence, randomize the characters
162
- 5. Transform the chartacters in a SHA256 hash
163
- 6. Transform the block info in before ticket opened in a SHA256 hash
164
- 5. Transform (Chars SHA256 hash + block info hash) in a SHA256 hash
165
- 6. If the hash is valid, the user will send the hash to the server
166
- 7. The server will check if the hash is valid
167
- 8. If the hash is valid, check if the same transactions have the same block state confirmation
168
- 9. If this transactions was not confirmed at this point at block history the server will add the user signature to the transaction contract
178
+ 5. Transform the shuffled chartacters in a SHA256 hash
179
+ 6. The user will send the hash to the server
180
+ 7. The server will validate the hash and will send a message to the user if the hash is valid
181
+ 8. If the hash is valid, check if the same transactions have the same block state confirmation, if yes, the user will have to mine again in a new state of the transactions timeline
182
+ 9. If this transactions was not confirmed at this point at block history the server will add the user signature to the transactions contracts included in the users ticket timeline range
169
183
  10. The block only can be hashed when the minimum number of contracts valids with minimum number of signatures is reached
170
184
  11. The server will use the signature timeline to determine what transactions will be added to the block
171
185
  12. The server will calculate the master hash after confirm all valid contracts signatures
172
- 13. The server will add the block to the blockchain and create a new one with last block unconfirmed transactions but completely unsigned
173
- 13. The server will start a open/closed pool cycle
186
+ 13. Assignmaster hash to the block, create new block and add to the blockchain with previous block hash
187
+ 13. The server will start a open/closed pool cycle ( pool is open only if has a minimun of transactions to mine )
174
188
  14. The server will send a message to the user to start mining when the POOL is open and user has a ticket
175
189
  <p>
176
190
  The timestamps of the signatures will be usefull to version the block, checking it as a timeline
@@ -178,7 +192,7 @@ The timestamps of the signatures will be usefull to version the block, checking
178
192
 
179
193
  **The miners will be rewarded with the block reward distributed by the number of signatures**
180
194
  ## Contributing
181
- Bug reports and pull requests are welcome on GitHub at https://github.com/outerspace-coding/outerspace-blockchain
195
+ Bug reports and pull requests are welcome on GitHub at https://github.com/JesusGautamah/outerspace-blockchain
182
196
 
183
197
  ## License
184
198
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Api::V1::ApplicationController < ActionController::API
4
+ def unauthorized?
5
+ return unauthorized_response unless find_user_by_header
6
+ end
7
+
8
+ def ticket_founded?
9
+ @ticket = Ticket.find_by(user_id: @user.id, status: :active)
10
+ return ticket_not_found_response unless @ticket.present?
11
+ end
12
+
13
+ private
14
+ attr_accessor :user
15
+
16
+ def find_user_by_header
17
+ return unless request.headers["X-API-KEY"].present?
18
+ api_key = request.headers["X-API-KEY"]
19
+ @user = User.find_by(api_key: api_key)
20
+ return unless @user.present?
21
+ @user.api_secret == request.headers["X-API-SECRET"]
22
+ end
23
+
24
+ def confirmation_hash_founded?
25
+ return confirmation_hash_not_found_response unless confirmation_hash.present?
26
+ end
27
+
28
+ def confirmation_hash
29
+ @confirmation_hash ||= block_confirmation_params[:user_confirmation_hash]
30
+ end
31
+
32
+ def confirmation_hash_not_found_response
33
+ render json: { error: "Confirmation hash not found" }, status: :not_found
34
+ end
35
+
36
+ def ticket_not_found_response
37
+ render json: { error: "Ticket not found" }, status: :not_found
38
+ end
39
+
40
+ def unauthorized_response
41
+ render json: { error: "Unauthorized" }, status: :unauthorized
42
+ end
43
+
44
+ def current_block
45
+ @current_block = Block.find_by(master_hash: nil)
46
+ end
47
+
48
+ def current_pool
49
+ @current_pool = Pool.find_by(block_id: current_block.id)
50
+ end
51
+
52
+ def ticket
53
+ @ticket = Ticket.find_by(user_id: user.id, status: :active)
54
+ end
55
+
56
+ def block_transactions
57
+ @block_transactions = Transaction.where(block_id: current_block.id)
58
+ end
59
+
60
+ def block_transactions_empty?
61
+ return no_transactions_response unless block_transactions.present?
62
+ end
63
+
64
+ def no_transactions_response
65
+ render json: { error: "No transactions in the block" }, status: :not_found
66
+ end
67
+ end
@@ -1,62 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Api::V1::BlockConfirmationsController < ActionController::API
3
+ class Api::V1::BlockConfirmationsController < Api::V1::ApplicationController
4
+ before_action :unauthorized?
5
+ before_action :ticket_founded?, only: [:confirm_block]
6
+ before_action :confirmation_hash_founded?, only: [:confirm_block]
7
+
4
8
  def confirm_block
5
- return unauthorized_response unless find_user_by_header
6
- @ticket = Ticket.find_by(user_id: @user.id, status: :active)
7
- return ticket_not_found_response unless @ticket.present?
8
- confirmation_hash = block_confirmation_params[:user_confirmation_hash]
9
- return confirmation_hash_not_found_response unless confirmation_hash.present?
10
- return not_valid_confirmation_hash_response unless @ticket.user_acceptable_hash == confirmation_hash
9
+ return not_valid_confirmation_hash_response unless hash_confirmed?
11
10
  assign_contract
12
11
  end
13
12
 
14
- # def transactions_to_mine
15
- # return unauthorized_response unless find_user_by_header
16
- # ticket = Ticket.find_by(user_id: @user.id)
17
- # return ticket_not_found_response unless ticket.present?
18
- # transactions_ids = ticket.transaction_id_list
19
- # transactions = Transaction.where(id: transactions_ids)
20
- # transactions_json = transactions.to_json
21
- # render json: transactions_json, status: :ok
22
- # end
23
-
24
13
  def info_to_mine
25
- return unauthorized_response unless find_user_by_header
26
- words = @user.acceptable_words
27
- number_sequences = @user.acceptable_number_sequences
28
- symbol_sequences = @user.acceptable_symbol_sequences
29
14
  render json: { words: words, number_sequences: number_sequences, symbol_sequences: symbol_sequences }, status: :ok
30
15
  end
31
16
 
32
17
  private
33
- def find_user_by_header
34
- return unless request.headers["X-API-KEY"].present?
35
- api_key = request.headers["X-API-KEY"]
36
- @user = User.find_by(api_key: api_key)
37
- return unless @user.present?
38
- @user.api_secret == request.headers["X-API-SECRET"]
18
+ def hash_confirmed?
19
+ @ticket.user_acceptable_hash == confirmation_hash
39
20
  end
40
21
 
41
- def unauthorized_response
42
- render json: { error: "Unauthorized" }, status: :unauthorized
22
+ def assign_contract
23
+ AssignContractWorker.perform_async(@ticket.id)
24
+ render json: { message: "Contract assigned" }, status: :ok
43
25
  end
44
26
 
45
- def ticket_not_found_response
46
- render json: { error: "Ticket not found" }, status: :not_found
27
+ def not_valid_confirmation_hash_response
28
+ render json: { error: "Not valid confirmation hash" }, status: :not_found
47
29
  end
48
30
 
49
- def confirmation_hash_not_found_response
50
- render json: { error: "Confirmation hash not found" }, status: :not_found
31
+ def words
32
+ @words = @user.acceptable_words
51
33
  end
52
34
 
53
- def assign_contract
54
- AssignContractWorker.perform_async(@ticket.id)
55
- render json: { message: "Contract assigned" }, status: :ok
35
+ def number_sequences
36
+ @number_sequences = @user.acceptable_number_sequences
56
37
  end
57
38
 
58
- def not_valid_confirmation_hash_response
59
- render json: { error: "Not valid confirmation hash" }, status: :not_found
39
+ def symbol_sequences
40
+ @symbol_sequences = @user.acceptable_symbol_sequences
60
41
  end
61
42
 
62
43
  def block_confirmation_params
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Api::V1::TicketManagerController < Api::V1::ApplicationController
4
+ before_action :unauthorized?
5
+ before_action :block_transactions_empty?, only: [:open_ticket]
6
+
7
+ def open_ticket
8
+ return ticket_already_opened_response unless ticket_nil?
9
+ return ticket_already_opened_response if ticket_active?
10
+ return terms_not_confirmed_response unless ticket_params_confirmed?
11
+ create_ticket if acceptable_create?
12
+ ticket_opened_response
13
+ end
14
+
15
+
16
+ private
17
+ def ticket_nil?
18
+ ticket.nil?
19
+ end
20
+
21
+ def ticket_active?
22
+ return false if ticket_nil?
23
+ ticket.status == "active"
24
+ end
25
+
26
+ def acceptable_create?
27
+ ticket_nil? && ticket_params_confirmed? || ticket_params_confirmed? && ticket_active? == false
28
+ end
29
+
30
+ def ticket_params_confirmed?
31
+ open_ticket_params[:ticket_terms] == "confirmed"
32
+ end
33
+
34
+ def ticket_already_opened_response
35
+ render json: { error: "Ticket already opened" }, status: :not_found
36
+ end
37
+
38
+ def ticket_opened_response
39
+ render json: { message: "Ticket opened" }, status: :ok
40
+ end
41
+
42
+ def terms_not_confirmed_response
43
+ render json: { error: "Ticket terms not confirmed" }, status: :not_found
44
+ end
45
+
46
+ def open_ticket_params
47
+ params.permit(:ticket_terms)
48
+ end
49
+
50
+ def time_ref
51
+ @time_ref = block_transactions.first.created_at.to_s
52
+ end
53
+
54
+ def user_id
55
+ @user_id = user.id.to_s
56
+ end
57
+
58
+ def current_pool_id
59
+ @current_pool_id = current_pool.id.to_s
60
+ end
61
+
62
+ def create_ticket
63
+ CreateTicketWorker.perform_async(user_id, current_pool_id, time_ref)
64
+ end
65
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class CreateTicketWorker < ApplicationWorker
4
+ include Sidekiq::Worker
4
5
  sidekiq_options retry: false
5
6
 
6
7
  def perform(user_id, pool_id, time_ref)
@@ -0,0 +1 @@
1
+ Sidekiq.strict_args!
data/config/routes/api.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  namespace :api do
4
4
  namespace :v1 do
5
5
  post "confirm_block", to: "block_confirmations#confirm_block"
6
- # get "tr_to_mine", to: "block_confirmations#transactions_to_mine"
6
+ post "open_ticket", to: "ticket_manager#open_ticket"
7
7
  get "info_to_mine", to: "block_confirmations#info_to_mine"
8
8
  end
9
9
  end
data/lib/osbc/osbc.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Osbc
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  class Osbc
6
6
  end
7
7
 
data/mining_concept.ipynb CHANGED
@@ -93,8 +93,8 @@
93
93
  "secret = 'a239c12ecc42911ecbc3b23a9539976caaa60f7d40028dea17cb67cc538c21bd'\n",
94
94
  "\n",
95
95
  "headers = {\n",
96
- " 'X-Api-Key': key,\n",
97
- " 'X-Api-Secret': secret,\n",
96
+ " 'X-API-KEY': key,\n",
97
+ " 'X-API-SECRET': secret,\n",
98
98
  "}\n",
99
99
  "\n",
100
100
  "\n",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - jesus_gautamah
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-24 00:00:00.000000000 Z
11
+ date: 2022-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -340,7 +340,9 @@ files:
340
340
  - app/assets/stylesheets/home.css
341
341
  - app/channels/application_cable/channel.rb
342
342
  - app/channels/application_cable/connection.rb
343
+ - app/controllers/api/v1/application_controller.rb
343
344
  - app/controllers/api/v1/block_confirmations_controller.rb
345
+ - app/controllers/api/v1/ticket_manager_controller.rb
344
346
  - app/controllers/application_controller.rb
345
347
  - app/controllers/blocks_controller.rb
346
348
  - app/controllers/chains_controller.rb
@@ -520,6 +522,7 @@ files:
520
522
  - config/initializers/filter_parameter_logging.rb
521
523
  - config/initializers/inflections.rb
522
524
  - config/initializers/permissions_policy.rb
525
+ - config/initializers/sidekiq.rb
523
526
  - config/locales/devise.en.yml
524
527
  - config/locales/en.yml
525
528
  - config/puma.rb
@@ -528,39 +531,6 @@ files:
528
531
  - config/sidekiq.yml
529
532
  - config/storage.yml
530
533
  - config/tailwind.config.js
531
- - coverage/.last_run.json
532
- - coverage/.resultset.json
533
- - coverage/.resultset.json.lock
534
- - coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc.png
535
- - coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc_disabled.png
536
- - coverage/assets/0.12.3/DataTables-1.10.20/images/sort_both.png
537
- - coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc.png
538
- - coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc_disabled.png
539
- - coverage/assets/0.12.3/application.css
540
- - coverage/assets/0.12.3/application.js
541
- - coverage/assets/0.12.3/colorbox/border.png
542
- - coverage/assets/0.12.3/colorbox/controls.png
543
- - coverage/assets/0.12.3/colorbox/loading.gif
544
- - coverage/assets/0.12.3/colorbox/loading_background.png
545
- - coverage/assets/0.12.3/favicon_green.png
546
- - coverage/assets/0.12.3/favicon_red.png
547
- - coverage/assets/0.12.3/favicon_yellow.png
548
- - coverage/assets/0.12.3/images/ui-bg_flat_0_aaaaaa_40x100.png
549
- - coverage/assets/0.12.3/images/ui-bg_flat_75_ffffff_40x100.png
550
- - coverage/assets/0.12.3/images/ui-bg_glass_55_fbf9ee_1x400.png
551
- - coverage/assets/0.12.3/images/ui-bg_glass_65_ffffff_1x400.png
552
- - coverage/assets/0.12.3/images/ui-bg_glass_75_dadada_1x400.png
553
- - coverage/assets/0.12.3/images/ui-bg_glass_75_e6e6e6_1x400.png
554
- - coverage/assets/0.12.3/images/ui-bg_glass_95_fef1ec_1x400.png
555
- - coverage/assets/0.12.3/images/ui-bg_highlight-soft_75_cccccc_1x100.png
556
- - coverage/assets/0.12.3/images/ui-icons_222222_256x240.png
557
- - coverage/assets/0.12.3/images/ui-icons_2e83ff_256x240.png
558
- - coverage/assets/0.12.3/images/ui-icons_454545_256x240.png
559
- - coverage/assets/0.12.3/images/ui-icons_888888_256x240.png
560
- - coverage/assets/0.12.3/images/ui-icons_cd0a0a_256x240.png
561
- - coverage/assets/0.12.3/loading.gif
562
- - coverage/assets/0.12.3/magnify.png
563
- - coverage/index.html
564
534
  - db/migrate/20221018053949_devise_create_users.rb
565
535
  - db/migrate/20221019002956_create_chains.rb
566
536
  - db/migrate/20221020112137_create_blocks.rb
@@ -622,7 +592,7 @@ metadata:
622
592
  allowed_push_host: https://rubygems.org
623
593
  homepage_uri: https://outerspace-blockchain.herokuapp.com/
624
594
  source_code_uri: https://github.com/JesusGautamah/outerspace-blockchain
625
- changelog_uri: https://github.com/outerspace-coding/outerspace-blockchain/blob/main/CHANGELOG.md
595
+ changelog_uri: https://github.com/JesusGautamah/outerspace-blockchain/blob/main/CHANGELOG.md
626
596
  post_install_message:
627
597
  rdoc_options: []
628
598
  require_paths:
@@ -1,5 +0,0 @@
1
- {
2
- "result": {
3
- "line": 80.9
4
- }
5
- }