Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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));
            }
        }
Ejemplo n.º 4
0
        protected static void AddCryptoToWalletWithRecieveTransaction(string walletAddress, string walletKey)
        {
            var api  = new BlockchainApi(BlockchainApi);
            var sign = new BlockchainSign(_currentSettings.Value.BlockchainSign);

            //build send transaction
            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
            });

            // wait for wallet present in history

            var history = api.Operations.GetTransactionHistorToAddress(walletAddress, "500").GetResponseObject();

            int i = 0;

            while (i++ < 150 && api.Operations.GetTransactionHistorToAddress(walletAddress, "500").GetResponseObject().Length == 0)
            {
                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(2));
            }

            history = api.Operations.GetTransactionHistorToAddress(walletAddress, "500").GetResponseObject();
            //BuildSingleReceiveTransactionRequest recieve transaction

            var reciveModel = new BuildSingleReceiveTransactionRequest()
            {
                operationId = Guid.NewGuid(), sendTransactionHash = history.ToList().First().hash
            };
            var recieve            = api.Operations.PostTranstactionSingleRecieve(reciveModel).GetResponseObject();
            var signReciveResponse = sign.PostSign(new SignRequest()
            {
                PrivateKeys = new List <string>()
                {
                    walletKey
                }, TransactionContext = recieve.transactionContext
            }).GetResponseObject();

            var responseRecieve = api.Operations.PostTransactionsBroadcast(new BroadcastTransactionRequest()
            {
                OperationId = reciveModel.operationId, SignedTransaction = signReciveResponse.SignedTransaction
            });

            WaitForBalance(walletAddress);
        }