| 177 | } |
| 178 | |
| 179 | void SecretStore::save(string const& _keysPath) |
| 180 | { |
| 181 | fs::path p(_keysPath); |
| 182 | fs::create_directories(p); |
| 183 | DEV_IGNORE_EXCEPTIONS(fs::permissions(p, fs::owner_all)); |
| 184 | for (auto& k: m_keys) |
| 185 | { |
| 186 | string uuid = toUUID(k.first); |
| 187 | string filename = (p / uuid).string() + ".json"; |
| 188 | js::mObject v; |
| 189 | js::mValue crypto; |
| 190 | js::read_string(k.second.encryptedKey, crypto); |
| 191 | v["address"] = k.second.address.hex(); |
| 192 | v["crypto"] = crypto; |
| 193 | v["id"] = uuid; |
| 194 | v["version"] = c_keyFileVersion; |
| 195 | writeFile(filename, js::write_string(js::mValue(v), true)); |
| 196 | swap(k.second.filename, filename); |
| 197 | if (!filename.empty() && !fs::equivalent(filename, k.second.filename)) |
| 198 | fs::remove(filename); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | bool SecretStore::noteAddress(h128 const& _uuid, Address const& _address) |
| 203 | { |