Trait coins_ledger::LedgerProtocol

source ·
pub trait LedgerProtocol {
    type Output;

    // Required method
    fn execute(
        &mut self,
        transport: &mut Ledger,
    ) -> Result<Self::Output, LedgerError>;

    // Provided methods
    fn recover(&self, _transport: &mut Ledger) -> Result<(), LedgerError> { ... }
    fn run(
        &mut self,
        transport: &mut Ledger,
    ) -> Result<Self::Output, LedgerError> { ... }
}
Expand description

A Ledger Recovery. A the device to perform some operation. Protocols are run in a task, and may send multiple commands to the device, and receive multiple responses. The protocol has exclusive access to the transport while it is running.

The protocol may fail, and the LedgerProtocol::recover function will be invoked. The protocol may also fail to recover, in which case future uses of the device may fail.

Required Associated Types§

source

type Output

The output of the protocol.

Required Methods§

source

fn execute( &mut self, transport: &mut Ledger, ) -> Result<Self::Output, LedgerError>

Run the protocol. This sends commands to the device, and receives responses. The transport is locked while this function is running. If the protocol fails, the app may be in an undefined state, and the LedgerProtocol::recover function will be invoked.

Provided Methods§

source

fn recover(&self, _transport: &mut Ledger) -> Result<(), LedgerError>

Run recovery if the protocol fails.

This is invoked after the protocol fails. This function should attempt to recover the app on the device to a known state.

Multi-APDU protocols MUST override this function. The recommended implementation is to retrieve a pubkey from the device twice.

source

fn run(&mut self, transport: &mut Ledger) -> Result<Self::Output, LedgerError>

Run the protocol. This sends commands to the device, and receives responses. The transport is locked while this function is running.

Implementors§