change blockchain service

This commit is contained in:
nigel007 2019-04-14 16:22:30 +08:00
parent 3094a4c19a
commit 49cac39403
1 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,44 @@
#coding=utf-8
class BlockchainsService
# 获取用户使用过的东西
def get_already_things(user)
result = get_networkids_ports(user)
ps = ProjectsService.new
project_names = ps.get_exist_project_names user
result[:project_names] = project_names
return result
end
# 获取用户使用过的networkid, port
def get_networkids_ports(user)
network_ids = []
ports = []
bcs = Blockchain.find_by_sql("select network_id, port from blockchains where user_id=#{user.id}")
bcs.each do |bc|
network_ids << bc.network_id
ports << bc.port
end
return {:network_ids => network_ids, :ports => ports, :status => 0}
end
# 创建新记录
def create_item(project, user, params)
status = -1
blockchain = Blockchain.new
blockchain.genesis_content = params[:genesis_content]
blockchain.network_id = params[:network_id]
blockchain.connect_ip = params[:connect_ip]
blockchain.port = params[:port]
blockchain.enode = params[:enode]
blockchain.project_id = project.id
blockchain.user_id = user.id
if blockchain.save
status = 0
return status, blockchain
end
return status, nil
end
end