mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
2018-2-27
This commit is contained in:
parent
b051cb6d41
commit
5f65581331
13 changed files with 1035 additions and 64 deletions
Binary file not shown.
|
|
@ -569,15 +569,7 @@ func AccumulateRewards(config *params.ChainConfig, state *state.StateDB, header
|
|||
//log.Info("参数变量","TotalReward",TotalReward,"Reward_Justnum",Reward_justnum)
|
||||
TotalReward.Div(TotalReward,math.Exp(big.NewInt(2),Reward_justnum)) // reward/2**justnum
|
||||
//log.Info("参数变量","TotalReward",TotalReward)
|
||||
if header.Number.Cmp(big.NewInt(100))>0 { //必须在区块号100以前完成挖矿智能合约的部署。
|
||||
minerpool:=TotalReward.Div(TotalReward,big.NewInt(100))
|
||||
state.AddBalance(header.Coinbase, minerpool)
|
||||
// log.Info("参数变量","minerpool",minerpool)
|
||||
// reward.Sub(reward,minerpool)
|
||||
state.AddBalance(params.PosMinerContractAddr, TotalReward.Mul(TotalReward,big.NewInt(99)))
|
||||
//log.Info("参数变量","TotalReward",TotalReward)
|
||||
}else{
|
||||
state.AddBalance(header.Coinbase, TotalReward)
|
||||
//log.Info("参数变量","TotalReward",TotalReward)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
95
contracts/MinerPoolManagement/MinerPoolManagement.abi
Normal file
95
contracts/MinerPoolManagement/MinerPoolManagement.abi
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
[
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "MinerPool",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "status",
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"name": "AppAddr",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"name": "MinerPoolSetting",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "MPools",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "status",
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"name": "AppAddr",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "Manager",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "RegistryPoolNum",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "newManager",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "transferManagement",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "constructor"
|
||||
}
|
||||
]
|
||||
6
contracts/MinerPoolManagement/MinerPoolManagement.bin
Normal file
6
contracts/MinerPoolManagement/MinerPoolManagement.bin
Normal file
File diff suppressed because one or more lines are too long
301
contracts/MinerPoolManagement/MinerPoolManagement.go
Normal file
301
contracts/MinerPoolManagement/MinerPoolManagement.go
Normal file
File diff suppressed because one or more lines are too long
36
contracts/MinerPoolManagement/MiningPoolManagement.sol
Normal file
36
contracts/MinerPoolManagement/MiningPoolManagement.sol
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
pragma solidity ^0.4.18;
|
||||
|
||||
contract MiningPoolManagement {
|
||||
//Define manager.
|
||||
address public Manager;
|
||||
//Only manager can modify.
|
||||
modifier onlyManager {
|
||||
require(msg.sender ==Manager);
|
||||
_;
|
||||
}
|
||||
//MiningPool Registry Information.
|
||||
struct mpool {
|
||||
bool status;
|
||||
string AppAddr;
|
||||
}
|
||||
mapping (address=>mpool) public MPools;
|
||||
uint public RegistryPoolNum;
|
||||
//Construction function, initially define the creator as the manager.
|
||||
function MiningPoolManagement() public {
|
||||
Manager=msg.sender;
|
||||
}
|
||||
//Management power thansfer.
|
||||
function transferManagement(address newManager) onlyManager public {
|
||||
Manager=newManager;
|
||||
}
|
||||
//MiningPool regstiry, only manager can modify.
|
||||
function MinerPoolSetting(address MinerPool,bool status,string AppAddr) onlyManager public {
|
||||
if (MPools[MinerPool].status!=true){
|
||||
RegistryPoolNum+=1;
|
||||
}
|
||||
MPools[MinerPool]=mpool(status,AppAddr);
|
||||
if (status==false&&RegistryPoolNum>1) {
|
||||
RegistryPoolNum-=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
132
contracts/MobileMine/MobileMine.abi
Normal file
132
contracts/MobileMine/MobileMine.abi
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
[
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [],
|
||||
"name": "Mine",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "success",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "Miners",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "Registry",
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"name": "TotalPay",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"name": "PayTime",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "Manager",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "ReceiveFoundation",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "MobileMiner",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "MinerSetting",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "ActiveUsers",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "LastTime",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"name": "ActiveNum",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"name": "RegistryUsers",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "newManager",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "transferManagement",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "constructor"
|
||||
},
|
||||
{
|
||||
"payable": true,
|
||||
"stateMutability": "payable",
|
||||
"type": "fallback"
|
||||
}
|
||||
]
|
||||
6
contracts/MobileMine/MobileMine.bin
Normal file
6
contracts/MobileMine/MobileMine.bin
Normal file
File diff suppressed because one or more lines are too long
360
contracts/MobileMine/MobileMine.go
Normal file
360
contracts/MobileMine/MobileMine.go
Normal file
File diff suppressed because one or more lines are too long
68
contracts/MobileMine/MobileMine.sol
Normal file
68
contracts/MobileMine/MobileMine.sol
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
pragma solidity ^0.4.18;
|
||||
|
||||
contract MobileMine {
|
||||
//Define the Manager
|
||||
address public Manager;
|
||||
//Only manager can modify.
|
||||
modifier onlyManager {
|
||||
require(msg.sender ==Manager);
|
||||
_;
|
||||
}
|
||||
//Define miner mining informaiton.
|
||||
struct Miner {
|
||||
bool Registry;
|
||||
uint TotalPay; //Having mined reward.
|
||||
uint PayTime; //Reward pay time.
|
||||
}
|
||||
//Active users' information.
|
||||
struct ActiveInfo {
|
||||
uint LastTime; //Last calculate time.
|
||||
uint ActiveNum; //Active users number.
|
||||
uint RegistryUsers; //the number of already registrtyUsers.
|
||||
}
|
||||
/*Miner and active users defining */
|
||||
mapping (address => Miner) public Miners;
|
||||
ActiveInfo public ActiveUsers;
|
||||
uint public ReceiveFoundation; //Having received reward foundation.
|
||||
uint MineAmount;
|
||||
//Constuct function£¬initially define the creator as the manager.
|
||||
function MobileMine() public {
|
||||
Manager=msg.sender;
|
||||
}
|
||||
//Define the contract can receive mining reward foundation.
|
||||
function () payable public {
|
||||
ReceiveFoundation+=msg.value;
|
||||
}
|
||||
//Management power transfer.
|
||||
function transferManagement(address newManager) onlyManager public {
|
||||
Manager=newManager;
|
||||
}
|
||||
//Miner registry setting, only manager can modify.
|
||||
function MinerSetting(address MobileMiner) onlyManager public {
|
||||
if (Miners[MobileMiner].Registry!=true){
|
||||
Miners[MobileMiner].Registry=true;
|
||||
ActiveUsers.RegistryUsers+=1;
|
||||
}
|
||||
}
|
||||
/* Miner mine function, modify miner's status*/
|
||||
function Mine() public returns (bool success){
|
||||
//If not registry or has been payed in one day, return false.
|
||||
if (Miners[msg.sender].Registry!=true||Miners[msg.sender].PayTime+86400>now){
|
||||
return false;
|
||||
}
|
||||
//Pay the reward and change the miner's status.
|
||||
MineAmount=this.balance/(ActiveUsers.RegistryUsers+1);
|
||||
msg.sender.transfer(MineAmount);
|
||||
Miners[msg.sender].TotalPay+= MineAmount;
|
||||
Miners[msg.sender].PayTime=now;
|
||||
//Check if the calculating time of active user is lasting one day or not.
|
||||
if(ActiveUsers.LastTime+86400<now){
|
||||
ActiveUsers.LastTime=now;
|
||||
ActiveUsers.ActiveNum=1;
|
||||
Manager.transfer(this.balance/100);
|
||||
}else{
|
||||
ActiveUsers.ActiveNum+=1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -42,9 +42,11 @@ import (
|
|||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
"github.com/hashicorp/golang-lru"
|
||||
"github.com/ethereum/go-ethereum/contracts/posminer"
|
||||
"github.com/ethereum/go-ethereum/contracts/MinerPoolManagement"
|
||||
"github.com/ethereum/go-ethereum/contracts/MobileMine"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
|
||||
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -859,59 +861,40 @@ func (bc *BlockChain) WriteBlockAndState(block *types.Block, receipts []*types.R
|
|||
|
||||
//统计移动应用权重帐户的用户权重
|
||||
func (bc *BlockChain) CalcTokenTime(Coinbase common.Address) (Tokentime *big.Int) {
|
||||
//var sumToken *big.Int = big.NewInt(0)
|
||||
//var Tokentime *big.Int = big.NewInt(0)
|
||||
var exist bool
|
||||
exist=false
|
||||
|
||||
//var Pos_Addjust *big.Int
|
||||
Tokentime=big.NewInt(0)
|
||||
var ActiveMiners []common.Address
|
||||
State,_:=bc.State()
|
||||
if State.Exist(params.PosMinerContractAddr)!=true{
|
||||
//log.Info("警告","RPC未使能",Tokentime)
|
||||
if State.Exist(params.PosMinerContractAddr)!=true || State.GetCode(Coinbase)==nil{
|
||||
log.Info("警告","矿池管理合约未部署,尚不能使用权重挖矿!",Tokentime)
|
||||
return Tokentime
|
||||
}
|
||||
//log.Info("posminer.PosConn",posminer.PosConn)
|
||||
if posminer.PosConn==nil {
|
||||
posminer.PosConn, _ = ethclient.Dial("//./pipe/geth.ipc")
|
||||
if MinerPoolManagement.PosConn==nil {
|
||||
MinerPoolManagement.PosConn, _ = ethclient.Dial("//./pipe/geth.ipc")
|
||||
log.Info("AppChain连接", "连接IPC服务")
|
||||
}
|
||||
//if err != nil {
|
||||
// log.Info("警告", "设置了ipcdisable,不能使用权重挖矿!",err)
|
||||
// return Tokentime
|
||||
//}
|
||||
PosMiner, err := posminer.NewPosminer(params.PosMinerContractAddr, posminer.PosConn)
|
||||
//log.Info("错误码","err",err,"PosMiner",PosMiner)
|
||||
MinerPool, err := MinerPoolManagement.NewMinerPoolManagement(params.PosMinerContractAddr, MinerPoolManagement.PosConn)
|
||||
//log.Info("params.posminerContractAddr",params.PosMinerContractAddr)
|
||||
if err !=nil{
|
||||
log.Info("调用挖矿智能合约posminer失败","错误",err)
|
||||
log.Info("调用矿池智能合约失败","错误",err)
|
||||
return Tokentime
|
||||
}
|
||||
//M,err:=PosMiner.RegLength(nil)
|
||||
for i:=uint64(0);i<bc.currentBlock.NumberU64() ;i++{
|
||||
for _,tx:=range bc.GetBlockByNumber(i).Transactions() {
|
||||
msg,err:= tx.AsMessage(types.MakeSigner(bc.Config(), bc.GetBlockByNumber(i).Header().Number))
|
||||
if err != nil {
|
||||
//查询移动应用矿池状态
|
||||
Mpool,err:= MinerPool.MPools(nil, Coinbase)
|
||||
//log.Info("警告","Mpool.status",Mpool.Status)
|
||||
if Mpool.Status!=true {
|
||||
return Tokentime
|
||||
}
|
||||
CmpMiner,err:= PosMiner.Registers(nil, msg.From())
|
||||
if err != nil {
|
||||
//查询移动应用矿池的权重
|
||||
MpoolMine,err:=MobileMine.NewMobileMine(Coinbase,MinerPoolManagement.PosConn)
|
||||
if err !=nil{
|
||||
log.Info("调用移动应用矿池合约失败","错误",err)
|
||||
return Tokentime
|
||||
}
|
||||
RegistryTime := new(big.Int).Set(CmpMiner.RegistryTime)
|
||||
if RegistryTime.Add(RegistryTime,big.NewInt(86400)).Cmp(bc.currentBlock.Time())>0 &&CmpMiner.MinerPool==Coinbase {
|
||||
for j:=0;j<len(ActiveMiners);j++{
|
||||
if ActiveMiners[j]==msg.From(){
|
||||
exist=true
|
||||
break
|
||||
}
|
||||
}
|
||||
if exist==false {
|
||||
Tokentime.Add(Tokentime,big.NewInt(1))
|
||||
ActiveMiners=append(ActiveMiners,msg.From())
|
||||
}
|
||||
exist=false
|
||||
}
|
||||
}
|
||||
}
|
||||
MpoolActiveNum,err:=MpoolMine.ActiveUsers(nil)
|
||||
Tokentime.Sqrt(MpoolActiveNum.ActiveNum)
|
||||
//log.Info("调用移动应用矿池合约失败","Tokentime1",Tokentime1,"Tokentime2",Tokentime2)
|
||||
return Tokentime
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -263,15 +263,7 @@ func (st *StateTransition) TransitionDb() (ret []byte, requiredGas, usedGas *big
|
|||
st.refundGas()
|
||||
|
||||
Total_gas := new(big.Int).Mul(st.gasUsed(), st.gasPrice)
|
||||
//检查合约帐号是否存在
|
||||
if st.evm.BlockNumber.Cmp(big.NewInt(100))>0 { //必须在区块号100以前完成挖矿智能合约的部署。
|
||||
MinerPool_gas := new(big.Int).Div(Total_gas, big.NewInt(100)) //计算总交易费的1%;
|
||||
Miners_gas := new(big.Int).Mul(MinerPool_gas, big.NewInt(99)) //计算总交易费的99%
|
||||
st.state.AddBalance(st.evm.Coinbase, MinerPool_gas) //为矿池帐户支付交易费的1%
|
||||
st.state.AddBalance(params.PosMinerContractAddr, Miners_gas)//将交易费的99%存入挖矿合约帐号
|
||||
}else {
|
||||
st.state.AddBalance(st.evm.Coinbase, Total_gas) //矿池合约未建立,全部支付给矿工。
|
||||
}
|
||||
st.state.AddBalance(st.evm.Coinbase, Total_gas)
|
||||
//st.state.AddBalance(st.evm.Coinbase, new(big.Int).Mul(st.gasUsed(), st.gasPrice))
|
||||
return ret, requiredGas, st.gasUsed(), vmerr != nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ var (
|
|||
//POSMINER相关定义
|
||||
var (
|
||||
PosMinerContractAddr = common.HexToAddress ("0x8C00B660792b235d4382368299E77C8c04ED4754") //POSMINER合约地址
|
||||
)
|
||||
)
|
||||
|
||||
var (
|
||||
// MainnetChainConfig is the chain parameters to run a node on the main network.
|
||||
|
|
|
|||
Loading…
Reference in a new issue