/** * 开启分红 * */ public static bool satrtClaim() { bool bol = false; if (Runtime.CheckWitness(ContractOwner)) { BPECPoolInfo bpecPoolInfo = getBPECPoolInfo(); if (bpecPoolInfo.bpecState == 1) { ClaimPoolInfo claimPoolInfo = getClaimPoolInfo(bpecPoolInfo.claimCode); if (claimPoolInfo.claimState == 0) { // ClaimPoolInfo claimPoolInfoTemp = new ClaimPoolInfo(); claimPoolInfoTemp.claimCode = claimPoolInfo.claimCode + 1; claimPoolInfoTemp.claimPool = 0; claimPoolInfoTemp.pCount = 0; claimPoolInfoTemp.saleCount = 0; claimPoolInfoTemp.shareCount = 0; claimPoolInfoTemp.teamCount = 0; claimPoolInfoTemp.commCount = 0; claimPoolInfoTemp.buyAddress = claimPoolInfo.buyAddress; claimPoolInfoTemp.claimState = 0; // var key = "claim_".AsByteArray().Concat(claimPoolInfoTemp.claimCode.AsByteArray()); Storage.Put(Storage.CurrentContext, key, Helper.Serialize(claimPoolInfoTemp)); // bpecPoolInfo.claimCode = claimPoolInfoTemp.claimCode; Storage.Put(Storage.CurrentContext, "BPECPoolInfo", Helper.Serialize(bpecPoolInfo)); // claimPoolInfo.claimState = 1; var key1 = "claim_".AsByteArray().Concat(claimPoolInfo.claimCode.AsByteArray()); Storage.Put(Storage.CurrentContext, key1, Helper.Serialize(claimPoolInfo)); bol = true; } //notify if (bol == true) { StartClaimed(1, claimPoolInfo.claimCode, claimPoolInfo.claimPool, bpecPoolInfo.totalBPEC, claimPoolInfo.claimCode + 1); } else { StartClaimed(0, claimPoolInfo.claimCode, claimPoolInfo.claimPool, bpecPoolInfo.totalBPEC, claimPoolInfo.claimCode + 1); } } } return(bol); }
/** * 初始化合约 **/ public static bool deploy() { bool bol = false; if (Runtime.CheckWitness(ContractOwner)) { BPECInfo bpecInfo = getBPECInfo(); if (bpecInfo.oTotalSupply == 0) { //基本配置 bpecInfo.oTotalSupply = OBPEC; bpecInfo.tTotalSupply = TBPEC; bpecInfo.cTotalSupply = CBPEC; Storage.Put(Storage.CurrentContext, "BPECInfo", Helper.Serialize(bpecInfo)); //余额池 BPECPoolInfo bpecPoolInfo = getBPECPoolInfo(); bpecPoolInfo.obpecBalance = OBPEC; bpecPoolInfo.tbpecBalance = TBPEC; bpecPoolInfo.cbpecBalance = CBPEC; bpecPoolInfo.obpecOver = 1; bpecPoolInfo.claimCode = 1; bpecPoolInfo.bpecState = 1; Storage.Put(Storage.CurrentContext, "BPECPoolInfo", Helper.Serialize(bpecPoolInfo)); //初始化分红池 ClaimPoolInfo claimPoolInfo = new ClaimPoolInfo(); claimPoolInfo.claimCode = 1; claimPoolInfo.claimPool = 0; claimPoolInfo.pCount = 0; claimPoolInfo.saleCount = 0; claimPoolInfo.shareCount = 0; claimPoolInfo.teamCount = 0; claimPoolInfo.commCount = 0; claimPoolInfo.claimState = 0; var key = "claim_".AsByteArray().Concat(claimPoolInfo.claimCode.AsByteArray()); Storage.Put(Storage.CurrentContext, key, Helper.Serialize(claimPoolInfo)); bol = true; } } // if (bol == true) { Deployed(1); } else { Deployed(0); } return(bol); }
/** * 购买、分享、解禁交易股权 * **/ public static bool transferOpen(byte[] owner, byte ttp, BigInteger value, BigInteger cValue) { bool bol = false; BigInteger gold = value; if (owner.Length > 0 && ttp > 0 && value > 0 && cValue > 0) { //获得当前块的高度 BigInteger height = Blockchain.GetHeight(); // ClaimPoolInfo claimPoolInfo = null; BPECPoolInfo bpecPoolInfo = getBPECPoolInfo(); bool isEnd = false; if (bpecPoolInfo.bpecState == 1) { claimPoolInfo = getClaimPoolInfo(bpecPoolInfo.claimCode); // if (ttp == 2) { if (bpecPoolInfo.obpecBalance > 0) { if (bpecPoolInfo.obpecBalance > value) { bpecPoolInfo.obpecBalance -= value; } else { value = bpecPoolInfo.obpecBalance; bpecPoolInfo.obpecBalance = 0; bpecPoolInfo.endBuyAddress = owner; isEnd = true; if (bpecPoolInfo.obpecOver == 1) { bpecPoolInfo.obpecOver = 0; } } // claimPoolInfo.buyAddress = owner; claimPoolInfo.saleCount += value; claimPoolInfo.claimPool += cValue; } else { //如果股权已经分完,则只累计分红池CAGS,不分发股权 claimPoolInfo.buyAddress = owner; claimPoolInfo.claimPool += cValue; } bol = true; } if (ttp == 3) { if (bpecPoolInfo.obpecBalance > 0) { if (bpecPoolInfo.obpecBalance > value) { bpecPoolInfo.obpecBalance -= value; } else { value = bpecPoolInfo.obpecBalance; bpecPoolInfo.obpecBalance = 0; bpecPoolInfo.endBuyAddress = claimPoolInfo.buyAddress; isEnd = true; if (bpecPoolInfo.obpecOver == 1) { bpecPoolInfo.obpecOver = 0; } } claimPoolInfo.shareCount += value; bol = true; } } else if (ttp == 4) { if (bpecPoolInfo.cbpecBalance > 0 && bpecPoolInfo.cbpecBalance >= value) { bpecPoolInfo.cbpecBalance -= value; claimPoolInfo.commCount += value; bol = true; } } else if (ttp == 5) { if (bpecPoolInfo.tbpecBalance > 0 && bpecPoolInfo.tbpecBalance >= value) { bpecPoolInfo.tbpecBalance -= value; claimPoolInfo.teamCount += value; bol = true; } } } // if (bol == true) { //保存分红池 var key = "claim_".AsByteArray().Concat(claimPoolInfo.claimCode.AsByteArray()); Storage.Put(Storage.CurrentContext, key, Helper.Serialize(claimPoolInfo)); if (ttp == 2 || ttp == 3) { if (bpecPoolInfo.obpecOver == 1 || (bpecPoolInfo.obpecOver == 0 && isEnd == true)) { //保存股权余额 bpecPoolInfo.totalBPEC += value; Storage.Put(Storage.CurrentContext, "BPECPoolInfo", Helper.Serialize(bpecPoolInfo)); //保存用户股权余额信息 Info ownerInfo = getInfo(owner); ownerInfo.balance += value; ownerInfo.block = height; var keyOwner = new byte[] { 0x11 }.Concat(owner); Storage.Put(Storage.CurrentContext, keyOwner, Helper.Serialize(ownerInfo)); } } else { //保存股权余额 bpecPoolInfo.totalBPEC += value; Storage.Put(Storage.CurrentContext, "BPECPoolInfo", Helper.Serialize(bpecPoolInfo)); //保存用户股权余额信息 Info ownerInfo = getInfo(owner); ownerInfo.balance += value; ownerInfo.block = height; var keyOwner = new byte[] { 0x11 }.Concat(owner); Storage.Put(Storage.CurrentContext, keyOwner, Helper.Serialize(ownerInfo)); } //保存交易记录 /*TransferInfo trInfo = new TransferInfo(); * trInfo.from = owner; * trInfo.to = owner; * trInfo.ttp = ttp; * trInfo.value = value; * txid = (ExecutionEngine.ScriptContainer as Transaction).Hash; * Storage.Put(Storage.CurrentContext, txid, Helper.Serialize(trInfo));*/ } //notify if (bol == true) { TransferOpened(1, owner, ttp, gold, value, bpecPoolInfo.obpecOver, bpecPoolInfo.claimCode); } else { TransferOpened(0, owner, ttp, gold, value, bpecPoolInfo.obpecOver, bpecPoolInfo.claimCode); } } return(bol); }