public static WithdrawalWrapper GetWithdrawal(MessageEnvelope messageEnvelope, ConstellationSettings constellationSettings)
        {
            var withdrawalRequest = ((WithdrawalRequest)((RequestQuantum)messageEnvelope.Message).RequestMessage);
            var transaction       = withdrawalRequest.DeserializeTransaction();
            var transactionHash   = transaction.Hash();
            var withdrawal        = new WithdrawalWrapper
            {
                Hash     = transactionHash,
                Envelope = messageEnvelope
            };

            withdrawal.Withdrawals = transaction.GetWithdrawals(withdrawal.Source.Account, constellationSettings);
            return(withdrawal);
        }
Exemple #2
0
        public void Add(WithdrawalWrapper withdrawal)
        {
            if (withdrawal == null)
            {
                throw new ArgumentNullException(nameof(withdrawal));
            }

            lock (withdrawals)
            {
                if (!withdrawals.TryAdd(withdrawal.Hash, withdrawal))
                {
                    throw new Exception("Payment with specified transaction hash already exists");
                }
            }
        }
Exemple #3
0
        public override Task <ResultMessage> Process(WithdrawalProcessorContext context)
        {
            context.UpdateNonce();

            var withdrawal = new WithdrawalWrapper
            {
                Envelope    = context.Envelope,
                Hash        = context.TransactionHash,
                Withdrawals = context.WithdrawalItems,
                MaxTime     = context.Transaction.TimeBounds.MaxTime
            };

            context.EffectProcessors.AddWithdrawalCreate(withdrawal, Global.WithdrawalStorage);

            var effects = context.EffectProcessors.Effects;

            var accountEffects = effects.Where(e => e.AccountWrapper?.Account.Id == context.WithdrawalRequest.Account).ToList();

            return(Task.FromResult(context.Envelope.CreateResult(ResultStatusCodes.Success, accountEffects)));
        }
        public void Add(WithdrawalWrapper withdrawal)
        {
            if (withdrawal == null)
            {
                throw new ArgumentNullException(nameof(withdrawal));
            }

            syncRoot.Wait();
            try
            {
                if (!withdrawals.TryAdd(withdrawal.Hash, withdrawal))
                {
                    throw new Exception("Payment with specified transaction hash already exists");
                }
            }
            finally
            {
                syncRoot.Release();
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="currentTime">Time in unix time seconds</param>
 /// <returns></returns>
 public static bool IsExpired(this WithdrawalWrapper withdrawal, long currentTime)
 {
     return(currentTime - withdrawal.MaxTime > ExecutionContext.MaxTxSubmitDelay);
 }
 public WithdrawalCreateEffectProcessor(WithdrawalCreateEffect effect, WithdrawalWrapper withdrawal, WithdrawalStorage withdrawalStorage)
     : base(effect)
 {
     this.withdrawalStorage = withdrawalStorage ?? throw new ArgumentNullException(nameof(withdrawalStorage));
     this.withdrawal        = withdrawal ?? throw new ArgumentNullException(nameof(withdrawal));
 }
        public static void AddWithdrawalRemove(this EffectProcessorsContainer effectProcessors, WithdrawalWrapper withdrawal, bool isSuccessful, WithdrawalStorage withdrawalStorage)
        {
            var effect = new WithdrawalRemoveEffect
            {
                Apex           = effectProcessors.Apex,
                Account        = withdrawal.Source.Account.Id,
                AccountWrapper = withdrawal.Source,
                IsSuccessful   = isSuccessful,
                Items          = withdrawal.Withdrawals.Select(w => new WithdrawalEffectItem {
                    Asset = w.Asset, Amount = w.Amount
                }).OrderBy(a => a.Asset).ToList()
            };

            effectProcessors.Add(new WithdrawalRemoveEffectProcessor(effect, withdrawal, withdrawalStorage));
        }