Skip to content

Commit

Permalink
Handle attributes in multiple minter | fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LorranSutter committed May 8, 2024
1 parent 24c3887 commit ddb2589
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@
| Selector | Signature |
|-|-|
| 0xfb1a28e8 | mintVehicleAndSdSign((uint256,address,(string,string)[],uint256,bytes,bytes,address,(string,string)[])) |
| 0x191292f8 | mintVehicleAndSdWithDeviceDefinitionSign((uint256,address,string,uint256,bytes,bytes,address,(string,string)[])) |
| 0xd23965e3 | mintVehicleAndSdWithDeviceDefinitionSign((uint256,address,string,(string,string)[],uint256,bytes,bytes,address,(string,string)[])) |

#### Events
| Selector | Signature |
Expand Down
17 changes: 17 additions & 0 deletions abis/DimoRegistry.json
Original file line number Diff line number Diff line change
Expand Up @@ -3222,6 +3222,23 @@
"name": "deviceDefinitionId",
"type": "string"
},
{
"components": [
{
"internalType": "string",
"name": "attribute",
"type": "string"
},
{
"internalType": "string",
"name": "info",
"type": "string"
}
],
"internalType": "struct AttributeInfoPair[]",
"name": "attrInfoPairsVehicle",
"type": "tuple[]"
},
{
"internalType": "uint256",
"name": "integrationNode",
Expand Down
19 changes: 15 additions & 4 deletions contracts/implementations/MultipleMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ contract MultipleMinter is
* manufacturerNode -> Parent manufacturer node id of the vehicle
* owner -> The new nodes owner
* deviceDefinitionId -> The Device Definition Id
* attrInfoPairsVehicle -> List of attribute-info pairs to be added of the vehicle
* integrationNode -> Parent integration node id of the synthetic device
* vehicleOwnerSig -> Vehicle owner signature hash
* syntheticDeviceSig -> Synthetic Device's signature hash
Expand All @@ -164,7 +165,6 @@ contract MultipleMinter is
function mintVehicleAndSdWithDeviceDefinitionSign(
MintVehicleAndSdWithDdInput calldata data
) external onlyRole(MINT_VEHICLE_SD_ROLE) {
NodesStorage.Storage storage ns = NodesStorage.getStorage();
MapperStorage.Storage storage ms = MapperStorage.getStorage();
VehicleStorage.Storage storage vs = VehicleStorage.getStorage();
SyntheticDeviceStorage.Storage storage sds = SyntheticDeviceStorage
Expand Down Expand Up @@ -210,12 +210,19 @@ contract MultipleMinter is
data.deviceDefinitionId
);

(bytes32 attributesHash, bytes32 infosHash) = _setInfosHash(
newTokenIdVehicle,
data.attrInfoPairsVehicle
);

message = keccak256(
abi.encode(
MINT_VEHICLE_WITH_DD_TYPEHASH,
data.manufacturerNode,
data.owner,
keccak256(bytes(data.deviceDefinitionId))
keccak256(bytes(data.deviceDefinitionId)),
attributesHash,
infosHash
)
);

Expand Down Expand Up @@ -244,12 +251,16 @@ contract MultipleMinter is
// ----- END Synthetic Device mint and attributes -----

// ----- Internal contract state change -----
ns.nodes[vehicleIdProxyAddress][newTokenIdVehicle].parentNode = data
NodesStorage
.getStorage()
.nodes[vehicleIdProxyAddress][newTokenIdVehicle].parentNode = data
.manufacturerNode;
vs.vehicleIdToDeviceDefinitionId[newTokenIdVehicle] = data
.deviceDefinitionId;

ns.nodes[sdIdProxyAddress][newTokenIdDevice].parentNode = data
NodesStorage
.getStorage()
.nodes[sdIdProxyAddress][newTokenIdDevice].parentNode = data
.integrationNode;

ms.nodeLinks[vehicleIdProxyAddress][sdIdProxyAddress][
Expand Down
15 changes: 7 additions & 8 deletions contracts/implementations/nodes/Vehicle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ contract Vehicle is AccessControlInternal, VehicleInternal {
AttributeInfoPair[] calldata attrInfo,
bytes calldata signature
) external onlyRole(MINT_VEHICLE_ROLE) {
// VehicleStorage.Storage storage vs = VehicleStorage.getStorage();
address vehicleIdProxyAddress = VehicleStorage
.getStorage()
.idProxyAddress;
Expand All @@ -172,6 +171,13 @@ contract Vehicle is AccessControlInternal, VehicleInternal {
newTokenId
] = deviceDefinitionId;

emit VehicleNodeMintedWithDeviceDefinition(
manufacturerNode,
newTokenId,
owner,
deviceDefinitionId
);

(bytes32 attributesHash, bytes32 infosHash) = _setInfosHash(
newTokenId,
attrInfo
Expand All @@ -190,13 +196,6 @@ contract Vehicle is AccessControlInternal, VehicleInternal {

if (!Eip712CheckerInternal._verifySignature(owner, message, signature))
revert InvalidOwnerSignature();

emit VehicleNodeMintedWithDeviceDefinition(
manufacturerNode,
newTokenId,
owner,
deviceDefinitionId
);
}

/**
Expand Down
1 change: 1 addition & 0 deletions contracts/shared/Types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct MintVehicleAndSdWithDdInput {
uint256 manufacturerNode;
address owner;
string deviceDefinitionId;
AttributeInfoPair[] attrInfoPairsVehicle;
uint256 integrationNode;
bytes vehicleOwnerSig;
bytes syntheticDeviceSig;
Expand Down
Loading

0 comments on commit ddb2589

Please sign in to comment.