use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.
the class TimestampedECDSASignatures method fromJSON.
public static TimestampedECDSASignatures fromJSON(JSONArray json) throws DeserializeException {
var builder = ImmutableMap.<BFTNode, TimestampedECDSASignature>builder();
for (int i = 0; i < json.length(); i++) {
var signatureJson = json.getJSONObject(i);
try {
var key = ECPublicKey.fromHex(signatureJson.getString("key"));
var bytes = Bytes.fromHexString(signatureJson.getString("signature"));
var signature = REFieldSerialization.deserializeSignature(ByteBuffer.wrap(bytes));
var timestamp = signatureJson.getLong("timestamp");
builder.put(BFTNode.create(key), TimestampedECDSASignature.from(timestamp, signature));
} catch (PublicKeyException e) {
throw new DeserializeException(e.getMessage());
}
}
return new TimestampedECDSASignatures(builder.build());
}
use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.
the class BerkeleySafetyStateStore method get.
@Override
public Optional<SafetyState> get() {
final var start = System.nanoTime();
try (com.sleepycat.je.Cursor cursor = this.safetyStore.openCursor(null, null)) {
DatabaseEntry pKey = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
OperationStatus status = cursor.getLast(pKey, value, LockMode.DEFAULT);
if (status == OperationStatus.SUCCESS) {
addBytesRead(pKey.getSize() + value.getSize());
try {
final SafetyState deserializedState = serialization.fromDson(value.getData(), SafetyState.class);
return Optional.of(deserializedState);
} catch (DeserializeException ex) {
logger.error("Failed to deserialize persisted SafetyState", ex);
return Optional.empty();
}
} else {
return Optional.empty();
}
} finally {
addTime(start);
}
}
use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.
the class CodecBenchmark method jacksonFromJsonTest.
@Benchmark
public void jacksonFromJsonTest(Blackhole bh) {
try {
DummyTestObject newObj = serialization.fromJson(jacksonJson, DummyTestObject.class);
bh.consume(newObj);
} catch (DeserializeException ex) {
throw new IllegalStateException("While deserializing from JSON", ex);
}
}
use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.
the class CandidateForkVotesPostProcessor method extractBftNodeAndVoteIfPresent.
private Optional<Pair<BFTNode, CandidateForkVote>> extractBftNodeAndVoteIfPresent(RawSubstateBytes rawSubstateBytes) {
try {
final var validatorSystemMetadataSubstate = (ValidatorSystemMetadata) substateDeserialization.deserialize(rawSubstateBytes.getData());
if (Bytes.isAllZeros(validatorSystemMetadataSubstate.data())) {
return Optional.empty();
}
final var candidateForkVote = new CandidateForkVote(HashCode.fromBytes(validatorSystemMetadataSubstate.data()));
return Optional.of(Pair.of(BFTNode.create(validatorSystemMetadataSubstate.validatorKey()), candidateForkVote));
} catch (DeserializeException e) {
throw new PostProcessorException("Error deserializing ValidatorSystemMetadata");
}
}
use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.
the class REFieldSerialization method deserializeKey.
public static ECPublicKey deserializeKey(ByteBuffer buf) throws DeserializeException {
try {
var keyBytes = new byte[33];
buf.get(keyBytes);
return ECPublicKey.fromBytes(keyBytes);
} catch (PublicKeyException | IllegalArgumentException e) {
throw new DeserializeException("Could not deserialize key");
}
}
Aggregations