Example #1
0
        public async Task <APIResultCodes> ReceiveAsync()
        {
            var blockresult = await _rpcClient.GetLastServiceBlockAsync();

            if (blockresult.ResultCode != APIResultCodes.Success)
            {
                return(blockresult.ResultCode);
            }

            ServiceBlock lastServiceBlock = blockresult.GetBlock() as ServiceBlock;

            //TransferFee = lastServiceBlock.TransferFee;
            //TokenGenerationFee = lastServiceBlock.TokenGenerationFee;
            //TradeFee = lastServiceBlock.TradeFee;

            try
            {
                var lookup_result = await _rpcClient.LookForNewTransferAsync(_accountId, _signer(lastServiceBlock.Hash));

                int max_counter = 0;

                while (lookup_result.Successful() && max_counter < 100) // we don't want to enter an endless loop...
                {
                    max_counter++;

                    //PrintConLine($"Received new transaction, sending request for settlement...");

                    var receive_result = await ReceiveTransfer(lookup_result);

                    if (!receive_result.Successful())
                    {
                        return(receive_result.ResultCode);
                    }

                    lookup_result = await _rpcClient.LookForNewTransferAsync(_accountId, _signer(lastServiceBlock.Hash));
                }

                // the fact that do one sent us any money does not mean this call failed...
                if (lookup_result.ResultCode == APIResultCodes.NoNewTransferFound)
                {
                    return(APIResultCodes.Success);
                }

                if (lookup_result.ResultCode == APIResultCodes.AccountAlreadyImported)
                {
                    //PrintConLine($"This account was imported (merged) to another account.");
                    //AccountAlreadyImported = true;
                    return(lookup_result.ResultCode);
                }

                return(lookup_result.ResultCode);
            }
            catch (Exception e)
            {
                //PrintConLine("Exception in SyncIncomingTransfers(): " + e.Message);
                return(APIResultCodes.UnknownError);
            }
        }
        private readonly SemaphoreSlim semaphore = new SemaphoreSlim(1);      // we need to run tests in serial

        private async Task <string> SignAPIAsync()
        {
            var lsb = await client.GetLastServiceBlockAsync();

            return(Signatures.GetSignature(testPrivateKey, lsb.GetBlock().Hash, testPublicKey));
        }
        private async Task <string> SignAPIAsync()
        {
            var lsb = await client.GetLastServiceBlockAsync();

            return(Signatures.GetSignature(PRIVATE_KEY_1, lsb.GetBlock().Hash, ADDRESS_ID_1));
        }