Search in sources :

Example 6 with DeserializeException

use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.

the class VirtualSubstateDeserialization method keyToSubstate.

public Particle keyToSubstate(byte typeByte, ByteBuffer buf) throws DeserializeException {
    var deserializer = byteToDeserializer.get(typeByte);
    if (deserializer == null) {
        throw new DeserializeException("Unknown byte type: " + typeByte);
    }
    try {
        var key = deserializer.keyDeserializer().deserialize(buf);
        var rawSubstate = deserializer.virtualMapper().map(key);
        if (buf.hasRemaining()) {
            throw new TrailingBytesException("Buffer has " + buf.remaining() + " bytes remaining.");
        }
        return rawSubstate;
    } catch (Exception e) {
        throw new SubstateDeserializationException(deserializer.substateClass(), e);
    }
}
Also used : TrailingBytesException(com.radixdlt.engine.parser.exceptions.TrailingBytesException) SubstateDeserializationException(com.radixdlt.engine.parser.exceptions.SubstateDeserializationException) DeserializeException(com.radixdlt.serialization.DeserializeException) SubstateDeserializationException(com.radixdlt.engine.parser.exceptions.SubstateDeserializationException) TrailingBytesException(com.radixdlt.engine.parser.exceptions.TrailingBytesException) DeserializeException(com.radixdlt.serialization.DeserializeException)

Example 7 with DeserializeException

use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.

the class CodecBenchmark method jacksonFromBytesTest.

@Benchmark
public void jacksonFromBytesTest(Blackhole bh) {
    try {
        DummyTestObject newObj = serialization.fromDson(jacksonBytes, DummyTestObject.class);
        bh.consume(newObj);
    } catch (DeserializeException ex) {
        throw new IllegalStateException("While deserializing from DSON", ex);
    }
}
Also used : DummyTestObject(org.radix.serialization.DummyTestObject) DeserializeException(com.radixdlt.serialization.DeserializeException) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 8 with DeserializeException

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());
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) PublicKeyException(com.radixdlt.crypto.exception.PublicKeyException) DeserializeException(com.radixdlt.serialization.DeserializeException)

Example 9 with DeserializeException

use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.

the class RecoverableSubstateVirtualShutdown method recover.

@Override
public SubstateOperation recover(Provider<RadixEngine<LedgerAndBFTProof>> radixEngineProvider) {
    var radixEngine = radixEngineProvider.get();
    var keyBuf = substateId.getVirtualKey().orElseThrow();
    Particle substate;
    try {
        substate = radixEngine.getVirtualSubstateDeserialization().keyToSubstate(typeByte, keyBuf);
    } catch (DeserializeException e) {
        throw new IllegalStateException("Could not deserialize virtual substate.");
    }
    return new SubstateOperation(substate, substateId, false);
}
Also used : Particle(com.radixdlt.constraintmachine.Particle) SubstateOperation(com.radixdlt.api.core.model.SubstateOperation) DeserializeException(com.radixdlt.serialization.DeserializeException)

Example 10 with DeserializeException

use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.

the class REInstruction method readFrom.

public static REInstruction readFrom(REParser.ParserState parserState, ByteBuffer buf) throws DeserializeException, REInstructionDataDeserializeException {
    var microOp = REMicroOp.fromByte(buf.get());
    var savedLimit = buf.limit();
    var pos = buf.position();
    try {
        // Set limit
        buf = microOp.lengthType.setNextLimit(buf, microOp.minLength, microOp.maxLength);
        var data = microOp.read(parserState, buf);
        // Sanity check
        if (buf.hasRemaining()) {
            throw new IllegalStateException();
        }
        var length = buf.position() - pos;
        buf.limit(savedLimit);
        return new REInstruction(microOp, data, buf.array(), pos, length);
    } catch (Exception e) {
        throw new REInstructionDataDeserializeException(microOp, e);
    }
}
Also used : REInstructionDataDeserializeException(com.radixdlt.engine.parser.exceptions.REInstructionDataDeserializeException) REInstructionDataDeserializeException(com.radixdlt.engine.parser.exceptions.REInstructionDataDeserializeException) DeserializeException(com.radixdlt.serialization.DeserializeException)

Aggregations

DeserializeException (com.radixdlt.serialization.DeserializeException)13 PublicKeyException (com.radixdlt.crypto.exception.PublicKeyException)3 REFieldSerialization (com.radixdlt.atom.REFieldSerialization)2 SubstateTypeId (com.radixdlt.atom.SubstateTypeId)2 ConstraintScrypt (com.radixdlt.atomos.ConstraintScrypt)2 Loader (com.radixdlt.atomos.Loader)2 SubstateDefinition (com.radixdlt.atomos.SubstateDefinition)2 ProcedureException (com.radixdlt.constraintmachine.exceptions.ProcedureException)2 SubstateDeserializationException (com.radixdlt.engine.parser.exceptions.SubstateDeserializationException)2 Benchmark (org.openjdk.jmh.annotations.Benchmark)2 SubstateOperation (com.radixdlt.api.core.model.SubstateOperation)1 SystemConstraintScrypt (com.radixdlt.application.system.scrypt.SystemConstraintScrypt)1 EpochData (com.radixdlt.application.system.state.EpochData)1 ValidatorStakeData (com.radixdlt.application.system.state.ValidatorStakeData)1 TokenResource (com.radixdlt.application.tokens.state.TokenResource)1 TokenResourceMetadata (com.radixdlt.application.tokens.state.TokenResourceMetadata)1 TokensInAccount (com.radixdlt.application.tokens.state.TokensInAccount)1 ValidatorFeeCopy (com.radixdlt.application.validators.state.ValidatorFeeCopy)1 ValidatorSystemMetadata (com.radixdlt.application.validators.state.ValidatorSystemMetadata)1 BFTNode (com.radixdlt.consensus.bft.BFTNode)1