Skip to content

Commit

Permalink
Use handle_actor_call to simplify error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Feb 26, 2025
1 parent 23cfd47 commit 412fe2b
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions src/rpc/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ use crate::fiber::{NetworkActorCommand, NetworkActorMessage};
use crate::invoice::{
add_invoice, CkbInvoice, CkbInvoiceStatus, Currency, InvoiceBuilder, InvoiceStore,
};
use crate::FiberConfig;
use crate::{handle_actor_call, log_and_error, FiberConfig};
use ckb_jsonrpc_types::Script;
use jsonrpsee::types::error::CALL_EXECUTION_FAILED_CODE;
use jsonrpsee::{core::async_trait, proc_macros::rpc, types::ErrorObjectOwned};
use ractor::{call_t, ActorRef};
use ractor::{call, ActorRef};
use secp256k1::{PublicKey, Secp256k1, SecretKey};
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use std::time::Duration;
use tentacle::secio::SecioKeyPair;

const RPC_TIMEOUT_MS: u64 = 3000;

/// The parameter struct for generating a new invoice.
#[serde_as]
#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -383,19 +381,6 @@ where
))
};

match call_t!(network_actor, message, RPC_TIMEOUT_MS).map_err(|ractor_error| {
ErrorObjectOwned::owned(
CALL_EXECUTION_FAILED_CODE,
ractor_error.to_string(),
Option::<()>::None,
)
})? {
Ok(_) => Ok(SettleInvoiceResult {}),
Err(e) => Err(ErrorObjectOwned::owned(
CALL_EXECUTION_FAILED_CODE,
e.to_string(),
Some(params),
)),
}
handle_actor_call!(network_actor, message, params).map(|_| SettleInvoiceResult {})
}
}

0 comments on commit 412fe2b

Please sign in to comment.