Skip to content

Commit 3da4b04

Browse files
authored
Merge pull request #434 from soomtochukwu/fix/428-nft-publish-event
2 parents 74b3401 + 51d4a9a commit 3da4b04

3 files changed

Lines changed: 80 additions & 25 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/invoice_liquidity/src/events.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,35 @@ pub struct InvoiceTokenChanged {
280280
pub old_token: Address,
281281
pub new_token: Address,
282282
}
283+
284+
// ── Invoice NFT lifecycle events (nft.rs) ─────────────────────────────────────
285+
286+
/// Emitted when an invoice NFT is minted (invoice submitted).
287+
#[contracttype]
288+
#[derive(Clone, Debug, PartialEq)]
289+
pub struct InvoiceNftMinted {
290+
pub invoice_id: u64,
291+
pub owner: Address,
292+
pub amount: i128,
293+
pub due_date: u32,
294+
pub timestamp: u64,
295+
}
296+
297+
/// Emitted when an invoice NFT is transferred (e.g. freelancer → LP on funding).
298+
#[contracttype]
299+
#[derive(Clone, Debug, PartialEq)]
300+
pub struct InvoiceNftTransferred {
301+
pub invoice_id: u64,
302+
pub from: Address,
303+
pub to: Address,
304+
pub timestamp: u64,
305+
}
306+
307+
/// Emitted when an invoice NFT is burned (invoice marked paid).
308+
#[contracttype]
309+
#[derive(Clone, Debug, PartialEq)]
310+
pub struct InvoiceNftBurned {
311+
pub invoice_id: u64,
312+
pub owner: Address,
313+
pub timestamp: u64,
314+
}

contracts/invoice_liquidity/src/nft.rs

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use soroban_sdk::{contracttype, Address, Env, Symbol};
1717

1818
use crate::errors::ContractError;
19+
use crate::events::{InvoiceNftBurned, InvoiceNftMinted, InvoiceNftTransferred};
1920
use crate::storage::DataKey;
2021

2122
/// NFT Metadata: complete information about an invoice NFT
@@ -85,8 +86,8 @@ pub fn mint_invoice_nft(
8586
due_date,
8687
discount_rate,
8788
token,
88-
owner,
89-
minted_at: env.ledger().timestamp(),
89+
owner: owner.clone(),
90+
minted_at: env.ledger().timestamp() as u32,
9091
};
9192

9293
env.storage()
@@ -97,14 +98,21 @@ pub fn mint_invoice_nft(
9798
.persistent()
9899
.set(&get_nft_owner_key(invoice_id), &owner);
99100

100-
// Publish NFT minting event
101-
env.events().publish_event((
102-
Symbol::new(env, "invoice_nft_minted"),
103-
invoice_id,
104-
owner,
105-
amount,
106-
due_date,
107-
));
101+
// Publish NFT minting event (Soroban SDK: publish(topics, data))
102+
env.events().publish(
103+
(
104+
Symbol::new(env, "invoice_nft_minted"),
105+
invoice_id,
106+
owner.clone(),
107+
),
108+
InvoiceNftMinted {
109+
invoice_id,
110+
owner,
111+
amount,
112+
due_date,
113+
timestamp: env.ledger().timestamp(),
114+
},
115+
);
108116

109117
Ok(())
110118
}
@@ -148,13 +156,21 @@ pub fn transfer_invoice_nft(
148156
.persistent()
149157
.set(&get_nft_owner_key(invoice_id), &to);
150158

151-
// Publish NFT transfer event
152-
env.events().publish_event((
153-
Symbol::new(env, "invoice_nft_transferred"),
154-
invoice_id,
155-
from,
156-
to,
157-
));
159+
// Publish NFT transfer event (Soroban SDK: publish(topics, data))
160+
env.events().publish(
161+
(
162+
Symbol::new(env, "invoice_nft_transferred"),
163+
invoice_id,
164+
from.clone(),
165+
to.clone(),
166+
),
167+
InvoiceNftTransferred {
168+
invoice_id,
169+
from,
170+
to,
171+
timestamp: env.ledger().timestamp(),
172+
},
173+
);
158174

159175
Ok(())
160176
}
@@ -191,12 +207,19 @@ pub fn burn_invoice_nft(env: &Env, invoice_id: u64, owner: Address) -> Result<()
191207
.persistent()
192208
.remove(&get_nft_owner_key(invoice_id));
193209

194-
// Publish NFT burn event
195-
env.events().publish_event((
196-
Symbol::new(env, "invoice_nft_burned"),
197-
invoice_id,
198-
owner,
199-
));
210+
// Publish NFT burn event (Soroban SDK: publish(topics, data))
211+
env.events().publish(
212+
(
213+
Symbol::new(env, "invoice_nft_burned"),
214+
invoice_id,
215+
owner.clone(),
216+
),
217+
InvoiceNftBurned {
218+
invoice_id,
219+
owner,
220+
timestamp: env.ledger().timestamp(),
221+
},
222+
);
200223

201224
Ok(())
202225
}

0 commit comments

Comments
 (0)