From e80b5b80ef259b7ca2435ae28c3f5c979109623b Mon Sep 17 00:00:00 2001 From: Eric Mastro Date: Mon, 28 Nov 2022 14:43:03 +1100 Subject: [PATCH] clean up --- contracts/libs/Mappings.sol | 16 ++++------------ contracts/{ => libs}/TestMappings.sol | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) rename contracts/{ => libs}/TestMappings.sol (98%) 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 {