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,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SignaturesController < ApplicationController
4
+ before_action :set_signature, only: %i[ show edit update destroy ]
5
+
6
+ # GET /signatures or /signatures.json
7
+ def index
8
+ @signatures = Signature.all
9
+ end
10
+
11
+ # GET /signatures/1 or /signatures/1.json
12
+ def show
13
+ end
14
+
15
+ private
16
+ # Use callbacks to share common setup or constraints between actions.
17
+ def set_signature
18
+ @signature = Signature.find(params[:id])
19
+ end
20
+
21
+ # Only allow a list of trusted parameters through.
22
+ def signature_params
23
+ params.require(:signature).permit(:signature, :time_ref, :contract_id, :common_word, :symbol_sequence, :number_sequence, :verify_sig, :block_hash, :signature_hash)
24
+ end
25
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TicketsController < ApplicationController
4
+ before_action :set_ticket, only: %i[ show edit update destroy ]
5
+ before_action :authenticate_user!
6
+
7
+ # GET /tickets or /tickets.json
8
+ def index
9
+ @tickets = Ticket.all
10
+ end
11
+
12
+ # GET /tickets/1 or /tickets/1.json
13
+ def show
14
+ end
15
+
16
+ # GET /tickets/new
17
+ def new
18
+ @ticket = Ticket.new
19
+ end
20
+
21
+ # GET /tickets/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /tickets or /tickets.json
26
+ def create
27
+ return no_transactions_response if block_transactions.empty?
28
+ create_ticket
29
+ redirect_to tickets_path, notice: "Processing ticket, please wait, wait a minute and refresh the page"
30
+ end
31
+
32
+ # PATCH/PUT /tickets/1 or /tickets/1.json
33
+ def update
34
+ respond_to do |format|
35
+ if @ticket.update(ticket_params)
36
+ format.html { redirect_to ticket_url(@ticket), notice: "Ticket was successfully updated." }
37
+ format.json { render :show, status: :ok, location: @ticket }
38
+ else
39
+ format.html { render :edit, status: :unprocessable_entity }
40
+ format.json { render json: @ticket.errors, status: :unprocessable_entity }
41
+ end
42
+ end
43
+ end
44
+
45
+ # DELETE /tickets/1 or /tickets/1.json
46
+ def destroy
47
+ @ticket.destroy
48
+
49
+ respond_to do |format|
50
+ format.html { redirect_to tickets_url, notice: "Ticket was successfully destroyed." }
51
+ format.json { head :no_content }
52
+ end
53
+ end
54
+
55
+ private
56
+ def create_ticket
57
+ CreateTicketWorker.perform_async(current_user.id, current_pool.id, time_ref)
58
+ end
59
+ # Use callbacks to share common setup or constraints between actions.
60
+ def set_ticket
61
+ @ticket = Ticket.find(params[:id])
62
+ end
63
+
64
+ def time_ref
65
+ @time_ref = block_transactions.first.created_at
66
+ end
67
+
68
+ def no_transactions_response
69
+ redirect_to root_path, notice: "No transactions yet"
70
+ end
71
+
72
+ # Only allow a list of trusted parameters through.
73
+ def ticket_params
74
+ params.require(:ticket).permit(:user_id, :pool_id, :status, :time_ref)
75
+ end
76
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TransactionsController < ApplicationController
4
+ before_action :set_transaction, only: %i[ show edit update destroy ]
5
+ before_action :authenticate_user!, except: [:index, :show]
6
+
7
+ # GET /transactions or /transactions.json
8
+ def index
9
+ @transactions = Transaction.all
10
+ end
11
+
12
+ # GET /transactions/1 or /transactions/1.json
13
+ def show
14
+ end
15
+
16
+ # GET /transactions/new
17
+ def new
18
+ @transaction = Transaction.new
19
+ end
20
+
21
+ # POST /transactions or /transactions.json
22
+ def create
23
+ @receiver_key = transaction_params[:receiver_key]
24
+ @amount = transaction_params[:amount]
25
+ @sender_key = Wallet.find_by(user_id: current_user.id).pv_key
26
+ create_transaction_in_block
27
+ redirect_to transactions_path, notice: "Processing transaction, please wait a minute and refresh the page"
28
+ end
29
+
30
+ private
31
+ def create_transaction_in_block
32
+ block = Block.where(master_hash: nil).first
33
+ work.perform_async(@receiver_key, @sender_key, @amount, block.id)
34
+ end
35
+
36
+ def work
37
+ TransactionToBlockWorker
38
+ end
39
+ # Use callbacks to share common setup or constraints between actions.
40
+ def set_transaction
41
+ @transaction = Transaction.find(params[:id])
42
+ end
43
+
44
+ # Only allow a list of trusted parameters through.
45
+ def transaction_params
46
+ params.require(:transaction).permit(:sender_key, :receiver_key, :signature_time, :status, :data, :upl_file, :upl_file_name, :upl_file_type, :upl_file_size, :upl_file_hash, :amount, :fee, :block_id)
47
+ end
48
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Users::ConfirmationsController < Devise::ConfirmationsController
4
+ # GET /resource/confirmation/new
5
+ # def new
6
+ # super
7
+ # end
8
+
9
+ # POST /resource/confirmation
10
+ # def create
11
+ # super
12
+ # end
13
+
14
+ # GET /resource/confirmation?confirmation_token=abcdef
15
+ # def show
16
+ # super
17
+ # end
18
+
19
+ # protected
20
+
21
+ # The path used after resending confirmation instructions.
22
+ # def after_resending_confirmation_instructions_path_for(resource_name)
23
+ # super(resource_name)
24
+ # end
25
+
26
+ # The path used after confirmation.
27
+ # def after_confirmation_path_for(resource_name, resource)
28
+ # super(resource_name, resource)
29
+ # end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
4
+ # You should configure your model like this:
5
+ # devise :omniauthable, omniauth_providers: [:twitter]
6
+
7
+ # You should also create an action method in this controller like this:
8
+ # def twitter
9
+ # end
10
+
11
+ # More info at:
12
+ # https://github.com/heartcombo/devise#omniauth
13
+
14
+ # GET|POST /resource/auth/twitter
15
+ # def passthru
16
+ # super
17
+ # end
18
+
19
+ # GET|POST /users/auth/twitter/callback
20
+ # def failure
21
+ # super
22
+ # end
23
+
24
+ # protected
25
+
26
+ # The path used when OmniAuth fails
27
+ # def after_omniauth_failure_path_for(scope)
28
+ # super(scope)
29
+ # end
30
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Users::PasswordsController < Devise::PasswordsController
4
+ # GET /resource/password/new
5
+ # def new
6
+ # super
7
+ # end
8
+
9
+ # POST /resource/password
10
+ # def create
11
+ # super
12
+ # end
13
+
14
+ # GET /resource/password/edit?reset_password_token=abcdef
15
+ # def edit
16
+ # super
17
+ # end
18
+
19
+ # PUT /resource/password
20
+ # def update
21
+ # super
22
+ # end
23
+
24
+ # protected
25
+
26
+ # def after_resetting_password_path_for(resource)
27
+ # super(resource)
28
+ # end
29
+
30
+ # The path used after sending reset password instructions
31
+ # def after_sending_reset_password_instructions_path_for(resource_name)
32
+ # super(resource_name)
33
+ # end
34
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Users::RegistrationsController < Devise::RegistrationsController
4
+ before_action :configure_sign_up_params, only: [:create]
5
+ # before_action :configure_account_update_params, only: [:update]
6
+
7
+ # GET /resource/sign_up
8
+ # def new
9
+ # super
10
+ # end
11
+
12
+ # POST /resource
13
+ def create
14
+ super
15
+ end
16
+
17
+ # GET /resource/edit
18
+ # def edit
19
+ # super
20
+ # end
21
+
22
+ # PUT /resource
23
+ # def update
24
+ # super
25
+ # end
26
+
27
+ # DELETE /resource
28
+ # def destroy
29
+ # super
30
+ # end
31
+
32
+ # GET /resource/cancel
33
+ # Forces the session data which is usually expired after sign
34
+ # in to be expired now. This is useful if the user wants to
35
+ # cancel oauth signing in/up in the middle of the process,
36
+ # removing all OAuth session data.
37
+ # def cancel
38
+ # super
39
+ # end
40
+
41
+ protected
42
+ # If you have extra params to permit, append them to the sanitizer.
43
+ def configure_sign_up_params
44
+ devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
45
+ end
46
+
47
+ # If you have extra params to permit, append them to the sanitizer.
48
+ # def configure_account_update_params
49
+ # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
50
+ # end
51
+
52
+ # The path used after sign up.
53
+ def after_sign_up_path_for(resource)
54
+ root_path
55
+ end
56
+
57
+ # The path used after sign up for inactive accounts.
58
+ # def after_inactive_sign_up_path_for(resource)
59
+ # super(resource)
60
+ # end
61
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Users::SessionsController < Devise::SessionsController
4
+ # before_action :configure_sign_in_params, only: [:create]
5
+
6
+ # GET /resource/sign_in
7
+ # def new
8
+ # super
9
+ # end
10
+
11
+ # POST /resource/sign_in
12
+ # def create
13
+ # super
14
+ # end
15
+
16
+ # DELETE /resource/sign_out
17
+ # def destroy
18
+ # super
19
+ # end
20
+
21
+ # protected
22
+
23
+ # If you have extra params to permit, append them to the sanitizer.
24
+ # def configure_sign_in_params
25
+ # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
26
+ # end
27
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Users::UnlocksController < Devise::UnlocksController
4
+ # GET /resource/unlock/new
5
+ # def new
6
+ # super
7
+ # end
8
+
9
+ # POST /resource/unlock
10
+ # def create
11
+ # super
12
+ # end
13
+
14
+ # GET /resource/unlock?unlock_token=abcdef
15
+ # def show
16
+ # super
17
+ # end
18
+
19
+ # protected
20
+
21
+ # The path used after sending unlock password instructions
22
+ # def after_sending_unlock_instructions_path_for(resource)
23
+ # super(resource)
24
+ # end
25
+
26
+ # The path used after unlocking the resource
27
+ # def after_unlock_path_for(resource)
28
+ # super(resource)
29
+ # end
30
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ class WalletsController < ApplicationController
4
+ before_action :set_wallet, only: %i[ show edit update destroy ]
5
+ before_action :authenticate_user!
6
+
7
+ def index
8
+ @wallets = current_user.wallet
9
+ end
10
+
11
+ def show
12
+ end
13
+
14
+ private
15
+ def set_wallet
16
+ @wallet = Wallet.find(params[:id])
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ApplicationHelper
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlocksHelper
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChainsHelper
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ContractsHelper
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PoolsHelper
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SignaturesHelper
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TicketsHelper
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TransactionsHelper
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WalletsHelper
4
+ end
@@ -0,0 +1,3 @@
1
+ // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
2
+ import "@hotwired/turbo-rails"
3
+ import "controllers"
@@ -0,0 +1,9 @@
1
+ import { Application } from "@hotwired/stimulus"
2
+
3
+ const application = Application.start()
4
+
5
+ // Configure Stimulus development experience
6
+ application.debug = false
7
+ window.Stimulus = application
8
+
9
+ export { application }
@@ -0,0 +1,7 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ connect() {
5
+ this.element.textContent = "Hello World!"
6
+ }
7
+ }
@@ -0,0 +1,11 @@
1
+ // Import and register all your controllers from the importmap under controllers/*
2
+
3
+ import { application } from "controllers/application"
4
+
5
+ // Eager load all controllers defined in the import map under controllers/**/*_controller
6
+ import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
7
+ eagerLoadControllersFrom("controllers", application)
8
+
9
+ // Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
10
+ // import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
11
+ // lazyLoadControllersFrom("controllers", application)
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationJob < ActiveJob::Base
4
+ # Automatically retry jobs that encountered a deadlock
5
+ # retry_on ActiveRecord::Deadlocked
6
+
7
+ # Most jobs are safe to ignore if the underlying records are no longer available
8
+ # discard_on ActiveJob::DeserializationError
9
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: "from@example.com"
5
+ layout "mailer"
6
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AcceptableNumberSequence < ApplicationRecord
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AcceptableSymbolSequence < ApplicationRecord
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AcceptableWord < ApplicationRecord
4
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ primary_abstract_class
5
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Block < ApplicationRecord
4
+ belongs_to :chain
5
+ validates :nonce, presence: true
6
+ validates :previous_hash, presence: true
7
+ validates :block_data, presence: true
8
+ validates :connections, presence: true
9
+ has_many :transactions, dependent: :destroy, counter_cache: true
10
+ after_create :create_pool
11
+ has_one :pool, dependent: :destroy, inverse_of: :block
12
+
13
+ private
14
+ def create_pool
15
+ Pool.create(block_id: self.id)
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Chain < ApplicationRecord
4
+ validates :name, presence: true, uniqueness: true, length: { maximum: 20 }
5
+ validates :maintainer, presence: true, length: { maximum: 50 }
6
+ validates :chain_version, presence: true, length: { maximum: 20 }
7
+ validates :description, presence: true, length: { maximum: 1000 }
8
+
9
+ has_many :blocks, dependent: :destroy
10
+ end
File without changes
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SequencesValidator < ActiveModel::Validator
4
+ def validate(record)
5
+ @record = record
6
+ @word = record.common_word
7
+ @symbol_seq = record.symbol_sequence
8
+ @number_seq = record.number_sequence
9
+ record.errors.add(:base, "Invalid Hashable Content") unless valid_checker
10
+ end
11
+
12
+ private
13
+ attr_reader :record, :word, :symbol_seq, :number_seq
14
+
15
+ def valid_checker
16
+ acceptable_word? && acceptable_symbol_sequence? && acceptable_number_sequence?
17
+ end
18
+
19
+ def acceptable_word?
20
+ AcceptableWord.find_by(word: word).present?
21
+ end
22
+
23
+ def acceptable_symbol_sequence?
24
+ AcceptableSymbolSequence.find_by(seq: symbol_seq).present?
25
+ end
26
+
27
+ def acceptable_number_sequence?
28
+ AcceptableNumberSequence.find_by(seq: number_seq).present?
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class WalletExistsValidator < ActiveModel::Validator
4
+ def validate(record)
5
+ if Wallet.find_by(pr_key: record.receiver_key).nil?
6
+ record.errors[:sender_key] << "Sender key is not valid"
7
+ end
8
+
9
+ if Wallet.find_by(pv_key: record.sender_key).nil?
10
+ record.errors[:receiver_key] << "Receiver key is not valid"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Contract < ApplicationRecord
4
+ validates :blk_transaction, presence: true
5
+ belongs_to :blk_transaction, class_name: "Transaction", foreign_key: "transaction_id", inverse_of: :contract
6
+ has_many :signatures, inverse_of: :contract, dependent: :destroy
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pool < ApplicationRecord
4
+ belongs_to :block
5
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Signature < ApplicationRecord
4
+ belongs_to :contract
5
+ belongs_to :ticket
6
+ belongs_to :user
7
+ validates :signature, presence: true, length: { is: 64 }, uniqueness: true
8
+ # validates :common_word, presence: true
9
+ # validates :symbol_sequence, presence: true
10
+ # validates :number_sequence, presence: true
11
+ # validates_with SequencesValidator
12
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Ticket < ApplicationRecord
4
+ belongs_to :user
5
+ belongs_to :pool
6
+ validates :time_ref, presence: true
7
+ validates :status, presence: true
8
+ has_many :signatures
9
+
10
+ enum status: { active: 0, inactive: 1 }
11
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Transaction < ApplicationRecord
4
+ include ActiveModel::Validations
5
+ validates :sender_key, presence: true
6
+ validates :receiver_key, presence: true
7
+ validates :fee, presence: true, numericality: { greater_than: 0 }
8
+ validates :amount, presence: true, numericality: { greater_than: 0 }
9
+ validates_with WalletExistsValidator
10
+ belongs_to :block
11
+ has_one :contract, dependent: :destroy, inverse_of: :blk_transaction
12
+ after_create :create_contract
13
+
14
+ def sender
15
+ Wallet.find_by(pv_key: sender_key).user.username
16
+ end
17
+
18
+ def receiver
19
+ Wallet.find_by(pr_key: receiver_key).user.username
20
+ end
21
+
22
+ def create_contract
23
+ Contract.create(blk_transaction: self)
24
+ end
25
+ end