Subscriptions Contract
This is the main Smart Contract that receives subscriptions from customers.
Events
NewCustomerRegistered
event NewCustomerRegistered(address _wallet, uint16 _countryOfResidence)
NewSubscription
event NewSubscription(address _wallet, uint256 _tokenId, enum Billing.SubscriptionPeriod _period, uint8 _prepaidPeriods, string _currency, uint256 _startTs, uint256 _endTs, uint256 _usdPrice, uint256 _usdTaxes, uint256 _priceRate, uint256 _vatRate)
ReloadSubscription
event ReloadSubscription(address _wallet, uint256 _tokenId, enum Billing.SubscriptionPeriod _period, uint8 _addedPeriods, string _currency, uint256 _startTs, uint256 _endTs, uint256 _usdPrice, uint256 _usdTaxes, uint256 _priceRate, uint256 _vatRate)
StopSubscription
event StopSubscription(address _wallet, uint256 _tokenId, uint256 _startTs, uint256 _endTs, uint256 _blocktime)
DestinationWalletChanged
event DestinationWalletChanged(address _oldWallet, address _newWallet)
NewRefund
event NewRefund(address _wallet, uint256 _tokenId, uint256 _startTs, string _currency, uint256 _amount, uint256 _refundPeriods)
RefundCompleted
event RefundCompleted(address _wallet, address _payer, uint256 _tokenId, string _currency, uint256 _amount)
Variables
destinationWallet
address destinationWallet
validationSlots
uint256 validationSlots
gtcVersion
uint16 gtcVersion
Customer
struct Customer {
bool registered;
uint16 countryOfResidence;
uint16 acceptedGtcVersion;
}
Subscription
struct Subscription {
uint256 startTs;
uint256 endTs;
enum Billing.SubscriptionPeriod period;
string currencySymbol;
uint256 priceRate;
uint256 vatRate;
}
Refund
struct Refund {
bool pending;
string currencySymbol;
uint256 amount;
}
customers
mapping(address => struct Subscriptions.Customer) customers
subscriptions
mapping(address => mapping(uint256 => struct Subscriptions.Subscription)) subscriptions
user's subscriptions
One customer can have multiple active subscriptions, but only for different node id
refunds
mapping(address => mapping(uint256 => struct Subscriptions.Refund)) refunds
User's refunds
Functions
initialize
function initialize(address _accessControl, address _billing, address _nodeIdToken, address _destinationWallet) public
Public initializer with published default settings
Parameters
Name | Type | Description |
---|---|---|
_accessControl | address | The c-chain address of access control contract |
_billing | address | The c-chain address of billing contract |
_nodeIdToken | address | The c-chain address of NodeidNFT contract |
_destinationWallet | address | The c-chain address of the wallet that collects user payments |
setGtcVersion
function setGtcVersion(uint16 _version) public
Set GTC version number
users must accept the latest version
changeDestationWallet
function changeDestationWallet(address _newDestinationWallet) public
Modifies the destination wallet address that collects user payments
Parameters
Name | Type | Description |
---|---|---|
_newDestinationWallet | address | The destination wallet address |
addValidationSlots
function addValidationSlots(uint256 _slots) public
Adds available validation slots
Parameters
Name | Type | Description |
---|---|---|
_slots | uint256 | Number of slots to add |
removeValidationSlots
function removeValidationSlots(uint256 _slots) public
Removes available validation slots
Parameters
Name | Type | Description |
---|---|---|
_slots | uint256 | Number of slots to remove |
completeRefund
function completeRefund(address _wallet, uint256 _tokenId) public
Refund user after a subscription
Parameters
Name | Type | Description |
---|---|---|
_wallet | address | The wallet address to refund |
_tokenId | uint256 | The NodeidNFT identifier associated to the refund |
register
function register(uint16 _countryOfResidence) public
Registers a user that implicitly accept GTC at the same time
Parameters
Name | Type | Description |
---|---|---|
_countryOfResidence | uint16 | The user's country of residence, which will be used to calculate VAT |
newSubscription
function newSubscription(enum Billing.SubscriptionPeriod _period, uint256 _tokenId, string _currencySymbol, uint8 _prepaidPeriods, bool _withdrawalRightWaiver) public
Allows a user to order a validator
Parameters
Name | Type | Description |
---|---|---|
_period | enum Billing.SubscriptionPeriod | The subscription period (weekly, monthly, yearly) |
_tokenId | uint256 | The NodeidNFT identifier |
_currencySymbol | string | The currency name used to pay the subscription |
_prepaidPeriods | uint8 | The number of periods a user wants to subscribe |
_withdrawalRightWaiver | bool | The user must explicitly agree to waive the 14-day right of withdrawal* |
*See Article 7 of the Terms & Conditions
reloadSubscription
function reloadSubscription(uint256 _tokenId, uint8 _addedPeriods) public
Allows a user to reload an existing subscription
Only allowed during the last subscription period
Parameters
Name | Type | Description |
---|---|---|
_tokenId | uint256 | The Nodeid NFT identifier |
_addedPeriods | uint8 | The number of added periods |
stopSubscription
function stopSubscription(uint256 _tokenId) public
Allows user to stop/terminate an existing subscription. Unused periods will be refunded
Parameters
Name | Type | Description |
---|---|---|
_tokenId | uint256 | The Nodeid NFT identifier |
customerExists
function customerExists(address _wallet) public view returns (bool)
Queries if a user is registered
Parameters
Name | Type | Description |
---|---|---|
_wallet | address | Customer's wallet address |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | boolean True if the user is registered, otherwise false. |
hasNodeIdCurrentSubscription
function hasNodeIdCurrentSubscription(uint256 _tokenId) public view returns (bool)
Queries whether a nodeid is used in an active subscription
Parameters
Name | Type | Description |
---|---|---|
_tokenId | uint256 | The Nodeid NFT identifier |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | boolean True if the NodeID as an active subscription, otherwise false |
hasActiveSubscription
function hasActiveSubscription(address _wallet, uint256 _tokenId) public view returns (bool)
Queries if a user has an active subscription for the given nft identifier
Parameters
Name | Type | Description |
---|---|---|
_wallet | address | Customer's wallet address |
_tokenId | uint256 | The Nodeid NFT identifier |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | boolean True if the NodeID as an active subscription, otherwise false |
hasPendingRefund
function hasPendingRefund(address _wallet, uint256 _tokenId) public view returns (bool)
Queries if a user has a pending refund for the given nft identifier
Parameters
Name | Type | Description |
---|---|---|
_wallet | address | Customer's wallet address |
_tokenId | uint256 | The Nodeid NFT identifier |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | boolean True if the is a pending refund for the given user's nft |
computeRefundPeriodsOf
function computeRefundPeriodsOf(uint256 _tokenId, address _user) public view returns (uint256)
Computes how many periods must be refund for a given subscription
_tokenId and _user are used to query the subscription
Parameters
Name | Type | Description |
---|---|---|
_tokenId | uint256 | The Nodeid NFT identifier |
_user | address | Customer's wallet address |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | refundPeriods Returns the number of periods to be refunded |