Пример #1
0
        protected static void AddCyptoToBalanceFromExternal(string walletAddress, string walletKey = null)
        {
            var api  = new BlockchainApi(BlockchainApi);
            var sign = new BlockchainSign(_currentSettings.Value.BlockchainSign);

            var transferSupported = api.Capabilities.GetCapabilities().GetResponseObject().IsTestingTransfersSupported;
            var recieveSupport    = api.Capabilities.GetCapabilities().GetResponseObject().IsReceiveTransactionRequired;

            if (transferSupported != null && transferSupported.Value)
            {
                api.Balances.PostBalances(walletAddress);
                TestingTransferRequest request = new TestingTransferRequest()
                {
                    amount = AMOUT_WITH_FEE, assetId = ASSET_ID, fromAddress = EXTERNAL_WALLET, fromPrivateKey = EXTERNAL_WALLET_KEY, toAddress = walletAddress
                };
                var response = api.Testing.PostTestingTransfer(request);
            }
            else if (BlockChainName == "RaiBlocks" || (recieveSupport != null && recieveSupport.Value))  //raiblocks - temp. will be removed after capablities enabled
            {
                AddCryptoToWalletWithRecieveTransaction(walletAddress, walletKey);
            }
            else
            {
                api.Balances.PostBalances(walletAddress);
                var model = new BuildSingleTransactionRequest()
                {
                    Amount             = AMOUT_WITH_FEE,
                    AssetId            = ASSET_ID,
                    FromAddress        = EXTERNAL_WALLET,
                    IncludeFee         = false,
                    OperationId        = Guid.NewGuid(),
                    ToAddress          = walletAddress,
                    FromAddressContext = EXTERNAL_WALLET_ADDRESS_CONTEXT
                };

                var    responseTransaction = api.Operations.PostTransactions(model).GetResponseObject();
                string operationId         = model.OperationId.ToString();

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

                var response = api.Operations.PostTransactionsBroadcast(new BroadcastTransactionRequest()
                {
                    OperationId = model.OperationId, SignedTransaction = signResponse.SignedTransaction
                });

                var getResponse = api.Operations.GetOperationId(operationId);
                WaitForOperationGotCompleteStatus(operationId);
            }
            WaitForBalance(walletAddress);
        }
Пример #2
0
        protected static void AddCyptoToBalanceFromExternal(string walletAddress)
        {
            var api  = new BlockchainApi(BlockchainApi);
            var sign = new BlockchainSign(_currentSettings.Value.BlockchainSign);

            bool transferSupported = api.Capabilities.GetCapabilities().GetResponseObject().IsTestingTransfersSupported;

            if (transferSupported)
            {
                api.Balances.PostBalances(EXTERNAL_WALLET);
                api.Balances.PostBalances(walletAddress);
                TestingTransferRequest request = new TestingTransferRequest()
                {
                    amount = "100001", assetId = ASSET_ID, fromAddress = EXTERNAL_WALLET, fromPrivateKey = EXTERNAL_WALLET_KEY, toAddress = walletAddress
                };
                var response = api.Testing.PostTestingTransfer(request);
            }
            else
            {
                api.Balances.PostBalances(walletAddress);
                var model = new BuildSingleTransactionRequest()
                {
                    Amount             = "100001",
                    AssetId            = ASSET_ID,
                    FromAddress        = EXTERNAL_WALLET,
                    IncludeFee         = false,
                    OperationId        = Guid.NewGuid(),
                    ToAddress          = walletAddress,
                    FromAddressContext = EXTERNAL_WALLET_ADDRESS_CONTEXT
                };

                var    responseTransaction = api.Operations.PostTransactions(model).GetResponseObject();
                string operationId         = model.OperationId.ToString("N");

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

                var response = api.Operations.PostTransactionsBroadcast(new BroadcastTransactionRequest()
                {
                    OperationId = model.OperationId, SignedTransaction = signResponse.SignedTransaction
                });

                var getResponse = api.Operations.GetOperationId(operationId);
                // response.Validate.StatusCode(HttpStatusCode.OK, "Could not update Balance from external wallet");
                Assert.That(getResponse.GetResponseObject().OperationId, Is.EqualTo(model.OperationId));
            }
        }
Пример #3
0
            public void EWDWTransferTest()
            {
                Assert.That(EXTERNAL_WALLET, Is.Not.Null.Or.Empty, "External wallet address and key are empty!");

                bool transferSupported = blockchainApi.Capabilities.GetCapabilities().GetResponseObject().IsTestingTransfersSupported;

                if (transferSupported)
                {
                    blockchainApi.Balances.PostBalances(EXTERNAL_WALLET);
                    var balanceBefore = blockchainApi.Balances.GetBalances("1000", null).GetResponseObject().
                                        Items.First(w => w.Address == EXTERNAL_WALLET).Balance;
                    TestingTransferRequest request = new TestingTransferRequest()
                    {
                        amount = "100001", assetId = ASSET_ID, fromAddress = EXTERNAL_WALLET, fromPrivateKey = EXTERNAL_WALLET_KEY, toAddress = WALLET_ADDRESS
                    };
                    var response = blockchainApi.Testing.PostTestingTransfer(request);
                    Assert.That(() => long.Parse(blockchainApi.Balances.GetBalances("1000", null).GetResponseObject().
                                                 Items.First(w => w.Address == EXTERNAL_WALLET).Balance), Is.GreaterThan(long.Parse(balanceBefore)).After(5 * 60 * 1000, 1 * 1000), "Balance after 5 minute after transaction not greater then berfore transaction");
                }
                else
                {
                    var model = new BuildSingleTransactionRequest()
                    {
                        Amount      = "100001",
                        AssetId     = ASSET_ID,
                        FromAddress = EXTERNAL_WALLET,
                        IncludeFee  = false,
                        OperationId = Guid.NewGuid(),
                        ToAddress   = WALLET_ADDRESS
                    };

                    var    responseTransaction = blockchainApi.Operations.PostTransactions(model).GetResponseObject();
                    string operationId         = model.OperationId.ToString("N");

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

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

                    var getResponse = blockchainApi.Operations.GetOperationId(operationId);
                    response.Validate.StatusCode(HttpStatusCode.OK);
                    Assert.That(getResponse.GetResponseObject().OperationId, Is.EqualTo(model.OperationId));
                }
            }
            public void EWDWTransferTest()
            {
                Assert.That(EXTERNAL_WALLET, Is.Not.Null.Or.Empty, "External wallet address and key are empty!");

                blockchainApi.Balances.PostBalances(wallet.PublicAddress);

                var transferSupported = blockchainApi.Capabilities.GetCapabilities().GetResponseObject().IsTestingTransfersSupported;

                if (transferSupported != null && transferSupported.Value)
                {
                    TestingTransferRequest request = new TestingTransferRequest()
                    {
                        amount = AMOUNT, assetId = ASSET_ID, fromAddress = EXTERNAL_WALLET, fromPrivateKey = EXTERNAL_WALLET_KEY, toAddress = wallet.PublicAddress
                    };
                    var response = blockchainApi.Testing.PostTestingTransfer(request);
                }
                else
                {
                    var model = new BuildSingleTransactionRequest()
                    {
                        Amount             = AMOUNT,
                        AssetId            = ASSET_ID,
                        FromAddress        = EXTERNAL_WALLET,
                        IncludeFee         = false,
                        OperationId        = Guid.NewGuid(),
                        ToAddress          = wallet.PublicAddress,
                        FromAddressContext = EXTERNAL_WALLET_ADDRESS_CONTEXT
                    };

                    var    responseTransaction = blockchainApi.Operations.PostTransactions(model).GetResponseObject();
                    string operationId         = model.OperationId.ToString();

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

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

                    var getResponse = blockchainApi.Operations.GetOperationId(operationId);
                    response.Validate.StatusCode(HttpStatusCode.OK);
                    Assert.That(getResponse.GetResponseObject().OperationId, Is.EqualTo(model.OperationId));
                }
            }
Пример #5
0
        public async Task <ActionResult> Transfer(TestingTransferRequest request)
        {
            var caps = _api.GetCapabilities();

            if (!caps.IsTestingTransfersSupported.HasValue ||
                !caps.IsTestingTransfersSupported.Value)
            {
                return(StatusCode(501));
            }

            var asset = await _assets.GetAsync(request.AssetId);

            if (asset == null)
            {
                return(BadRequest(BlockchainErrorResponse.Create("Unknown asset")));
            }

            var amount = 0M;

            try
            {
                amount = Conversions.CoinsFromContract(request.Amount, asset.Accuracy);
            }
            catch (ConversionException)
            {
                return(BadRequest(BlockchainErrorResponse.Create("Invalid amount format")));
            }

            if (amount < 0 || !_api.AddressIsValid(request.FromAddress) || !_api.AddressIsValid(request.ToAddress))
            {
                return(BadRequest(BlockchainErrorResponse.Create("Invalid address(es) and/or negative amount")));
            }

            var result = await _api.TestingTransfer(
                request.FromAddress,
                request.FromPrivateKey,
                request.ToAddress,
                asset,
                amount);

            return(Ok(result));
        }
Пример #6
0
        protected void AddCyptoToBalanceFromExternal(string walletAddress, string walletKey = null, bool wait = true)
        {
            var transferSupported = blockchainApi.Capabilities.GetCapabilities().GetResponseObject().IsTestingTransfersSupported;
            var recieveSupport    = blockchainApi.Capabilities.GetCapabilities().GetResponseObject().IsReceiveTransactionRequired;

            if (transferSupported != null && transferSupported.Value)
            {
                blockchainApi.Balances.PostBalances(walletAddress);
                TestingTransferRequest request = new TestingTransferRequest()
                {
                    amount = AMOUT_WITH_FEE, assetId = ASSET_ID, fromAddress = EXTERNAL_WALLET, fromPrivateKey = EXTERNAL_WALLET_KEY, toAddress = walletAddress
                };
                var response = blockchainApi.Testing.PostTestingTransfer(request);
            }
            else if (BlockChainName == "RaiBlocks" || (recieveSupport != null && recieveSupport.Value))  //raiblocks - temp. will be removed after capablities enabled
            {
                AddCryptoToWalletWithRecieveTransaction(walletAddress, walletKey, wait);
            }
            else
            {
                blockchainApi.Balances.PostBalances(walletAddress);
                var model = new BuildSingleTransactionRequest()
                {
                    Amount             = AMOUT_WITH_FEE,
                    AssetId            = ASSET_ID,
                    FromAddress        = EXTERNAL_WALLET,
                    IncludeFee         = false,
                    OperationId        = Guid.NewGuid(),
                    ToAddress          = walletAddress,
                    FromAddressContext = EXTERNAL_WALLET_ADDRESS_CONTEXT
                };

                int i = 1;
                BuildTransactionResponse responseTransaction = new BuildTransactionResponse()
                {
                    TransactionContext = null
                };

                while (i < 6)
                {
                    var singleTransactionResponse = blockchainApi.Operations.PostTransactions(model);
                    if (singleTransactionResponse.StatusCode == HttpStatusCode.OK)
                    {
                        responseTransaction = singleTransactionResponse.GetResponseObject();
                        break;
                    }
                    System.Threading.Thread.Sleep(TimeSpan.FromSeconds((int)(Math.Pow(3, i))));
                    i++;
                }

                Assert.That(responseTransaction.TransactionContext, Is.Not.Null, "Transaction context is null");
                string operationId = model.OperationId.ToString();

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

                Assert.That(signResponse.SignedTransaction, Is.Not.Null, "Signed transaction is null");

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

                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));

                var getResponse = blockchainApi.Operations.GetOperationId(operationId);

                if (wait)
                {
                    WaitForOperationGotCompleteStatus(operationId);
                }
            }
            if (wait)
            {
                WaitForBalance(walletAddress);
            }
        }
Пример #7
0
 public IResponse PostTestingTransfer(TestingTransferRequest request)
 {
     return(Request.Post("/testing/transfers").AddJsonBody(request).Build().Execute());
 }
Пример #8
0
 public ActionResult Transfer(
     [FromBody] TestingTransferRequest request)
 => StatusCode(StatusCodes.Status501NotImplemented);
 public IActionResult Transfers([Required, FromBody] TestingTransferRequest request)
 {
     return(new StatusCodeResult(StatusCodes.Status501NotImplemented));
 }