/// <summary> /// Release 0 generation gladiators to the auction house /// </summary> private static bool CreateGenerationZeroAuction(byte strength, byte power, byte agile, byte speed, byte generation) { byte[] tokenOwner = ExecutionEngine.ExecutingScriptHash; if (Runtime.CheckWitness(ContractMain.MintOwner)) { object[] args = new object[] { tokenOwner, strength, power, agile, speed, generation }; BigInteger tokenId = (BigInteger)ContractMain.NftContractCall("createGenerationZeroFromAuction_app", args); if (tokenId == 0) { return(false); } BigInteger auctionStartPrice = GenerationZeroMaxPrice; BigInteger auctionEndPrice = GenerationZeroMinPrice; BigInteger auctionDuration = GenerationZeroAuctionDuration; object[] rawPrice = DataAccess.GetGenerationZeroPricesAsObjects(); if (rawPrice.Length > 0) { GenerationZeroPrice price = (GenerationZeroPrice)(object)rawPrice; auctionStartPrice = price.MaxPrice; auctionEndPrice = price.MinPrice; auctionDuration = price.Duration; } return(SaleGenerationZero( ContractMain.ContractOwner, tokenId, auctionStartPrice, auctionEndPrice, auctionDuration, 0)); } return(false); }
/// <summary> /// Cancel the auction /// </summary> private static bool CancelAuction(byte[] sender, BigInteger tokenId) { object[] rawAuction = DataAccess.GetAuctionAsObjects(tokenId.AsByteArray()); if (rawAuction.Length > 0) { MarketAuction auction = (MarketAuction)(object)rawAuction; bool isAdmin = Runtime.CheckWitness(ContractMain.ContractOwner); if (sender != auction.Owner && isAdmin == false) { return(false); } if (Runtime.CheckWitness(sender) || isAdmin) { object[] args = new object[] { ExecutionEngine.ExecutingScriptHash, auction.Owner, tokenId }; bool appCallSuccess = (bool)ContractMain.NftContractCall("transfer_app", args); if (appCallSuccess) { DataAccess.DeleteAuction(tokenId.AsByteArray()); Events.RaiseCancelAuctioned(auction.Owner, tokenId); return(true); } } } return(false); }
/// <summary> /// sellType:0 Auction 1 clone auction /// </summary> private static bool SaleItemWithType( byte[] tokenOwner, BigInteger tokenId, BigInteger startPrice, BigInteger endPrice, BigInteger duration, int sellType) { Runtime.Notify("Initiating SaleItemWithType"); if (tokenOwner.Length != 20) { Runtime.Log("Owner error."); return(false); } if (startPrice < 0 || endPrice < 0 || startPrice < endPrice) { return(false); } Runtime.Notify("Price validation passed"); if (endPrice < ContractMain.MinTxFee) { // End price cannot be lower than the minimum handling fee return(false); } Runtime.Notify("Fee validation passed."); //if (Runtime.CheckWitness(tokenOwner)) // Items are placed in the auction house object[] args = new object[3] { tokenOwner, ExecutionEngine.ExecutingScriptHash, tokenId }; Runtime.Notify("Initiating app call"); bool appCallSuccess = (bool)ContractMain.NftContractCall("transferFrom_app", args); Runtime.Notify(appCallSuccess ? "app call success" : "app call failed"); if (appCallSuccess) { var nowtime = Blockchain.GetHeader(Blockchain.GetHeight()).Timestamp; MarketAuction auction = new MarketAuction { Owner = tokenOwner, SellType = sellType, SellTime = nowtime, BeginPrice = startPrice, EndPrice = endPrice, Duration = duration }; DataAccess.SetAuction(tokenId.AsByteArray(), auction); Events.RaiseAuctioned(tokenOwner, tokenId, startPrice, endPrice, duration, sellType, nowtime); return(true); } return(false); }
public override MvcViewContext LoadDataFields() { // 后台获取Url的参数(通过Request来获取) string url = Request.Url.ToString(); string ContractNo = Common.getUrlParam(url, "ContractNo"); if (!ContractNo.Equals("")) { ContractMain con = Common.getContractByBizId(ContractNo); this.ActionContext.InstanceData["Currency"].Value = con.Currency; } // 获取取回子流程的版本号 int versionBack = OThinker.H3.Controllers.AppUtility.Engine.WorkflowManager.GetWorkflowDefaultVersion("GetBackContract"); this.ActionContext.InstanceData["WorkflowVersion_Back"].Value = versionBack; // 获取回退记录 System.Data.DataTable dt_back = OThinker.H3.Controllers.AppUtility.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteDataTable( " SELECT ins.OriginatorName Approver,ins.StartTime ApproveDate,ins.State Status,ins.ObjectID, " + " gb.OldInstanceActivityName,gb.InstanceActivityName,c.[Text] Remark " + " FROM I_GetBackContract gb, OT_InstanceContext ins, OT_Comment c " + " where gb.NeedInstanceId = '" + this.ActionContext.InstanceId + "' and gb.ObjectID = ins.BizObjectId and ins.ObjectID = c.InstanceId"); if (dt_back.Rows.Count > 0) { BizObject[] bizObjects = new BizObject[dt_back.Rows.Count]; var i = 0; foreach (DataRow dr in dt_back.Rows) { BizObjectSchema childSchema = this.ActionContext.Schema.GetProperty("GetBackPaymentSubTbl").ChildSchema; // 第一行 bizObjects[i] = new BizObject(this.ActionContext.Engine, childSchema, this.ActionContext.User.UserID); bizObjects[i]["Approver"] = dr["Approver"].ToString(); bizObjects[i]["ApproveDate"] = dr["ApproveDate"].ToString(); bizObjects[i]["Remark"] = dr["Remark"].ToString(); bizObjects[i]["OldInstanceActivityName"] = dr["OldInstanceActivityName"].ToString(); bizObjects[i]["InstanceActivityName"] = dr["InstanceActivityName"].ToString(); var st = dr["Status"].ToString(); Dictionary <string, string> workItemDic = Common.getWorkItemId(dr["ObjectID"].ToString(), st); foreach (var item in workItemDic) { Console.WriteLine(item.Key + item.Value); if (item.Key.Equals("workItemId")) { bizObjects[i]["WorkItemId"] = item.Value; } } bizObjects[i]["Status"] = st == "2" ? "审批中" : (st == "4" ? "已回退" : ""); i++; } this.ActionContext.InstanceData["GetBackPaymentSubTbl"].Value = bizObjects; } return(base.LoadDataFields()); }
/// <summary> /// Clone with your own gladiator /// </summary> private static bool BreedWithMy(byte[] sender, BigInteger motherId, BigInteger fatherId) { if (!Runtime.CheckWitness(sender)) { return(false); } byte[] senderBalanceKey = Keys.UserBalanceKey(sender); BigInteger senderBalance = Storage.Get(Storage.CurrentContext, senderBalanceKey).AsBigInteger(); var fee = ContractMain.MinTxFee; if (senderBalance < fee) { return(false); } // Start cloning object[] args = new object[] { sender, motherId, fatherId }; bool appCallSuccess = (bool)ContractMain.NftContractCall("breedWithMy_app", args); if (appCallSuccess) { senderBalance -= fee; Storage.Put(Storage.CurrentContext, senderBalanceKey, senderBalance); DecreaseCGasBalance(fee); var nowtime = Blockchain.GetHeader(Blockchain.GetHeight()).Timestamp; Events.RaiseMyClone(sender, motherId, fatherId, fee, nowtime); return(true); } return(false); }
public override MvcViewContext LoadDataFields() { //string flg = ""; var ContractNo = this.ActionContext.InstanceData["ContractNo"].Value; System.Data.DataTable dt = OThinker.H3.Controllers.AppUtility.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteDataTable( "SELECT UpdateNoFlg," + " ApproveFlg," + " OperateFlg," + " CompleteFlg " + " FROM I_ContractStatus where ContractNo = '" + ContractNo + "' " ); if (dt.Rows.Count > 0) { this.ActionContext.InstanceData["UpdateNoFlg"].Value = dt.Rows[0]["UpdateNoFlg"].ToString(); this.ActionContext.InstanceData["ApproveFlg"].Value = dt.Rows[0]["ApproveFlg"].ToString(); this.ActionContext.InstanceData["OperateFlg"].Value = dt.Rows[0]["OperateFlg"].ToString(); this.ActionContext.InstanceData["CompleteFlg"].Value = dt.Rows[0]["CompleteFlg"].ToString(); } ContractMain con = Common.getContractByBizId(this.ActionContext.BizObjectID); this.ActionContext.InstanceData["ContractNo"].Value = con.ContractNo; //if ("4".Equals(flg)) //{ // this.ActionContext.InstanceData["flgapply"].Value = "1"; //} //else //{ // this.ActionContext.InstanceData["flgapply"].Value = "00"; //} // 获取合同主流程状态表数据 // 获取申请修改合同号子流程的版本号 int versionUpdateContractNo = OThinker.H3.Controllers.AppUtility.Engine.WorkflowManager.GetWorkflowDefaultVersion("UpdateContractNo"); this.ActionContext.InstanceData["WorkflowVersion_Update"].Value = versionUpdateContractNo; this.ActionContext.InstanceData.Submit(); return(base.LoadDataFields()); }
// 传入id或者ContractNo public static ContractMain getContractByBizId(string id) { // 国内合同 ContractMain con = new ContractMain(); System.Data.DataTable dt = OThinker.H3.Controllers.AppUtility.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteDataTable( " SELECT * FROM I_ContractMain con" + " where con.ObjectID = '" + id + "' or con.ContractNo = '" + id + "'"); if (dt.Rows.Count > 0) { con.ContractNo = dt.Rows[0]["ContractNo"].ToString(); con.ContractTotalPrice = dt.Rows[0]["ContractTotalPrice"].ToString(); con.JKTotalAmount = dt.Rows[0]["JKTotalAmount"].ToString(); con.ContractDHDate = dt.Rows[0]["ContractDHDate"].ToString(); con.AgencyComputerNum = dt.Rows[0]["AgencyComputerNum"].ToString(); con.PayCondition = dt.Rows[0]["PayCondition"].ToString(); con.Currency = dt.Rows[0]["Currency"].ToString(); } return(con); }
/// <summary> /// Buy auction clones /// </summary> private static bool CloneOnAuction(byte[] sender, BigInteger motherId, BigInteger fatherId) { if (!Runtime.CheckWitness(sender)) { return(false); } object[] rawFatherAuction = DataAccess.GetAuctionAsObjects(fatherId.AsByteArray()); if (rawFatherAuction.Length > 0) { MarketAuction fatherAuction = (MarketAuction)(object)rawFatherAuction; byte[] owner = fatherAuction.Owner; if (fatherAuction.SellType == 1) { byte[] senderBalanceKey = Keys.UserBalanceKey(sender); var nowtime = Blockchain.GetHeader(Blockchain.GetHeight()).Timestamp; var secondPass = nowtime - fatherAuction.SellTime; //var secondPass = (nowtime - fatherInfo.sellTime) / 1000; BigInteger senderBalance = Storage.Get(Storage.CurrentContext, senderBalanceKey).AsBigInteger(); BigInteger currentBuyPrice = ComputeCurrentPrice( fatherAuction.BeginPrice, fatherAuction.EndPrice, fatherAuction.Duration, secondPass); var fee = currentBuyPrice * 199 / 10000; if (fee < ContractMain.MinTxFee) { fee = ContractMain.MinTxFee; } if (currentBuyPrice < fee) { currentBuyPrice = fee; } if (senderBalance < currentBuyPrice) { return(false); } object[] args = new object[] { sender, motherId, fatherId }; bool appCallSuccess = (bool)ContractMain.NftContractCall("bidOnClone_app", args); if (!appCallSuccess) { return(false); } Storage.Put(Storage.CurrentContext, senderBalanceKey, senderBalance - currentBuyPrice); currentBuyPrice -= fee; DecreaseCGasBalance(fee); BigInteger newBalance = 0; byte[] ownerBalanceKey = Keys.UserBalanceKey(owner); byte[] sellerBalance = Storage.Get(Storage.CurrentContext, ownerBalanceKey); if (sellerBalance.Length > 0) { newBalance = sellerBalance.AsBigInteger(); } newBalance = newBalance + currentBuyPrice; Storage.Put(Storage.CurrentContext, ownerBalanceKey, newBalance); //// Do not delete the auction record //Storage.Delete(Storage.CurrentContext, tokenId.AsByteArray()); // transaction record /*AuctionRecord record = new AuctionRecord(); * record.tokenId = fatherGlaId; * record.seller = owner; * record.buyer = sender; * record.sellType = 1; * record.sellPrice = curBuyPrice + fee; * record.sellTime = nowtime; * * _putAuctionRecord(fatherGlaId.AsByteArray(), record);*/ Events.RaiseAuctionClone(sender, motherId, fatherId, currentBuyPrice, fee, nowtime); return(true); } } return(false); }
/// <summary> /// Buy from the auction house, put the money under the contract name, and give the goods to the buyer. /// </summary> private static bool BuyOnAuction(byte[] sender, BigInteger tokenId) { if (!Runtime.CheckWitness(sender)) { return(false); } object[] rawAuction = DataAccess.GetAuctionAsObjects(tokenId.AsByteArray()); if (rawAuction.Length > 0) { MarketAuction info = (MarketAuction)(object)rawAuction; var nowtime = Blockchain.GetHeader(Blockchain.GetHeight()).Timestamp; var secondPass = nowtime - info.SellTime; //var secondPass = (nowtime - info.sellTime) / 1000; byte[] senderBalanceKey = Keys.UserBalanceKey(sender); byte[] ownerBalanceKey = Keys.UserBalanceKey(info.Owner); BigInteger senderBalance = Storage.Get(Storage.CurrentContext, senderBalanceKey).AsBigInteger(); BigInteger currentPrice = ComputeCurrentPrice(info.BeginPrice, info.EndPrice, info.Duration, secondPass); var fee = currentPrice * 199 / 10000; if (fee < ContractMain.MinTxFee) { fee = ContractMain.MinTxFee; } if (currentPrice < fee) { currentPrice = fee; } if (senderBalance < currentPrice) { // Not enough money return(false); } object[] args = new object[] { ExecutionEngine.ExecutingScriptHash, sender, tokenId }; bool appCallSuccess = (bool)ContractMain.NftContractCall("transfer_app", args); if (!appCallSuccess) { return(false); } Storage.Put(Storage.CurrentContext, senderBalanceKey, senderBalance - currentPrice); BigInteger sellPrice = currentPrice - fee; DecreaseCGasBalance(fee); // The money is in the name of the seller/ BigInteger newBalance = 0; byte[] sellerBalance = Storage.Get(Storage.CurrentContext, ownerBalanceKey); if (sellerBalance.Length > 0) { newBalance = sellerBalance.AsBigInteger(); } newBalance = newBalance + sellPrice; Storage.Put(Storage.CurrentContext, ownerBalanceKey, newBalance); Storage.Delete(Storage.CurrentContext, tokenId.AsByteArray()); // transaction record /*AuctionRecord record = new AuctionRecord(); * record.tokenId = tokenId; * record.seller = owner; * record.buyer = sender; * record.sellType = 0; * record.sellPrice = curBuyPrice; * record.sellTime = nowtime; * * _putAuctionRecord(tokenId.AsByteArray(), record); * * if(owner == ContractOwner) * { * Gene0Record gene0Record; * byte[] v = (byte[])Storage.Get(Storage.CurrentContext, "gene0Record"); * if(v.Length==0) * { * gene0Record = new Gene0Record(); * } * else * { * object[] infoRec = (object[])Helper.Deserialize(v); * gene0Record = (Gene0Record)(object)infoRec; * } * int idx = (int)gene0Record.totalSellCount % 5; * if (idx == 0) * { * gene0Record.lastPrice0 = curBuyPrice; * } * else if (idx == 1) * { * gene0Record.lastPrice1 = curBuyPrice; * } * else if (idx == 2) * { * gene0Record.lastPrice1 = curBuyPrice; * } * else if (idx == 3) * { * gene0Record.lastPrice1 = curBuyPrice; * } * else if (idx == 4) * { * gene0Record.lastPrice1 = curBuyPrice; * } * * gene0Record.totalSellCount += 1; * * // * byte[] infoRec2 = Helper.Serialize(gene0Record); * Storage.Put(Storage.CurrentContext, "gene0Record", infoRec2); * }*/ Events.RaiseAuctionBuy(sender, tokenId, currentPrice, fee, nowtime); return(true); } return(false); }