public void GetTransactionsManyOutputsTest()
            {
                var run = blockchainApi.Capabilities.GetCapabilities().GetResponseObject().AreManyOutputsSupported;

                if (!run.Value)
                {
                    Assert.Ignore("Many outputs are not supported by blockchain");
                }

                AddCyptoToBalanceFromExternal(wallet.PublicAddress, wallet.PrivateKey);

                var model = new BuildSingleTransactionRequest()
                {
                    Amount             = AMOUNT,
                    AssetId            = ASSET_ID,
                    FromAddress        = wallet.PublicAddress,
                    IncludeFee         = false,
                    OperationId        = Guid.NewGuid(),
                    ToAddress          = HOT_WALLET,
                    FromAddressContext = wallet.AddressContext
                };

                var request = new BuildTransactionWithManyOutputsRequest()
                {
                    AssetId     = ASSET_ID,
                    OperationId = model.OperationId,
                    FromAddress = wallet.PublicAddress,
                    Outputs     = new List <TransactionOutputContract>()
                    {
                        new TransactionOutputContract()
                        {
                            Amount = AMOUNT, ToAddress = HOT_WALLET
                        }
                    }
                };

                var response = blockchainApi.Operations.PostTransactionsManyOutputs(request);

                response.Validate.StatusCode(HttpStatusCode.OK);

                var signResponse = blockchainSign.PostSign(new SignRequest()
                {
                    TransactionContext = response.GetResponseObject().TransactionContext, PrivateKeys = new List <string>()
                    {
                        wallet.PrivateKey
                    }
                });

                var broadcastRequset = new BroadcastTransactionRequest()
                {
                    OperationId = model.OperationId, SignedTransaction = signResponse.GetResponseObject().SignedTransaction
                };
                var broadcatedResponse = blockchainApi.Operations.PostTransactionsBroadcast(broadcastRequset);

                var getResponse = blockchainApi.Operations.GetTransactionsManyOutputs(model.OperationId.ToString());

                getResponse.Validate.StatusCode(HttpStatusCode.OK);
            }
Exemplo n.º 2
0
        private bool SetBalanceWIthManyOutputs(List <WalletCreationResponse> wallets)
        {
            var run = blockchainApi.Capabilities.GetCapabilities().GetResponseObject().AreManyOutputsSupported;

            if (run == null || !run.Value)
            {
                return(false);
            }

            List <TransactionOutputContract> transactions = new List <TransactionOutputContract>();

            wallets.ForEach(w => transactions.Add(new TransactionOutputContract()
            {
                Amount = AMOUT_WITH_FEE, ToAddress = w.PublicAddress
            }));
            var request = new BuildTransactionWithManyOutputsRequest()
            {
                AssetId     = ASSET_ID,
                OperationId = Guid.NewGuid(),
                FromAddress = EXTERNAL_WALLET,
                Outputs     = transactions
            };

            wallets.ForEach(w =>
                            blockchainApi.Balances.PostBalances(w.PublicAddress));

            var response = blockchainApi.Operations.PostTransactionsManyOutputs(request);

            response.Validate.StatusCode(HttpStatusCode.OK);

            var signResponse = blockchainSign.PostSign(new SignRequest()
            {
                TransactionContext = response.GetResponseObject().TransactionContext, PrivateKeys = new List <string>()
                {
                    EXTERNAL_WALLET_KEY
                }
            });

            var broadcastRequset = new BroadcastTransactionRequest()
            {
                OperationId = request.OperationId, SignedTransaction = signResponse.GetResponseObject().SignedTransaction
            };
            var broadcatedResponse = blockchainApi.Operations.PostTransactionsBroadcast(broadcastRequset);

            WaitForBalance(wallets[0].PublicAddress);

            return(true);
        }
 public ActionResult Build(
     [FromBody] BuildTransactionWithManyOutputsRequest request)
 => StatusCode(StatusCodes.Status501NotImplemented);
Exemplo n.º 4
0
 public IResponse <BuildTransactionResponse> PostTransactionsManyOutputs(BuildTransactionWithManyOutputsRequest model)
 {
     return(Request.Post("/transactions/many-outputs").AddJsonBody(model).Build().Execute <BuildTransactionResponse>());
 }
 public IActionResult BuildManyOutputsTransaction([FromBody] BuildTransactionWithManyOutputsRequest request)
 {
     return(StatusCode((int)HttpStatusCode.NotImplemented));
 }
        public async Task <IActionResult> BuildTransactionManyOutputs([FromBody] BuildTransactionWithManyOutputsRequest request)
        {
            if (request == null)
            {
                throw new ValidationApiException("Unable deserialize request");
            }

            var outputs = request.Outputs.Select(o =>
            {
                var amountSatoshi = MoneyConversionHelper.SatoshiFromContract(o.Amount);
                if (amountSatoshi <= 0)
                {
                    throw new ValidationApiException($"Amount can't be less or equal to zero: {amountSatoshi}");
                }
                return(new OperationOutput
                {
                    Address = o.ToAddress,
                    Amount = amountSatoshi
                });
            }).ToList();

            if (request.AssetId != Constants.Assets.Bitcoin.AssetId)
            {
                throw new ValidationApiException("Invalid assetId");
            }

            if (request.OperationId == Guid.Empty)
            {
                throw new ValidationApiException("Invalid operation id (GUID)");
            }

            if (await _operationEventRepository.ExistAsync(request.OperationId, OperationEventType.Broadcasted))
            {
                return(Conflict());
            }

            BuiltTransactionInfo tx;

            try
            {
                tx = await _operationService.GetOrBuildTransferTransactionAsync(request.OperationId, new List <OperationInput>
                {
                    new OperationInput
                    {
                        Address        = request.FromAddress,
                        AddressContext = request.FromAddressContext?.DeserializeJson <AddressContextContract>()?.PubKey
                    }
                },
                                                                                outputs, OperationType.ManyOutputs, request.AssetId, false);
            }
            catch (NotEnoughFundsException)
            {
                return(BadRequest(BlockchainErrorResponse.FromKnownError(BlockchainErrorCode.NotEnoughBalance)));
            }
            catch (BusinessException e) when(e.Code == ErrorCode.NotEnoughFundsAvailable)
            {
                return(BadRequest(BlockchainErrorResponse.FromKnownError(BlockchainErrorCode.NotEnoughBalance)));
            }

            return(Ok(new BuildTransactionResponse
            {
                TransactionContext = tx.ToJson(_network)
            }));
        }
Exemplo n.º 7
0
 public IActionResult BuildWithManyOutputs([Required, FromBody] BuildTransactionWithManyOutputsRequest request)
 {
     return(new StatusCodeResult(StatusCodes.Status501NotImplemented));
 }