fix insert_entry retval

feat/vaults
Tomáš Mládek 2022-01-22 17:45:46 +01:00
parent 0920fec0ce
commit a4caf9b8b3
No known key found for this signature in database
GPG Key ID: ED21612889E75EC5
1 changed files with 14 additions and 12 deletions

View File

@ -336,29 +336,31 @@ impl UpEndConnection {
pub fn insert_entry(&self, entry: Entry) -> Result<Address> {
debug!("Inserting: {}", entry);
let entry = models::Entry::try_from(&entry)?;
self._insert_entry(entry)
let db_entry = models::Entry::try_from(&entry)?;
self._insert_entry(db_entry)?;
entry.address()
}
pub fn insert_entry_immutable(&self, entry: Entry) -> Result<Address> {
debug!("Inserting immutably: {}", entry);
let entry = models::Entry::try_from(&ImmutableEntry(entry))?;
self._insert_entry(entry)
let address = entry.address()?;
let db_entry = models::Entry::try_from(&ImmutableEntry(entry))?;
self._insert_entry(db_entry)?;
Ok(address)
}
fn _insert_entry(&self, entry: models::Entry) -> Result<Address> {
fn _insert_entry(&self, entry: models::Entry) -> Result<usize> {
let result = diesel::insert_into(data::table)
.values(&entry)
.execute(&self.conn);
if let Some(error) = result.err() {
match error {
Error::DatabaseError(DatabaseErrorKind::UniqueViolation, _) => {}
_ => return Err(anyhow!(error)),
}
match result {
Ok(num) => Ok(num),
Err(error) => match error {
Error::DatabaseError(DatabaseErrorKind::UniqueViolation, _) => Ok(0),
_ => Err(anyhow!(error)),
},
}
Ok(Address::Hash(Hash(entry.identity)))
}
// #[deprecated]