public async Task CanGetLedger()
        {
            var request = new LedgerRequest {
                LedgerIndex = new LedgerIndex(LedgerIndexType.Validated), Transactions = true, Expand = true, Binary = true
            };

            var ledger = await client.Ledger(request);

            Assert.IsNotNull(ledger);
        }
Ejemplo n.º 2
0
        public Task <Ledger> Ledger(LedgerRequest request)
        {
            var command = JsonConvert.SerializeObject(request, serializerSettings);
            TaskCompletionSource <Ledger> task = new TaskCompletionSource <Ledger>();

            TaskInfo taskInfo = new TaskInfo();

            taskInfo.TaskId = request.Id;
            taskInfo.TaskCompletionResult = task;
            taskInfo.Type = typeof(Ledger);

            tasks.TryAdd(request.Id, taskInfo);

            client.SendMessage(command);
            return(task.Task);
        }
Ejemplo n.º 3
0
        public async Task <ParticipantResponse> UpdateParticipantLedger(Guid userId, LedgerRequest request)
        {
            var participant = await _participantRepo.Get(userId, request.GoalId);

            participant.EnsureExists("User not in competition.");

            //verify ledger is of correct type
            foreach (var item in request.Ledger)
            {
                if (item != null && item.GetType() != typeof(Decimal))
                {
                    throw new ApiError(400, "Invalid inputs.");
                }
            }

            participant.Ledger = JsonSerializer.Serialize(request.Ledger);
            _participantRepo.Update(participant);
            await _participantRepo.Save();

            return(new ParticipantResponse(participant));
        }
Ejemplo n.º 4
0
        public async Task <GoalResponse> UpdateGoalLedger(Guid userId, LedgerRequest request)
        {
            var goal = await _goalRepo.Get(request.GoalId);

            goal.EnsureExists("Goal not found.");
            VerifyUserOwnsGoal(userId, goal);

            // //verify ledger is of correct type
            foreach (var item in request.Ledger)
            {
                if (item != null && item.GetType() != typeof(Decimal))
                {
                    throw new ApiError(400, "Invalid inputs.");
                }
            }

            goal.Ledger = JsonSerializer.Serialize(request.Ledger);
            _goalRepo.Update(goal);
            await _goalRepo.Save();

            return(new GoalResponse(goal));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Retrieve information about the public ledger.
        /// </summary>
        public async Task <LedgerResponse> Ledger(LedgerRequest request, CancellationToken cancellationToken = default)
        {
            jsonBuffer.Clear();
            jsonWriter.Reset();
            jsonWriter.WriteStartObject();
            var requestId = WriteHeader(jsonWriter, "ledger");

            LedgerSpecification.Write(jsonWriter, request.Ledger);
            jsonWriter.WriteBoolean("binary", true);
            jsonWriter.WriteBoolean("full", request.Full);
            jsonWriter.WriteBoolean("accounts", request.Accounts);
            jsonWriter.WriteBoolean("transactions", request.Transactions);
            jsonWriter.WriteBoolean("expand", request.Expand);
            jsonWriter.WriteBoolean("owner_funds", request.OwnerFunds);
            jsonWriter.WriteBoolean("queue", request.Queue);
            WriteFooter(jsonWriter);
            jsonWriter.WriteEndObject();
            jsonWriter.Flush();
            var response = await SendReceiveAsync(requestId, jsonBuffer.WrittenMemory, cancellationToken);

            return(new LedgerResponse(response));
        }
Ejemplo n.º 6
0
        public void CallLedger()
        {
            // Arrange
            var request = new LedgerRequest();

            request.Params.Add(new LedgerRequestParams
            {
                LedgerIndex  = LedgerIndex.Validated.ToLower(),
                Accounts     = false,
                Full         = false,
                Transactions = true,
                Expand       = false,
                OwnerFunds   = false
            });

            // Act
            var response =
                _client.Ledger.LedgerAsync(request).Result;

            // Assert
            Assert.AreEqual(Status.Success, response.Result.Status);
        }
Ejemplo n.º 7
0
 public async Task <RpcJsonResponse <LedgerResult> > LedgerAsync(LedgerRequest request)
 {
     return(await PostAsync <RpcJsonResponse <LedgerResult>, LedgerResult>(request));
 }
 public async Task <ActionResult <GoalResponse> > UpdateGoalLedger(LedgerRequest request)
 {
     return(Ok(await _goalService.UpdateGoalLedger(UserId, request)));
 }