コード例 #1
0
        public async Task <Fees> GetFeesAsync()
        {
            var latest = await _horizonService.GetLatestLedger();

            var fees = new Fees
            {
                BaseFee     = latest.BaseFee,
                BaseReserve = Convert.ToDecimal(latest.BaseReserve)
            };

            return(fees);
        }
コード例 #2
0
        private async Task <bool> ProcessDwToHwTransaction(Guid operationId, stellar_dotnet_sdk.xdr.Transaction tx)
        {
            var fromKeyPair = KeyPair.FromPublicKey(tx.SourceAccount.Ed25519.InnerValue);

            if (!_balanceService.IsDepositBaseAddress(fromKeyPair.Address) || tx.Operations.Length != 1 ||
                tx.Operations[0].Body.PaymentOp == null || string.IsNullOrWhiteSpace(tx.Memo.Text))
            {
                return(false);
            }

            var toKeyPair = KeyPair.FromPublicKey(tx.Operations[0].Body.PaymentOp.Destination.Ed25519.InnerValue);

            if (!_balanceService.IsDepositBaseAddress(toKeyPair.Address))
            {
                return(false);
            }

            var fromAddress = $"{fromKeyPair.Address}{Constants.PublicAddressExtension.Separator}{tx.Memo.Text}";
            var amount      = tx.Operations[0].Body.PaymentOp.Amount.InnerValue;

            // Use our guid-ed OperationId as transaction hash, as it uniquely identifies the transaction,
            // just without dashes to look more hash-y.
            var hash = operationId.ToString("N");

            // While we have only single action within DW->HW transaction,
            // we can use any value to identify action within transaction.
            // Use hashed operation ID to add more diversity.
            var opId = operationId.ToString("N").CalculateHash64();

            var ledger = await _horizonService.GetLatestLedger();

            var updateLedger = (ledger.Sequence * 10) + 1;
            var broadcast    = new TxBroadcast
            {
                OperationId = operationId,
                Amount      = amount,
                Fee         = 0,
                Hash        = hash,
                // ReSharper disable once ArrangeRedundantParentheses
                Ledger    = updateLedger,
                CreatedAt = DateTime.UtcNow
            };

            var assetId = _blockchainAssetsService.GetNativeAsset().Id;
            var balance = await _balanceRepository.GetAsync(assetId, fromAddress);

            if (balance.Balance < amount)
            {
                broadcast.State     = TxBroadcastState.Failed;
                broadcast.Error     = "Not enough balance!";
                broadcast.ErrorCode = TxExecutionError.NotEnoughBalance;
            }
            else
            {
                await _balanceRepository.RecordOperationAsync(assetId, fromAddress, updateLedger, opId, hash, (-1) *amount);

                await _balanceRepository.RefreshBalance(assetId, fromAddress);

                broadcast.State = TxBroadcastState.Completed;
            }

            _chaos.Meow(nameof(ProcessDwToHwTransaction));

            // update state
            await _broadcastRepository.InsertOrReplaceAsync(broadcast);

            return(true);
        }