@@ -83,22 +83,22 @@ class LedgerImpl(vm: VM, blockchainConfig: BlockchainConfig) extends Ledger with
83
83
* if one of them failed
84
84
*/
85
85
@ tailrec
86
- private def executeTransactions (signedTransactions : Seq [SignedTransaction ], world : InMemoryWorldStateProxy ,
86
+ private [ledger] final def executeTransactions (signedTransactions : Seq [SignedTransaction ], world : InMemoryWorldStateProxy ,
87
87
blockHeader : BlockHeader , signedTransactionValidator : SignedTransactionValidator ,
88
88
acumGas : BigInt = 0 , acumReceipts : Seq [Receipt ] = Nil ): Either [TxsExecutionError , BlockResult ] =
89
89
signedTransactions match {
90
90
case Nil =>
91
91
Right (BlockResult (worldState = world, gasUsed = acumGas, receipts = acumReceipts))
92
92
93
93
case Seq (stx, otherStxs@_* ) =>
94
- val senderAccount = world.getAccount(stx.senderAddress)
94
+ val (senderAccount, worldForTx) = world.getAccount(stx.senderAddress).map(a => (a, world))
95
+ .getOrElse ((Account .Empty , world.saveAccount(stx.senderAddress, Account .Empty )))
95
96
val upfrontCost = calculateUpfrontCost(stx.tx)
96
- val validatedStx = senderAccount
97
- .toRight(Left (TxsExecutionError (s " Account of tx sender ${stx.senderAddress.toString} not found " )))
98
- .flatMap(account => signedTransactionValidator.validate(stx, account, blockHeader, upfrontCost, acumGas))
97
+ val validatedStx = signedTransactionValidator.validate(stx, senderAccount, blockHeader, upfrontCost, acumGas)
98
+
99
99
validatedStx match {
100
100
case Right (_) =>
101
- val TxResult (newWorld, gasUsed, logs) = executeTransaction(stx, blockHeader, world )
101
+ val TxResult (newWorld, gasUsed, logs) = executeTransaction(stx, blockHeader, worldForTx )
102
102
103
103
val receipt = Receipt (
104
104
postTransactionStateHash = newWorld.stateRootHash,
@@ -254,7 +254,7 @@ class LedgerImpl(vm: VM, blockchainConfig: BlockchainConfig) extends Ledger with
254
254
private [ledger] def prepareProgramContext (stx : SignedTransaction , blockHeader : BlockHeader , worldStateProxy : InMemoryWorldStateProxy , config : EvmConfig ): PC =
255
255
stx.tx.receivingAddress match {
256
256
case None =>
257
- val address = worldStateProxy.createAddress(stx.senderAddress)
257
+ val address = worldStateProxy.createAddress(creatorAddr = stx.senderAddress)
258
258
val world1 = worldStateProxy.transfer(stx.senderAddress, address, UInt256 (stx.tx.value))
259
259
ProgramContext (stx, address, Program (stx.tx.payload), blockHeader, world1, config)
260
260
0 commit comments