Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Deshare

Git Source

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

NameTypeDescription
adminaddressAddress for validation (required but not used in implementation)

initialize

Initialize the Deshare proxy

function initialize(address admin) external payable initializer;

Parameters

NameTypeDescription
adminaddressAddress that will be granted admin and operator roles

registerPartner

Register a new partner

function registerPartner(PartnerParams calldata params)
    external
    override
    onlyRole(OPERATOR_ROLE);

Parameters

NameTypeDescription
paramsPartnerParamsPartner registration parameters

registerMerchant

Register a new merchant

function registerMerchant(MerchantParams calldata params)
    external
    override
    onlyRole(OPERATOR_ROLE);

Parameters

NameTypeDescription
paramsMerchantParamsMerchant registration parameters

registerDevice

Register a new device

function registerDevice(DeviceParams calldata params)
    external
    override
    onlyRole(OPERATOR_ROLE);

Parameters

NameTypeDescription
paramsDeviceParamsDevice registration parameters

uploadTransactionBatch

Upload a transaction batch

function uploadTransactionBatch(UploadBatchParams calldata params)
    external
    override
    onlyRole(OPERATOR_ROLE)
    nonReentrant;

Parameters

NameTypeDescription
paramsUploadBatchParamsUpload batch parameters

registerCountry

Register a country

function registerCountry(bytes2 iso2) external override onlyRole(OPERATOR_ROLE);

Parameters

NameTypeDescription
iso2bytes2The ISO2 country code

getVersion

Get the contract version

function getVersion() external view override returns (Version memory);

Returns

NameTypeDescription
<none>Versionversion The current version

getStats

Get statistics information

function getStats() external view override returns (StatsInfo memory stats);

Returns

NameTypeDescription
statsStatsInfoThe current statistics

getDetailedStats

Get detailed statistics information with descriptive labels

function getDetailedStats()
    external
    view
    override
    returns (DetailedStatsInfo memory detailedStats);

Returns

NameTypeDescription
detailedStatsDetailedStatsInfoThe detailed statistics with labels and metadata

getPartner

Get partner information by ID

function getPartner(uint256 partnerId) external view override returns (PartnerInfo memory);

Parameters

NameTypeDescription
partnerIduint256The partner ID

Returns

NameTypeDescription
<none>PartnerInfopartner The partner information

getPartnerByCode

Get partner information by partner code

function getPartnerByCode(string calldata partnerCode)
    external
    view
    override
    returns (PartnerInfo memory);

Parameters

NameTypeDescription
partnerCodestringThe partner code

Returns

NameTypeDescription
<none>PartnerInfopartner The partner information

partnerExists

Check if a partner exists by code

function partnerExists(string calldata partnerCode)
    external
    view
    override
    returns (bool exists);

Parameters

NameTypeDescription
partnerCodestringThe partner code

Returns

NameTypeDescription
existsboolWhether the partner exists

getMerchant

Get merchant information by ID

function getMerchant(uint256 merchantId) external view override returns (MerchantInfo memory);

Parameters

NameTypeDescription
merchantIduint256The merchant ID

Returns

NameTypeDescription
<none>MerchantInfomerchant The merchant information

getMerchantById

Get merchant information by merchant ID

function getMerchantById(string calldata merchantId)
    external
    view
    override
    returns (MerchantInfo memory);

Parameters

NameTypeDescription
merchantIdstringThe merchant ID (string)

Returns

NameTypeDescription
<none>MerchantInfomerchant The merchant information

merchantExists

Check if a merchant exists by ID

function merchantExists(string calldata merchantId)
    external
    view
    override
    returns (bool exists);

Parameters

NameTypeDescription
merchantIdstringThe merchant ID

Returns

NameTypeDescription
existsboolWhether the merchant exists

getDevice

Get device information by ID

function getDevice(uint256 deviceId) external view override returns (DeviceInfo memory);

Parameters

NameTypeDescription
deviceIduint256The device ID

Returns

NameTypeDescription
<none>DeviceInfodevice The device information

getDeviceById

Get device information by device ID

function getDeviceById(string calldata deviceId)
    external
    view
    override
    returns (DeviceInfo memory);

Parameters

NameTypeDescription
deviceIdstringThe device ID (string)

Returns

NameTypeDescription
<none>DeviceInfodevice The device information

deviceExists

Check if a device exists by ID

function deviceExists(string calldata deviceId) external view override returns (bool exists);

Parameters

NameTypeDescription
deviceIdstringThe device ID

Returns

NameTypeDescription
existsboolWhether the device exists

getTransactionBatch

Get transaction batch by ID

function getTransactionBatch(uint256 batchId)
    external
    view
    override
    returns (TransactionBatch memory);

Parameters

NameTypeDescription
batchIduint256The batch ID

Returns

NameTypeDescription
<none>TransactionBatchbatch The transaction batch

getTransactionData

Retrieves transaction data for a batch

function getTransactionData(uint256 batchId)
    external
    view
    override
    returns (string memory jsonData);

Parameters

NameTypeDescription
batchIduint256The batch ID to retrieve data for

Returns

NameTypeDescription
jsonDatastringThe transaction data as JSON string

getCountry

Get country information

function getCountry(bytes2 iso2) external view override returns (CountryInfo memory);

Parameters

NameTypeDescription
iso2bytes2The ISO2 country code

Returns

NameTypeDescription
<none>CountryInfocountry The country information

countryExists

Check if a country is registered

function countryExists(bytes2 iso2) external view override returns (bool exists);

Parameters

NameTypeDescription
iso2bytes2The ISO2 country code

Returns

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

NameTypeDescription
businessTypestringThe business type to query

Returns

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

NameTypeDescription
iso2bytes2The ISO2 country code
locationIdstringThe location ID (e.g., city identifier)

Returns

NameTypeDescription
countuint256The count of merchants

_getCountriesCount

Returns the count of registered countries

function _getCountriesCount() internal view returns (uint256 count);

Returns

NameTypeDescription
countuint256The number of registered countries

_createTransactionBatch

Creates and stores a new transaction batch

function _createTransactionBatch(UploadBatchParams calldata params)
    private
    returns (uint64 batchId);

Parameters

NameTypeDescription
paramsUploadBatchParamsThe upload batch parameters

Returns

NameTypeDescription
batchIduint64The ID of the created batch

_storeTransactionData

Stores transaction data for a batch

function _storeTransactionData(uint64 batchId, bytes calldata transactionData) private;

Parameters

NameTypeDescription
batchIduint64The batch ID to store data for
transactionDatabytesThe transaction data to store

_emitBatchEvents

Emits events for transaction batch upload

function _emitBatchEvents(
    uint64 batchId,
    bytes32 deviceIdHash,
    UploadBatchParams calldata params
) private;

Parameters

NameTypeDescription
batchIduint64The batch ID
deviceIdHashbytes32The hash of the device ID
paramsUploadBatchParamsThe upload batch parameters

_validateUploadBatchParams

Validates the upload batch parameters

function _validateUploadBatchParams(UploadBatchParams calldata params)
    private
    view
    returns (bytes32 deviceIdHash);

Parameters

NameTypeDescription
paramsUploadBatchParamsThe upload batch parameters to validate

Returns

NameTypeDescription
deviceIdHashbytes32The hash of the device ID for later use