fn apply(
    request: &TpProcessRequest,
    context: &mut dyn TransactionContext,
) -> Result<bool, ApplyError> {
    match {
        let payload = IntkeyPayload::new(request.get_payload());
        let payload = match payload {
            Err(e) => return Err(e),
            Ok(payload) => payload,
        };
        let payload = match payload {
            Some(x) => x,
            None => {
                return Err(ApplyError::InvalidTransaction(String::from(
                    "Request must contain a payload",
                )));
            }
        };
        let mut state = IntkeyState::new(context);
        info!(
            "payload: {} {} {}",
            payload.get_name_a(),
            payload.get_name_b(),
            payload.get_name_c()
        );

        match state.get(payload.get_name_a()) {
            Ok(None) => (),
            Ok(Some(_)) => {
                return Err(ApplyError::InvalidTransaction(format!(
                    "{} is already set",
                    payload.get_name_a()
                )));
            }
            Err(err) => return Err(err),
        };

        let orig_value_b: u64 = match state.get(payload.get_name_b()) {
            Ok(Some(v)) => u64::from(v),
            Ok(None) => {
                return Err(ApplyError::InvalidTransaction(String::from(
                    "Multiply requires a set value for name_b",
                )));
            }
            Err(err) => return Err(err),
        };

        let orig_value_c: u64 = match state.get(payload.get_name_c()) {
            Ok(Some(v)) => u64::from(v),
            Ok(None) => {
                return Err(ApplyError::InvalidTransaction(String::from(
                    "Multiply requires a set value for name_c",
                )));
            }
            Err(err) => return Err(err),
        };
        let new_value = orig_value_b * orig_value_c;
        if new_value > u64::from(MAX_VALUE) {
            return Err(ApplyError::InvalidTransaction(format!(
                "Multiplied value is larger then max allowed: {}",
                new_value
            )));
        };
        state.set(&payload.get_name_a(), new_value as u32)
    } {
        Ok(_) => Ok(true),
        Err(err) => {
            info!("{}", err);
            Err(err)
        }
    }
}
// Sabre apply must return a bool
Sabre apply must return a bool
Sabre apply must return a bool
fn apply(
    request: &TpProcessRequest,
    context: &mut dyn TransactionContext,
) -> Result<bool, ApplyError> {
    match {
        let payload = IntkeyPayload::new(request.get_payload());
        let payload = match payload {
            Err(e) => return Err(e),
            Ok(payload) => payload,
        };
        let payload = match payload {
            Some(x) => x,
            None => {
                return Err(ApplyError::InvalidTransaction(String::from(
                    "Request must contain a payload",
                )));
            }
        };
        let mut state = IntkeyState::new(context);
        info!(
            "payload: {} {} {}",
            payload.get_name_a(),
            payload.get_name_b(),
            payload.get_name_c()
        );
        match state.get(payload.get_name_a()) {
            Ok(None) => (),
            Ok(Some(_)) => {
                return Err(ApplyError::InvalidTransaction(format!(
                    "{} is already set",
                    payload.get_name_a()
                )));
            }
            Err(err) => return Err(err),
        };
        let orig_value_b: u64 = match state.get(payload.get_name_b()) {
            Ok(Some(v)) => u64::from(v),
            Ok(None) => {
                return Err(ApplyError::InvalidTransaction(String::from(
                    "Multiply requires a set value for name_b",
                )));
            }
            Err(err) => return Err(err),
        };
        let orig_value_c: u64 = match state.get(payload.get_name_c()) {
            Ok(Some(v)) => u64::from(v),
            Ok(None) => {
                return Err(ApplyError::InvalidTransaction(String::from(
                    "Multiply requires a set value for name_c",
                )));
            }
            Err(err) => return Err(err),
        };
        let new_value = orig_value_b * orig_value_c;
        if new_value > u64::from(MAX_VALUE) {
            return Err(ApplyError::InvalidTransaction(format!(
                "Multiplied value is larger then max allowed: {}",
                new_value
            )));
        };
        state.set(&payload.get_name_a(), new_value as u32)
    } {
        Ok(_) => Ok(true),
        Err(err) => {
            info!("{}", err);
            Err(err)
        }
    }
}
fn apply ( request : & TpProcessRequest , context : & mut dyn TransactionContext , ) -> Result < bool , ApplyError > { match { let payload = IntkeyPayload :: new ( request . get_payload ( ) ) ; let payload = match payload { Err ( e ) => return Err ( e ) , Ok ( payload ) => payload , } ; let payload = match payload { Some ( x ) => x , None => { return Err ( ApplyError :: InvalidTransaction ( String :: from ( " " , ) ) ) ; } } ; let mut state = IntkeyState :: new ( context ) ; info ! ( " " payload get_name_a ( ) payload get_name_b ( ) payload get_name_c ( ) ) ; match state . get ( payload . get_name_a ( ) ) { Ok ( None ) => ( ) , Ok ( Some ( _ ) ) => { return Err ( ApplyError :: InvalidTransaction ( format ! ( " " payload get_name_a ( ) ) ) ) ; } Err ( err ) => return Err ( err ) , } ; let orig_value_b : u64 = match state . get ( payload . get_name_b ( ) ) { Ok ( Some ( v ) ) => u64 :: from ( v ) , Ok ( None ) => { return Err ( ApplyError :: InvalidTransaction ( String :: from ( " " , ) ) ) ; } Err ( err ) => return Err ( err ) , } ; let orig_value_c : u64 = match state . get ( payload . get_name_c ( ) ) { Ok ( Some ( v ) ) => u64 :: from ( v ) , Ok ( None ) => { return Err ( ApplyError :: InvalidTransaction ( String :: from ( " " , ) ) ) ; } Err ( err ) => return Err ( err ) , } ; let new_value = orig_value_b * orig_value_c ; if new_value > u64 :: from ( MAX_VALUE ) { return Err ( ApplyError :: InvalidTransaction ( format ! ( " " new_value ) ) ) ; } ; state . set ( & payload . get_name_a ( ) , new_value as u32 ) } { Ok ( _ ) => Ok ( true ) , Err ( err ) => { info ! ( " " err ) ; Err ( err ) } } }
Sabre apply must return a bool
Sabre apply must return a bool
request
&TpProcessRequest
context
&mut dyn TransactionContext
request
&TpProcessRequest
context
&mut dyn TransactionContext