-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1454 from nervosnetwork/testnet
Deploy to mainnet
- Loading branch information
Showing
34 changed files
with
665 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Api | ||
module V1 | ||
class UdtVerificationsController < ApplicationController | ||
before_action :check_udt_info, only: :update | ||
before_action :set_locale, only: :update | ||
|
||
def update | ||
udt_verification = UdtVerification.find_or_create_by(udt_id: @udt.id) | ||
|
||
udt_verification.refresh_token!(request.remote_ip) | ||
UdtVerificationMailer.with(email: @udt.email, token: udt_verification.token, | ||
locale: @locale).send_token.deliver_later | ||
render json: :ok | ||
rescue UdtVerification::TokenSentTooFrequentlyError | ||
raise Api::V1::Exceptions::TokenSentTooFrequentlyError | ||
end | ||
|
||
private | ||
|
||
def check_udt_info | ||
@udt = Udt.find_by(type_hash: params[:id]) | ||
raise Api::V1::Exceptions::UdtNotFoundError if @udt.nil? | ||
raise Api::V1::Exceptions::UdtNoContactEmailError if @udt.email.blank? | ||
end | ||
|
||
def set_locale | ||
@locale = params[:locale] == "zh_CN" ? "zh_CN" : "en" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class UdtVerificationMailer < ApplicationMailer | ||
default from: "[email protected]" | ||
|
||
def send_token | ||
email = params[:email] | ||
@token = params[:token] | ||
locale = params[:locale] || "en" | ||
I18n.with_locale(locale) do | ||
mail(to: email, subject: "Token Info Verification") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class UdtVerification < ApplicationRecord | ||
SENT_FREQUENCY_MINUTES = 1 | ||
KEEP_ALIVE_MINUTES = 10 | ||
|
||
class TokenExpiredError < StandardError; end | ||
class TokenNotMatchError < StandardError; end | ||
class TokenSentTooFrequentlyError < StandardError; end | ||
|
||
belongs_to :udt | ||
|
||
def refresh_token!(ip) | ||
raise TokenSentTooFrequentlyError if sent_at.present? && self.sent_at + SENT_FREQUENCY_MINUTES.minutes > Time.now | ||
|
||
self.token = rand(999999).to_s.rjust(6, "0") | ||
self.sent_at = Time.now | ||
self.last_ip = ip | ||
self.save! | ||
end | ||
|
||
def validate_token!(token_params) | ||
raise TokenExpiredError if self.sent_at + KEEP_ALIVE_MINUTES.minutes < Time.now | ||
raise TokenNotMatchError if token != token_params.to_i | ||
end | ||
end | ||
|
||
# == Schema Information | ||
# | ||
# Table name: udt_verifications | ||
# | ||
# id :bigint not null, primary key | ||
# token :integer | ||
# sent_at :datetime | ||
# last_ip :inet | ||
# udt_id :bigint | ||
# udt_type_hash :integer | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
# Indexes | ||
# | ||
# index_udt_verifications_on_udt_id (udt_id) | ||
# index_udt_verifications_on_udt_type_hash (udt_type_hash) UNIQUE | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,29 @@ | ||
json.data do | ||
json.deployed_cells @deployed_cells do |deployed_cell| | ||
cell_output = deployed_cell.cell_output | ||
json.id deployed_cell.cell_output.id | ||
json.capacity deployed_cell.cell_output.capacity | ||
json.ckb_transaction_id deployed_cell.cell_output.ckb_transaction_id | ||
json.created_at deployed_cell.cell_output.created_at | ||
json.updated_at deployed_cell.cell_output.updated_at | ||
json.status cell_output.status | ||
json.address_id cell_output.address_id | ||
json.block_id cell_output.block_id | ||
json.tx_hash cell_output.tx_hash | ||
json.cell_index cell_output.cell_index | ||
json.consumed_by_id cell_output.consumed_by_id | ||
json.cell_type cell_output.cell_type | ||
json.data_size cell_output.data_size | ||
json.occupied_capacity cell_output.occupied_capacity | ||
json.block_timestamp cell_output.block_timestamp | ||
json.consumed_block_timestamp cell_output.consumed_block_timestamp | ||
json.type_hash cell_output.type_hash | ||
json.udt_amount cell_output.udt_amount | ||
json.dao cell_output.dao | ||
json.lock_script_id cell_output.lock_script_id | ||
json.type_script_id cell_output.type_script_id | ||
json.id deployed_cell.id | ||
json.capacity deployed_cell.capacity | ||
json.ckb_transaction_id deployed_cell.ckb_transaction_id | ||
json.created_at deployed_cell.created_at | ||
json.updated_at deployed_cell.updated_at | ||
json.status deployed_cell.status | ||
json.address_id deployed_cell.address_id | ||
json.block_id deployed_cell.block_id | ||
json.tx_hash deployed_cell.tx_hash | ||
json.cell_index deployed_cell.cell_index | ||
json.consumed_by_id deployed_cell.consumed_by_id | ||
json.cell_type deployed_cell.cell_type | ||
json.data_size deployed_cell.data_size | ||
json.occupied_capacity deployed_cell.occupied_capacity | ||
json.block_timestamp deployed_cell.block_timestamp | ||
json.consumed_block_timestamp deployed_cell.consumed_block_timestamp | ||
json.type_hash deployed_cell.type_hash | ||
json.udt_amount deployed_cell.udt_amount | ||
json.dao deployed_cell.dao | ||
json.lock_script_id deployed_cell.lock_script_id | ||
json.type_script_id deployed_cell.type_script_id | ||
end | ||
json.meta do | ||
json.total @deployed_cells.total_count | ||
json.total @contract.deployed_cells_count | ||
json.page_size @page_size.to_i | ||
end | ||
end |
Oops, something went wrong.