/** * <p>Cancel the current operation and return to the initialised state</p> * * <p>This will trigger a SHOW_OPERATION_FAILED and a DEVICE_READY event during the reset phase</p> */ public void requestCancel() { // Let the state changes occur as a result of the internal messages context.getClient().cancel(); }
/** * <p>Ping the device</p> * * <p>This will trigger a SHOW_OPERATION_SUCCEEDED</p> */ public void requestPing() { // Let the state changes occur as a result of the internal messages context.getClient().ping(); }
@Override public void await(HardwareWalletContext context) { // Trigger a state transition via the response event context.getClient().connect(); }
@Override public void await(HardwareWalletContext context) { // Trigger a state transition via the response event context.getClient().initialise(); }
/** * Determine a wallet mode from a hardware wallet service. This does not work * out connectivity status, it is purely from the client name. * * @param hardwareWalletService The optional hardware wallet service * * @return A matching wallet mode (STANDARD for an absent hardware wallet service) */ public static WalletMode of(Optional<HardwareWalletService> hardwareWalletService) { if (hardwareWalletService.isPresent()) { try { String name = hardwareWalletService.get().getContext().getClient().name(); return WalletMode.valueOf(name.toUpperCase().trim()); } catch (IllegalStateException | IllegalArgumentException e) { return UNKNOWN; } } // No hardware wallet service so use standard return STANDARD; } }
/** * @param event The low level message event */ @Subscribe public void onMessageEvent(MessageEvent event) { // Filter messages not associated with this context if (!getClient().name().equalsIgnoreCase(event.getSource())) { log.debug("Discarded message event: '{}' (different device)", event.getEventType().name()); return; } log.debug("Received message event: '{}'", event.getEventType().name()); // Perform a state transition as a result of this event try { currentState.transition(client, this, event); } catch (Exception e) { e.printStackTrace(); } }
/** * <p>Provide standard handling for an unexpected message so the downstream consumer can react appropriately</p> * * @param context The current context providing parameters for decisions * @param event The event driving the transition */ protected void handleUnexpectedMessageEvent(HardwareWalletContext context, MessageEvent event) { log.warn("Unexpected message event '{}'", event.getEventType().name()); if (event.getMessage().isPresent()) { HardwareWalletEvents.fireHardwareWalletEvent(HardwareWalletEventType.SHOW_OPERATION_FAILED, event.getMessage().get(), context.getClient().name()); } else { HardwareWalletEvents.fireHardwareWalletEvent(HardwareWalletEventType.SHOW_OPERATION_FAILED, context.getClient().name()); } context.resetToConnected(); } }
log.info("Starting hardware wallet service: {}", hardwareWalletService.get().getContext().getClient().name()); hardwareWalletService.get().start();
String currentSource = currentHardwareWalletService.get().getContext().getClient().name(); String newSource = event.getSource();