示例#1
0
 public StateSnapshot(IContractLogHolder logHolder, IReadOnlyList <TransferInfo> internalTransfers, ulong nonce, IContractState contractState)
 {
     this.Logs = logHolder.GetRawLogs().ToImmutableList();
     this.InternalTransfers = internalTransfers.ToImmutableList();
     this.Nonce             = nonce;
     this.ContractState     = contractState;
 }
示例#2
0
 public State(ISmartContractStateFactory smartContractStateFactory,
              IStateRepository repository,
              IContractLogHolder contractLogHolder,
              List <TransferInfo> internalTransfers,
              IBlock block,
              uint256 transactionHash)
 {
     this.ContractState             = repository;
     this.LogHolder                 = contractLogHolder;
     this.internalTransfers         = internalTransfers;
     this.BalanceState              = new BalanceState(this.ContractState, this.InternalTransfers);
     this.NonceGenerator            = new NonceGenerator();
     this.Block                     = block;
     this.TransactionHash           = transactionHash;
     this.smartContractStateFactory = smartContractStateFactory;
 }
示例#3
0
 public IInternalTransactionExecutor Create(ISmartContractVirtualMachine vm,
                                            IContractLogHolder contractLogHolder,
                                            IContractStateRepository stateRepository,
                                            List <TransferInfo> internalTransferList,
                                            ITransactionContext transactionContext)
 {
     return(new InternalTransactionExecutor(
                transactionContext,
                vm,
                contractLogHolder,
                stateRepository,
                internalTransferList,
                this.keyEncodingStrategy,
                this.loggerFactory,
                this.network
                ));
 }
示例#4
0
 public InternalTransactionExecutor(ITransactionContext transactionContext,
                                    ISmartContractVirtualMachine vm,
                                    IContractLogHolder contractLogHolder,
                                    IContractState contractStateRepository,
                                    List <TransferInfo> internalTransferList,
                                    IKeyEncodingStrategy keyEncodingStrategy,
                                    ILoggerFactory loggerFactory,
                                    Network network)
 {
     this.transactionContext      = transactionContext;
     this.contractLogHolder       = contractLogHolder;
     this.contractStateRepository = contractStateRepository;
     this.internalTransferList    = internalTransferList;
     this.keyEncodingStrategy     = keyEncodingStrategy;
     this.loggerFactory           = loggerFactory;
     this.logger  = loggerFactory.CreateLogger(this.GetType());
     this.network = network;
     this.vm      = vm;
 }
 public State(
     ISmartContractStateFactory smartContractStateFactory,
     IStateRepository repository,
     IContractLogHolder contractLogHolder,
     List <TransferInfo> internalTransfers,
     IBlock block,
     Network network,
     ulong txAmount,
     uint256 transactionHash)
 {
     this.ContractState             = repository;
     this.LogHolder                 = contractLogHolder;
     this.internalTransfers         = internalTransfers;
     this.BalanceState              = new BalanceState(this.ContractState, txAmount, this.InternalTransfers);
     this.Network                   = network;
     this.Nonce                     = 0;
     this.Block                     = block;
     this.TransactionHash           = transactionHash;
     this.smartContractStateFactory = smartContractStateFactory;
 }
        /// <summary>
        /// Sets up the state object for the contract execution
        /// </summary>
        private ISmartContractState SetupState(
            IContractLogHolder contractLogger,
            List <TransferInfo> internalTransferList,
            IGasMeter gasMeter,
            IContractState repository,
            ITransactionContext transactionContext,
            uint160 contractAddress)
        {
            IPersistenceStrategy persistenceStrategy =
                new MeteredPersistenceStrategy(repository, gasMeter, new BasicKeyEncodingStrategy());

            var persistentState = new PersistentState(persistenceStrategy, this.contractPrimitiveSerializer, contractAddress);

            IInternalTransactionExecutor internalTransactionExecutor = this.internalTransactionExecutorFactory.Create(this, contractLogger, repository, internalTransferList, transactionContext);

            var balanceState = new BalanceState(repository, transactionContext.Amount, internalTransferList);

            var contractState = new SmartContractState(
                new Block(
                    transactionContext.BlockHeight,
                    transactionContext.Coinbase.ToAddress(this.network)
                    ),
                new Message(
                    contractAddress.ToAddress(this.network),
                    transactionContext.From.ToAddress(this.network),
                    transactionContext.Amount
                    ),
                persistentState,
                this.contractPrimitiveSerializer,
                gasMeter,
                contractLogger,
                internalTransactionExecutor,
                new InternalHashHelper(),
                () => balanceState.GetBalance(contractAddress));

            return(contractState);
        }