Project

General

Profile

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
  1. calculatePrepaidKilobytesForDays - ext 1 & 2
  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
  3. beforeCreate - ext 1,2&3
  4. onRevoked - ext 4
  5. saveSubscriptionsToLedger - ext 5&6

NContract extension

  1. getPayment() - “calculatedPayment” gets ammount of "U" paid by this NContract
  2. getRate() - “Config.kilobytesAndDaysPerU” gets NCONTRACT_SPECIFIC_UNITS/U. It could be kilobytesAndDaysPerU/NamesAndDaysPerU etc. Config is storing MAP "NContract ExtendedType" -> "NContractSpecificUnits/U"
  3. getMinPayment() - Config.getMinSlotPayment() get min payment in U. Config is storing MAP "NContract ExtendedType" -> MIN_PAYMENT
  4. Subscriptions are automatically removed when NContract is revoked/expired
  5. MutableEnvironment is saved by node after returning from NContract method / MutableEnvironment has .save() method
  6. 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);