NContract implementations refactoring (SLOT1/UNS1).
Added by Roman Uskov over 7 years ago
- Remove imports from SlotContract
import com.icodici.universa.node.Ledger;
import com.icodici.universa.node2.Config;
import com.icodici.universa.node2.NodeInfo;
- Remove corresponding member variables
- Five problematic methods appear. Fixed by using NContract extensions listed below
- calculatePrepaidKilobytesForDays - ext 1 & 2
- onContractStorageSubscriptionEvent - update subscription expires_at/destroy subscription depending on event type. DO NOT create replace existing subscriptions with new ones. DO NOT CALL saveSubscriptionsToLedger
- beforeCreate - ext 1,2&3
- onRevoked - ext 4
- saveSubscriptionsToLedger - ext 5&6
NContract extension
- getPayment() - “calculatedPayment” gets ammount of "U" paid by this NContract
- getRate() - “Config.kilobytesAndDaysPerU” gets NCONTRACT_SPECIFIC_UNITS/U. It could be kilobytesAndDaysPerU/NamesAndDaysPerU etc. Config is storing MAP "NContract ExtendedType" -> "NContractSpecificUnits/U"
- getMinPayment() - Config.getMinSlotPayment() get min payment in U. Config is storing MAP "NContract ExtendedType" -> MIN_PAYMENT
- Subscriptions are automatically removed when NContract is revoked/expired
- MutableEnvironment is saved by node after returning from NContract method / MutableEnvironment has .save() method
- MutableEnvironment.createStorageSubscription does all the following stuff inside itself
ContractStorageSubscription css = me.createStorageSubscription(tc.getId(), newExpires);
css.receiveEvents(true);
long contractStorageId = ledger.saveContractInStorage(tc.getId(), tc.getPackedTransaction(), css.expiresAt(), tc.getOrigin());
long subscriptionId = ledger.saveSubscriptionInStorage(contractStorageId, css.expiresAt());
ledger.saveEnvironmentSubscription(subscriptionId, environmentId);