Skip to main content

System Overview

The dapp we will be building consists of two blockchains: the Subscription Chain and the Digital Warehouse Chain.

The user makes a payment to the Subscription Chain to create a "subscription". The payment flow will be simplified to just deducting a value from the account. This part can easily be extended later using the FT-library. The user then presents a receipt for this payment to the Digital Warehouse Chain, which grants them access to the system. This allows the user to add inventory updates to a fictional warehouse.

This architecture allows us to easily manage multiple warehouses by deploying multiple warehouse chains. By offloading the payment to another chain, this part could theoretically be part of another, more generic system.

Subscription model

To model our subscription, we will create a structure that can be passed to the Subscription Chain and later be verified on the Digital Warehouse chain. This will act as meta-data to be extracted by the warehouse when verifying the payment. Let's open up a new file src/subscription.rell and add the following:

src/subscription.rell
module;

struct subscription {
account_id: pubkey;
period;
}

enum period {
WEEK,
MONTH,
}

function period_price(period): integer {
return when (period) {
MONTH -> 90;
else -> 30;
};
}

val MILLIS_IN_A_DAY = 24 * 60 * 60 * 1000;

function period_to_millis(period): integer {
return MILLIS_IN_A_DAY * when (period) {
MONTH -> 30;
else -> 7;
} ;
}

When a user requests a new subscription, then set the account ID and a period. We also supply utility functions to convert the period to a associated price and duration.