Search in sources :

Example 1 with SSZException

use of org.apache.tuweni.ssz.SSZException in project teku by ConsenSys.

the class TransitionCommand method processStateTransition.

private int processStateTransition(final InAndOutParams params, final StateTransitionFunction transition) {
    final Spec spec = params.eth2NetworkOptions.getNetworkConfiguration().getSpec();
    try (final InputStream in = selectInputStream(params);
        final OutputStream out = selectOutputStream(params)) {
        final Bytes inData = Bytes.wrap(ByteStreams.toByteArray(in));
        BeaconState state = readState(spec, inData);
        try {
            BeaconState result = transition.applyTransition(spec, state);
            out.write(result.sszSerialize().toArrayUnsafe());
            return 0;
        } catch (final StateTransitionException | EpochProcessingException | SlotProcessingException e) {
            SUB_COMMAND_LOG.error("State transition failed", e);
            return 1;
        }
    } catch (final SSZException e) {
        SUB_COMMAND_LOG.error(e.getMessage());
        return 1;
    } catch (final IOException e) {
        SUB_COMMAND_LOG.error("I/O error: " + e.toString());
        return 1;
    } catch (final Throwable t) {
        t.printStackTrace();
        return 2;
    }
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) SlotProcessingException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.SlotProcessingException) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) EpochProcessingException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.EpochProcessingException) SSZException(org.apache.tuweni.ssz.SSZException) IOException(java.io.IOException) Spec(tech.pegasys.teku.spec.Spec) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) StateTransitionException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Bytes (org.apache.tuweni.bytes.Bytes)1 SSZException (org.apache.tuweni.ssz.SSZException)1 Spec (tech.pegasys.teku.spec.Spec)1 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)1 EpochProcessingException (tech.pegasys.teku.spec.logic.common.statetransition.exceptions.EpochProcessingException)1 SlotProcessingException (tech.pegasys.teku.spec.logic.common.statetransition.exceptions.SlotProcessingException)1 StateTransitionException (tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException)1