Deshare
Inherits: Initializable, AccessControl, ReentrancyGuard, IDeshare
Title: Deshare Contract
Handles partner, merchant, device registration and transaction processing
Core business logic contract for Deshare ecosystem data management
State Variables
_version
Core system state including version
Version private _version
_counters
Packed counters instance
PackedCounters private _counters
_partners
Mapping from partner ID to partner information
mapping(uint256 partnerId => PartnerInfo partner) private _partners
_partnerCodeToId
Mapping from partner code hash to partner ID
mapping(bytes32 partnerCode => uint256 partnerId) private _partnerCodeToId
_merchants
Mapping from merchant ID to merchant information
mapping(uint256 merchantId => MerchantInfo merchant) private _merchants
_merchantIdToId
Mapping from merchant ID hash to internal ID
mapping(bytes32 merchantId => uint256 id) private _merchantIdToId
_devices
Mapping from device ID to device information
mapping(uint256 deviceId => DeviceInfo device) private _devices
_deviceIdToId
Mapping from device ID hash to internal ID
mapping(bytes32 deviceId => uint256 id) private _deviceIdToId
_transactionBatches
Mapping from batch ID to transaction batch information
mapping(uint256 batchId => TransactionBatch batch) private _transactionBatches
_transactionData
Mapping from batch ID to transaction data
mapping(uint256 batchId => bytes transactionData) private _transactionData
_countries
Mapping from ISO2 country code to country information
mapping(bytes2 iso2 => CountryInfo country) private _countries
_partnerStatsByBusinessType
Mapping from business type hash to partner count
mapping(bytes32 businessTypeHash => uint256 count) private _partnerStatsByBusinessType
_merchantStatsByRegion
Mapping from country code and location ID hash to merchant count
mapping(bytes2 iso2 => mapping(bytes32 locationIdHash => uint256 count)) private
_merchantStatsByRegion
Functions
constructor
Constructor that disables initializers to prevent implementation initialization
constructor(address admin) payable;
Parameters
| Name | Type | Description |
|---|---|---|
admin | address | Address for validation (required but not used in implementation) |
initialize
Initialize the Deshare proxy
function initialize(address admin) external payable initializer;
Parameters
| Name | Type | Description |
|---|---|---|
admin | address | Address that will be granted admin and operator roles |
registerPartner
Register a new partner
function registerPartner(PartnerParams calldata params)
external
override
onlyRole(OPERATOR_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
params | PartnerParams | Partner registration parameters |
registerMerchant
Register a new merchant
function registerMerchant(MerchantParams calldata params)
external
override
onlyRole(OPERATOR_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
params | MerchantParams | Merchant registration parameters |
registerDevice
Register a new device
function registerDevice(DeviceParams calldata params)
external
override
onlyRole(OPERATOR_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
params | DeviceParams | Device registration parameters |
uploadTransactionBatch
Upload a transaction batch
function uploadTransactionBatch(UploadBatchParams calldata params)
external
override
onlyRole(OPERATOR_ROLE)
nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
params | UploadBatchParams | Upload batch parameters |
registerCountry
Register a country
function registerCountry(bytes2 iso2) external override onlyRole(OPERATOR_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
iso2 | bytes2 | The ISO2 country code |
getVersion
Get the contract version
function getVersion() external view override returns (Version memory);
Returns
| Name | Type | Description |
|---|---|---|
<none> | Version | version The current version |
getStats
Get statistics information
function getStats() external view override returns (StatsInfo memory stats);
Returns
| Name | Type | Description |
|---|---|---|
stats | StatsInfo | The current statistics |
getDetailedStats
Get detailed statistics information with descriptive labels
function getDetailedStats()
external
view
override
returns (DetailedStatsInfo memory detailedStats);
Returns
| Name | Type | Description |
|---|---|---|
detailedStats | DetailedStatsInfo | The detailed statistics with labels and metadata |
getPartner
Get partner information by ID
function getPartner(uint256 partnerId) external view override returns (PartnerInfo memory);
Parameters
| Name | Type | Description |
|---|---|---|
partnerId | uint256 | The partner ID |
Returns
| Name | Type | Description |
|---|---|---|
<none> | PartnerInfo | partner The partner information |
getPartnerByCode
Get partner information by partner code
function getPartnerByCode(string calldata partnerCode)
external
view
override
returns (PartnerInfo memory);
Parameters
| Name | Type | Description |
|---|---|---|
partnerCode | string | The partner code |
Returns
| Name | Type | Description |
|---|---|---|
<none> | PartnerInfo | partner The partner information |
partnerExists
Check if a partner exists by code
function partnerExists(string calldata partnerCode)
external
view
override
returns (bool exists);
Parameters
| Name | Type | Description |
|---|---|---|
partnerCode | string | The partner code |
Returns
| Name | Type | Description |
|---|---|---|
exists | bool | Whether the partner exists |
getMerchant
Get merchant information by ID
function getMerchant(uint256 merchantId) external view override returns (MerchantInfo memory);
Parameters
| Name | Type | Description |
|---|---|---|
merchantId | uint256 | The merchant ID |
Returns
| Name | Type | Description |
|---|---|---|
<none> | MerchantInfo | merchant The merchant information |
getMerchantById
Get merchant information by merchant ID
function getMerchantById(string calldata merchantId)
external
view
override
returns (MerchantInfo memory);
Parameters
| Name | Type | Description |
|---|---|---|
merchantId | string | The merchant ID (string) |
Returns
| Name | Type | Description |
|---|---|---|
<none> | MerchantInfo | merchant The merchant information |
merchantExists
Check if a merchant exists by ID
function merchantExists(string calldata merchantId)
external
view
override
returns (bool exists);
Parameters
| Name | Type | Description |
|---|---|---|
merchantId | string | The merchant ID |
Returns
| Name | Type | Description |
|---|---|---|
exists | bool | Whether the merchant exists |
getDevice
Get device information by ID
function getDevice(uint256 deviceId) external view override returns (DeviceInfo memory);
Parameters
| Name | Type | Description |
|---|---|---|
deviceId | uint256 | The device ID |
Returns
| Name | Type | Description |
|---|---|---|
<none> | DeviceInfo | device The device information |
getDeviceById
Get device information by device ID
function getDeviceById(string calldata deviceId)
external
view
override
returns (DeviceInfo memory);
Parameters
| Name | Type | Description |
|---|---|---|
deviceId | string | The device ID (string) |
Returns
| Name | Type | Description |
|---|---|---|
<none> | DeviceInfo | device The device information |
deviceExists
Check if a device exists by ID
function deviceExists(string calldata deviceId) external view override returns (bool exists);
Parameters
| Name | Type | Description |
|---|---|---|
deviceId | string | The device ID |
Returns
| Name | Type | Description |
|---|---|---|
exists | bool | Whether the device exists |
getTransactionBatch
Get transaction batch by ID
function getTransactionBatch(uint256 batchId)
external
view
override
returns (TransactionBatch memory);
Parameters
| Name | Type | Description |
|---|---|---|
batchId | uint256 | The batch ID |
Returns
| Name | Type | Description |
|---|---|---|
<none> | TransactionBatch | batch The transaction batch |
getTransactionData
Retrieves transaction data for a batch
function getTransactionData(uint256 batchId)
external
view
override
returns (string memory jsonData);
Parameters
| Name | Type | Description |
|---|---|---|
batchId | uint256 | The batch ID to retrieve data for |
Returns
| Name | Type | Description |
|---|---|---|
jsonData | string | The transaction data as JSON string |
getCountry
Get country information
function getCountry(bytes2 iso2) external view override returns (CountryInfo memory);
Parameters
| Name | Type | Description |
|---|---|---|
iso2 | bytes2 | The ISO2 country code |
Returns
| Name | Type | Description |
|---|---|---|
<none> | CountryInfo | country The country information |
countryExists
Check if a country is registered
function countryExists(bytes2 iso2) external view override returns (bool exists);
Parameters
| Name | Type | Description |
|---|---|---|
iso2 | bytes2 | The ISO2 country code |
Returns
| Name | Type | Description |
|---|---|---|
exists | bool | Whether the country is registered |
getPartnerCountByBusinessType
Get the number of partners for a given business type
function getPartnerCountByBusinessType(string calldata businessType)
external
view
override
returns (uint256 count);
Parameters
| Name | Type | Description |
|---|---|---|
businessType | string | The business type to query |
Returns
| Name | Type | Description |
|---|---|---|
count | uint256 | The count of partners |
getMerchantCountByRegion
Get the number of merchants for a given region
function getMerchantCountByRegion(bytes2 iso2, string calldata locationId)
external
view
override
returns (uint256 count);
Parameters
| Name | Type | Description |
|---|---|---|
iso2 | bytes2 | The ISO2 country code |
locationId | string | The location ID (e.g., city identifier) |
Returns
| Name | Type | Description |
|---|---|---|
count | uint256 | The count of merchants |
_getCountriesCount
Returns the count of registered countries
function _getCountriesCount() internal view returns (uint256 count);
Returns
| Name | Type | Description |
|---|---|---|
count | uint256 | The number of registered countries |
_createTransactionBatch
Creates and stores a new transaction batch
function _createTransactionBatch(UploadBatchParams calldata params)
private
returns (uint64 batchId);
Parameters
| Name | Type | Description |
|---|---|---|
params | UploadBatchParams | The upload batch parameters |
Returns
| Name | Type | Description |
|---|---|---|
batchId | uint64 | The ID of the created batch |
_storeTransactionData
Stores transaction data for a batch
function _storeTransactionData(uint64 batchId, bytes calldata transactionData) private;
Parameters
| Name | Type | Description |
|---|---|---|
batchId | uint64 | The batch ID to store data for |
transactionData | bytes | The transaction data to store |
_emitBatchEvents
Emits events for transaction batch upload
function _emitBatchEvents(
uint64 batchId,
bytes32 deviceIdHash,
UploadBatchParams calldata params
) private;
Parameters
| Name | Type | Description |
|---|---|---|
batchId | uint64 | The batch ID |
deviceIdHash | bytes32 | The hash of the device ID |
params | UploadBatchParams | The upload batch parameters |
_validateUploadBatchParams
Validates the upload batch parameters
function _validateUploadBatchParams(UploadBatchParams calldata params)
private
view
returns (bytes32 deviceIdHash);
Parameters
| Name | Type | Description |
|---|---|---|
params | UploadBatchParams | The upload batch parameters to validate |
Returns
| Name | Type | Description |
|---|---|---|
deviceIdHash | bytes32 | The hash of the device ID for later use |