diff --git a/contracts/proxy/proxy.cpp b/contracts/proxy/proxy.cpp index 9b5e434bee3861a86545626944d5a4516cfa355e..58a8176a259e44f08a5e858a950e5dfa7e44209b 100644 --- a/contracts/proxy/proxy.cpp +++ b/contracts/proxy/proxy.cpp @@ -11,16 +11,27 @@ namespace proxy { using namespace eosio; namespace configs { + + typedef multi_index config_table; + bool get(config &out, const account_name &self) { - auto read = load_i64(self, self, N(config), (char*)&out, sizeof(config)); - if (read < 0) { + auto it = db_find_i64(self, self, N(config), config::key); + if (it != -1) { + auto size = db_get_i64(it, (char*)&out, sizeof(config)); + eosio_assert(size == sizeof(config), "Wrong record size"); + return true; + } else { return false; } - return true; } void store(const config &in, const account_name &self) { - store_i64(self, N(config), self, (const char *)&in, sizeof(config)); + auto it = db_find_i64(self, self, N(config), config::key); + if (it != -1) { + db_update_i64(it, self, (const char *)&in, sizeof(config)); + } else { + db_store_i64(self, N(config), self, config::key, (const char *)&in, sizeof(config)); + } } }; diff --git a/contracts/proxy/proxy.hpp b/contracts/proxy/proxy.hpp index 95a7e498ff6245835555c8bada0c31dadc4d6f08..f85b9ea2c57dd645589ec4b265eaa97f50902714 100644 --- a/contracts/proxy/proxy.hpp +++ b/contracts/proxy/proxy.hpp @@ -15,7 +15,7 @@ namespace proxy { //@abi table struct config { config(){} - const uint64_t key = N(config); + constexpr static uint64_t key = N(config); account_name owner = 0; uint32_t delay = 0; uint32_t next_id = 0;