public override BalanceChanges GetBalanceChanges(TransactionBlock previousBlock)
        {
            var bc = new BalanceChanges();

            // transfer unchanged token balances from the previous block
            foreach (var balance in Balances)
            {
                decimal amount;
                if (previousBlock?.Balances?.ContainsKey(balance.Key) == true)
                {
                    amount = (balance.Value - previousBlock.Balances[balance.Key]).ToBalanceDecimal();
                }
                else
                {
                    amount = balance.Value.ToBalanceDecimal();
                }

                if (amount != 0)
                {
                    bc.Changes.Add(balance.Key, amount);
                }
            }
            bc.FeeCode   = this.FeeCode;
            bc.FeeAmount = this.Fee;

            return(bc);
        }
Example #2
0
        public override BalanceChanges GetBalanceChanges(TransactionBlock previousBlock)
        {
            var bc = new BalanceChanges();

            // transfer unchanged token balances from the previous block
            foreach (var prevKvp in previousBlock.Balances)
            {
                decimal amount;
                if (Balances.ContainsKey(prevKvp.Key))
                {
                    amount = (prevKvp.Value - Balances[prevKvp.Key]).ToBalanceDecimal();
                }
                else
                {
                    // all spent. zero. ommit
                    amount = prevKvp.Value.ToBalanceDecimal();
                }

                if (prevKvp.Key == FeeCode)
                {
                    amount -= Fee;
                }

                if (amount != 0)
                {
                    bc.Changes.Add(prevKvp.Key, amount);
                }
            }
            bc.FeeCode   = this.FeeCode;
            bc.FeeAmount = this.Fee;

            return(bc);
        }