return new DatabaseEntry(makeBytes(USERS.getData(), SEPARATOR, publicHash, SEPARATOR, KEY));
}
@Override
public boolean addUser(byte[] publicKey, byte[] publicHash) {
Transaction txn = null;
try {
txn = env.beginTransaction(null, null);
if (haveUser(txn, publicHash)) {
txn.commit();
return false;// User already exists
}
DatabaseEntry ph = new DatabaseEntry(publicHash);
OperationStatus res = db.put(txn, USERS, ph);
if (res != OperationStatus.SUCCESS) {
log.severe("Could not add ph: " + res.toString());
txn.abort();
return false;
}
DatabaseEntry regDateKey = makeRegDateKey(publicHash);
DatabaseEntry regTime = new DatabaseEntry(Util.long2bin(System.currentTimeMillis()));
res = db.put(txn, regDateKey, regTime);
if (res != OperationStatus.SUCCESS) {
log.severe("Could not add regTime: " + res.toString());
txn.abort();
return false;
}
DatabaseEntry regPublicKeyKey = makePublicKeyKey(publicHash);
DatabaseEntry regPublicKey = new DatabaseEntry(publicKey);
res = db.put(txn, regPublicKeyKey, regPublicKey);
if (res != OperationStatus.SUCCESS) {
log.severe("Could not add publicKey: " + res.toString());
txn.abort();
return false;
}
txn.commit();
return true;
} catch (DatabaseException e) {
severe("Exception while adding user", e);
try {
if (txn != null) {
txn.abort();
}
} catch (DatabaseException e1) {
// we already had a failure, ignore this one.
}
return false;