in projects/web3/eth_wallet/ta/src/main.rs [123:141]
fn handle_invoke(command: Command, serialized_input: &[u8]) -> Result<Vec<u8>> {
fn process<T: serde::de::DeserializeOwned, U: serde::Serialize, F: Fn(&T) -> Result<U>>(
serialized_input: &[u8],
handler: F,
) -> Result<Vec<u8>> {
let input: T = bincode::deserialize(serialized_input)?;
let output = handler(&input)?;
let serialized_output = bincode::serialize(&output)?;
Ok(serialized_output)
}
match command {
Command::CreateWallet => process(serialized_input, create_wallet),
Command::RemoveWallet => process(serialized_input, remove_wallet),
Command::DeriveAddress => process(serialized_input, derive_address),
Command::SignTransaction => process(serialized_input, sign_transaction),
_ => bail!("Unsupported command"),
}
}