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,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DeviseCreateUsers < ActiveRecord::Migration[7.0]
4
+ def change
5
+ create_table :users do |t|
6
+ ## Database authenticatable
7
+ t.string :username, null: false, index: { unique: true }, limit: 10
8
+ t.string :email, null: false, default: ""
9
+ t.string :encrypted_password, null: false, default: ""
10
+
11
+ ## Recoverable
12
+ t.string :reset_password_token
13
+ t.datetime :reset_password_sent_at
14
+
15
+ ## Rememberable
16
+ t.datetime :remember_created_at
17
+
18
+ ## Trackable
19
+ t.integer :sign_in_count, default: 0, null: false
20
+ t.datetime :current_sign_in_at
21
+ t.datetime :last_sign_in_at
22
+ t.string :current_sign_in_ip
23
+ t.string :last_sign_in_ip
24
+
25
+ ## Confirmable
26
+ t.string :confirmation_token
27
+ t.datetime :confirmed_at
28
+ t.datetime :confirmation_sent_at
29
+ # t.string :unconfirmed_email
30
+
31
+ ## Lockable
32
+ t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
33
+ t.string :unlock_token # Only if unlock strategy is :email or :both
34
+ t.datetime :locked_at
35
+
36
+
37
+ t.timestamps null: false
38
+ end
39
+
40
+ add_index :users, :email, unique: true
41
+ add_index :users, :reset_password_token, unique: true
42
+ add_index :users, :confirmation_token, unique: true
43
+ add_index :users, :unlock_token, unique: true
44
+ end
45
+ end
@@ -0,0 +1,13 @@
1
+ class CreateChains < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :chains do |t|
4
+ t.string :name, null: false, index: { unique: true }
5
+ t.integer :blocks_count, null: false, default: 0
6
+ t.string :maintainer, null: false
7
+ t.string :chain_version, null: false
8
+ t.text :description, null: false
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ class CreateBlocks < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :blocks do |t|
4
+ t.integer :nonce, default: 0, null: false
5
+ t.string :previous_hash
6
+ t.text :block_data
7
+ t.integer :connections, null: false, default: 0
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ class AddChainToBlocks < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_reference :blocks, :chain, null: false, foreign_key: true
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ class CreateWallets < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :wallets do |t|
4
+ t.references :user, null: false, foreign_key: true
5
+ t.string :pr_key, null: false
6
+ t.string :pv_key, null: false
7
+ t.decimal :balance, null: false, default: 0.0, precision: 16, scale: 2
8
+ t.integer :status, null: false, default: 0
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ class CreateTransactions < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :transactions do |t|
4
+ t.string :sender_key, null: false
5
+ t.string :receiver_key, null: false
6
+ t.time :signature_time
7
+ t.integer :status, null: false, default: 0
8
+ t.text :data
9
+ t.string :upl_file
10
+ t.string :upl_file_name
11
+ t.string :upl_file_type
12
+ t.string :upl_file_size
13
+ t.string :upl_file_hash
14
+ t.decimal :amount, null: false, default: 0.0, precision: 16, scale: 2
15
+ t.float :fee, null: false, default: 0.0, precision: 16, scale: 2
16
+
17
+ t.timestamps
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ class AddBlockToTransactions < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_reference :transactions, :block, null: false, foreign_key: true
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class CreateContracts < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :contracts do |t|
4
+ t.integer :signatures_count, default: 0, null: false
5
+ t.integer :status, default: 0, null: false
6
+ t.integer :transaction_id, null: false
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePools < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :pools do |t|
4
+ t.references :block, null: false, foreign_key: true
5
+ t.integer :users_count, default: 0, null: false
6
+ t.integer :signatures_count, default: 0, null: false
7
+ t.decimal :amount, null: false, default: 0.0, precision: 16, scale: 2
8
+ t.integer :stage, default: 0, null: false
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ class CreateTickets < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :tickets do |t|
4
+ t.references :user, null: false, foreign_key: true
5
+ t.references :pool, null: false, foreign_key: true
6
+ t.integer :status
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ class AddContractsCountToBlock < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :blocks, :contracts_count, :integer, default: 0, null: false
4
+ add_column :blocks, :contracts_limit, :integer, default: 0, null: false
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ class AddAcceptableWordListToUsers < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :users, :acceptable_words, :text, array: true, default: [], null: false
4
+ add_column :users, :acceptable_number_sequences, :text, array: true, default: [], null: false
5
+ add_column :users, :acceptable_symbol_sequences, :text, array: true, default: [], null: false
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ class CreateSignatures < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :signatures do |t|
4
+ t.string :signature, null: false
5
+ # t.datetime :time_ref, null: false
6
+ t.references :contract, null: false, foreign_key: true
7
+ t.references :ticket, null: false, foreign_key: true
8
+ t.references :user, null: false, foreign_key: true
9
+ # t.string :common_word, null: false
10
+ # t.string :symbol_sequence, null: false
11
+ # t.string :number_sequence, null: false
12
+ # t.string :verify_sig, null: false
13
+ # t.string :block_hash, null: false
14
+ # t.string :signature_hash, null: false
15
+
16
+ t.timestamps
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ class CreateAcceptableWords < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :acceptable_words do |t|
4
+ t.string :word, unique: true, null: false
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateAcceptableNumberSequences < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :acceptable_number_sequences do |t|
4
+ t.string :seq, unique: true, null: false
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateAcceptableSymbolSequences < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :acceptable_symbol_sequences do |t|
4
+ t.string :seq, unique: true, null: false
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ class AddUserAcceptableHashToTickets < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :tickets, :user_acceptable_hash, :string
4
+ add_column :tickets, :confirmation_hash, :string
5
+ add_column :tickets, :block_hash, :string
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class AddTimeRefToTickets < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :tickets, :time_ref, :datetime
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddMasterHashToBlocks < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :blocks, :master_hash, :string, length: 64
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddTransactionsCountToBlocks < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :blocks, :transactions_count, :integer, default: 0, null: false
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddBalanceToChains < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :chains, :balance, :decimal, null: false, default: 0.0, precision: 16, scale: 2
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddTransactionIdListToTickets < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :tickets, :transaction_id_list, :text, array: true, default: []
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddApiKeysToUsers < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :users, :api_key, :string
4
+ add_column :users, :api_secret, :string
5
+ end
6
+ end
data/db/schema.rb ADDED
@@ -0,0 +1,179 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema[7.0].define(version: 2022_11_18_080357) do
14
+ # These are extensions that must be enabled in order to support this database
15
+ enable_extension "plpgsql"
16
+
17
+ create_table "acceptable_number_sequences", force: :cascade do |t|
18
+ t.string "seq", null: false
19
+ t.datetime "created_at", null: false
20
+ t.datetime "updated_at", null: false
21
+ end
22
+
23
+ create_table "acceptable_symbol_sequences", force: :cascade do |t|
24
+ t.string "seq", null: false
25
+ t.datetime "created_at", null: false
26
+ t.datetime "updated_at", null: false
27
+ end
28
+
29
+ create_table "acceptable_words", force: :cascade do |t|
30
+ t.string "word", null: false
31
+ t.datetime "created_at", null: false
32
+ t.datetime "updated_at", null: false
33
+ end
34
+
35
+ create_table "blocks", force: :cascade do |t|
36
+ t.integer "nonce", default: 0, null: false
37
+ t.string "previous_hash"
38
+ t.text "block_data"
39
+ t.integer "connections", default: 0, null: false
40
+ t.datetime "created_at", null: false
41
+ t.datetime "updated_at", null: false
42
+ t.bigint "chain_id", null: false
43
+ t.integer "contracts_count", default: 0, null: false
44
+ t.integer "contracts_limit", default: 0, null: false
45
+ t.string "master_hash"
46
+ t.integer "transactions_count", default: 0, null: false
47
+ t.index ["chain_id"], name: "index_blocks_on_chain_id"
48
+ end
49
+
50
+ create_table "chains", force: :cascade do |t|
51
+ t.string "name", null: false
52
+ t.integer "blocks_count", default: 0, null: false
53
+ t.string "maintainer", null: false
54
+ t.string "chain_version", null: false
55
+ t.text "description", null: false
56
+ t.datetime "created_at", null: false
57
+ t.datetime "updated_at", null: false
58
+ t.decimal "balance", precision: 16, scale: 2, default: "0.0", null: false
59
+ t.index ["name"], name: "index_chains_on_name", unique: true
60
+ end
61
+
62
+ create_table "contracts", force: :cascade do |t|
63
+ t.integer "signatures_count", default: 0, null: false
64
+ t.integer "status", default: 0, null: false
65
+ t.integer "transaction_id", null: false
66
+ t.datetime "created_at", null: false
67
+ t.datetime "updated_at", null: false
68
+ end
69
+
70
+ create_table "pools", force: :cascade do |t|
71
+ t.bigint "block_id", null: false
72
+ t.integer "users_count", default: 0, null: false
73
+ t.integer "signatures_count", default: 0, null: false
74
+ t.decimal "amount", precision: 16, scale: 2, default: "0.0", null: false
75
+ t.integer "stage", default: 0, null: false
76
+ t.datetime "created_at", null: false
77
+ t.datetime "updated_at", null: false
78
+ t.index ["block_id"], name: "index_pools_on_block_id"
79
+ end
80
+
81
+ create_table "signatures", force: :cascade do |t|
82
+ t.string "signature", null: false
83
+ t.bigint "contract_id", null: false
84
+ t.bigint "ticket_id", null: false
85
+ t.bigint "user_id", null: false
86
+ t.datetime "created_at", null: false
87
+ t.datetime "updated_at", null: false
88
+ t.index ["contract_id"], name: "index_signatures_on_contract_id"
89
+ t.index ["ticket_id"], name: "index_signatures_on_ticket_id"
90
+ t.index ["user_id"], name: "index_signatures_on_user_id"
91
+ end
92
+
93
+ create_table "tickets", force: :cascade do |t|
94
+ t.bigint "user_id", null: false
95
+ t.bigint "pool_id", null: false
96
+ t.integer "status"
97
+ t.datetime "created_at", null: false
98
+ t.datetime "updated_at", null: false
99
+ t.string "user_acceptable_hash"
100
+ t.string "confirmation_hash"
101
+ t.string "block_hash"
102
+ t.datetime "time_ref"
103
+ t.text "transaction_id_list", default: [], array: true
104
+ t.index ["pool_id"], name: "index_tickets_on_pool_id"
105
+ t.index ["user_id"], name: "index_tickets_on_user_id"
106
+ end
107
+
108
+ create_table "transactions", force: :cascade do |t|
109
+ t.string "sender_key", null: false
110
+ t.string "receiver_key", null: false
111
+ t.time "signature_time"
112
+ t.integer "status", default: 0, null: false
113
+ t.text "data"
114
+ t.string "upl_file"
115
+ t.string "upl_file_name"
116
+ t.string "upl_file_type"
117
+ t.string "upl_file_size"
118
+ t.string "upl_file_hash"
119
+ t.decimal "amount", precision: 16, scale: 2, default: "0.0", null: false
120
+ t.float "fee", default: 0.0, null: false
121
+ t.datetime "created_at", null: false
122
+ t.datetime "updated_at", null: false
123
+ t.bigint "block_id", null: false
124
+ t.index ["block_id"], name: "index_transactions_on_block_id"
125
+ end
126
+
127
+ create_table "users", force: :cascade do |t|
128
+ t.string "username", limit: 10, null: false
129
+ t.string "email", default: "", null: false
130
+ t.string "encrypted_password", default: "", null: false
131
+ t.string "reset_password_token"
132
+ t.datetime "reset_password_sent_at"
133
+ t.datetime "remember_created_at"
134
+ t.integer "sign_in_count", default: 0, null: false
135
+ t.datetime "current_sign_in_at"
136
+ t.datetime "last_sign_in_at"
137
+ t.string "current_sign_in_ip"
138
+ t.string "last_sign_in_ip"
139
+ t.string "confirmation_token"
140
+ t.datetime "confirmed_at"
141
+ t.datetime "confirmation_sent_at"
142
+ t.integer "failed_attempts", default: 0, null: false
143
+ t.string "unlock_token"
144
+ t.datetime "locked_at"
145
+ t.datetime "created_at", null: false
146
+ t.datetime "updated_at", null: false
147
+ t.text "acceptable_words", default: [], null: false, array: true
148
+ t.text "acceptable_number_sequences", default: [], null: false, array: true
149
+ t.text "acceptable_symbol_sequences", default: [], null: false, array: true
150
+ t.string "api_key"
151
+ t.string "api_secret"
152
+ t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
153
+ t.index ["email"], name: "index_users_on_email", unique: true
154
+ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
155
+ t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
156
+ t.index ["username"], name: "index_users_on_username", unique: true
157
+ end
158
+
159
+ create_table "wallets", force: :cascade do |t|
160
+ t.bigint "user_id", null: false
161
+ t.string "pr_key", null: false
162
+ t.string "pv_key", null: false
163
+ t.decimal "balance", precision: 16, scale: 2, default: "0.0", null: false
164
+ t.integer "status", default: 0, null: false
165
+ t.datetime "created_at", null: false
166
+ t.datetime "updated_at", null: false
167
+ t.index ["user_id"], name: "index_wallets_on_user_id"
168
+ end
169
+
170
+ add_foreign_key "blocks", "chains"
171
+ add_foreign_key "pools", "blocks"
172
+ add_foreign_key "signatures", "contracts"
173
+ add_foreign_key "signatures", "tickets"
174
+ add_foreign_key "signatures", "users"
175
+ add_foreign_key "tickets", "pools"
176
+ add_foreign_key "tickets", "users"
177
+ add_foreign_key "transactions", "blocks"
178
+ add_foreign_key "wallets", "users"
179
+ end
data/db/seeds.rb ADDED
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ def seed_exec
4
+ create_first_chain
5
+ create_acceptable_word_lists
6
+ create_first_block
7
+ end
8
+
9
+ def dev_seed_exec
10
+ puts "Seeding development database"
11
+ puts "Creating first chain"
12
+ create_first_chain
13
+ puts "Creating acceptable word lists"
14
+ create_acceptable_word_lists
15
+ puts "Creating first block"
16
+ create_first_block
17
+ puts "Creating test users"
18
+ create_test_users
19
+ end
20
+
21
+ def create_first_chain
22
+ Chain.create(
23
+ name: ENV["FIRST_CHAIN_NAME"],
24
+ maintainer: ENV["FIRST_CHAIN_MAINTAINER"],
25
+ chain_version: "0.0.1",
26
+ description: "This is a blockchain project generated with outerspace-blockchain."
27
+ )
28
+
29
+ puts "Chain created"
30
+ puts "Chain name: #{ENV["FIRST_CHAIN_NAME"]}"
31
+ puts "Chain maintainer: #{ENV["FIRST_CHAIN_MAINTAINER"]}"
32
+ end
33
+
34
+ def create_acceptable_word_lists
35
+ create_acceptable_words
36
+ create_acceptable_symbol_sequences
37
+ create_acceptable_number_sequences
38
+ end
39
+
40
+ def create_acceptable_words
41
+ word_list = %w[the of and to a in
42
+ is you that it he
43
+ was for on are as
44
+ with his they I at
45
+ be this have from or
46
+ one had by word but
47
+ not what all were we
48
+ when your can said there
49
+ use an each which she do
50
+ how their if will up other
51
+ about out many then them
52
+ these so some her would
53
+ make like him into time
54
+ as look two more write
55
+ go see number no way could
56
+ people my than first water
57
+ been call who oil its now
58
+ find long down day did get
59
+ come made may part]
60
+ words = []
61
+ word_list.each do |word|
62
+ words << AcceptableWord.new(word: word) # rubocop:disable Lint/UselessAssignment
63
+ end
64
+
65
+ AcceptableWord.import words
66
+ end
67
+
68
+ def create_acceptable_symbol_sequences
69
+ symbol_sequence_list = %w[!!! !@# !@#$ !@#$% !@#$%^ !@#$%^& !@#$%^&* !@#$%^&*(
70
+ !@#$%^&*( )@#$%^&*( )@#$%^&*() @#$%^&*() @#$%^&*()_
71
+ @#$%^&*()_ @#$%^&*()_+ #$%^&*()_+ #$%^&*()_+{
72
+ #$%^&*()_+{ #$%^&*()_+{ }%^&*()_+{ }%^&*()_+{
73
+ @#¨$@¨$$¨@(#$ @#¨$@¨$$¨@(#$ @#¨$@¨$$¨ @(#$¨@#¨$@¨$$¨@(#$)
74
+ $#$¨@*#$¨$(@#) $@$(*#&$) $@#$&)@#$() @&(*@#&$$]
75
+ symbols = []
76
+ symbol_sequence_list.each do |symbol_sequence|
77
+ symbols << AcceptableSymbolSequence.new(seq: symbol_sequence) # rubocop:disable Lint/UselessAssignment
78
+ end
79
+
80
+ AcceptableSymbolSequence.import symbols
81
+ end
82
+
83
+ def create_acceptable_number_sequences
84
+ number_sequence_list = (0..9999).map { |n| format("%04d", n) }
85
+
86
+ numbers = []
87
+ number_sequence_list.each do |number_sequence|
88
+ numbers << AcceptableNumberSequence.new(seq: number_sequence) # rubocop:disable Lint/UselessAssignment
89
+ end
90
+
91
+ AcceptableNumberSequence.import numbers
92
+ end
93
+
94
+
95
+ def create_first_block
96
+ Block.create(
97
+ chain: Chain.first,
98
+ previous_hash: "0000000000000000000000000000000000000000000000000000000000000000",
99
+ block_data: "This is the first block of the blockchain.",
100
+ nonce: 0,
101
+ connections: 0,
102
+ contracts_count: 0,
103
+ contracts_limit: ENV["CONTRACTS_LIMIT"].to_i,
104
+ # timestamp: Time.now
105
+ )
106
+
107
+ puts "First block created"
108
+ end
109
+
110
+ def create_test_users
111
+ if User.find_by(email: "lorem@ipsum.com", username: "lorem")
112
+ puts "Test user already exists"
113
+ else
114
+ User.create(
115
+ email: "lorem@ipsum.com", username: "lorem", password: "password", password_confirmation: "password"
116
+ )
117
+ puts "Test user created"
118
+ end
119
+
120
+ if User.find_by(email: "lorem_sec@ipsum.com", username: "lorem_sec")
121
+ puts "Test user already exists"
122
+ else
123
+ User.create(
124
+ email: "lorem_sec@ipsum.com", username: "lorem_sec", password: "password", password_confirmation: "password"
125
+ )
126
+ puts "Test user created"
127
+ end
128
+ end
129
+
130
+ if Rails.env.development?
131
+ dev_seed_exec
132
+ else
133
+ seed_exec
134
+ end
@@ -0,0 +1,53 @@
1
+ version: "3.3"
2
+ services:
3
+ redis:
4
+ image: redis:6.0.9-alpine
5
+ restart: always
6
+ ports:
7
+ - 6379:6379
8
+ volumes:
9
+ - ./data:/data
10
+ command: redis-server
11
+ db:
12
+ image: postgres
13
+ ports:
14
+ - "5432:5432"
15
+ volumes:
16
+ - ./tmp/db:/var/lib/postgresql/data
17
+ environment:
18
+ POSTGRES_PASSWORD: secret
19
+ web:
20
+ build: .
21
+ command: bash -c "rm -f tmp/pids/server.pid && foreman start -f Procfile.dev"
22
+ volumes:
23
+ - .:/myapp
24
+ ports:
25
+ - "80:80"
26
+ depends_on:
27
+ - redis
28
+ - db
29
+ - sidekiq
30
+ - chrome
31
+ env_file:
32
+ - .env
33
+ sidekiq:
34
+ build: .
35
+ command: bundle exec sidekiq -C config/sidekiq.yml
36
+ volumes:
37
+ - .:/myapp
38
+ depends_on:
39
+ - redis
40
+ - db
41
+ env_file:
42
+ - .env
43
+ chrome:
44
+ image: selenium/standalone-chrome
45
+ ports:
46
+ - "4444:4444"
47
+ depends_on:
48
+ - sidekiq
49
+ volumes:
50
+ - /dev/shm:/dev/shm
51
+ volumes:
52
+ redis:
53
+ postgres:
data/entrypoint.sh ADDED
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ # Remove a potentially pre-existing server.pid for Rails.
5
+ rm -f /myapp/tmp/pids/server.pid
6
+
7
+ # Then exec the container's main process (what's set as CMD in the Dockerfile).
8
+ exec "$@"
data/lib/assets/.keep ADDED
File without changes
data/lib/osbc/osbc.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Osbc
4
+ VERSION = "0.1.5"
5
+ class Osbc
6
+ end
7
+
8
+ class Error < StandardError; end
9
+ end