/// <summary> /// Executes the smart contract part of a transaction /// </summary> protected void ExecuteContractTransaction(RuleContext context, Transaction transaction) { ISmartContractTransactionContext txContext = GetSmartContractTransactionContext(context, transaction); ISmartContractExecutor executor = this.ContractCoinviewRule.ExecutorFactory.CreateExecutor(this.ContractCoinviewRule.OriginalStateRoot, txContext); ISmartContractExecutionResult result = executor.Execute(txContext); var receipt = new Receipt( new uint256(this.ContractCoinviewRule.OriginalStateRoot.Root), result.GasConsumed, result.Logs.ToArray(), txContext.TransactionHash, txContext.Sender, result.To, result.NewContractAddress, !result.Revert ) { BlockHash = context.ValidationContext.Block.GetHash() }; this.receipts.Add(receipt); ValidateRefunds(result.Refunds, context.ValidationContext.Block.Transactions[0]); if (result.InternalTransaction != null) { this.generatedTransaction = result.InternalTransaction; } }
/// <summary> /// Execute the contract and add all relevant fees and refunds to the block. /// </summary> /// <remarks>TODO: At some point we need to change height to a ulong.</remarks> private ISmartContractExecutionResult ExecuteSmartContract(TxMempoolEntry mempoolEntry) { this.logger.LogTrace("()"); GetSenderResult getSenderResult = this.senderRetriever.GetSender(mempoolEntry.Transaction, this.coinView, this.inBlock.Select(x => x.Transaction).ToList()); if (!getSenderResult.Success) { throw new ConsensusErrorException(new ConsensusError("sc-block-assembler-addcontracttoblock", getSenderResult.Error)); } ISmartContractTransactionContext transactionContext = new SmartContractTransactionContext((ulong)this.height, this.coinbaseAddress, mempoolEntry.Fee, getSenderResult.Sender, mempoolEntry.Transaction); ISmartContractExecutor executor = this.executorFactory.CreateExecutor(this.stateSnapshot, transactionContext); ISmartContractExecutionResult result = executor.Execute(transactionContext); var receipt = new Receipt( new uint256(this.stateSnapshot.Root), result.GasConsumed, result.Logs.ToArray() ); this.receipts.Add(receipt); this.logger.LogTrace("(-)"); return(result); }
/// <summary> /// Executes the smart contract part of a transaction /// </summary> protected void ExecuteContractTransaction(RuleContext context, Transaction transaction) { ISmartContractTransactionContext txContext = GetSmartContractTransactionContext(context, transaction); ISmartContractExecutor executor = this.ContractCoinviewRule.ExecutorFactory.CreateExecutor(this.ContractCoinviewRule.OriginalStateRoot, txContext); ISmartContractExecutionResult result = executor.Execute(txContext); ValidateRefunds(result.Refunds, context.ValidationContext.Block.Transactions[0]); if (result.InternalTransaction != null) { this.generatedTransaction = result.InternalTransaction; } SaveReceipt(txContext, result); }