Skip to content

Commit

Permalink
Merge pull request fedimint#5869 from tvolk131/move_lnv2_endpoint_con…
Browse files Browse the repository at this point in the history
…stants

fix: move lnv2 endpoint consts to lnv2 module
  • Loading branch information
m1sterc001guy authored Aug 15, 2024
2 parents b2464ee + 921414a commit 889ea4f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 26 deletions.
16 changes: 10 additions & 6 deletions gateway/ln-gateway/src/rpc/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use bitcoin::Address;
use fedimint_core::util::SafeUrl;
use fedimint_core::{Amount, TransactionId};
use fedimint_ln_common::gateway_endpoint_constants::{
BACKUP_ENDPOINT, BALANCE_ENDPOINT, CLOSE_CHANNELS_WITH_PEER_ENDPOINT, CONFIGURATION_ENDPOINT,
CONNECT_FED_ENDPOINT, GATEWAY_INFO_ENDPOINT, GATEWAY_INFO_POST_ENDPOINT, GET_BALANCES_ENDPOINT,
GET_FUNDING_ADDRESS_ENDPOINT, LEAVE_FED_ENDPOINT, LIST_ACTIVE_CHANNELS_ENDPOINT,
OPEN_CHANNEL_ENDPOINT, RECEIVE_ECASH_ENDPOINT, RESTORE_ENDPOINT, SET_CONFIGURATION_ENDPOINT,
SPEND_ECASH_ENDPOINT, WITHDRAW_ENDPOINT,
ADDRESS_ENDPOINT, BACKUP_ENDPOINT, BALANCE_ENDPOINT, CLOSE_CHANNELS_WITH_PEER_ENDPOINT,
CONFIGURATION_ENDPOINT, CONNECT_FED_ENDPOINT, GATEWAY_INFO_ENDPOINT,
GATEWAY_INFO_POST_ENDPOINT, GET_BALANCES_ENDPOINT, GET_FUNDING_ADDRESS_ENDPOINT,
LEAVE_FED_ENDPOINT, LIST_ACTIVE_CHANNELS_ENDPOINT, OPEN_CHANNEL_ENDPOINT,
RECEIVE_ECASH_ENDPOINT, RESTORE_ENDPOINT, SET_CONFIGURATION_ENDPOINT, SPEND_ECASH_ENDPOINT,
WITHDRAW_ENDPOINT,
};
use reqwest::{Method, StatusCode};
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -83,7 +84,10 @@ impl GatewayRpcClient {
&self,
payload: DepositAddressPayload,
) -> GatewayRpcResult<Address<NetworkUnchecked>> {
let url = self.base_url.join("/address").expect("invalid base url");
let url = self
.base_url
.join(ADDRESS_ENDPOINT)
.expect("invalid base url");
self.call_post(url, payload).await
}

Expand Down
18 changes: 10 additions & 8 deletions gateway/ln-gateway/src/rpc/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ use fedimint_core::task::TaskGroup;
use fedimint_ln_client::pay::PayInvoicePayload;
use fedimint_ln_common::gateway_endpoint_constants::{
ADDRESS_ENDPOINT, BACKUP_ENDPOINT, BALANCE_ENDPOINT, CLOSE_CHANNELS_WITH_PEER_ENDPOINT,
CONFIGURATION_ENDPOINT, CONNECT_FED_ENDPOINT, CREATE_BOLT11_INVOICE_V2_ENDPOINT,
GATEWAY_INFO_ENDPOINT, GATEWAY_INFO_POST_ENDPOINT, GET_BALANCES_ENDPOINT,
GET_FUNDING_ADDRESS_ENDPOINT, GET_GATEWAY_ID_ENDPOINT, LEAVE_FED_ENDPOINT,
LIST_ACTIVE_CHANNELS_ENDPOINT, OPEN_CHANNEL_ENDPOINT, PAY_INVOICE_ENDPOINT,
RECEIVE_ECASH_ENDPOINT, RESTORE_ENDPOINT, ROUTING_INFO_V2_ENDPOINT, SEND_PAYMENT_V2_ENDPOINT,
CONFIGURATION_ENDPOINT, CONNECT_FED_ENDPOINT, GATEWAY_INFO_ENDPOINT,
GATEWAY_INFO_POST_ENDPOINT, GET_BALANCES_ENDPOINT, GET_FUNDING_ADDRESS_ENDPOINT,
GET_GATEWAY_ID_ENDPOINT, LEAVE_FED_ENDPOINT, LIST_ACTIVE_CHANNELS_ENDPOINT,
OPEN_CHANNEL_ENDPOINT, PAY_INVOICE_ENDPOINT, RECEIVE_ECASH_ENDPOINT, RESTORE_ENDPOINT,
SET_CONFIGURATION_ENDPOINT, SPEND_ECASH_ENDPOINT, WITHDRAW_ENDPOINT,
};
use fedimint_lnv2_client::{CreateBolt11InvoicePayload, SendPaymentPayload};
use fedimint_lnv2_common::endpoint_constants::{
CREATE_BOLT11_INVOICE_ENDPOINT, ROUTING_INFO_ENDPOINT, SEND_PAYMENT_ENDPOINT,
};
use hex::ToHex;
use serde_json::{json, Value};
use tokio::net::TcpListener;
Expand Down Expand Up @@ -151,10 +153,10 @@ fn v1_routes(gateway: Arc<Gateway>) -> Router {
.route(PAY_INVOICE_ENDPOINT, post(pay_invoice))
.route(GET_GATEWAY_ID_ENDPOINT, get(get_gateway_id))
// These routes are for next generation lightning
.route(ROUTING_INFO_V2_ENDPOINT, post(routing_info_v2))
.route(SEND_PAYMENT_V2_ENDPOINT, post(pay_bolt11_invoice_v2))
.route(ROUTING_INFO_ENDPOINT, post(routing_info_v2))
.route(SEND_PAYMENT_ENDPOINT, post(pay_bolt11_invoice_v2))
.route(
CREATE_BOLT11_INVOICE_V2_ENDPOINT,
CREATE_BOLT11_INVOICE_ENDPOINT,
post(create_bolt11_invoice_v2),
)
.route(SPEND_ECASH_ENDPOINT, post(spend_ecash))
Expand Down
7 changes: 5 additions & 2 deletions modules/fedimint-ln-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ use fedimint_ln_common::contracts::{
Contract, ContractId, DecryptedPreimage, EncryptedPreimage, IdentifiableContract, Preimage,
PreimageKey,
};
use fedimint_ln_common::gateway_endpoint_constants::{
GET_GATEWAY_ID_ENDPOINT, PAY_INVOICE_ENDPOINT,
};
use fedimint_ln_common::{
ContractOutput, LightningCommonInit, LightningGateway, LightningGatewayAnnouncement,
LightningGatewayRegistration, LightningInput, LightningModuleTypes, LightningOutput,
Expand Down Expand Up @@ -2032,7 +2035,7 @@ impl GatewayConnection for RealGatewayConnection {
.get(
gateway
.api
.join("id")
.join(GET_GATEWAY_ID_ENDPOINT)
.expect("id contains no invalid characters for a URL")
.as_str(),
)
Expand Down Expand Up @@ -2065,7 +2068,7 @@ impl GatewayConnection for RealGatewayConnection {
.post(
gateway
.api
.join("pay_invoice")
.join(PAY_INVOICE_ENDPOINT)
.expect("'pay_invoice' contains no invalid characters for a URL")
.as_str(),
)
Expand Down
3 changes: 0 additions & 3 deletions modules/fedimint-ln-common/src/gateway_endpoint_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub const BACKUP_ENDPOINT: &str = "/backup";
pub const BALANCE_ENDPOINT: &str = "/balance";
pub const CONFIGURATION_ENDPOINT: &str = "/config";
pub const CONNECT_FED_ENDPOINT: &str = "/connect-fed"; // uses `-` for backwards compatibility
pub const CREATE_BOLT11_INVOICE_V2_ENDPOINT: &str = "/create_bolt11_invoice";
pub const GATEWAY_INFO_ENDPOINT: &str = "/info";
pub const GET_BALANCES_ENDPOINT: &str = "/balances";
pub const GET_GATEWAY_ID_ENDPOINT: &str = "/id";
Expand All @@ -16,10 +15,8 @@ pub const LIST_ACTIVE_CHANNELS_ENDPOINT: &str = "/list_active_channels";
pub const OPEN_CHANNEL_ENDPOINT: &str = "/open_channel";
pub const CLOSE_CHANNELS_WITH_PEER_ENDPOINT: &str = "/close_channels_with_peer";
pub const RECEIVE_ECASH_ENDPOINT: &str = "/receive_ecash";
pub const ROUTING_INFO_V2_ENDPOINT: &str = "/routing_info";
pub const PAY_INVOICE_ENDPOINT: &str = "/pay_invoice";
pub const RESTORE_ENDPOINT: &str = "/restore";
pub const SEND_PAYMENT_V2_ENDPOINT: &str = "/send_payment";
pub const SET_CONFIGURATION_ENDPOINT: &str = "/set_configuration";
pub const SPEND_ECASH_ENDPOINT: &str = "/spend_ecash";
pub const WITHDRAW_ENDPOINT: &str = "/withdraw";
11 changes: 6 additions & 5 deletions modules/fedimint-lnv2-client/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use fedimint_core::{apply, async_trait_maybe_send, NumPeersExt, PeerId};
use fedimint_lnv2_common::contracts::OutgoingContract;
use fedimint_lnv2_common::endpoint_constants::{
ADD_GATEWAY_ENDPOINT, AWAIT_INCOMING_CONTRACT_ENDPOINT, AWAIT_PREIMAGE_ENDPOINT,
CONSENSUS_BLOCK_COUNT_ENDPOINT, GATEWAYS_ENDPOINT, OUTGOING_CONTRACT_EXPIRATION_ENDPOINT,
REMOVE_GATEWAY_ENDPOINT,
CONSENSUS_BLOCK_COUNT_ENDPOINT, CREATE_BOLT11_INVOICE_ENDPOINT, GATEWAYS_ENDPOINT,
OUTGOING_CONTRACT_EXPIRATION_ENDPOINT, REMOVE_GATEWAY_ENDPOINT, ROUTING_INFO_ENDPOINT,
SEND_PAYMENT_ENDPOINT,
};
use fedimint_lnv2_common::{ContractId, GatewayEndpoint};
use itertools::Itertools;
Expand Down Expand Up @@ -222,7 +223,7 @@ impl GatewayConnection for RealGatewayConnection {
.post(
gateway_api
.into_url()
.join("routing_info")
.join(ROUTING_INFO_ENDPOINT)
.expect("'routing_info' contains no invalid characters for a URL")
.as_str(),
)
Expand All @@ -244,7 +245,7 @@ impl GatewayConnection for RealGatewayConnection {
.post(
gateway_api
.into_url()
.join("create_bolt11_invoice")
.join(CREATE_BOLT11_INVOICE_ENDPOINT)
.expect("'create_bolt11_invoice' contains no invalid characters for a URL")
.as_str(),
)
Expand All @@ -269,7 +270,7 @@ impl GatewayConnection for RealGatewayConnection {
.post(
gateway_api
.into_url()
.join("send_payment")
.join(SEND_PAYMENT_ENDPOINT)
.expect("'send_payment' contains no invalid characters for a URL")
.as_str(),
)
Expand Down
7 changes: 5 additions & 2 deletions modules/fedimint-lnv2-common/src/endpoint_constants.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
pub const ADD_GATEWAY_ENDPOINT: &str = "add_gateway";
pub const AWAIT_INCOMING_CONTRACT_ENDPOINT: &str = "await_incoming_contract";
pub const AWAIT_PREIMAGE_ENDPOINT: &str = "await_preimage";
pub const CONSENSUS_BLOCK_COUNT_ENDPOINT: &str = "consensus_block_count";
pub const OUTGOING_CONTRACT_EXPIRATION_ENDPOINT: &str = "outgoing_contract_expiration";
pub const CREATE_BOLT11_INVOICE_ENDPOINT: &str = "/create_bolt11_invoice";
pub const GATEWAYS_ENDPOINT: &str = "gateways";
pub const ADD_GATEWAY_ENDPOINT: &str = "add_gateway";
pub const OUTGOING_CONTRACT_EXPIRATION_ENDPOINT: &str = "outgoing_contract_expiration";
pub const REMOVE_GATEWAY_ENDPOINT: &str = "remove_gateway";
pub const ROUTING_INFO_ENDPOINT: &str = "/routing_info";
pub const SEND_PAYMENT_ENDPOINT: &str = "/send_payment";

0 comments on commit 889ea4f

Please sign in to comment.