Ejemplo n.º 1
0
        public AccountsState ExecuteBlock(Block block, AccountsState initialstate)
        {
            if (block.Transactions == null)
            {
                return(initialstate);
            }

            var state = initialstate;

            foreach (var tx in block.Transactions)
            {
                this.ExecuteTransaction(tx, state, ref state);
            }

            return(state);
        }
Ejemplo n.º 2
0
 public BlockInfo(Block block, AccountsState state)
 {
     this.block = block;
     this.state = state;
 }
Ejemplo n.º 3
0
        public bool ExecuteTransaction(Transaction transaction, AccountsState initialstate, ref AccountsState newstate)
        {
            var state = initialstate;

            try
            {
                var addr        = transaction.Sender;
                var accstate    = state.Get(addr);
                var newaccstate = accstate.SubtractFromBalance(transaction.Value);
                state = state.Put(addr, newaccstate);

                addr        = transaction.Receiver;
                accstate    = state.Get(addr);
                newaccstate = accstate.AddToBalance(transaction.Value);
                state       = state.Put(addr, newaccstate);

                newstate = state;

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }