Skip to content

Commit 791d707

Browse files
committed
fix: integrate revenue module into workspace contract structure
- Fix contracts/Cargo.toml: remove duplicate [package] section, make it a proper workspace root only - Move revenue module from contracts/src/ to contracts/subscription/src/ adapted for the new storage-contract delegation pattern - Add revenue StorageKey variants to contracts/types/src/lib.rs: RevenueRecognitionRule, RevenueSchedule, RevenueDeferredBalance, RevenueRecognisedBalance, RevenueMerchantSubscriptions - Hook revenue schedule generation into charge_subscription in contracts/subscription/src/lib.rs - Add revenue public API to SubTrackrSubscription: set_revenue_rule, recognize_revenue, get_deferred_revenue, get_revenue_schedule - Fix clippy::manual_div_ceil in revenue.rs (use .div_ceil()) - Add #[allow(clippy::too_many_arguments)] to subscription and proxy crates (pre-existing upstream issue with Soroban contractimpl macro) - Remove obsolete contracts/src/ directory - All workspace tests pass, cargo fmt --check clean, clippy -D warnings clean
1 parent 4fac118 commit 791d707

12 files changed

Lines changed: 6293 additions & 4412 deletions

contracts/Cargo.toml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
[package]
2-
name = "subtrackr-subscription"
3-
version = "0.2.0"
4-
edition = "2021"
5-
authors = ["SubTrackr Team"]
6-
description = "SubTrackr subscription implementation contract (Soroban)"
7-
8-
[lib]
9-
crate-type = ["cdylib", "rlib"]
10-
11-
[dependencies]
12-
soroban-sdk = "21.0.0"
13-
subtrackr-types = { path = "../types" }
14-
15-
[dev-dependencies]
16-
soroban-sdk = { version = "21.0.0", features = ["testutils"] }
17-
arbitrary = { version = "1.3", features = ["derive"] }
181
[workspace]
192
resolver = "2"
203
members = [

contracts/proxy/src/lib.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![no_std]
2+
#![allow(clippy::too_many_arguments)]
23

34
mod storage;
45

@@ -13,11 +14,7 @@ fn current_proxy_address(env: &Env) -> Address {
1314
env.current_contract_address()
1415
}
1516

16-
fn invoke_impl<T: TryFromVal<Env, Val>>(
17-
env: &Env,
18-
func: &str,
19-
args: Vec<Val>,
20-
) -> T {
17+
fn invoke_impl<T: TryFromVal<Env, Val>>(env: &Env, func: &str, args: Vec<Val>) -> T {
2118
let impl_addr = proxy_storage::implementation(env);
2219
env.invoke_contract(&impl_addr, &soroban_sdk::Symbol::new(env, func), args)
2320
}
@@ -92,11 +89,7 @@ impl UpgradeableProxy {
9289
let target_version: u32 = env.invoke_contract(
9390
&implementation,
9491
&soroban_sdk::Symbol::new(&env, "get_version"),
95-
soroban_sdk::vec![
96-
&env,
97-
proxy_addr.into_val(&env),
98-
storage.into_val(&env)
99-
],
92+
soroban_sdk::vec![&env, proxy_addr.into_val(&env), storage.into_val(&env)],
10093
);
10194
proxy_storage::set_version(&env, target_version);
10295
}
@@ -133,13 +126,13 @@ impl UpgradeableProxy {
133126
// Basic interface validation: ensure new implementation supports expected interface.
134127
let proxy_addr = current_proxy_address(&env);
135128
let storage_addr = proxy_storage::storage_address(&env);
136-
let args: Vec<Val> = soroban_sdk::vec![
137-
&env,
138-
proxy_addr.into_val(&env),
139-
storage_addr.into_val(&env)
140-
];
141-
let _target_version: u32 =
142-
env.invoke_contract(&implementation, &soroban_sdk::Symbol::new(&env, "get_version"), args);
129+
let args: Vec<Val> =
130+
soroban_sdk::vec![&env, proxy_addr.into_val(&env), storage_addr.into_val(&env)];
131+
let _target_version: u32 = env.invoke_contract(
132+
&implementation,
133+
&soroban_sdk::Symbol::new(&env, "get_version"),
134+
args,
135+
);
143136

144137
proxy_storage::set_scheduled_upgrade(
145138
&env,
@@ -194,7 +187,10 @@ impl UpgradeableProxy {
194187
);
195188

196189
let now = env.ledger().timestamp();
197-
assert!(now >= scheduled.execute_after, "Upgrade timelock not expired");
190+
assert!(
191+
now >= scheduled.execute_after,
192+
"Upgrade timelock not expired"
193+
);
198194

199195
let proxy_addr = current_proxy_address(&env);
200196
let storage_addr = proxy_storage::storage_address(&env);
@@ -471,12 +467,7 @@ impl UpgradeableProxy {
471467
);
472468
}
473469

474-
pub fn pause_by_subscriber(
475-
env: Env,
476-
subscriber: Address,
477-
subscription_id: u64,
478-
duration: u64,
479-
) {
470+
pub fn pause_by_subscriber(env: Env, subscriber: Address, subscription_id: u64, duration: u64) {
480471
let proxy_addr = current_proxy_address(&env);
481472
let storage_addr = proxy_storage::storage_address(&env);
482473
invoke_impl::<()>(

contracts/proxy/src/storage.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ pub(crate) fn set_rollback_delay_secs(env: &Env, delay_secs: u64) {
8080
}
8181

8282
pub(crate) fn scheduled_upgrade(env: &Env) -> Option<ScheduledUpgrade> {
83-
env.storage().instance().get(&StorageKey::ProxyScheduledUpgrade)
83+
env.storage()
84+
.instance()
85+
.get(&StorageKey::ProxyScheduledUpgrade)
8486
}
8587

8688
pub(crate) fn set_scheduled_upgrade(env: &Env, upgrade: &ScheduledUpgrade) {
@@ -90,7 +92,9 @@ pub(crate) fn set_scheduled_upgrade(env: &Env, upgrade: &ScheduledUpgrade) {
9092
}
9193

9294
pub(crate) fn clear_scheduled_upgrade(env: &Env) {
93-
env.storage().instance().remove(&StorageKey::ProxyScheduledUpgrade);
95+
env.storage()
96+
.instance()
97+
.remove(&StorageKey::ProxyScheduledUpgrade);
9498
}
9599

96100
pub(crate) fn previous_count(env: &Env) -> u32 {
@@ -112,9 +116,10 @@ pub(crate) fn previous_top(env: &Env) -> Option<Address> {
112116

113117
pub(crate) fn push_previous(env: &Env, implementation: &Address) {
114118
let count = previous_count(env);
115-
env.storage()
116-
.instance()
117-
.set(&StorageKey::ProxyPreviousImplementation(count), implementation);
119+
env.storage().instance().set(
120+
&StorageKey::ProxyPreviousImplementation(count),
121+
implementation,
122+
);
118123
env.storage()
119124
.instance()
120125
.set(&StorageKey::ProxyPreviousImplementationCount, &(count + 1));

0 commit comments

Comments
 (0)