Support fast withdrawal option in RPC server
@@ -247,6 +247,7 @@ pub enum RpcErrorCodes {
Other = 300,
AccountCloseDisabled = 301,
OperationsLimitReached = 302,
+ UnsupportedFastProcessing = 303,
}
impl From<TxAddError> for RpcErrorCodes {
@@ -290,6 +291,7 @@ pub trait Rpc {
&self,
tx: Box<FranklinTx>,
signature: Box<Option<TxEthSignature>>,
+ fast_processing: Option<bool>,
) -> Box<dyn futures01::Future<Item = TxHash, Error = Error> + Send>;
#[rpc(name = "contract_address")]
@@ -793,6 +795,7 @@ impl Rpc for RpcApp {
&self,
tx: Box<FranklinTx>,
signature: Box<Option<TxEthSignature>>,
+ fast_processing: Option<bool>,
) -> Box<dyn futures01::Future<Item = TxHash, Error = Error> + Send> {
if tx.is_close() {
return Box::new(futures01::future::err(Error {
@@ -802,18 +805,37 @@ impl Rpc for RpcApp {
}));
}
+ let fast_processing = fast_processing.unwrap_or_default(); // `None` => false
+
+ if fast_processing && !tx.is_withdraw() {
+ return Box::new(futures01::future::err(Error {
+ code: RpcErrorCodes::UnsupportedFastProcessing.into(),
+ message: "Fast processing available only for 'withdraw' operation type."
+ .to_string(),
+ data: None,
+ }));
+ }
+
let msg_to_sign = match self.get_tx_info_message_to_sign(&tx) {
Ok(res) => res,
Err(e) => return Box::new(futures01::future::err(e)),
};
let tx_fee_info = match tx.as_ref() {
- FranklinTx::Withdraw(withdraw) => Some((
- TxFeeTypes::Withdraw,
+ FranklinTx::Withdraw(withdraw) => {
+ let fee_type = if fast_processing {
+ TxFeeTypes::FastWithdraw
+ } else {
+ TxFeeTypes::Withdraw
+ };
+
+ Some((
+ fee_type,
TokenLike::Id(withdraw.token),
withdraw.to,
withdraw.fee.clone(),
- )),
+ ))
+ }
FranklinTx::Transfer(transfer) => Some((
TxFeeTypes::Transfer,
TokenLike::Id(transfer.token),
