Skip to content

Commit

Permalink
Merge pull request #1288 from getlipa/feat/add-referral-code-to-topup…
Browse files Browse the repository at this point in the history
…-registration

Add referral code to topup registration
  • Loading branch information
gcomte authored Dec 2, 2024
2 parents 20d6349 + c789ad4 commit 35f0b45
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 39 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ parser = { path = "parser" }
pocketclient = { path = "pocketclient", optional = true }
pocketclient-mock = { path = "mock/pocketclient", optional = true }

chameleon = { git = "https://github.com/getlipa/wild", tag = "v1.27.0", optional = true }
chameleon = { git = "https://github.com/getlipa/wild", tag = "v1.28.0", optional = true }
chameleon-mock = { path = "mock/wild/chameleon", optional = true }
crow = { git = "https://github.com/getlipa/wild", tag = "v1.27.0", optional = true }
crow = { git = "https://github.com/getlipa/wild", tag = "v1.28.0", optional = true }
crow-mock = { path = "mock/wild/crow", optional = true }
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.27.0" }
honeybadger = { git = "https://github.com/getlipa/wild", tag = "v1.27.0", optional = true }
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.28.0" }
honeybadger = { git = "https://github.com/getlipa/wild", tag = "v1.28.0", optional = true }
honeybadger-mock = { path = "mock/wild/honeybadger", optional = true }
parrot = { git = "https://github.com/getlipa/wild", tag = "v1.27.0", optional = true }
parrot = { git = "https://github.com/getlipa/wild", tag = "v1.28.0", optional = true }
parrot-mock = { path = "mock/wild/parrot", optional = true }
perro = { git = "https://github.com/getlipa/perro", tag = "v1.2.0" }
pigeon = { git = "https://github.com/getlipa/wild", tag = "v1.27.0", optional = true }
pigeon = { git = "https://github.com/getlipa/wild", tag = "v1.28.0", optional = true }
pigeon-mock = { path = "mock/wild/pigeon", optional = true }
squirrel = { git = "https://github.com/getlipa/wild", tag = "v1.27.0", optional = true }
squirrel = { git = "https://github.com/getlipa/wild", tag = "v1.28.0", optional = true }
squirrel-mock = { path = "mock/wild/squirrel", optional = true }

breez-sdk-core = { git = "https://github.com/breez/breez-sdk", tag = "0.6.4", optional = true }
Expand Down
11 changes: 6 additions & 5 deletions examples/node/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ fn setup_editor(history_path: &Path) -> Editor<CommandHinter, DefaultHistory> {
));

hints.insert(CommandHint::new(
"registertopup <IBAN> <currency> [email]",
"registertopup <IBAN> <currency> [email] [referral code]",
"registertopup ",
));
hints.insert(CommandHint::new("resettopup", "resettopup"));
Expand Down Expand Up @@ -559,7 +559,7 @@ fn help() {
println!(" getfailedswapresolvingfees <swap address>");
println!(" refundfailedswap <swap address> <to address>");
println!();
println!(" registertopup <IBAN> <currency> [email]");
println!(" registertopup <IBAN> <currency> [email] [referral code]");
println!(" resettopup");
println!(" getregisteredtopup");
println!(" listoffers");
Expand Down Expand Up @@ -1152,10 +1152,11 @@ fn register_topup(node: &LightningNode, words: &mut dyn Iterator<Item = &str>) -
let currency = words.next().ok_or(anyhow!("Currency is required"))?;

let email = words.next().map(String::from);
let referral = words.next().map(String::from);

let topup_info = node
.fiat_topup()
.register(email, iban.to_string(), currency.to_string())?;
let topup_info =
node.fiat_topup()
.register(email, referral, iban.to_string(), currency.to_string())?;
println!("{topup_info:?}");

Ok(())
Expand Down
1 change: 1 addition & 0 deletions examples/node/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ fn main() {
max_receive_amount_sat: 1_000_000,
min_receive_channel_open_fee_multiplier: 2.0,
},
topup_referral_code_max_length: 40,
};

let node = LightningNode::new(config, events).unwrap();
Expand Down
1 change: 1 addition & 0 deletions examples/notification_handler/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ fn get_config() -> LightningNodeConfig {
max_receive_amount_sat: 1_000_000,
min_receive_channel_open_fee_multiplier: 2.0,
},
topup_referral_code_max_length: 40,
}
}

Expand Down
4 changes: 2 additions & 2 deletions mock/wild/chameleon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2021"
name = "chameleon"

[dependencies]
chameleon = { git = "https://github.com/getlipa/wild", tag = "v1.27.0" }
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.27.0" }
chameleon = { git = "https://github.com/getlipa/wild", tag = "v1.28.0" }
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.28.0" }
honeybadger-mock = { path = "../honeybadger" }
lazy_static = "1.4.0"
rand = "0.8.5"
4 changes: 2 additions & 2 deletions mock/wild/crow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2021"
name = "crow"

[dependencies]
crow = { git = "https://github.com/getlipa/wild", tag = "v1.27.0" }
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.27.0" }
crow = { git = "https://github.com/getlipa/wild", tag = "v1.28.0" }
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.28.0" }
honeybadger-mock = { path = "../honeybadger" }
isocountry = { version = "0.3.2" }
isolanguage-1 = { version = "0.2.2" }
Expand Down
7 changes: 6 additions & 1 deletion mock/wild/crow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ impl OfferManager {
Self {}
}

pub fn register_topup(&self, order_id: String, email: Option<String>) -> graphql::Result<()> {
pub fn register_topup(
&self,
order_id: String,
email: Option<String>,
_referral: Option<String>,
) -> graphql::Result<()> {
let mut status = TopupStatus::READY;

if let Some(email) = email {
Expand Down
4 changes: 2 additions & 2 deletions mock/wild/honeybadger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2021"
name = "honeybadger"

[dependencies]
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.27.0" }
honeybadger = { git = "https://github.com/getlipa/wild", tag = "v1.27.0" }
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.28.0" }
honeybadger = { git = "https://github.com/getlipa/wild", tag = "v1.28.0" }
rand = "0.8.5"
secp256k1 = { version = "0.27.0", features = ["global-context"] }
tokio = "1.37.0"
Expand Down
4 changes: 2 additions & 2 deletions mock/wild/parrot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2021"
name = "parrot"

[dependencies]
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.27.0" }
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.28.0" }
honeybadger-mock = { path = "../honeybadger" }
parrot = { git = "https://github.com/getlipa/wild", tag = "v1.27.0" }
parrot = { git = "https://github.com/getlipa/wild", tag = "v1.28.0" }
2 changes: 1 addition & 1 deletion mock/wild/pigeon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2021"
name = "pigeon"

[dependencies]
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.27.0" }
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.28.0" }
honeybadger-mock = { path = "../honeybadger" }
lazy_static = "1.4.0"
4 changes: 2 additions & 2 deletions mock/wild/squirrel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2021"
name = "squirrel"

[dependencies]
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.27.0" }
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.28.0" }
honeybadger-mock = { path = "../honeybadger" }
squirrel = { git = "https://github.com/getlipa/wild", tag = "v1.27.0" }
squirrel = { git = "https://github.com/getlipa/wild", tag = "v1.28.0" }
12 changes: 10 additions & 2 deletions src/fiat_topup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ impl FiatTopup {
pub fn register(
&self,
email: Option<String>,
referral: Option<String>,
user_iban: String,
user_currency: String,
) -> Result<FiatTopupInfo> {
debug!("fiat_topup().register() - called with - email: {email:?} - user_iban: {user_iban} - user_currency: {user_currency:?}");
debug!("fiat_topup().register() - called with - email: {email:?} - referral code: {referral:?} - user_iban: {user_iban} - user_currency: {user_currency:?}");
user_iban
.parse::<Iban>()
.map_to_invalid_input("Invalid user_iban")?;
Expand All @@ -87,6 +88,13 @@ impl FiatTopup {
EmailAddress::from_str(email).map_to_invalid_input("Invalid email")?;
}

if let Some(referral) = referral.as_ref() {
let string_length = referral.len();
if referral.len() > self.support.node_config.topup_referral_code_max_length as usize {
invalid_input!("Invalid referral code [string length: {string_length}]");
}
}

let sdk = Arc::clone(&self.support.sdk);
let sign_message = |message| async move {
sdk.sign_message(SignMessageRequest { message })
Expand Down Expand Up @@ -116,7 +124,7 @@ impl FiatTopup {

self.support
.offer_manager
.register_topup(topup_info.order_id.clone(), email)
.register_topup(topup_info.order_id.clone(), email, referral)
.map_runtime_error_to(RuntimeErrorCode::OfferServiceUnavailable)?;

Ok(topup_info)
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,7 @@ impl LightningNode {
///
/// Parameters:
/// * `email` - this email will be used to send status information about different topups
/// * `referral` - the referral code of another user
/// * `user_iban` - the user will send fiat from this iban
/// * `user_currency` - the fiat currency (ISO 4217 currency code) that will be sent for
/// exchange. Not all are supported. A consumer of this library should find out about available
Expand All @@ -1067,7 +1068,8 @@ impl LightningNode {
user_iban: String,
user_currency: String,
) -> Result<FiatTopupInfo> {
self.fiat_topup.register(email, user_iban, user_currency)
self.fiat_topup
.register(email, None, user_iban, user_currency)
}

/// Resets a previous fiat topups registration.
Expand Down
3 changes: 2 additions & 1 deletion src/lipalightninglib.udl
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ interface FiatTopup {
TermsAndConditionsStatus query_tc_status();

[Throws=LnError]
FiatTopupInfo register(string? email, string user_iban, string user_currency);
FiatTopupInfo register(string? email, string? referral_code, string user_iban, string user_currency);

[Throws=LnError]
void reset();
Expand Down Expand Up @@ -445,6 +445,7 @@ dictionary LightningNodeConfig {
BreezSdkConfig breez_sdk_config;
MaxRoutingFeeConfig max_routing_fee_config;
ReceiveLimitsConfig receive_limits_config;
u32 topup_referral_code_max_length;
};

dictionary RemoteServicesConfig {
Expand Down
1 change: 1 addition & 0 deletions src/node_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct LightningNodeConfig {
pub breez_sdk_config: BreezSdkConfig,
pub max_routing_fee_config: MaxRoutingFeeConfig,
pub receive_limits_config: ReceiveLimitsConfig,
pub topup_referral_code_max_length: u32,
}

#[derive(Debug, Clone)]
Expand Down
1 change: 1 addition & 0 deletions tests/register_node_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fn test_register_node() {
max_receive_amount_sat: 1_000_000,
min_receive_channel_open_fee_multiplier: 2.0,
},
topup_referral_code_max_length: 40,
};

let events_handler = PrintEventsHandler {};
Expand Down
2 changes: 2 additions & 0 deletions tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::string::ToString;
type Result<T> = std::result::Result<T, perro::Error<RuntimeErrorCode>>;

const LOCAL_PERSISTENCE_PATH: &str = ".3l_local_test";
pub const MAX_REFERRAL_CODE_LENGTH: u32 = 40;

#[allow(dead_code)]
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -144,6 +145,7 @@ pub fn start_specific_node(
max_receive_amount_sat: 1_000_000,
min_receive_channel_open_fee_multiplier: 2.0,
},
topup_referral_code_max_length: MAX_REFERRAL_CODE_LENGTH,
};

let node = LightningNode::new(config, events_callback)?;
Expand Down
Loading

0 comments on commit 35f0b45

Please sign in to comment.