Contracts
ServicesRegistry

Solidity API

ServicesRegistry

Contract for creating and updating services for service owners and adding/removing services for chip owners. Services contain a recordType and record content. The recordType is intended to be a standardized off-chain string that clients can use to interpret the record content. Record types could be a tokenUri, a URL, a smart contract, or any other value. Chips are always enrolled in a primary service, in most cases this is the service the chip should resolve to when scanned. Additionally, a chip can be enrolled in secondary services that allow it to access additional functionality. Primary services have a timelock that must expire before the primary service can be changed. Secondary services can be added and removed at any time. The primary service cannot be one of the chip's secondary services.

ServiceCreated

event ServiceCreated(bytes32 serviceId, address owner)

ServiceRecordAdded

event ServiceRecordAdded(bytes32 serviceId, bytes32 recordType, bytes content, bool appendId)

ServiceRecordEdited

event ServiceRecordEdited(bytes32 serviceId, bytes32 recordType, bytes newContent, bool appendId)

ServiceRecordRemoved

event ServiceRecordRemoved(bytes32 serviceId, bytes32 recordType)

ServiceOwnershipTransferred

event ServiceOwnershipTransferred(bytes32 serviceId, address oldOwner, address newOwner)

PrimaryServiceUpdated

event PrimaryServiceUpdated(address chipId, bytes32 newPrimaryService, bytes32 oldPrimaryService, uint256 serviceTimelock)

SecondaryServiceAdded

event SecondaryServiceAdded(address chipId, bytes32 serviceId)

SecondaryServiceRemoved

event SecondaryServiceRemoved(address chipId, bytes32 serviceId)

RecordContent

struct RecordContent {
  bool enabled;
  bool appendId;
  bytes content;
}

ServiceRecord

struct ServiceRecord {
  bytes32 recordType;
  bytes content;
  bool appendId;
}

ServiceInfo

struct ServiceInfo {
  address owner;
  bytes32[] recordTypes;
}

ChipServices

struct ChipServices {
  bytes32 primaryService;
  uint256 serviceTimelock;
  bytes32[] secondaryServices;
}

onlyServiceOwner

modifier onlyServiceOwner(bytes32 _serviceId)

onlyChipOwner

modifier onlyChipOwner(address _chipId)

chipRegistry

contract IChipRegistry chipRegistry

maxBlockWindow

uint256 maxBlockWindow

chipServices

mapping(address => struct ServicesRegistry.ChipServices) chipServices

enrolledServices

mapping(address => mapping(bytes32 => bool)) enrolledServices

serviceInfo

mapping(bytes32 => struct ServicesRegistry.ServiceInfo) serviceInfo

serviceRecords

mapping(bytes32 => mapping(bytes32 => struct ServicesRegistry.RecordContent)) serviceRecords

constructor

constructor(contract IChipRegistry _chipRegistry, uint256 _maxBlockWindow) public

Constructor for ServicesRegistry

Parameters

NameTypeDescription
_chipRegistrycontract IChipRegistryAddress of the ChipRegistry contract
_maxBlockWindowuint256The maximum amount of blocks a signature used for updating chip table is valid for

createService

function createService(bytes32 _serviceId, struct ServicesRegistry.ServiceRecord[] _serviceRecords) external

Creates a new service. Services contain multiple different record types which could be a tokenUri, a URL or any other unstructured content. Each record is identified by its recordType. We expect off-chain standardization around recordTypes and do not maintain a canonical on-chain list of records. Associated with each recordType is a content string which is intended to be interpreted by the client. The service ID must be unique and the service records must not contain duplicate record types.

Parameters

NameTypeDescription
_serviceIdbytes32The service ID
_serviceRecordsstruct ServicesRegistry.ServiceRecord[]The service records

addServiceRecords

function addServiceRecords(bytes32 _serviceId, struct ServicesRegistry.ServiceRecord[] _serviceRecords) external

ONLY SERVICE OWNER: Adds new service records to an existing service. The service records must not contain duplicate record types or have an existing record of the same type. Don't need to explicitly check that the service has been created because if it has then there should be an owner address if not then the owner address is the zero address thus it will revert.

Parameters

NameTypeDescription
_serviceIdbytes32The service ID
_serviceRecordsstruct ServicesRegistry.ServiceRecord[]The service records

editServiceRecords

function editServiceRecords(bytes32 _serviceId, struct ServicesRegistry.ServiceRecord[] _serviceRecords) external

ONLY SERVICE OWNER: Edits existing service records for an existing service. The service records must not contain duplicate record types.

Parameters

NameTypeDescription
_serviceIdbytes32The service ID
_serviceRecordsstruct ServicesRegistry.ServiceRecord[]The service records

removeServiceRecords

function removeServiceRecords(bytes32 _serviceId, bytes32[] _recordTypes) external

ONLY SERVICE OWNER: Removes existing service records for an existing service. The service records must not contain duplicate record types.

Parameters

NameTypeDescription
_serviceIdbytes32The service ID
_recordTypesbytes32[]The record types to remove

setServiceOwner

function setServiceOwner(bytes32 _serviceId, address _newOwner) external

ONLY SERVICE OWNER: Sets the service owner to a new address. The new address cannot be the zero address.

Parameters

NameTypeDescription
_serviceIdbytes32The service ID
_newOwneraddressThe new owner address

setInitialService

function setInitialService(address _chipId, bytes32 _serviceId, uint256 _timelock) external

ONLY CHIP REGISTRY: Sets the initial service for a chip. The service must exist and the passed _timelock must not be 0. If the current primaryService state is set to bytes32(0) then the chip has NOT been enrolled in a service and thus this function can be called.

Parameters

NameTypeDescription
_chipIdaddressThe chip ID
_serviceIdbytes32The service ID to enroll
_timelockuint256Timelock before which the primaryService cannot be changed

setNewPrimaryService

function setNewPrimaryService(address _chipId, bytes32 _serviceId, uint256 _newTimelock, uint256 _commitBlock, bytes _signature) external

ONLY CHIP OWNER: Sets the primary service for the calling chip. In order for this function to succeed the following conditions must be met:

  • The caller is the chip owner
  • The new service must exist
  • The new service must not be the same as the current primary service
  • The new timelock must be greater than the current block timestamp
  • The timelock for the previous primaryService must have expired
  • The new service must not be enrolled as a secondary service for the chip
  • The signature was generated by the chip This function can't be called until after the chip has been claimed and enrolled in a primary service (enforced by onlyChipOwner).

Parameters

NameTypeDescription
_chipIdaddressAddress of chip removing secondary service
_serviceIdbytes32New primary service ID
_newTimelockuint256Timelock for the new primary service
_commitBlockuint256The block the signature is tied to (used to put a time limit on the signature)
_signaturebytesThe signature generated by the chipId (should just be a signature of the commitBlock)

addSecondaryService

function addSecondaryService(address _chipId, bytes32 _serviceId, uint256 _commitBlock, bytes _signature) external

ONLY CHIP OWNER: Adds a secondary service for the calling chip. In order for this function to succeed the following conditions must be met:

  • The caller is the chip owner
  • The new service must exist
  • The new service must not be enrolled as a secondary service for the chip
  • The new service must not be the same as the primary service
  • The signature was generated by the chip This function can't be called until after the chip has been claimed and enrolled in a primary service (enforced by onlyChipOwner).

Parameters

NameTypeDescription
_chipIdaddressAddress of chip removing secondary service
_serviceIdbytes32The service ID
_commitBlockuint256The block the signature is tied to (used to put a time limit on the signature)
_signaturebytesThe signature generated by the chipId (should just be a signature of the commitBlock)

removeSecondaryService

function removeSecondaryService(address _chipId, bytes32 _serviceId, uint256 _commitBlock, bytes _signature) external

ONLY CHIP OWNER: Removes a secondary service for the calling chip. In order for this function to succeed the following conditions must be met:

  • The caller is the chip owner
  • The service must exist
  • The service must be enrolled as a secondary service for the chip
  • The signature was generated by the chip This function can't be called until after the chip has been claimed and enrolled in a primary service (enforced by onlyChipOwner).

Parameters

NameTypeDescription
_chipIdaddressAddress of chip removing secondary service
_serviceIdbytes32The service ID
_commitBlockuint256The block the signature is tied to (used to put a time limit on the signature)
_signaturebytesThe signature generated by the chipId (should just be a signature of the commitBlock)

getServiceInfo

function getServiceInfo(bytes32 _serviceId) external view returns (struct ServicesRegistry.ServiceInfo)

Return information about owner and record types for a service

Parameters

NameTypeDescription
_serviceIdbytes32The service ID

Return Values

NameTypeDescription
[0]struct ServicesRegistry.ServiceInfoServiceInfo struct (owner and recordTypes)

getPrimaryServiceContentByRecordtype

function getPrimaryServiceContentByRecordtype(address _chipId, bytes32 _recordType) external view returns (bytes)

Get the content of the given record type for a chip's primary service

Parameters

NameTypeDescription
_chipIdaddressThe chip ID
_recordTypebytes32The record type

Return Values

NameTypeDescription
[0]bytesbytes representing the content of the record

getServiceContent

function getServiceContent(address _chipId, bytes32 _serviceId) public view returns (struct IServicesRegistry.Record[] records)

Get a list of all records for a given service

Parameters

NameTypeDescription
_chipIdaddress
_serviceIdbytes32The service ID

Return Values

NameTypeDescription
recordsstruct IServicesRegistry.Record[]List of ServiceRecords for the passed serviceId

getAllChipServiceData

function getAllChipServiceData(address _chipId) external view returns (struct IServicesRegistry.ExpandedChipServices)

Get records for every secondary service and primary service for a chip. Primary service timelock is also included in struct.

Parameters

NameTypeDescription
_chipIdaddressThe chip ID

Return Values

NameTypeDescription
[0]struct IServicesRegistry.ExpandedChipServicesStruct containing all records for each secondary service and primary service for the chip

getPrimaryServiceContent

function getPrimaryServiceContent(address _chipId) external view returns (struct IServicesRegistry.Record[])

Get records for every secondary service and primary service for a chip. Primary service timelock is also included in struct.

Parameters

NameTypeDescription
_chipIdaddressThe chip ID

Return Values

NameTypeDescription
[0]struct IServicesRegistry.Record[]List of ServiceRecords for the chip's primary service

getChipSecondaryServices

function getChipSecondaryServices(address _chipId) public view returns (bytes32[])

Get list of secondary service Id's for a chip

Parameters

NameTypeDescription
_chipIdaddressThe chip ID

Return Values

NameTypeDescription
[0]bytes32[]List of secondary serviceIds for the chip

_addServiceRecord

function _addServiceRecord(bytes32 _serviceId, struct ServicesRegistry.ServiceRecord _record) internal

Adds a new service record to an existing service. The service records must not contain duplicate record types or have an existing record of the same type.

Parameters

NameTypeDescription
_serviceIdbytes32The service ID
_recordstruct ServicesRegistry.ServiceRecordServiceRecord struct containing recordType, content, and appendId

_isService

function _isService(bytes32 _serviceId) internal view returns (bool)

Checks if a service exists

Parameters

NameTypeDescription
_serviceIdbytes32The service ID

Return Values

NameTypeDescription
[0]boolTrue if service exists, false otherwise

_createContentString

function _createContentString(address _chipId, bytes _content, bool _appendId) internal pure returns (bytes)

Build a content string based on if the chipId should be appended to the base content

Parameters

NameTypeDescription
_chipIdaddressThe chip ID
_contentbytesThe base content
_appendIdboolWhether or not to append the chipId to the content

Return Values

NameTypeDescription
[0]bytesBytestring representing the content