跳到主要内容

JBDelegateMetadataLib

Git Source

Library to parse and create delegate metadata

Metadata are built as:

  • 32B of reserved space for the protocol
  • a lookup table delegateId: offset, defining the offset of the metadata for each delegate. The offset fits 1 bytes, the ID 4 bytes. This table is padded to 32B.
  • the metadata for each delegate, padded to 32B each
+-----------------------+ offset: 0
| 32B reserved |
+-----------------------+ offset: 1 = end of first 32B
| (delegate1 ID,offset1)|
| (delegate2 ID,offset2)|
| 0's padding |
+-----------------------+ offset: offset1 = 1 + number of words taken by the padded table
| delegate 1 metadata1 |
| 0's padding |
+-----------------------+ offset: offset2 = offset1 + number of words taken by the metadata1
| delegate 2 metadata2 |
| 0's padding |
+-----------------------+

Functions

getMetadata

Parse the metadata to find the metadata for a specific delegate

Returns false and an empty bytes if no metadata is found

function getMetadata(bytes4 _id, bytes calldata _metadata)
internal
pure
returns (bool _found, bytes memory _targetMetadata);

Parameters

NameTypeDescription
_idbytes4The delegate id to find
_metadatabytesThe metadata to parse

Returns

NameTypeDescription
_foundboolWhether the metadata was found
_targetMetadatabytesThe metadata for the delegate

addToMetadata

Add a delegate to an existing metadata

function addToMetadata(bytes4 _idToAdd, bytes calldata _dataToAdd, bytes calldata _originalMetadata)
public
pure
returns (bytes memory _newMetadata);

Parameters

NameTypeDescription
_idToAddbytes4The id of the delegate to add
_dataToAddbytesThe metadata of the delegate to add
_originalMetadatabytesThe original metadata

Returns

NameTypeDescription
_newMetadatabytesThe new metadata with the delegate added