/** * 关闭合约 */ public static bool closeBPEC() { BPECPoolInfo bpecPoolInfo = getBPECPoolInfo(); bpecPoolInfo.bpecState = 0; //保存股权余额 Storage.Put(Storage.CurrentContext, "BPECPoolInfo", Helper.Serialize(bpecPoolInfo)); CloseBPECed(1); return(true); }
/** * 用户交易股权 * **/ public static bool transfer(byte[] from, byte[] to, BigInteger value) { bool bol = false; BigInteger claimId = 0; if (from.Length > 0 && to.Length > 0 && value > 0 && from != to) { BPECPoolInfo bpecPoolInfo = getBPECPoolInfo(); if (bpecPoolInfo.bpecState == 1) { claimId = bpecPoolInfo.claimCode; // BPECInfo bpecInfo = getBPECInfo(); //获得当前块的高度 BigInteger height = Blockchain.GetHeight(); //付款方 var keyFrom = new byte[] { 0x11 }.Concat(from); Info fromInfo = getInfo(from); var from_value = fromInfo.balance; if (from_value >= value) { fromInfo.block = height; fromInfo.balance = from_value - value; Storage.Put(Storage.CurrentContext, keyFrom, Helper.Serialize(fromInfo)); //收款方 var keyTo = new byte[] { 0x11 }.Concat(to); Info toInfo = getInfo(to); var to_value = toInfo.balance; toInfo.block = height; toInfo.balance = to_value + value; Storage.Put(Storage.CurrentContext, keyTo, Helper.Serialize(toInfo)); //保存交易记录 /*TransferInfo trInfo = new TransferInfo(); * trInfo.from = from; * trInfo.to = to; * trInfo.ttp = 1; * trInfo.value = value; * txid = (ExecutionEngine.ScriptContainer as Transaction).Hash; * Storage.Put(Storage.CurrentContext, txid, Helper.Serialize(trInfo));*/ bol = true; } } //notify if (bol == true) { Transfered(1, from, to, 1, value, claimId); } else { Transfered(0, from, to, 1, value, claimId); } } return(bol); }
/** * 开启分红 * */ 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 object[] getNowClaimPoolInfo() { BPECPoolInfo BPECPoolInfo = getBPECPoolInfo(); var key = "claim_".AsByteArray().Concat(BPECPoolInfo.claimCode.AsByteArray()); byte[] data = Storage.Get(Storage.CurrentContext, key); if (data.Length > 0) { return((object[])Helper.Deserialize(data)); } else { return(new object[0]); } }
/** * 购买、分享、解禁交易股权 * **/ 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); }
/** * 查询合约状态 */ public static byte getBPECState() { BPECPoolInfo bpecPoolInfo = getBPECPoolInfo(); return(bpecPoolInfo.bpecState); }