Skip to main content

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

NameTypeDescription
_accessControladdressThe c-chain address of access control contract
_billingaddressThe c-chain address of billing contract
_nodeIdTokenaddressThe c-chain address of NodeidNFT contract
_destinationWalletaddressThe 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

NameTypeDescription
_newDestinationWalletaddressThe destination wallet address

addValidationSlots

function addValidationSlots(uint256 _slots) public

Adds available validation slots

Parameters

NameTypeDescription
_slotsuint256Number of slots to add

removeValidationSlots

function removeValidationSlots(uint256 _slots) public

Removes available validation slots

Parameters

NameTypeDescription
_slotsuint256Number of slots to remove

completeRefund

function completeRefund(address _wallet, uint256 _tokenId) public

Refund user after a subscription

Parameters

NameTypeDescription
_walletaddressThe wallet address to refund
_tokenIduint256The NodeidNFT identifier associated to the refund

register

function register(uint16 _countryOfResidence) public

Registers a user that implicitly accept GTC at the same time

Parameters

NameTypeDescription
_countryOfResidenceuint16The 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

NameTypeDescription
_periodenum Billing.SubscriptionPeriodThe subscription period (weekly, monthly, yearly)
_tokenIduint256The NodeidNFT identifier
_currencySymbolstringThe currency name used to pay the subscription
_prepaidPeriodsuint8The number of periods a user wants to subscribe
_withdrawalRightWaiverboolThe 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

NameTypeDescription
_tokenIduint256The Nodeid NFT identifier
_addedPeriodsuint8The number of added periods

stopSubscription

function stopSubscription(uint256 _tokenId) public

Allows user to stop/terminate an existing subscription. Unused periods will be refunded

Parameters

NameTypeDescription
_tokenIduint256The Nodeid NFT identifier

customerExists

function customerExists(address _wallet) public view returns (bool)

Queries if a user is registered

Parameters

NameTypeDescription
_walletaddressCustomer's wallet address

Return Values

NameTypeDescription
[0]boolboolean 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

NameTypeDescription
_tokenIduint256The Nodeid NFT identifier

Return Values

NameTypeDescription
[0]boolboolean 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

NameTypeDescription
_walletaddressCustomer's wallet address
_tokenIduint256The Nodeid NFT identifier

Return Values

NameTypeDescription
[0]boolboolean 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

NameTypeDescription
_walletaddressCustomer's wallet address
_tokenIduint256The Nodeid NFT identifier

Return Values

NameTypeDescription
[0]boolboolean 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

NameTypeDescription
_tokenIduint256The Nodeid NFT identifier
_useraddressCustomer's wallet address

Return Values

NameTypeDescription
[0]uint256refundPeriods Returns the number of periods to be refunded