Exemplo n.º 1
0
        public MutableAccount GetOrCreateMutableAccount(Address address)
        {
            // if we already modified it
            if (accounts.TryGetValue(address, out var account))
            {
                return(account);
            }

            Tree.CreateOrUpdate(address.ToRawBytes(), old =>
            {
                // try to get it into the previous state
                if (old != null)
                {
                    // make a new copy
                    account = new MutableAccount(old, Height);
                }
                else
                {
                    account = new MutableAccount(address, Height);
                    AccountCreated.Call(account);
                }

                return(account);
            });

            accounts.Add(address, account);
            return(account);
        }
        public static AccountBalance SetBalance(this MutableAccount account, Currency currency, Amount amount)
        {
            var balance = new AccountBalance(currency, amount);

            account.SetBalance(balance);

            return(balance);
        }
        private static List <Account> MarkNewAccounts(HashSet <Address> knownAccounts, List <Account> accounts)
        {
            var results = new List <Account>();

            foreach (var account in accounts)
            {
                if (knownAccounts.Add(account.Address))
                {
                    var mutable = new MutableAccount(account.Address, account.CurrentLedger);
                    results.Add(mutable.SetBalances(account.Balances).SetDeclaration(account.Declaration));
                }
                else
                {
                    results.Add(account);
                }
            }

            return(results);
        }
Exemplo n.º 4
0
 public void SetBalance(MutableAccount account, Currency currency, Amount amount)
 {
     account.SetBalance(currency, amount);
 }