mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-22 12:45:46 +08:00
新增:初始化区块链脚本
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
# 执行示例 bundle exec rake "sync_mindspore:contributor_to_user"
|
||||
# RAILS_ENV=production bundle exec rake "sync_mindspore:contributor_to_user"
|
||||
desc "mindspore项目贡献者数据"
|
||||
|
||||
# 同步mindspre贡献者数据至用户表
|
||||
@@ -46,9 +48,32 @@ namespace :sync_mindspore do
|
||||
|
||||
file.close
|
||||
end
|
||||
|
||||
# 执行示例 bundle exec rake "sync_mindspore:init_project_blockchain[1,2]"
|
||||
# RAILS_ENV=production bundle exec rake "sync_mindspore:init_project_blockchain[1,2]"
|
||||
desc "初始化区块链项目"
|
||||
task init_project_blockchain: :environment do
|
||||
task :init_project_blockchain, [:id, :init_id] => :environment do |t, args|
|
||||
puts "=====Init Project Blockchain: #{args.id}====="
|
||||
project = Project.find_by_id(args.id)
|
||||
project.update_column(:use_blockchain, true)
|
||||
|
||||
username = project.user_id.to_s
|
||||
token_name = project.id.to_s
|
||||
total_supply = 10000
|
||||
token_balance = [[init_id.to_s, 100]]
|
||||
|
||||
contributions = Project.mindspore_contributors
|
||||
total_contributions = contributions.sum{|i| i["contributions"]}
|
||||
contributions.each do |con|
|
||||
cont_balance = Float(con["contributions"]*9900/total_contributions).round(0)
|
||||
token_balance << [con["id"], cont_balance] if cont_balance > 0
|
||||
end
|
||||
params = {
|
||||
"request-type": "create repo",
|
||||
"username": username,
|
||||
"token_name": token_name,
|
||||
"total_supply": total_supply,
|
||||
"token_balance": token_balance
|
||||
}.to_json
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user