/// <summary> /// 获取投票结果详情 /// </summary> /// <returns></returns> public ActionResult VoteResult() { int id = GetRouteInt("id"); if (id == 0) { id = WebHelper.GetQueryInt("id"); } VoteInfo voteInfo = Vote.GetVote(id); if (voteInfo == null) { return(PromptView("/", "您访问的页面不存在")); } List <VoteResultInfo> voteResultInfo = Vote.GetVoteResultsList(id); VoteResultModel model = new VoteResultModel { ResultsList = voteResultInfo, Id = voteInfo.Id, Title = voteInfo.Title, State = voteInfo.State, Type = voteInfo.Type }; return(View(model)); }
public ActionResult AddVoteResult(int voteID = -1) { VoteResultModel model = new VoteResultModel { VoteId = voteID }; return(View(model)); }
public ActionResult AddVoteResult(VoteResultModel model) { if (ModelState.IsValid) { VoteResultInfo voteResultInfo = new VoteResultInfo { VoteId = model.VoteId, DisplayOrder = model.DisplayOrder, Result = model.Result, Count = model.Count }; Vote.CreateVoteResults(voteResultInfo); return(PromptView("投票选项添加成功")); } ViewData["referer"] = SiteUtils.GetAdminRefererCookie(); return(View(model)); }
public ActionResult EditVoteResult(int Id = -1, int resultId = -1) { VoteResultInfo voteResultInfo = Vote.GetVoteResult(resultId); if (voteResultInfo == null) { return(PromptView("投票结果不存在")); } VoteResultModel model = new VoteResultModel { VoteId = voteResultInfo.VoteId, DisplayOrder = voteResultInfo.DisplayOrder, Result = voteResultInfo.Result, Count = voteResultInfo.Count }; return(View(model)); }
/// <summary> /// vote for consensus node /// </summary> /// <returns></returns> public async Task <object> VoteCN(UInt160 account, string[] pubkeys) { if (CurrentWallet == null) { return(Error(ErrorCode.WalletNotOpen)); } if (account == null || pubkeys.IsEmpty()) { return(Error(ErrorCode.ParameterIsNull)); } ECPoint[] publicKeys = null; try { publicKeys = pubkeys.Select(p => ECPoint.Parse(p, ECCurve.Secp256r1)).ToArray(); } catch (Exception e) { return(Error(ErrorCode.InvalidPara)); } using ScriptBuilder sb = new ScriptBuilder(); sb.EmitAppCall(NativeContract.NEO.Hash, "vote", new ContractParameter { Type = ContractParameterType.Hash160, Value = account }, new ContractParameter { Type = ContractParameterType.Array, Value = publicKeys.Select(p => new ContractParameter { Type = ContractParameterType.PublicKey, Value = p }).ToArray() }); Transaction tx = null; try { tx = CurrentWallet.InitTransaction(sb.ToArray(), account); } catch (InvalidOperationException) { return(Error(ErrorCode.EngineFault)); } catch (Exception ex) { if (ex.Message.Contains("Insufficient GAS")) { return(Error(ErrorCode.GasNotEnough)); } throw; } var(signSuccess, context) = CurrentWallet.TrySignTx(tx); if (!signSuccess) { return(Error(ErrorCode.SignFail, context.SafeSerialize())); } var result = new VoteResultModel(); await tx.Broadcast(); result.TxId = tx.Hash; return(result); }
/// <summary> /// apply for new validator /// </summary> /// <param name="pubkey"></param> /// <returns></returns> public async Task <object> ApplyForValidator(string pubkey) { if (CurrentWallet == null) { return(Error(ErrorCode.WalletNotOpen)); } if (pubkey.IsNull()) { return(Error(ErrorCode.ParameterIsNull)); } ECPoint publicKey = null; try { publicKey = ECPoint.Parse(pubkey, ECCurve.Secp256r1); } catch (Exception e) { return(Error(ErrorCode.InvalidPara)); } using var snapshot = Blockchain.Singleton.GetSnapshot(); var validators = NativeContract.NEO.GetRegisteredValidators(snapshot); if (validators.Any(v => v.PublicKey.ToString() == pubkey)) { return(Error(ErrorCode.ValidatorAlreadyExist)); } VerificationContract contract = new VerificationContract { Script = SmartContract.Contract.CreateSignatureRedeemScript(publicKey), ParameterList = new[] { ContractParameterType.Signature } }; var account = contract.ScriptHash; using ScriptBuilder sb = new ScriptBuilder(); sb.EmitAppCall(NativeContract.NEO.Hash, "registerValidator", publicKey); Transaction tx = null; try { tx = CurrentWallet.InitTransaction(sb.ToArray(), account); } catch (InvalidOperationException) { return(Error(ErrorCode.EngineFault)); } catch (Exception ex) { if (ex.Message.Contains("Insufficient GAS")) { return(Error(ErrorCode.GasNotEnough)); } throw; } var(signSuccess, context) = CurrentWallet.TrySignTx(tx); if (!signSuccess) { return(Error(ErrorCode.SignFail, context.SafeSerialize())); } var result = new VoteResultModel(); await tx.Broadcast(); result.TxId = tx.Hash; return(result); }