#![deny(missing_docs)]
#![allow(async_fn_in_trait)]
use std::collections::HashSet;
use async_trait::async_trait;
use bytes::Bytes;
use lexe_common::api::{
MegaId,
auth::{
BearerAuthRequestWire, BearerAuthResponse, BearerAuthToken,
UserSignupRequestWire, UserSignupRequestWireV1,
},
fiat_rates::FiatRates,
models::{
SignMsgRequest, SignMsgResponse, Status, VerifyMsgRequest,
VerifyMsgResponse,
},
provision::NodeProvisionRequest,
revocable_clients::{
CreateRevocableClientRequest, CreateRevocableClientResponse,
GetRevocableClients, RevocableClients, UpdateClientRequest,
UpdateClientResponse,
},
test_event::TestEventOp,
user::{GetNewScidsRequest, MaybeScid, MaybeUser, Scids, UserPk},
version::{CurrentEnclaves, EnclavesToProvision, NodeEnclave},
};
#[cfg(doc)]
use lexe_common::{
api::MegaIdStruct,
api::models::BroadcastedTxInfo,
api::user::NodePkStruct,
api::user::{UserPkSet, UserPkStruct},
api::version::MeasurementStruct,
};
use lexe_crypto::ed25519;
use lexe_enclave::enclave::Measurement;
use lightning::events::Event;
#[cfg(doc)]
use crate::types::payments::{PaymentCreatedIndex, PaymentId};
use crate::{
error::{
BackendApiError, GatewayApiError, LspApiError, MegaApiError,
NodeApiError, RunnerApiError,
},
models::{
command::{
BackupInfo, ClaimGeneratedHumanBitcoinAddress, CloseChannelRequest,
CreateInvoiceRequest, CreateInvoiceResponse, CreateOfferRequest,
CreateOfferResponse, DebugInfo, EnclavesToProvisionRequest,
GetAddressResponse, GetGeneratedUsernameResponse, GetNewPayments,
GetUpdatedPaymentMetadata, GetUpdatedPayments, HumanBitcoinAddress,
ListChannelsResponse, NodeInfo, NodeInfoV1, OpenChannelRequest,
OpenChannelResponse, PayInvoiceRequest, PayInvoiceResponse,
PayOfferRequest, PayOfferResponse, PayOnchainRequest,
PayOnchainResponse, PaymentCreatedIndexStruct,
PaymentCreatedIndexes, PaymentIdStruct,
PreflightCloseChannelRequest, PreflightCloseChannelResponse,
PreflightOpenChannelRequest, PreflightOpenChannelResponse,
PreflightPayInvoiceRequest, PreflightPayInvoiceResponse,
PreflightPayOfferRequest, PreflightPayOfferResponse,
PreflightPayOnchainRequest, PreflightPayOnchainResponse,
ResyncRequest, SetupGDrive, UpdateHumanBitcoinAddress,
UpdatePaymentNote, VecPaymentId,
},
nwc::{
CreateNwcClientRequest, CreateNwcClientResponse, DbNwcClient,
DbNwcClientFields, GetNwcClients, ListNwcClientResponse,
NostrPkStruct, NostrSignedEvent, NwcRequest,
UpdateNwcClientRequest, UpdateNwcClientResponse, VecDbNwcClient,
},
runner::{
MegaNodeApiUserEvictRequest, MegaNodeApiUserRunRequest,
MegaNodeApiUserRunResponse, UserFinishedRequest,
UserLeaseRenewalRequest,
},
},
types::{
Empty,
lnurl::{
LnurlCallbackRequest, LnurlCallbackResponse, LnurlError,
LnurlPayRequestWire,
},
payments::{
DbPaymentMetadata, DbPaymentV1, DbPaymentV2, MaybeBasicPaymentV2,
MaybeDbPaymentMetadata, MaybeDbPaymentV1, MaybeDbPaymentV2,
VecBasicPaymentV1, VecBasicPaymentV2, VecDbPaymentMetadata,
VecDbPaymentV1, VecDbPaymentV2,
},
ports::MegaPorts,
sealed_seed::{MaybeSealedSeed, SealedSeed, SealedSeedId},
username::UsernameStruct,
},
vfs::{
MaybeVfsFile, VecVfsFile, VfsDirectory, VfsDirectoryList, VfsFile,
VfsFileId,
},
};
pub trait AppBackendApi {
async fn signup_v2(
&self,
signed_req: &ed25519::Signed<&UserSignupRequestWire>,
) -> Result<Empty, BackendApiError>;
#[deprecated = "Use the `signup_v2` API instead"]
async fn signup_v1(
&self,
signed_req: &ed25519::Signed<&UserSignupRequestWireV1>,
) -> Result<Empty, BackendApiError>;
async fn enclaves_to_provision(
&self,
req: &EnclavesToProvisionRequest,
auth: BearerAuthToken,
) -> Result<EnclavesToProvision, BackendApiError>;
}
pub trait AppGatewayApi {
async fn get_fiat_rates(&self) -> Result<FiatRates, GatewayApiError>;
#[deprecated(note = "since app-v0.8.1: Use current_releases() instead")]
async fn latest_release(&self) -> Result<NodeEnclave, GatewayApiError>;
#[deprecated(note = "since app-v0.8.8: Use current_enclaves() instead")]
async fn current_releases(
&self,
) -> Result<CurrentEnclaves, GatewayApiError>;
async fn current_enclaves(
&self,
) -> Result<CurrentEnclaves, GatewayApiError>;
}
pub trait AppNodeProvisionApi {
async fn provision(
&self,
measurement: Measurement,
data: NodeProvisionRequest,
) -> Result<Empty, NodeApiError>;
}
pub trait AppNodeRunApi {
async fn node_info(&self) -> Result<NodeInfo, NodeApiError>;
#[deprecated(note = "since node-v0.9.4: Use node_info instead")]
async fn node_info_v1(&self) -> Result<NodeInfoV1, NodeApiError>;
async fn debug_info(&self) -> Result<DebugInfo, NodeApiError>;
async fn list_channels(&self)
-> Result<ListChannelsResponse, NodeApiError>;
async fn sign_message(
&self,
req: SignMsgRequest,
) -> Result<SignMsgResponse, NodeApiError>;
async fn verify_message(
&self,
req: VerifyMsgRequest,
) -> Result<VerifyMsgResponse, NodeApiError>;
async fn open_channel(
&self,
req: OpenChannelRequest,
) -> Result<OpenChannelResponse, NodeApiError>;
async fn preflight_open_channel(
&self,
req: PreflightOpenChannelRequest,
) -> Result<PreflightOpenChannelResponse, NodeApiError>;
async fn close_channel(
&self,
req: CloseChannelRequest,
) -> Result<Empty, NodeApiError>;
async fn preflight_close_channel(
&self,
req: PreflightCloseChannelRequest,
) -> Result<PreflightCloseChannelResponse, NodeApiError>;
async fn create_invoice(
&self,
req: CreateInvoiceRequest,
) -> Result<CreateInvoiceResponse, NodeApiError>;
async fn pay_invoice(
&self,
req: PayInvoiceRequest,
) -> Result<PayInvoiceResponse, NodeApiError>;
async fn preflight_pay_invoice(
&self,
req: PreflightPayInvoiceRequest,
) -> Result<PreflightPayInvoiceResponse, NodeApiError>;
async fn create_offer(
&self,
req: CreateOfferRequest,
) -> Result<CreateOfferResponse, NodeApiError>;
async fn pay_offer(
&self,
req: PayOfferRequest,
) -> Result<PayOfferResponse, NodeApiError>;
async fn preflight_pay_offer(
&self,
req: PreflightPayOfferRequest,
) -> Result<PreflightPayOfferResponse, NodeApiError>;
async fn get_address(&self) -> Result<GetAddressResponse, NodeApiError>;
async fn pay_onchain(
&self,
req: PayOnchainRequest,
) -> Result<PayOnchainResponse, NodeApiError>;
async fn preflight_pay_onchain(
&self,
req: PreflightPayOnchainRequest,
) -> Result<PreflightPayOnchainResponse, NodeApiError>;
async fn get_payment_by_id(
&self,
req: PaymentIdStruct,
) -> Result<MaybeBasicPaymentV2, NodeApiError>;
#[deprecated(note = "since app-v0.8.9+29 and sdk-sidecar-v0.3.1: \
Use get_payments_by_ids instead")]
async fn get_payments_by_indexes(
&self,
req: PaymentCreatedIndexes,
) -> Result<VecBasicPaymentV1, NodeApiError>;
#[deprecated(note = "since app-v0.8.9+29 and sdk-sidecar-v0.3.1: \
Use get_updated_payments instead")]
async fn get_new_payments(
&self,
req: GetNewPayments,
) -> Result<VecBasicPaymentV1, NodeApiError>;
async fn get_updated_payments(
&self,
req: GetUpdatedPayments,
) -> Result<VecBasicPaymentV2, NodeApiError>;
async fn update_payment_note(
&self,
req: UpdatePaymentNote,
) -> Result<Empty, NodeApiError>;
async fn get_revocable_clients(
&self,
req: GetRevocableClients,
) -> Result<RevocableClients, NodeApiError>;
async fn create_revocable_client(
&self,
req: CreateRevocableClientRequest,
) -> Result<CreateRevocableClientResponse, NodeApiError>;
async fn update_revocable_client(
&self,
req: UpdateClientRequest,
) -> Result<UpdateClientResponse, NodeApiError>;
async fn list_broadcasted_txs(
&self,
) -> Result<serde_json::Value, NodeApiError>;
async fn backup_info(&self) -> Result<BackupInfo, NodeApiError>;
async fn setup_gdrive(
&self,
req: SetupGDrive,
) -> Result<Empty, NodeApiError>;
async fn get_human_bitcoin_address(
&self,
) -> Result<HumanBitcoinAddress, NodeApiError>;
async fn update_human_bitcoin_address(
&self,
req: UsernameStruct,
) -> Result<HumanBitcoinAddress, NodeApiError>;
#[deprecated(note = "since app-v0.9.3 and sdk-sidecar-v0.4.2: \
Use get_human_bitcoin_address instead")]
async fn get_payment_address(
&self,
) -> Result<HumanBitcoinAddress, NodeApiError> {
self.get_human_bitcoin_address().await
}
#[deprecated(note = "since app-v0.9.3 and sdk-sidecar-v0.4.2: \
Use update_human_bitcoin_address instead")]
async fn update_payment_address(
&self,
req: UsernameStruct,
) -> Result<HumanBitcoinAddress, NodeApiError> {
self.update_human_bitcoin_address(req).await
}
async fn list_nwc_clients(
&self,
) -> Result<ListNwcClientResponse, NodeApiError>;
async fn create_nwc_client(
&self,
req: CreateNwcClientRequest,
) -> Result<CreateNwcClientResponse, NodeApiError>;
async fn update_nwc_client(
&self,
req: UpdateNwcClientRequest,
) -> Result<UpdateNwcClientResponse, NodeApiError>;
async fn delete_nwc_client(
&self,
req: NostrPkStruct,
) -> Result<Empty, NodeApiError>;
}
#[async_trait]
pub trait BearerAuthBackendApi {
async fn bearer_auth(
&self,
signed_req: &ed25519::Signed<&BearerAuthRequestWire>,
) -> Result<BearerAuthResponse, BackendApiError>;
}
pub trait LexeMegaApi {
async fn run_user(
&self,
req: MegaNodeApiUserRunRequest,
) -> Result<MegaNodeApiUserRunResponse, MegaApiError>;
async fn evict_user(
&self,
req: MegaNodeApiUserEvictRequest,
) -> Result<Empty, MegaApiError>;
async fn status_mega(
&self,
mega_id: MegaId,
) -> Result<Status, MegaApiError>;
async fn shutdown_mega(&self) -> Result<Empty, MegaApiError>;
}
pub trait LexeNodeRunApi {
async fn status_run(&self, user_pk: UserPk)
-> Result<Status, NodeApiError>;
async fn resync(&self, req: ResyncRequest) -> Result<Empty, NodeApiError>;
async fn test_event(&self, op: &TestEventOp)
-> Result<Empty, NodeApiError>;
async fn shutdown_run(
&self,
user_pk: UserPk,
) -> Result<Empty, NodeApiError>;
async fn create_invoice(
&self,
req: CreateInvoiceRequest,
) -> Result<CreateInvoiceResponse, NodeApiError>;
async fn nwc_request(
&self,
req: NwcRequest,
) -> Result<NostrSignedEvent, NodeApiError>;
}
pub trait MegaRunnerApi {
async fn mega_ready(
&self,
ports: &MegaPorts,
) -> Result<Empty, RunnerApiError>;
async fn activity(
&self,
user_pks: HashSet<UserPk>,
) -> Result<Empty, RunnerApiError>;
async fn user_finished(
&self,
req: &UserFinishedRequest,
) -> Result<Empty, RunnerApiError>;
}
pub trait NodeBackendApi {
async fn get_user(
&self,
user_pk: UserPk,
) -> Result<MaybeUser, BackendApiError>;
async fn get_sealed_seed(
&self,
data: &SealedSeedId,
) -> Result<MaybeSealedSeed, BackendApiError>;
async fn create_sealed_seed(
&self,
data: &SealedSeed,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
async fn delete_sealed_seeds(
&self,
measurement: Measurement,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
async fn get_scids(
&self,
auth: BearerAuthToken,
) -> Result<Scids, BackendApiError>;
#[deprecated(note = "since lsp-v0.7.3: Use multi scid version instead")]
async fn get_scid(
&self,
auth: BearerAuthToken,
) -> Result<MaybeScid, BackendApiError>;
#[deprecated(note = "since node-v0.8.5: Use get_file instead")]
async fn get_file_v1(
&self,
file_id: &VfsFileId,
auth: BearerAuthToken,
) -> Result<MaybeVfsFile, BackendApiError>;
async fn get_file(
&self,
file_id: &VfsFileId,
token: BearerAuthToken,
) -> Result<Bytes, BackendApiError>;
#[deprecated(note = "since node-v0.8.5: Use create_file instead")]
async fn create_file_v1(
&self,
file: &VfsFile,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
async fn create_file(
&self,
file_id: &VfsFileId,
data: bytes::Bytes,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
#[deprecated(note = "since node-v0.8.5: Use upsert_file instead")]
async fn upsert_file_v1(
&self,
file: &VfsFile,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
async fn upsert_file(
&self,
file_id: &VfsFileId,
data: bytes::Bytes,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
async fn delete_file(
&self,
file_id: &VfsFileId,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
#[deprecated(note = "since node-v0.8.5: Use list_directory instead")]
async fn get_directory_v1(
&self,
dir: &VfsDirectory,
auth: BearerAuthToken,
) -> Result<VecVfsFile, BackendApiError>;
async fn list_directory(
&self,
dir: &VfsDirectory,
auth: BearerAuthToken,
) -> Result<VfsDirectoryList, BackendApiError>;
#[deprecated(note = "since node-v0.8.8: Use get_payment_by_index instead")]
async fn get_payment_by_index_v1(
&self,
req: PaymentCreatedIndexStruct,
auth: BearerAuthToken,
) -> Result<MaybeDbPaymentV1, BackendApiError>;
#[deprecated(note = "since node-v0.8.10: Use upsert_payment instead")]
async fn create_payment(
&self,
payment: DbPaymentV1,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
#[deprecated(note = "since node-v0.8.8: Use upsert_payment instead")]
async fn upsert_payment_v1(
&self,
payment: DbPaymentV1,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
async fn upsert_payment(
&self,
payment: DbPaymentV2,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
#[deprecated(note = "since node-v0.8.10: Use get_payment_by_id instead")]
async fn get_payment_by_id_v1(
&self,
req: PaymentIdStruct,
auth: BearerAuthToken,
) -> Result<MaybeDbPaymentV1, BackendApiError>;
async fn get_payment_by_id(
&self,
req: PaymentIdStruct,
auth: BearerAuthToken,
) -> Result<MaybeDbPaymentV2, BackendApiError>;
#[deprecated(note = "since node-v0.8.10: Use get_payment_by_id instead")]
async fn get_payment_by_index(
&self,
req: PaymentCreatedIndexStruct,
auth: BearerAuthToken,
) -> Result<MaybeDbPaymentV1, BackendApiError>;
#[deprecated(note = "since node-v0.8.8: Use upsert_payment_batch instead")]
async fn upsert_payment_batch_v1(
&self,
payments: VecDbPaymentV1,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
async fn upsert_payment_batch(
&self,
payments: VecDbPaymentV2,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
#[deprecated(note = "since node-v0.8.10: Use get_payments_by_ids instead")]
async fn get_payments_by_indexes(
&self,
req: PaymentCreatedIndexes,
auth: BearerAuthToken,
) -> Result<VecDbPaymentV1, BackendApiError>;
async fn get_payments_by_ids(
&self,
req: VecPaymentId,
auth: BearerAuthToken,
) -> Result<VecDbPaymentV2, BackendApiError>;
#[deprecated(note = "since app-v0.8.9+29 and sdk-sidecar-v0.3.1: \
Use get_updated_payments instead")]
async fn get_new_payments(
&self,
req: GetNewPayments,
auth: BearerAuthToken,
) -> Result<VecDbPaymentV1, BackendApiError>;
async fn get_updated_payments(
&self,
req: GetUpdatedPayments,
auth: BearerAuthToken,
) -> Result<VecDbPaymentV2, BackendApiError>;
#[deprecated(note = "since node-v0.8.10: Use get_pending_payments instead")]
async fn get_pending_payments_v1(
&self,
auth: BearerAuthToken,
) -> Result<VecDbPaymentV1, BackendApiError>;
async fn get_pending_payments(
&self,
auth: BearerAuthToken,
) -> Result<VecDbPaymentV2, BackendApiError>;
#[deprecated(note = "since node-v0.8.8")]
async fn get_finalized_payment_ids(
&self,
auth: BearerAuthToken,
) -> Result<VecPaymentId, BackendApiError>;
async fn upsert_payment_metadata(
&self,
metadata: DbPaymentMetadata,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
async fn upsert_payment_metadata_batch(
&self,
payments: VecDbPaymentMetadata,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
async fn get_payment_metadata_by_id(
&self,
req: PaymentIdStruct,
token: BearerAuthToken,
) -> Result<MaybeDbPaymentMetadata, BackendApiError>;
async fn get_payment_metadata_by_ids(
&self,
req: VecPaymentId,
token: BearerAuthToken,
) -> Result<VecDbPaymentMetadata, BackendApiError>;
async fn get_updated_payment_metadata(
&self,
req: GetUpdatedPaymentMetadata,
auth: BearerAuthToken,
) -> Result<VecDbPaymentMetadata, BackendApiError>;
async fn update_human_bitcoin_address(
&self,
req: UpdateHumanBitcoinAddress,
auth: BearerAuthToken,
) -> Result<HumanBitcoinAddress, BackendApiError>;
#[deprecated(note = "since node-v0.9.3: \
Use update_human_bitcoin_address instead")]
async fn update_payment_address(
&self,
req: UpdateHumanBitcoinAddress,
auth: BearerAuthToken,
) -> Result<HumanBitcoinAddress, BackendApiError> {
self.update_human_bitcoin_address(req, auth).await
}
async fn get_human_bitcoin_address(
&self,
auth: BearerAuthToken,
) -> Result<HumanBitcoinAddress, BackendApiError>;
#[deprecated(note = "since node-v0.9.3: \
Use get_human_bitcoin_address instead")]
async fn get_payment_address(
&self,
auth: BearerAuthToken,
) -> Result<HumanBitcoinAddress, BackendApiError> {
self.get_human_bitcoin_address(auth).await
}
async fn claim_generated_human_bitcoin_address(
&self,
req: ClaimGeneratedHumanBitcoinAddress,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
#[deprecated(note = "since node-v0.9.3: \
Use claim_generated_human_bitcoin_address instead")]
async fn claim_generated_payment_address(
&self,
req: ClaimGeneratedHumanBitcoinAddress,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError> {
self.claim_generated_human_bitcoin_address(req, auth).await
}
async fn get_generated_username(
&self,
auth: BearerAuthToken,
) -> Result<GetGeneratedUsernameResponse, BackendApiError>;
async fn get_nwc_clients(
&self,
req: GetNwcClients,
auth: BearerAuthToken,
) -> Result<VecDbNwcClient, BackendApiError>;
async fn upsert_nwc_client(
&self,
req: DbNwcClientFields,
auth: BearerAuthToken,
) -> Result<DbNwcClient, BackendApiError>;
async fn delete_nwc_client(
&self,
req: NostrPkStruct,
auth: BearerAuthToken,
) -> Result<Empty, BackendApiError>;
}
pub trait NodeLspApi {
async fn get_new_scids(
&self,
req: &GetNewScidsRequest,
) -> Result<Scids, LspApiError>;
async fn get_network_graph(&self) -> Result<Bytes, LspApiError>;
async fn get_prob_scorer(&self) -> Result<Bytes, LspApiError>;
async fn payment_path(&self, event: &Event) -> Result<Empty, LspApiError>;
}
pub trait NodeRunnerApi {
async fn renew_lease(
&self,
req: &UserLeaseRenewalRequest,
) -> Result<Empty, RunnerApiError>;
async fn sync_succ(&self, user_pk: UserPk)
-> Result<Empty, RunnerApiError>;
}
pub trait PublicGatewayApi {
async fn get_lnurl_pay_request(
&self,
) -> Result<LnurlPayRequestWire, LnurlError>;
async fn lnurl_callback(
&self,
req: LnurlCallbackRequest,
) -> Result<LnurlCallbackResponse, LnurlError>;
}