Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusGautamah committed Feb 13, 2023
2 parents 14510b7 + dc8f0af commit 3555eab
Show file tree
Hide file tree
Showing 22 changed files with 136 additions and 459 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@
/coverage/*
osbc-*.gem
.env
.env_production
/.env_production
/.env_production.*
/.env
/.env.*
/mining_concept.ipynb
/mining_concept.ipynb_checkpoints
/hyperminer.py
/hyperminer.py
/.ipynb_checkpoints
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ group :test do
gem "selenium-webdriver", "~> 4.5"
gem "webdrivers", "~> 5.2"
end

# local gem, is outside this project root folder, and calls lucy_dockerunner
gem "lucy_dockerunner", "~> 0.1.4"
34 changes: 18 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
GIT
remote: https://github.com/heartcombo/devise.git
revision: 3632ddf67473880ed9583201ce13f108c620514f
revision: 8e2e3f6fda1ceabe2eff08cf34a6e663527c438b
specs:
devise (4.8.1)
devise (4.9.0.alpha)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
Expand Down Expand Up @@ -129,7 +129,8 @@ GEM
loofah (2.19.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.8.0.1)
lucy_dockerunner (0.1.4)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
Expand All @@ -150,11 +151,11 @@ GEM
net-smtp (0.3.3)
net-protocol
nio4r (2.5.8)
nokogiri (1.14.1-x86_64-linux)
nokogiri (1.14.2-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.22.1)
parser (3.2.0.0)
parser (3.2.1.0)
ast (~> 2.4.1)
pg (1.4.5)
public_suffix (5.0.1)
Expand Down Expand Up @@ -198,13 +199,13 @@ GEM
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.0.6)
redis (4.8.0)
regexp_parser (2.6.2)
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
redis (4.8.1)
regexp_parser (2.7.0)
responders (3.1.0)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.5)
rspec-core (3.12.0)
rspec-core (3.12.1)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.2)
diff-lcs (>= 1.2.0, < 2.0)
Expand All @@ -221,7 +222,7 @@ GEM
rspec-mocks (~> 3.11)
rspec-support (~> 3.11)
rspec-support (3.12.0)
rubocop (1.44.1)
rubocop (1.45.1)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
Expand All @@ -231,8 +232,8 @@ GEM
rubocop-ast (>= 1.24.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.24.1)
parser (>= 3.1.1.0)
rubocop-ast (1.26.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.17.0)
rubocop (~> 1.41)
rubocop-rails (2.17.4)
Expand Down Expand Up @@ -276,7 +277,7 @@ GEM
sprockets (>= 3.0.0)
stimulus-rails (1.2.1)
railties (>= 6.0.0)
tailwindcss-rails (2.0.21-x86_64-linux)
tailwindcss-rails (2.0.22-x86_64-linux)
railties (>= 6.0.0)
temple (0.8.2)
thor (1.2.1)
Expand Down Expand Up @@ -306,7 +307,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.6)
zeitwerk (2.6.7)

PLATFORMS
x86_64-linux
Expand All @@ -322,6 +323,7 @@ DEPENDENCIES
faker (~> 2.23)
importmap-rails (~> 1.1)
jbuilder (~> 2.11)
lucy_dockerunner (~> 0.1.4)
pg (~> 1.4)
puma (~> 5.6)
rack-cors
Expand Down
1 change: 0 additions & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
web: bin/rails server
release: bin/rails db:migrate
release: bin/rails assets:precompile
sidekiq: bundle exec sidekiq -C config/sidekiq.yml
37 changes: 9 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ Remember always to verify your enviroment variables and do security modification

### This application is unstable and under development.
### Please, use it with caution and at your own risk.
### Demo version:
### Demo version: (temporary down)
https://osbc.outerspacecoding.com

### Demo staging version:
https://blockchain-staging.outerspacecoding.com

#### Developed using TDD (Test Driven Development).
#### Github Actions CI/CD pipeline.
#### Firestore will be used to store the blockchain data.
Expand Down Expand Up @@ -135,42 +132,34 @@ The application has a .env file in root folder with the following environment va
CONTRACTS_LIMIT=100
SIGNATURES_LIMIT=5
## Configuration
### Rake tasks
### Lucy Dockerunner gem

This application has rake tasks to help you with the development process with docker.
The tasks are:
This application has rake tasks to help you with the development process with docker imported from the [Lucy Dockerunner](https://rubygems.org/gems/lucy_dockerunner) gem.
Example of the rake tasks:
#### Docker actions
* `rake compose:install` - build docker compose and migrate the database
* `rake compose:build` - build docker compose services
* `rake compose:up` - start the docker compose services
* `rake compose:down` - stop the docker compose services
* `rake compose:db_detach` - detach the database from the docker compose services
* `rake compose:redis_detach` - detach the redis from the docker compose services
* `rake compose:back_detach` - detach the backend(redis, sidekiq, db) from the docker compose services
* `rake compose:restart` - restart the docker compose services
* `rake compose:clean_all` - clean all docker compose services
* `rake compose:clean_volumes` - clean docker compose volumes
... more commands in the [Github: Lucy Dockerunner](https://gitub.com/JesusGautamah/lucy_dockerunner) gem
#### Database actions
* `rake compose_db:migrate` - migrate the database
* `rake compose_db:reset` - reset the database
* `rake compose_db:drop` - drop the database
* `rake compose_db:create` - create the database
* `rake compose_db:seed` - seed the database
* `rake compose_db:rollback` - rollback the database
* `rake compose_db:setup` - setup the database
* `rake compose_db:complete_setup` - complete setup the database
* `rake compose_db:reset_setup` - drop and setup the database
* `rake compose_db:reset` - reset the database
... more commands in the [Github: Lucy Dockerunner](https://gitub.com/JesusGautamah/lucy_dockerunner) gem

### Tests actions
* `rake compose_test:all` - run all tests
* `rake compose_test:clean_all` - run all tests after cleaning docker compose services
* `rake compose_test:controllers` - run controllers tests
* `rake compose_test:models` - run models tests
* `rake compose_test:requests` - run requests tests
* `rake compose_test:helpers` - run helpers tests
* `rake compose_test:mailers` - run mailers tests
* `rake compose_test:routing` - run routing tests
* `rake compose_test:views` - run views tests
... more commands in the [Github: Lucy Dockerunner](https://gitub.com/JesusGautamah/lucy_dockerunner) gem

### LOGS actions
* `rake compose_logs:web` - show web logs
Expand All @@ -180,15 +169,7 @@ The tasks are:
* `rake compose_logs:all` - show all logs
* `rake compose_logs:tail_web` - tail web logs
* `rake compose_logs:tail_db` - tail db logs
* `rake compose_logs:tail_redis` - tail redis logs
* `rake compose_logs:tail_sidekiq` - tail sidekiq logs
* `rake compose_logs:tail_all` - tail all logs
* `rake compose_logs:follow_web` - follow web logs
* `rake compose_logs:follow_db` - follow db logs
* `rake compose_logs:follow_redis` - follow redis logs
* `rake compose_logs:follow_sidekiq` - follow sidekiq logs
* `rake compose_logs:follow_all` - follow all logs

... more commands in the [Github: Lucy Dockerunner](https://gitub.com/JesusGautamah/lucy_dockerunner) gem
## Start the blockchain
````bash
$ rake compose:up
Expand Down
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ Bundler::GemHelper.install_tasks name: "outerspace-blockchain"
require_relative "config/application"

Rails.application.load_tasks


# Import tasks from lucy_dockerunner local gem, registered in gemfile with path

require "lucy_dockerunner"

LucyDockerunner.load_tasks
17 changes: 17 additions & 0 deletions app/controllers/api/v1/ticket_manager_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ def open_ticket
ticket_opened_response
end

def transactions_to_mine
return unauthorized_response unless find_user_by_header
ticket = Ticket.find_by(user_id: @user.id)
return ticket_not_found_response unless ticket.present?
transactions_ids = ticket.transaction_id_list
transactions = Transaction.where(id: transactions_ids)
transactions_json = transactions.to_json
render json: transactions_json, status: :ok
end

def retrieve_ticket_keys
return unauthorized_response unless find_user_by_header
ticket = Ticket.find_by(user_id: @user.id)
ticket_key_one = ticket.first_five
ticket_key_two = ticket.last_five
render json: { ticket_key_one: ticket_key_one, ticket_key_two: ticket_key_two }, status: :ok
end

private
def ticket_nil?
Expand Down
2 changes: 2 additions & 0 deletions app/models/ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
class Ticket < ApplicationRecord
belongs_to :user
belongs_to :pool
validates :first_five, presence: true
validates :last_five, presence: true
validates :time_ref, presence: true
validates :status, presence: true
has_many :signatures
Expand Down
3 changes: 2 additions & 1 deletion app/services/create_ticket_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def update_block_connections
def ticket_created?
hash, block_hash, master_hash = generate_user_acceptable_hash
@ticket = Ticket.new(user_id: user_id, status: :active, pool_id: pool_id,
time_ref: time_ref, user_acceptable_hash: hash,
time_ref: time_ref, user_acceptable_hash: nil,
first_five: hash[0..4], last_five: hash[-5..-1],
confirmation_hash: master_hash, block_hash: block_hash,
transaction_id_list: generate_transaction_id_list)
@ticket.save ? true : false
Expand Down
6 changes: 5 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
require "active_support/core_ext/integer/time"

Rails.application.configure do
config.hosts << ENV["HOST"]
config.hosts << "localhost"
config.hosts << "outersapce-blockchain.eastus.cloudapp.azure.com"
config.hosts << "20.172.245.50"
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
Expand Down Expand Up @@ -33,7 +37,7 @@
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
config.assets.compile = true

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.asset_host = "http://assets.example.com"
Expand Down
2 changes: 2 additions & 0 deletions config/routes/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
post "confirm_block", to: "block_confirmations#confirm_block"
post "open_ticket", to: "ticket_manager#open_ticket"
get "info_to_mine", to: "block_confirmations#info_to_mine"
get "tr_to_mine", to: "ticket_manager#transactions_to_mine"
get "ticket_keys", to: "ticket_manager#retrieve_ticket_keys"
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class AddUserAcceptableHashToTickets < ActiveRecord::Migration[7.0]
def change
add_column :tickets, :user_acceptable_hash, :string
add_column :tickets, :confirmation_hash, :string
add_column :tickets, :block_hash, :string
add_column :tickets, :confirmation_hash, :string, null: false
add_column :tickets, :block_hash, :string, null: false
end
end
6 changes: 6 additions & 0 deletions db/migrate/20230203141405_add_first_and_last_to_tickets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddFirstAndLastToTickets < ActiveRecord::Migration[7.0]
def change
add_column :tickets, :first_five, :string, null: false
add_column :tickets, :last_five, :string, null: false
end
end
8 changes: 5 additions & 3 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
version: "3.3"
services:
redis:
image: redis:6.0.9-alpine
restart: always
ports:
- 6379:6379
volumes:
- ./data:/data
command: redis-server
db:
image: postgres
ports:
- "5432:5432"
volumes:
- ./tmp/db:/var/lib/postgresql/data
env_file:
- .env
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && foreman start"
volumes:
- .:/myapp
ports:
- "80:80"
depends_on:
- redis
- db
- sidekiq
env_file:
- .env
tty: true
sidekiq:
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
volumes:
- .:/myapp
depends_on:
- redis
- db
env_file:
- .env
# chrome:
# image: selenium/standalone-chrome
# ports:
# - "4444:4444"
# depends_on:
# - sidekiq
# volumes:
# - /dev/shm:/dev/shm
volumes:
redis:
postgres:
Empty file removed lib/tasks/.keep
Empty file.
Loading

0 comments on commit 3555eab

Please sign in to comment.