osbc 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (310) hide show
  1. checksums.yaml +7 -0
  2. data/.env +5 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +273 -0
  5. data/.ruby-version +1 -0
  6. data/CHANGELOG.md +5 -0
  7. data/CODE_OF_CONDUCT.md +84 -0
  8. data/Dockerfile +17 -0
  9. data/Gemfile +109 -0
  10. data/Gemfile.lock +343 -0
  11. data/LICENSE.md +21 -0
  12. data/LICENSE.txt +21 -0
  13. data/Procfile +3 -0
  14. data/Procfile.dev +2 -0
  15. data/README.md +185 -0
  16. data/Rakefile +6 -0
  17. data/app/assets/builds/.keep +0 -0
  18. data/app/assets/config/manifest.js +5 -0
  19. data/app/assets/images/.keep +0 -0
  20. data/app/assets/images/bg.png +0 -0
  21. data/app/assets/images/gimage.png +0 -0
  22. data/app/assets/images/image.png +0 -0
  23. data/app/assets/images/logo.png +0 -0
  24. data/app/assets/images/outerspc.jpg +0 -0
  25. data/app/assets/images/proxy.jpg +0 -0
  26. data/app/assets/images/space.jpg +0 -0
  27. data/app/assets/images/space_four.jpg +0 -0
  28. data/app/assets/images/space_t.jpg +0 -0
  29. data/app/assets/images/space_th.jpg +0 -0
  30. data/app/assets/images/space_two.jpg +0 -0
  31. data/app/assets/images/th.jpg +0 -0
  32. data/app/assets/stylesheets/application.css +344 -0
  33. data/app/assets/stylesheets/application.tailwind.css +13 -0
  34. data/app/assets/stylesheets/home.css +0 -0
  35. data/app/channels/application_cable/channel.rb +6 -0
  36. data/app/channels/application_cable/connection.rb +6 -0
  37. data/app/controllers/api/v1/block_confirmations_controller.rb +65 -0
  38. data/app/controllers/application_controller.rb +72 -0
  39. data/app/controllers/blocks_controller.rb +20 -0
  40. data/app/controllers/chains_controller.rb +72 -0
  41. data/app/controllers/concerns/.keep +0 -0
  42. data/app/controllers/contracts_controller.rb +25 -0
  43. data/app/controllers/pools_controller.rb +73 -0
  44. data/app/controllers/signatures_controller.rb +25 -0
  45. data/app/controllers/tickets_controller.rb +76 -0
  46. data/app/controllers/transactions_controller.rb +48 -0
  47. data/app/controllers/users/confirmations_controller.rb +30 -0
  48. data/app/controllers/users/omniauth_callbacks_controller.rb +30 -0
  49. data/app/controllers/users/passwords_controller.rb +34 -0
  50. data/app/controllers/users/registrations_controller.rb +61 -0
  51. data/app/controllers/users/sessions_controller.rb +27 -0
  52. data/app/controllers/users/unlocks_controller.rb +30 -0
  53. data/app/controllers/wallets_controller.rb +18 -0
  54. data/app/helpers/application_helper.rb +4 -0
  55. data/app/helpers/blocks_helper.rb +4 -0
  56. data/app/helpers/chains_helper.rb +4 -0
  57. data/app/helpers/contracts_helper.rb +4 -0
  58. data/app/helpers/pools_helper.rb +4 -0
  59. data/app/helpers/signatures_helper.rb +4 -0
  60. data/app/helpers/tickets_helper.rb +4 -0
  61. data/app/helpers/transactions_helper.rb +4 -0
  62. data/app/helpers/wallets_helper.rb +4 -0
  63. data/app/javascript/application.js +3 -0
  64. data/app/javascript/controllers/application.js +9 -0
  65. data/app/javascript/controllers/hello_controller.js +7 -0
  66. data/app/javascript/controllers/index.js +11 -0
  67. data/app/jobs/application_job.rb +9 -0
  68. data/app/mailers/application_mailer.rb +6 -0
  69. data/app/models/acceptable_number_sequence.rb +4 -0
  70. data/app/models/acceptable_symbol_sequence.rb +4 -0
  71. data/app/models/acceptable_word.rb +4 -0
  72. data/app/models/application_record.rb +5 -0
  73. data/app/models/block.rb +17 -0
  74. data/app/models/chain.rb +10 -0
  75. data/app/models/concerns/.keep +0 -0
  76. data/app/models/concerns/sequences_validator.rb +30 -0
  77. data/app/models/concerns/wallet_exists_validator.rb +13 -0
  78. data/app/models/contract.rb +7 -0
  79. data/app/models/pool.rb +5 -0
  80. data/app/models/signature.rb +12 -0
  81. data/app/models/ticket.rb +11 -0
  82. data/app/models/transaction.rb +25 -0
  83. data/app/models/user.rb +44 -0
  84. data/app/models/wallet.rb +33 -0
  85. data/app/services/application_service.rb +23 -0
  86. data/app/services/assign_contracts_service.rb +162 -0
  87. data/app/services/create_ticket_service.rb +87 -0
  88. data/app/services/create_wallet_service.rb +20 -0
  89. data/app/services/transaction_to_block_service.rb +62 -0
  90. data/app/views/application/_featured_board.html.erb +77 -0
  91. data/app/views/application/home.html.slim +1 -0
  92. data/app/views/application/mining_profile.html.slim +59 -0
  93. data/app/views/application/privacy_policy.html.erb +0 -0
  94. data/app/views/application/terms.html.erb +0 -0
  95. data/app/views/blocks/_block.html.slim +13 -0
  96. data/app/views/blocks/_block.json.jbuilder +4 -0
  97. data/app/views/blocks/_form.html.slim +26 -0
  98. data/app/views/blocks/edit.html.slim +10 -0
  99. data/app/views/blocks/index.html.slim +12 -0
  100. data/app/views/blocks/index.json.jbuilder +3 -0
  101. data/app/views/blocks/new.html.slim +8 -0
  102. data/app/views/blocks/show.html.slim +8 -0
  103. data/app/views/blocks/show.json.jbuilder +3 -0
  104. data/app/views/chains/_chain.html.slim +16 -0
  105. data/app/views/chains/_chain.json.jbuilder +4 -0
  106. data/app/views/chains/_form.html.slim +30 -0
  107. data/app/views/chains/edit.html.slim +10 -0
  108. data/app/views/chains/index.html.slim +11 -0
  109. data/app/views/chains/index.json.jbuilder +3 -0
  110. data/app/views/chains/new.html.slim +8 -0
  111. data/app/views/chains/show.html.slim +10 -0
  112. data/app/views/chains/show.json.jbuilder +3 -0
  113. data/app/views/contracts/_contract.html.slim +8 -0
  114. data/app/views/contracts/_contract.json.jbuilder +4 -0
  115. data/app/views/contracts/_form.html.slim +34 -0
  116. data/app/views/contracts/edit.html.slim +10 -0
  117. data/app/views/contracts/index.html.slim +12 -0
  118. data/app/views/contracts/index.json.jbuilder +3 -0
  119. data/app/views/contracts/new.html.slim +8 -0
  120. data/app/views/contracts/show.html.slim +8 -0
  121. data/app/views/contracts/show.json.jbuilder +3 -0
  122. data/app/views/layouts/_alert.html.slim +6 -0
  123. data/app/views/layouts/_navbar.html.slim +27 -0
  124. data/app/views/layouts/_notice.html.slim +6 -0
  125. data/app/views/layouts/application.html.erb +32 -0
  126. data/app/views/layouts/mailer.html.erb +13 -0
  127. data/app/views/layouts/mailer.text.erb +1 -0
  128. data/app/views/pools/_form.html.slim +30 -0
  129. data/app/views/pools/_pool.html.slim +16 -0
  130. data/app/views/pools/_pool.json.jbuilder +4 -0
  131. data/app/views/pools/edit.html.slim +10 -0
  132. data/app/views/pools/index.html.slim +12 -0
  133. data/app/views/pools/index.json.jbuilder +3 -0
  134. data/app/views/pools/new.html.slim +8 -0
  135. data/app/views/pools/show.html.slim +8 -0
  136. data/app/views/pools/show.json.jbuilder +3 -0
  137. data/app/views/signatures/_form.html.slim +46 -0
  138. data/app/views/signatures/_signature.html.slim +28 -0
  139. data/app/views/signatures/_signature.json.jbuilder +4 -0
  140. data/app/views/signatures/edit.html.slim +10 -0
  141. data/app/views/signatures/index.html.slim +10 -0
  142. data/app/views/signatures/index.json.jbuilder +3 -0
  143. data/app/views/signatures/new.html.slim +8 -0
  144. data/app/views/signatures/show.html.slim +10 -0
  145. data/app/views/signatures/show.json.jbuilder +3 -0
  146. data/app/views/tickets/_form.html.slim +26 -0
  147. data/app/views/tickets/_ticket.html.slim +10 -0
  148. data/app/views/tickets/_ticket.json.jbuilder +4 -0
  149. data/app/views/tickets/edit.html.slim +10 -0
  150. data/app/views/tickets/index.html.slim +16 -0
  151. data/app/views/tickets/index.json.jbuilder +3 -0
  152. data/app/views/tickets/new.html.slim +10 -0
  153. data/app/views/tickets/show.html.slim +8 -0
  154. data/app/views/tickets/show.json.jbuilder +3 -0
  155. data/app/views/transactions/_form.html.slim +16 -0
  156. data/app/views/transactions/_transaction.html.slim +24 -0
  157. data/app/views/transactions/_transaction.json.jbuilder +4 -0
  158. data/app/views/transactions/edit.html.slim +10 -0
  159. data/app/views/transactions/index.html.slim +19 -0
  160. data/app/views/transactions/index.json.jbuilder +3 -0
  161. data/app/views/transactions/new.html.slim +9 -0
  162. data/app/views/transactions/show.html.slim +8 -0
  163. data/app/views/transactions/show.json.jbuilder +3 -0
  164. data/app/views/users/confirmations/new.html.erb +16 -0
  165. data/app/views/users/mailer/confirmation_instructions.html.erb +5 -0
  166. data/app/views/users/mailer/email_changed.html.erb +7 -0
  167. data/app/views/users/mailer/password_change.html.erb +3 -0
  168. data/app/views/users/mailer/reset_password_instructions.html.erb +8 -0
  169. data/app/views/users/mailer/unlock_instructions.html.erb +7 -0
  170. data/app/views/users/passwords/edit.html.erb +25 -0
  171. data/app/views/users/passwords/new.html.erb +16 -0
  172. data/app/views/users/registrations/edit.html.erb +43 -0
  173. data/app/views/users/registrations/new.html.erb +37 -0
  174. data/app/views/users/sessions/new.html.erb +30 -0
  175. data/app/views/users/shared/_error_messages.html.erb +15 -0
  176. data/app/views/users/shared/_links.html.erb +25 -0
  177. data/app/views/users/unlocks/new.html.erb +16 -0
  178. data/app/views/wallets/_form.html.slim +30 -0
  179. data/app/views/wallets/_wallet.html.slim +13 -0
  180. data/app/views/wallets/_wallet.json.jbuilder +4 -0
  181. data/app/views/wallets/edit.html.slim +10 -0
  182. data/app/views/wallets/index.html.slim +18 -0
  183. data/app/views/wallets/index.json.jbuilder +3 -0
  184. data/app/views/wallets/new.html.slim +8 -0
  185. data/app/views/wallets/show.html.slim +11 -0
  186. data/app/views/wallets/show.json.jbuilder +3 -0
  187. data/app/workers/application_worker.rb +82 -0
  188. data/app/workers/assign_contract_worker.rb +27 -0
  189. data/app/workers/create_ticket_worker.rb +23 -0
  190. data/app/workers/create_wallet_worker.rb +21 -0
  191. data/app/workers/transaction_to_block_worker.rb +48 -0
  192. data/bin/bundle +114 -0
  193. data/bin/console +15 -0
  194. data/bin/dev +9 -0
  195. data/bin/importmap +5 -0
  196. data/bin/osbc +77 -0
  197. data/bin/rails +6 -0
  198. data/bin/rake +6 -0
  199. data/bin/setup +35 -0
  200. data/config/application.rb +25 -0
  201. data/config/boot.rb +6 -0
  202. data/config/cable.yml +10 -0
  203. data/config/credentials.yml.enc +1 -0
  204. data/config/database.yml +21 -0
  205. data/config/environment.rb +7 -0
  206. data/config/environments/development.rb +73 -0
  207. data/config/environments/production.rb +95 -0
  208. data/config/environments/test.rb +62 -0
  209. data/config/importmap.rb +9 -0
  210. data/config/initializers/assets.rb +14 -0
  211. data/config/initializers/content_security_policy.rb +26 -0
  212. data/config/initializers/devise.rb +311 -0
  213. data/config/initializers/filter_parameter_logging.rb +10 -0
  214. data/config/initializers/inflections.rb +17 -0
  215. data/config/initializers/permissions_policy.rb +12 -0
  216. data/config/locales/devise.en.yml +65 -0
  217. data/config/locales/en.yml +33 -0
  218. data/config/puma.rb +45 -0
  219. data/config/routes/api.rb +9 -0
  220. data/config/routes.rb +30 -0
  221. data/config/sidekiq.yml +10 -0
  222. data/config/storage.yml +34 -0
  223. data/config/tailwind.config.js +23 -0
  224. data/config.ru +8 -0
  225. data/coverage/.last_run.json +5 -0
  226. data/coverage/.resultset.json +1853 -0
  227. data/coverage/.resultset.json.lock +0 -0
  228. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc.png +0 -0
  229. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc_disabled.png +0 -0
  230. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_both.png +0 -0
  231. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc.png +0 -0
  232. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc_disabled.png +0 -0
  233. data/coverage/assets/0.12.3/application.css +1 -0
  234. data/coverage/assets/0.12.3/application.js +7 -0
  235. data/coverage/assets/0.12.3/colorbox/border.png +0 -0
  236. data/coverage/assets/0.12.3/colorbox/controls.png +0 -0
  237. data/coverage/assets/0.12.3/colorbox/loading.gif +0 -0
  238. data/coverage/assets/0.12.3/colorbox/loading_background.png +0 -0
  239. data/coverage/assets/0.12.3/favicon_green.png +0 -0
  240. data/coverage/assets/0.12.3/favicon_red.png +0 -0
  241. data/coverage/assets/0.12.3/favicon_yellow.png +0 -0
  242. data/coverage/assets/0.12.3/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  243. data/coverage/assets/0.12.3/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  244. data/coverage/assets/0.12.3/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  245. data/coverage/assets/0.12.3/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  246. data/coverage/assets/0.12.3/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  247. data/coverage/assets/0.12.3/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  248. data/coverage/assets/0.12.3/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  249. data/coverage/assets/0.12.3/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  250. data/coverage/assets/0.12.3/images/ui-icons_222222_256x240.png +0 -0
  251. data/coverage/assets/0.12.3/images/ui-icons_2e83ff_256x240.png +0 -0
  252. data/coverage/assets/0.12.3/images/ui-icons_454545_256x240.png +0 -0
  253. data/coverage/assets/0.12.3/images/ui-icons_888888_256x240.png +0 -0
  254. data/coverage/assets/0.12.3/images/ui-icons_cd0a0a_256x240.png +0 -0
  255. data/coverage/assets/0.12.3/loading.gif +0 -0
  256. data/coverage/assets/0.12.3/magnify.png +0 -0
  257. data/coverage/index.html +20731 -0
  258. data/db/migrate/20221018053949_devise_create_users.rb +45 -0
  259. data/db/migrate/20221019002956_create_chains.rb +13 -0
  260. data/db/migrate/20221020112137_create_blocks.rb +12 -0
  261. data/db/migrate/20221020123102_add_chain_to_blocks.rb +5 -0
  262. data/db/migrate/20221020150504_create_wallets.rb +13 -0
  263. data/db/migrate/20221022221059_create_transactions.rb +20 -0
  264. data/db/migrate/20221023011005_add_block_to_transactions.rb +5 -0
  265. data/db/migrate/20221023014707_create_contracts.rb +11 -0
  266. data/db/migrate/20221023040749_create_pools.rb +13 -0
  267. data/db/migrate/20221023041015_create_tickets.rb +11 -0
  268. data/db/migrate/20221023103509_add_contracts_count_to_block.rb +6 -0
  269. data/db/migrate/20221023110613_add_acceptable_word_list_to_users.rb +7 -0
  270. data/db/migrate/20221023113539_create_signatures.rb +19 -0
  271. data/db/migrate/20221023113750_create_acceptable_words.rb +9 -0
  272. data/db/migrate/20221023114152_create_acceptable_number_sequences.rb +9 -0
  273. data/db/migrate/20221023114203_create_acceptable_symbol_sequences.rb +9 -0
  274. data/db/migrate/20221023114324_add_user_acceptable_hash_to_tickets.rb +7 -0
  275. data/db/migrate/20221023114408_add_time_ref_to_tickets.rb +5 -0
  276. data/db/migrate/20221024125047_add_master_hash_to_blocks.rb +5 -0
  277. data/db/migrate/20221109161845_add_transactions_count_to_blocks.rb +5 -0
  278. data/db/migrate/20221117135003_add_balance_to_chains.rb +5 -0
  279. data/db/migrate/20221117203417_add_transaction_id_list_to_tickets.rb +5 -0
  280. data/db/migrate/20221118080357_add_api_keys_to_users.rb +6 -0
  281. data/db/schema.rb +179 -0
  282. data/db/seeds.rb +134 -0
  283. data/docker-compose.yml +53 -0
  284. data/entrypoint.sh +8 -0
  285. data/lib/assets/.keep +0 -0
  286. data/lib/osbc/osbc.rb +9 -0
  287. data/lib/outerspace/blockchain/version.rb +7 -0
  288. data/lib/outerspace/blockchain.rb +10 -0
  289. data/lib/tasks/.keep +0 -0
  290. data/lib/tasks/compose.rake +92 -0
  291. data/lib/tasks/compose_db.rake +71 -0
  292. data/lib/tasks/compose_logs.rake +95 -0
  293. data/lib/tasks/compose_test.rake +62 -0
  294. data/log/.keep +0 -0
  295. data/mining_concept.ipynb +284 -0
  296. data/outerspace-blockchain.gemspec +50 -0
  297. data/public/404.html +67 -0
  298. data/public/422.html +67 -0
  299. data/public/500.html +66 -0
  300. data/public/apple-touch-icon-precomposed.png +0 -0
  301. data/public/apple-touch-icon.png +0 -0
  302. data/public/favicon.ico +0 -0
  303. data/public/robots.txt +1 -0
  304. data/storage/.keep +0 -0
  305. data/tmp/.keep +0 -0
  306. data/tmp/pids/.keep +0 -0
  307. data/tmp/storage/.keep +0 -0
  308. data/vendor/.keep +0 -0
  309. data/vendor/javascript/.keep +0 -0
  310. metadata +643 -0
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Outerspace
4
+ module Blockchain
5
+ VERSION = "0.1.1"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "blockchain/version"
4
+
5
+ module Outerspace
6
+ module Blockchain
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
10
+ end
data/lib/tasks/.keep ADDED
File without changes
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake"
4
+
5
+ namespace :compose do
6
+ task :install do
7
+ puts "Installing Blockchain and Database Containers"
8
+ system "sudo docker compose build"
9
+ puts "Creating Database"
10
+ system "sudo docker compose run --rm web rails db:create"
11
+ puts "Migrating Database"
12
+ system "sudo docker compose run --rm web rails db:migrate"
13
+ puts "Seeding Database"
14
+ system "sudo docker compose run --rm web rails db:seed"
15
+ puts "Stopping Containers"
16
+ system "sudo docker compose down"
17
+ puts "Installing Blockchain and Database Containers... Done!"
18
+ puts "This already setup your database with some initial values"
19
+ puts "Start the containers with command: rake compose:up"
20
+ puts "Stop the containers with command: rake compose:down"
21
+ puts "Restart the containers with command: rake compose:restart"
22
+ puts "Clean up the containers with command: rake compose:clean_all"
23
+ puts "Test your containers with command: rake compose:test"
24
+ puts "Build the containers againg with command: rake compose:build"
25
+ puts "rake compose_db command documentation at README.md to see database commands usage examples"
26
+ puts "See the development and test log files in Rails default logs folder when using compose:up"
27
+ puts "-----------------------------------------------------------------------------------"
28
+ puts "Access the web server on port 80."
29
+ puts "http://localhost"
30
+ puts "Look at README.md for more details."
31
+ end
32
+
33
+ task :build do
34
+ puts "Building Compose..."
35
+ system "sudo docker compose build"
36
+ puts "Building Compose... Done!"
37
+ end
38
+
39
+ task :up do
40
+ puts "Running Compose..."
41
+ system "sudo docker compose up -d --remove-orphans"
42
+ puts "Running Compose... Done!"
43
+ end
44
+
45
+ task :down do
46
+ puts "Stopping Compose..."
47
+ system "sudo docker compose down"
48
+ puts "Stopping Compose... Done!"
49
+ end
50
+
51
+ task :db_detach do
52
+ puts "Running Database Detached..."
53
+ system "sudo docker compose up -d db"
54
+ puts "Running Database Detached... Done!"
55
+ end
56
+
57
+ task :redis_detach do
58
+ puts "Running Redis Detached..."
59
+ system "sudo docker compose up -d redis"
60
+ puts "Running Redis Detached... Done!"
61
+ end
62
+
63
+ task :back_detach do
64
+ puts "Running Backend Detached..."
65
+ system "sudo docker compose up -d --remove-orphans db redis sidekiq"
66
+ puts "Running Backend Detached... Done!"
67
+ end
68
+
69
+ task :restart do
70
+ puts "Restarting Compose..."
71
+ puts "Stopping Compose..."
72
+ system "sudo docker compose down"
73
+ puts "Stopping Compose... Done!"
74
+ puts "Running Compose..."
75
+ system "sudo docker compose up -d --remove-orphans"
76
+ puts "Restarting Compose... Done!"
77
+ end
78
+
79
+ task :clean_all do
80
+ puts "Cleaning Images..."
81
+ puts "Stopping Compose..."
82
+ system "sudo docker compose down"
83
+ puts "Stopping Compose... Done!"
84
+ puts "Removing Compose..."
85
+ system "sudo docker compose rm -v"
86
+ puts "Removing Compose... Done!"
87
+ puts "Removing Containers..."
88
+ system "sudo docker rm -f $(sudo docker ps -a -q)"
89
+ puts "Removing Containers... Done!"
90
+ puts "Cleaning Images... Done!"
91
+ end
92
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake"
4
+
5
+ namespace :compose_db do
6
+ task :drop do
7
+ puts "Dropping Database..."
8
+ system("sudo docker compose run --rm web rake db:drop")
9
+ puts "Dropping Database... Done!"
10
+ end
11
+
12
+ task :rollback do
13
+ puts "Rolling Back Database..."
14
+ system("sudo docker compose run --rm web rails db:rollback")
15
+ puts "Rolling Back Database... Done!"
16
+ end
17
+
18
+ task :complete_setup do
19
+ puts "Setting up Database..."
20
+ system("sudo docker compose run --rm web rake db:create")
21
+ system("sudo docker compose run --rm web rake db:migrate")
22
+ system("sudo docker compose run --rm web rake db:seed")
23
+ puts "Setting up Database... Done!"
24
+ end
25
+
26
+ task :setup do
27
+ puts "Setting up and seeding Database..."
28
+ system("sudo docker compose run --rm web rake db:setup")
29
+ puts "Setting up and seeding Database... Done!"
30
+ end
31
+
32
+ task :create do
33
+ puts "Creating Database..."
34
+ system("sudo docker compose run --rm web rake db:create")
35
+ puts "Creating Database... Done!"
36
+ end
37
+
38
+ task :migrate do
39
+ puts "Running Migration..."
40
+ system("sudo docker compose run --rm web rake db:migrate")
41
+ puts "Running Migration... Done!"
42
+ end
43
+
44
+ task :seed do
45
+ puts "Running Seed..."
46
+ system("sudo docker compose run --rm web rake db:seed")
47
+ puts "Running Seed... Done!"
48
+ end
49
+
50
+ task :reset_setup do
51
+ puts "Resettting Database..."
52
+ system("sudo docker compose run --rm web rake db:drop")
53
+ system("sudo docker compose run --rm web rake db:setup")
54
+ puts "Resetting up Database... Done!"
55
+ end
56
+
57
+ task :reset do
58
+ puts "Resetting Database..."
59
+ system("sudo docker compose run --rm web rake db:drop")
60
+ system("sudo docker compose run --rm web rake db:create")
61
+ system("sudo docker compose run --rm web rake db:migrate")
62
+ system("sudo docker compose run --rm web rake db:seed")
63
+ puts "Resetting Compose... Done!"
64
+ end
65
+
66
+ task :force_reset do
67
+ puts "Running Compose Down"
68
+ system("rake compose:down")
69
+ system("rake compose_db:reset")
70
+ end
71
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake"
4
+
5
+ namespace :compose_logs do
6
+ task :web do
7
+ puts "Showing Web Logs..."
8
+ system "sudo docker compose logs web"
9
+ puts "Showing Web Logs... Done!"
10
+ end
11
+
12
+ task :db do
13
+ puts "Showing Database Logs..."
14
+ system "sudo docker compose logs db"
15
+ puts "Showing Database Logs... Done!"
16
+ end
17
+
18
+ task :redis do
19
+ puts "Showing Redis Logs..."
20
+ system "sudo docker compose logs redis"
21
+ puts "Showing Redis Logs... Done!"
22
+ end
23
+
24
+ task :sidekiq do
25
+ puts "Showing Sidekiq Logs..."
26
+ system "sudo docker compose logs sidekiq"
27
+ puts "Showing Sidekiq Logs... Done!"
28
+ end
29
+
30
+ task :all do
31
+ puts "Showing All Logs..."
32
+ system "sudo docker compose logs"
33
+ puts "Showing All Logs... Done!"
34
+ end
35
+
36
+ task :tail_web do
37
+ puts "Tailing Web Logs..."
38
+ system "sudo docker compose logs -f web"
39
+ puts "Tailing Web Logs... Done!"
40
+ end
41
+
42
+ task :tail_db do
43
+ puts "Tailing Database Logs..."
44
+ system "sudo docker compose logs -f db"
45
+ puts "Tailing Database Logs... Done!"
46
+ end
47
+
48
+ task :tail_redis do
49
+ puts "Tailing Redis Logs..."
50
+ system "sudo docker compose logs -f redis"
51
+ puts "Tailing Redis Logs... Done!"
52
+ end
53
+
54
+ task :tail_sidekiq do
55
+ puts "Tailing Sidekiq Logs..."
56
+ system "sudo docker compose logs -f sidekiq"
57
+ puts "Tailing Sidekiq Logs... Done!"
58
+ end
59
+
60
+ task :tail_all do
61
+ puts "Tailing All Logs..."
62
+ system "sudo docker compose logs -f"
63
+ puts "Tailing All Logs... Done!"
64
+ end
65
+
66
+ task :follow_web do
67
+ puts "Following Web Logs..."
68
+ system "sudo docker compose logs -f web"
69
+ puts "Following Web Logs... Done!"
70
+ end
71
+
72
+ task :follow_db do
73
+ puts "Following Database Logs..."
74
+ system "sudo docker compose logs -f db"
75
+ puts "Following Database Logs... Done!"
76
+ end
77
+
78
+ task :follow_redis do
79
+ puts "Following Redis Logs..."
80
+ system "sudo docker compose logs -f redis"
81
+ puts "Following Redis Logs... Done!"
82
+ end
83
+
84
+ task :follow_sidekiq do
85
+ puts "Following Sidekiq Logs..."
86
+ system "sudo docker compose logs -f sidekiq"
87
+ puts "Following Sidekiq Logs... Done!"
88
+ end
89
+
90
+ task :follow_all do
91
+ puts "Following All Logs..."
92
+ system "sudo docker compose logs -f"
93
+ puts "Following All Logs... Done!"
94
+ end
95
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake"
4
+
5
+ namespace :compose_test do
6
+ task :all do
7
+ puts "Running Test..."
8
+ system "sudo docker compose run --rm web bundle exec rspec"
9
+ puts "Running Test... Done!"
10
+ end
11
+
12
+ task :clean_test do
13
+ puts "Running Clean Test..."
14
+ system "rake compose:clean_all"
15
+ puts "Cleaning Compose Images... Done!"
16
+ puts "Running Tests ..."
17
+ system "sudo docker compose run --rm web bundle exec rspec"
18
+ puts "Running Clean Test... Done!"
19
+ end
20
+
21
+ task :controllers do
22
+ puts "Running Controllers Test..."
23
+ system "sudo docker compose run --rm web bundle exec rspec spec/controllers"
24
+ puts "Running Controllers Test... Done!"
25
+ end
26
+
27
+ task :models do
28
+ puts "Running Models Test..."
29
+ system "sudo docker compose run --rm web bundle exec rspec spec/models"
30
+ puts "Running Models Test... Done!"
31
+ end
32
+
33
+ task :requests do
34
+ puts "Running Requests Test..."
35
+ system "sudo docker compose run --rm web bundle exec rspec spec/requests"
36
+ puts "Running Requests Test... Done!"
37
+ end
38
+
39
+ task :helpers do
40
+ puts "Running Helpers Test..."
41
+ system "sudo docker compose run --rm web bundle exec rspec spec/helpers"
42
+ puts "Running Helpers Test... Done!"
43
+ end
44
+
45
+ task :mailers do
46
+ puts "Running Mailers Test..."
47
+ system "sudo docker compose run --rm web bundle exec rspec spec/mailers"
48
+ puts "Running Mailers Test... Done!"
49
+ end
50
+
51
+ task :routing do
52
+ puts "Running Routing Test..."
53
+ system "sudo docker compose run --rm web bundle exec rspec spec/routing"
54
+ puts "Running Routing Test... Done!"
55
+ end
56
+
57
+ task :views do
58
+ puts "Running Views Test..."
59
+ system "sudo docker compose run --rm web bundle exec rspec spec/views"
60
+ puts "Running Views Test... Done!"
61
+ end
62
+ end
data/log/.keep ADDED
File without changes
@@ -0,0 +1,284 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "## Mining Concept\n",
8
+ "- Every user will have a **randomized acceptable word list**\n",
9
+ "- This word list will have three classes of words\n",
10
+ "1. Common words\n",
11
+ "2. Symbol Sequence\n",
12
+ "3. Number Sequence\n",
13
+ "\n",
14
+ "<p> \n",
15
+ "When a user want to mine a block, the user will open a ticket in the server\n",
16
+ "and after the ticket is open, the user will start to mine the block\n",
17
+ "</p> \n",
18
+ "\n",
19
+ "<p>\n",
20
+ "The mine will depend of the contract signatures that will be formed by the server using the word list of the user\n",
21
+ "</p>\n",
22
+ "\n",
23
+ "\n",
24
+ "## Steps to mine a block:\n",
25
+ "\n",
26
+ "1. The user will open a TICKET in the server\n",
27
+ "2. The server will send a message to the user to start mining if the POOL is open\n",
28
+ "3. The users will load the RANDOM WORD LIST provided by the server API\n",
29
+ "4. The user have to use 1 common word, 1 symbol sequence and 1 number sequence, randomize the characters\n",
30
+ "5. Transform the chartacters in a SHA256 hash\n",
31
+ "6. Transform the block info in before ticket opened in a SHA256 hash\n",
32
+ "5. Transform (Chars SHA256 hash + block info hash) in a SHA256 hash - or - send only the chars SHA256 hash\n",
33
+ "6. If the hash is valid, the user will send the hash to the server\n",
34
+ "7. The server will check if the hash is valid\n",
35
+ "8. If the hash is valid, check if the same transactions have the same block state confirmation\n",
36
+ "9. If this transactions was not confirmed at this point at block history the server will add the user signature to the transaction contract\n",
37
+ "10. The block only can be hashed when the minimum number of contracts valids with minimum number of signatures is reached\n",
38
+ "11. The server will use the signature timeline to determine what transactions will be added to the block\n",
39
+ "12. The server will calculate the master hash after confirm all valid contracts signatures\n",
40
+ "13. The server will add the block to the blockchain and create a new one with last block unconfirmed transactions but completely unsigned\n",
41
+ "13. The server will start a open/closed pool cycle\n",
42
+ "14. The server will send a message to the user to start mining when the POOL is open and user has a ticket\n",
43
+ "<p>\n",
44
+ "The timestamps of the signatures will be usefull to version the block, checking it as a timeline\n",
45
+ "</p>\n",
46
+ "\n",
47
+ "**The miners will be rewarded with the block reward distributed by the number of signatures**\n"
48
+ ]
49
+ },
50
+ {
51
+ "cell_type": "code",
52
+ "execution_count": 1,
53
+ "metadata": {},
54
+ "outputs": [],
55
+ "source": [
56
+ "import pandas as pd\n",
57
+ "import numpy as np\n",
58
+ "import matplotlib.pyplot as plt\n",
59
+ "import seaborn as sns\n",
60
+ "import datetime\n",
61
+ "import hashlib\n",
62
+ "import itertools\n",
63
+ "import requests as re"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": 2,
69
+ "metadata": {},
70
+ "outputs": [
71
+ {
72
+ "name": "stdout",
73
+ "output_type": "stream",
74
+ "text": [
75
+ "551e86307dfaddeb02f0326ec1667eac3257817b41ae8916531a06fbcdf9148c\n"
76
+ ]
77
+ },
78
+ {
79
+ "data": {
80
+ "text/plain": [
81
+ "(['her', 'number', 'it', 'at'],\n",
82
+ " ['0654', '1523', '2307', '5890'],\n",
83
+ " ['@(#$¨@#¨$@¨$$¨@(#$)', '$#$¨@*#$¨$(@#)', '@#$%^&*()_', ')@#$%^&*('])"
84
+ ]
85
+ },
86
+ "execution_count": 2,
87
+ "metadata": {},
88
+ "output_type": "execute_result"
89
+ }
90
+ ],
91
+ "source": [
92
+ "key = '9e8b3f4bf92577861e06e3bc84a809794dd6a7ab9da1070a78eb763b3399595a'\n",
93
+ "secret = 'a239c12ecc42911ecbc3b23a9539976caaa60f7d40028dea17cb67cc538c21bd'\n",
94
+ "\n",
95
+ "headers = {\n",
96
+ " 'X-Api-Key': key,\n",
97
+ " 'X-Api-Secret': secret,\n",
98
+ "}\n",
99
+ "\n",
100
+ "\n",
101
+ "transactions = re.get('http://localhost/api/v1/tr_to_mine', headers=headers)\n",
102
+ "\n",
103
+ "transactions = str(transactions.json())\n",
104
+ "\n",
105
+ "transactions_hash = hashlib.sha256(transactions.encode('utf-8')).hexdigest()\n",
106
+ "\n",
107
+ "print(transactions_hash)\n",
108
+ "\n",
109
+ "accepted_sequences = re.get('http://localhost/api/v1/info_to_mine', headers=headers)\n",
110
+ "\n",
111
+ "accepted_sequences = accepted_sequences.json()\n",
112
+ "\n",
113
+ "accepted_sequences\n",
114
+ "\n",
115
+ "def parse_accepted_sequences(accepted_sequences):\n",
116
+ " words = accepted_sequences['words']\n",
117
+ " numbers = accepted_sequences['number_sequences']\n",
118
+ " symbols = accepted_sequences['symbol_sequences']\n",
119
+ " return words, numbers, symbols\n",
120
+ "\n",
121
+ "words, numbers, symbols = parse_accepted_sequences(accepted_sequences)\n",
122
+ "\n",
123
+ "words, numbers, symbols"
124
+ ]
125
+ },
126
+ {
127
+ "cell_type": "code",
128
+ "execution_count": 3,
129
+ "metadata": {},
130
+ "outputs": [],
131
+ "source": [
132
+ "def all_combinations(acceptable_words, acceptable_number_sequences, acceptables_symbol_sequences):\n",
133
+ " combinations = []\n",
134
+ " for comb in itertools.product(acceptable_words, acceptable_number_sequences, acceptables_symbol_sequences):\n",
135
+ " combinations.append(''.join(comb))\n",
136
+ " return combinations\n",
137
+ "\n",
138
+ "def hash_combinations(combinations, transactions_hash, run_on=0):\n",
139
+ " hash_list = []\n",
140
+ " counter = 0\n",
141
+ " for combination in combinations:\n",
142
+ " for comb in itertools.permutations(combination):\n",
143
+ " counter += 1\n",
144
+ " if counter > run_on:\n",
145
+ " random_hash = hashlib.sha256(''.join(comb).encode('utf-8')).hexdigest()\n",
146
+ " hash_list.append(hashlib.sha256((transactions_hash + random_hash).encode('utf-8')).hexdigest())\n",
147
+ " if len(hash_list) == 1000000:\n",
148
+ " return hash_list"
149
+ ]
150
+ },
151
+ {
152
+ "cell_type": "code",
153
+ "execution_count": 4,
154
+ "metadata": {},
155
+ "outputs": [],
156
+ "source": [
157
+ "def calculate_hash_rate(acceptable_w, acceptable_n, acceptables_s, transactions_hash, run_on=0):\n",
158
+ " start = datetime.datetime.now()\n",
159
+ " all_combs = all_combinations(acceptable_w, acceptable_n, acceptables_s)\n",
160
+ " hash_list = hash_combinations(all_combs, transactions_hash)\n",
161
+ " end = datetime.datetime.now()\n",
162
+ " total_seconds = (end - start).total_seconds()\n",
163
+ " hash_rate = len(hash_list) / total_seconds\n",
164
+ " return hash_rate, start, end, total_seconds, hash_list\n",
165
+ "\n",
166
+ "def benchmark_table(hash_rate, start, end, total_seconds, hash_list):\n",
167
+ " hash_list_table = pd.DataFrame({\n",
168
+ " 'hash': hash_list,\n",
169
+ " })\n",
170
+ " hash_rate_table = pd.DataFrame({\n",
171
+ " 'Hash rate': [hash_rate, hash_rate / 1000, hash_rate / 1000000, hash_rate / 1000000000],\n",
172
+ " 'Unit': ['h/s', 'kh/s', 'Mh/s', 'Gh/s']\n",
173
+ " })\n",
174
+ " time_table = pd.DataFrame({\n",
175
+ " 'Time': [start, end, total_seconds],\n",
176
+ " 'Unit': ['start', 'end', 'total_seconds'],\n",
177
+ " })\n",
178
+ " return hash_rate_table, time_table, hash_list_table"
179
+ ]
180
+ },
181
+ {
182
+ "cell_type": "code",
183
+ "execution_count": null,
184
+ "metadata": {},
185
+ "outputs": [],
186
+ "source": [
187
+ "hash_rate, start, end, total_seconds, hash_list = calculate_hash_rate(words, numbers, symbols, transactions_hash)\n",
188
+ "hash_rate_table, time_table, hash_list_table = benchmark_table(hash_rate, start, end, total_seconds, hash_list)"
189
+ ]
190
+ },
191
+ {
192
+ "cell_type": "code",
193
+ "execution_count": null,
194
+ "metadata": {},
195
+ "outputs": [],
196
+ "source": [
197
+ "hash_list_table"
198
+ ]
199
+ },
200
+ {
201
+ "cell_type": "code",
202
+ "execution_count": null,
203
+ "metadata": {},
204
+ "outputs": [],
205
+ "source": [
206
+ "time_table"
207
+ ]
208
+ },
209
+ {
210
+ "cell_type": "code",
211
+ "execution_count": null,
212
+ "metadata": {},
213
+ "outputs": [],
214
+ "source": [
215
+ "hash_rate_table"
216
+ ]
217
+ },
218
+ {
219
+ "cell_type": "code",
220
+ "execution_count": null,
221
+ "metadata": {},
222
+ "outputs": [],
223
+ "source": [
224
+ "def plot_hash_rate(hash_rate_table):\n",
225
+ " hash_rate_table.plot(x='Unit', y='Hash rate', kind='bar', logy=True)\n",
226
+ " plt.show()\n",
227
+ "\n",
228
+ "plot_hash_rate(hash_rate_table)"
229
+ ]
230
+ },
231
+ {
232
+ "cell_type": "code",
233
+ "execution_count": 10,
234
+ "metadata": {},
235
+ "outputs": [
236
+ {
237
+ "data": {
238
+ "text/plain": [
239
+ "{'message': 'Contract assigned'}"
240
+ ]
241
+ },
242
+ "execution_count": 10,
243
+ "metadata": {},
244
+ "output_type": "execute_result"
245
+ }
246
+ ],
247
+ "source": [
248
+ "hash_to_send = '99893b819abfa80498f244fddd080f570cecdc994199d5c6a8148141401cdff1'\n",
249
+ "\n",
250
+ "params = { 'user_confirmation_hash' : hash_to_send }\n",
251
+ "confirm_request = re.post('http://localhost/api/v1/confirm_block', headers=headers, params=params)\n",
252
+ "\n",
253
+ "confirm_request.json()"
254
+ ]
255
+ }
256
+ ],
257
+ "metadata": {
258
+ "kernelspec": {
259
+ "display_name": "Python 3.9.2 64-bit",
260
+ "language": "python",
261
+ "name": "python3"
262
+ },
263
+ "language_info": {
264
+ "codemirror_mode": {
265
+ "name": "ipython",
266
+ "version": 3
267
+ },
268
+ "file_extension": ".py",
269
+ "mimetype": "text/x-python",
270
+ "name": "python",
271
+ "nbconvert_exporter": "python",
272
+ "pygments_lexer": "ipython3",
273
+ "version": "3.9.2"
274
+ },
275
+ "orig_nbformat": 4,
276
+ "vscode": {
277
+ "interpreter": {
278
+ "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1"
279
+ }
280
+ }
281
+ },
282
+ "nbformat": 4,
283
+ "nbformat_minor": 2
284
+ }
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/outerspace/blockchain/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "outerspace-blockchain"
7
+ spec.version = Outerspace::Blockchain::VERSION
8
+ spec.authors = ["JesusGautamah"]
9
+ spec.email = ["lima.jesuscc@gmail.com"]
10
+
11
+ spec.summary = "Blockchain implementation in Ruby"
12
+ spec.description = "Blockchain implementation in Ruby using Rails and Docker"
13
+ spec.homepage = "https://outerspace-blockchain.herokuapp.com/"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.0.3"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/outerspace-coding/outerspace-blockchain"
21
+ spec.metadata["changelog_uri"] = "https://github.com/outerspace-coding/outerspace-blockchain/blob/main/CHANGELOG.md"
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = "bin"
28
+ spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+ spec.add_runtime_dependency "bundler", "~> 2.2"
31
+ spec.add_runtime_dependency "rails", "~> 7.0.4"
32
+ spec.add_runtime_dependency "pg", "~> 1.4"
33
+ spec.add_runtime_dependency "puma", "~> 5.0"
34
+ spec.add_runtime_dependency "importmap-rails", "~> 1.1"
35
+ spec.add_runtime_dependency "tailwindcss-rails", "~> 2.0"
36
+ spec.add_runtime_dependency "rubocop-rails", "~> 2.16"
37
+ spec.add_runtime_dependency "rubocop-rspec", "~> 2.13"
38
+ spec.add_runtime_dependency "sidekiq", "~> 6.5"
39
+ spec.add_runtime_dependency "devise", "~> 4.8"
40
+ spec.add_runtime_dependency "rspec-rails", "~> 6.0"
41
+ spec.add_runtime_dependency "factory_bot_rails", "~> 6.2"
42
+ spec.add_runtime_dependency "faker", "~> 2.23"
43
+ spec.add_runtime_dependency "simplecov", "~> 0.21"
44
+ spec.add_runtime_dependency "selenium-webdriver", "~> 4.5"
45
+ spec.add_runtime_dependency "sprockets-rails", "~> 3.4"
46
+ spec.add_runtime_dependency "webdrivers", "~> 5.2"
47
+ spec.add_runtime_dependency "turbo-rails", "~> 1.3"
48
+ spec.add_runtime_dependency "stimulus-rails", "~> 1.1"
49
+ spec.add_runtime_dependency "jbuilder", "~> 2.11"
50
+ end