diff --git a/contracts/libs/Mappings.sol b/contracts/libs/Mappings.sol index 290b2a5..06de565 100644 --- a/contracts/libs/Mappings.sol +++ b/contracts/libs/Mappings.sol @@ -20,17 +20,10 @@ library Mappings { mapping(ValueId => Value) _values; } struct Key { - string name; - bool delux; - uint price; - EnumerableSetExtensions.ClearableBytes32Set _values; } - struct Value { - string name; - bool delux; - uint price; + struct Value { KeyId _keyId; } @@ -118,10 +111,9 @@ library Mappings { success = insertKey(map, key); assert (success); // key insertion failure } - map._valueIds.add(ValueId.unwrap(value)); - map._values[value]._keyId = key; - - success = map._keys[key]._values.add(ValueId.unwrap(value)); + if (!exists(map, key, value)) { + success = insertValue(map, key, value); + } } function deleteKey(Mapping storage map, KeyId key) diff --git a/contracts/TestMappings.sol b/contracts/libs/TestMappings.sol similarity index 98% rename from contracts/TestMappings.sol rename to contracts/libs/TestMappings.sol index 9d60a1f..b0a2090 100644 --- a/contracts/TestMappings.sol +++ b/contracts/libs/TestMappings.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "./libs/Mappings.sol"; +import "./Mappings.sol"; // exposes public functions for testing contract TestMappings {