- java.lang.Object
-
- io.hotmoka.local.internal.transactions.AbstractResponseBuilder.ResponseCreator
-
- io.hotmoka.local.NonInitialResponseBuilder.ResponseCreator
-
- Enclosing class:
- NonInitialResponseBuilder<Request extends NonInitialTransactionRequest<Response>,Response extends NonInitialTransactionResponse>
protected abstract class NonInitialResponseBuilder.ResponseCreator extends io.hotmoka.local.internal.transactions.AbstractResponseBuilder.ResponseCreator
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedResponseCreator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidchargeGasForClassLoader()Charges gas proportional to the complexity of the class loader that has been created.voidchargeGasForCPU(BigInteger amount)Decreases the available gas by the given amount, for CPU execution.voidchargeGasForRAM(BigInteger amount)Decreases the available gas by the given amount, for RAM execution.protected voidchargeGasForStorageOf(Response response)Decreases the available gas for the given response, for storage allocation.protected ObjectdeserializedPayer()Yields the contract that pays for the transaction.protected BigIntegergasConsumedForCPU()Yields the amount of gas consumed for CPU execution.protected BigIntegergasConsumedForPenalty()Yields the gas that would be paid if the transaction fails.protected BigIntegergasConsumedForRAM()Yields the amount of gas consumed for RAM allocation.protected BigIntegergasConsumedForStorage()Yields the amount of gas consumed for storage consumption.protected ObjectgetDeserializedCaller()Yields the deserialized caller of the transaction.protected Optional<Object>getDeserializedValidators()Yields the contract that collects the validators of the node.protected voidinit()protected booleanisUpdateToBalanceOrNonceOfCaller(Update update)Determines if the given update affects the balance or the nonce of the caller of the transaction.protected voidrefundPayerForAllRemainingGas()Pays back the remaining gas to the payer of the transaction.protected voidresetBalanceOfPayerToInitialValueMinusAllPromisedGas()protected Stream<Update>updatesToBalanceOrNonceOfCaller()Collects all updates to the balance or nonce of the caller of the transaction.<T> TwithGas(BigInteger amount, Callable<T> what)Runs a given piece of code with a subset of the available gas.
-
-
-
Constructor Detail
-
ResponseCreator
protected ResponseCreator() throws TransactionRejectedException- Throws:
TransactionRejectedException
-
-
Method Detail
-
init
protected final void init()
-
deserializedPayer
protected Object deserializedPayer()
Yields the contract that pays for the transaction. This normally coincides withgetDeserializedCaller()but subclasses may redefine.- Returns:
- the payer for the transaction
-
getDeserializedCaller
protected final Object getDeserializedCaller()
Yields the deserialized caller of the transaction.- Returns:
- the deserialized caller
-
getDeserializedValidators
protected final Optional<Object> getDeserializedValidators()
Yields the contract that collects the validators of the node. After each transaction that consumes gas, the price of the gas is sent to this contract, that can later redistribute the reward to all validators.- Returns:
- the contract, inside the store of the node, if the node is already initialized
-
gasConsumedForCPU
protected final BigInteger gasConsumedForCPU()
Yields the amount of gas consumed for CPU execution.- Returns:
- the amount of gas
-
gasConsumedForRAM
protected final BigInteger gasConsumedForRAM()
Yields the amount of gas consumed for RAM allocation.- Returns:
- the amount of gas
-
gasConsumedForStorage
protected final BigInteger gasConsumedForStorage()
Yields the amount of gas consumed for storage consumption.- Returns:
- the amount of gas
-
gasConsumedForPenalty
protected final BigInteger gasConsumedForPenalty()
Yields the gas that would be paid if the transaction fails.- Returns:
- the gas for penalty, computed as the total initial gas minus the gas already consumed for PCU, for RAM and for storage
-
chargeGasForStorageOf
protected final void chargeGasForStorageOf(Response response)
Decreases the available gas for the given response, for storage allocation.- Parameters:
response- the response
-
chargeGasForCPU
public final void chargeGasForCPU(BigInteger amount)
Description copied from class:io.hotmoka.local.internal.transactions.AbstractResponseBuilder.ResponseCreatorDecreases the available gas by the given amount, for CPU execution.- Specified by:
chargeGasForCPUin classio.hotmoka.local.internal.transactions.AbstractResponseBuilder.ResponseCreator- Parameters:
amount- the amount of gas to consume
-
chargeGasForRAM
public final void chargeGasForRAM(BigInteger amount)
Description copied from class:io.hotmoka.local.internal.transactions.AbstractResponseBuilder.ResponseCreatorDecreases the available gas by the given amount, for RAM execution.- Specified by:
chargeGasForRAMin classio.hotmoka.local.internal.transactions.AbstractResponseBuilder.ResponseCreator- Parameters:
amount- the amount of gas to consume
-
chargeGasForClassLoader
protected final void chargeGasForClassLoader()
Charges gas proportional to the complexity of the class loader that has been created.
-
updatesToBalanceOrNonceOfCaller
protected final Stream<Update> updatesToBalanceOrNonceOfCaller()
Collects all updates to the balance or nonce of the caller of the transaction.- Returns:
- the updates
-
isUpdateToBalanceOrNonceOfCaller
protected final boolean isUpdateToBalanceOrNonceOfCaller(Update update)
Determines if the given update affects the balance or the nonce of the caller of the transaction. Those are the only updates that are allowed during the execution of a view method.- Parameters:
update- the update- Returns:
- true if and only if that condition holds
-
refundPayerForAllRemainingGas
protected final void refundPayerForAllRemainingGas()
Pays back the remaining gas to the payer of the transaction.
-
resetBalanceOfPayerToInitialValueMinusAllPromisedGas
protected final void resetBalanceOfPayerToInitialValueMinusAllPromisedGas()
-
withGas
public final <T> T withGas(BigInteger amount, Callable<T> what) throws Exception
Description copied from class:io.hotmoka.local.internal.transactions.AbstractResponseBuilder.ResponseCreatorRuns a given piece of code with a subset of the available gas. It first charges the given amount of gas. Then runs the code with the charged gas only. At its end, the remaining gas is added to the available gas to continue the computation.- Specified by:
withGasin classio.hotmoka.local.internal.transactions.AbstractResponseBuilder.ResponseCreator- Parameters:
amount- the amount of gas provided to the codewhat- the code to run- Returns:
- the result of the execution of the code
- Throws:
Exception- if the code runs into this exception
-
-