Exemple #1
0
        public override async Task <OperationResult <VoteResponse> > Vote(VoteModel model, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                if (!TryReconnectChain(ct))
                {
                    return new OperationResult <VoteResponse>(new AppError(LocalizationKeys.EnableConnectToBlockchain));
                }

                var keys = ToKeyArr(model.PostingKey);
                if (keys == null)
                {
                    return new OperationResult <VoteResponse>(new AppError(LocalizationKeys.WrongPrivatePostingKey));
                }

                short weigth = 0;
                if (model.Type == VoteType.Up)
                {
                    weigth = 10000;
                }
                if (model.Type == VoteType.Flag)
                {
                    weigth = -10000;
                }

                var op = new VoteOperation(model.Login, model.Author, model.Permlink, weigth);
                var resp = _operationManager.BroadcastOperationsSynchronous(keys, ct, op);

                var result = new OperationResult <VoteResponse>();
                if (!resp.IsError)
                {
                    var dt = DateTime.Now;
                    var content = _operationManager.GetContent(model.Author, model.Permlink, ct);
                    if (!content.IsError)
                    {
                        //Convert Asset type to double
                        result.Result = new VoteResponse(true)
                        {
                            NewTotalPayoutReward = GbgKof * (content.Result.TotalPayoutValue + content.Result.CuratorPayoutValue + content.Result.PendingPayoutValue).ToDouble(),
                            NetVotes = content.Result.NetVotes,
                            VoteTime = dt
                        };
                    }
                }
                else
                {
                    OnError(resp, result);
                }
                return result;
            }, ct));
        }
Exemple #2
0
        public override async Task <OperationResult <VoidResponse> > Vote(VoteModel model, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                if (!TryReconnectChain(ct))
                {
                    return new OperationResult <VoidResponse>(new AppError(LocalizationKeys.EnableConnectToBlockchain));
                }

                var keys = ToKeyArr(model.PostingKey);
                if (keys == null)
                {
                    return new OperationResult <VoidResponse>(new AppError(LocalizationKeys.WrongPrivatePostingKey));
                }

                short weigth = 0;
                if (model.Type == VoteType.Up)
                {
                    weigth = (short)(AppSettings.User.VotePower * 100);
                }
                if (model.Type == VoteType.Flag)
                {
                    weigth = -10000;
                }

                var op = new VoteOperation(model.Login, model.Author, model.Permlink, weigth);
                var resp = _operationManager.BroadcastOperationsSynchronous(keys, ct, op);

                var result = new OperationResult <VoidResponse>();
                if (!resp.IsError)
                {
                    result.Result = new VoidResponse();
                }
                else
                {
                    OnError(resp, result);
                }

                return result;
            }, ct));
        }
Exemple #3
0
        public override async Task <OperationResult <VoidResponse> > Vote(VoteModel model, CancellationToken ct)
        {
            var isConnected = await TryReconnectChain(ct);

            if (!isConnected)
            {
                return(new OperationResult <VoidResponse>(new ValidationException(LocalizationKeys.EnableConnectToBlockchain)));
            }

            var keys = ToKeyArr(model.PostingKey);

            if (keys == null)
            {
                return(new OperationResult <VoidResponse>(new ValidationException(LocalizationKeys.WrongPrivatePostingKey)));
            }

            short weigth = 0;

            if (model.Type == VoteType.Up)
            {
                weigth = 10000;
            }
            if (model.Type == VoteType.Flag)
            {
                weigth = -10000;
            }

            var op   = new VoteOperation(model.Login, model.Author, model.Permlink, weigth);
            var resp = await _operationManager.BroadcastOperationsSynchronous(keys, ct, op);

            var result = new OperationResult <VoidResponse>();

            if (resp.IsError)
            {
                result.Exception = new RequestException(resp);
            }
            else
            {
                result.Result = new VoidResponse();
            }

            return(result);
        }