public (string assetId, string address, string addressExtension, double minCashOut) GetBlockchainCashoutData(BlockchainSettings blockchain)
            {
                try
                {
                    var currentAsset = lykkePrivateApi.Assets.GetAssets().GetResponseObject().FirstOrDefault(a =>
                    {
                        if (a.BlockchainIntegrationLayerId != null)
                        {
                            return(a.BlockchainIntegrationLayerId.ToString().ToLower() == blockchain.Type.ToLower());
                        }
                        else
                        {
                            return(false);
                        }
                    });
                    var currentAssetId = currentAsset?.Id;
                    var minCashout     = currentAsset?.CashoutMinimalAmount;

                    blockchain.SignServiceUrl = blockchain.SignServiceUrl.TrimEnd('/');
                    blockchainSign            = new BlockchainSign(blockchain.SignServiceUrl + "/api");
                    WalletCreationResponse wallet = blockchainSign.PostWallet().GetResponseObject();

                    return(currentAssetId, wallet.PublicAddress, wallet.AddressContext, minCashout.Value);
                }
                catch (Exception e)
                {
                    return($"error with {blockchain.Type}", $"error with {blockchain.Type}", $"error with {blockchain.Type}", 0);
                }
            }
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);
        }