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