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

Commit

Permalink
Merge commit 'c3ba4a85c1bb9f620b7d6cd344d6d8477e567608' into tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusGautamah committed Nov 25, 2022
2 parents 244b38b + c3ba4a8 commit b9974a4
Show file tree
Hide file tree
Showing 12 changed files with 1,693 additions and 440 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## [Unreleased]

## [0.1.0] - 2022-10-18

- Initial release
## [0.1.5]
### Added
- Initial Version
## [0.1.6]
### Added
- Docker Compose Installation Recognition
- Refactored some tests
- Added lib tasks helper to created rake tasks for blockchain
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#### Rspec is used to test the blockchain.


## Build Version: 0.1.6
### Last Update:
#### Added Docker Compose Installation Recognition and Refactored some tests
Expand All @@ -26,10 +25,7 @@
###### Add more documentation
###### Add NFT Generator
###### Increase the environment variables for autoconfig
###### Add features of autogeneration of blockchain for better configuration



###### Add features to autogeneration of blockchain for better configuration

## System dependencies
1. Docker
Expand Down Expand Up @@ -195,7 +191,7 @@ The timestamps of the signatures will be usefull to version the block, checking

**The miners will be rewarded with the block reward distributed by the number of signatures**
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/outerspace-coding/outerspace-blockchain
Bug reports and pull requests are welcome on GitHub at https://github.com/JesusGautamah/outerspace-blockchain

## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Expand Down
26 changes: 26 additions & 0 deletions app/controllers/api/v1/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def ticket_founded?
end

private
attr_accessor :user

def find_user_by_header
return unless request.headers["X-API-KEY"].present?
api_key = request.headers["X-API-KEY"]
Expand Down Expand Up @@ -38,4 +40,28 @@ def ticket_not_found_response
def unauthorized_response
render json: { error: "Unauthorized" }, status: :unauthorized
end

def current_block
@current_block = Block.find_by(master_hash: nil)
end

def current_pool
@current_pool = Pool.find_by(block_id: current_block.id)
end

def ticket
@ticket = Ticket.find_by(user_id: user.id, status: :active)
end

def block_transactions
@block_transactions = Transaction.where(block_id: current_block.id)
end

def block_transactions_empty?
return no_transactions_response unless block_transactions.present?
end

def no_transactions_response
render json: { error: "No transactions in the block" }, status: :not_found
end
end
65 changes: 65 additions & 0 deletions app/controllers/api/v1/ticket_manager_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# frozen_string_literal: true

class Api::V1::TicketManagerController < Api::V1::ApplicationController
before_action :unauthorized?
before_action :block_transactions_empty?, only: [:open_ticket]

def open_ticket
return ticket_already_opened_response unless ticket_nil?
return ticket_already_opened_response if ticket_active?
return terms_not_confirmed_response unless ticket_params_confirmed?
create_ticket if acceptable_create?
ticket_opened_response
end


private
def ticket_nil?
ticket.nil?
end

def ticket_active?
return false if ticket_nil?
ticket.status == "active"
end

def acceptable_create?
ticket_nil? && ticket_params_confirmed? || ticket_params_confirmed? && ticket_active? == false
end

def ticket_params_confirmed?
open_ticket_params[:ticket_terms] == "confirmed"
end

def ticket_already_opened_response
render json: { error: "Ticket already opened" }, status: :not_found
end

def ticket_opened_response
render json: { message: "Ticket opened" }, status: :ok
end

def terms_not_confirmed_response
render json: { error: "Ticket terms not confirmed" }, status: :not_found
end

def open_ticket_params
params.permit(:ticket_terms)
end

def time_ref
@time_ref = block_transactions.first.created_at.to_s
end

def user_id
@user_id = user.id.to_s
end

def current_pool_id
@current_pool_id = current_pool.id.to_s
end

def create_ticket
CreateTicketWorker.perform_async(user_id, current_pool_id, time_ref)
end
end
1 change: 1 addition & 0 deletions app/workers/create_ticket_worker.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

class CreateTicketWorker < ApplicationWorker
include Sidekiq::Worker
sidekiq_options retry: false

def perform(user_id, pool_id, time_ref)
Expand Down
1 change: 1 addition & 0 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sidekiq.strict_args!
2 changes: 1 addition & 1 deletion config/routes/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace :api do
namespace :v1 do
post "confirm_block", to: "block_confirmations#confirm_block"
# get "tr_to_mine", to: "block_confirmations#transactions_to_mine"
post "open_ticket", to: "ticket_manager#open_ticket"
get "info_to_mine", to: "block_confirmations#info_to_mine"
end
end
2 changes: 1 addition & 1 deletion coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"result": {
"line": 81.24
"line": 83.46
}
}
Loading

0 comments on commit b9974a4

Please sign in to comment.