Skip to content

Commit f49e1f4

Browse files
committed
solana: Update release_inbox_item to return Result<Option<_>>
1 parent bb9d83f commit f49e1f4

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

solana/programs/example-native-token-transfers/src/instructions/release_inbound.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ pub fn release_inbound_mint<'info>(
7979
args: ReleaseInboundArgs,
8080
) -> Result<()> {
8181
let inbox_item = release_inbox_item(&mut ctx.accounts.common.inbox_item, args.revert_on_delay)?;
82+
if inbox_item.is_none() {
83+
return Ok(());
84+
}
85+
let inbox_item = inbox_item.unwrap();
86+
assert!(inbox_item.release_status == ReleaseStatus::Released);
8287

8388
// NOTE: minting tokens is a two-step process:
8489
// 1. Mint tokens to the custody account
@@ -149,6 +154,11 @@ pub fn release_inbound_mint_multisig<'info>(
149154
args: ReleaseInboundArgs,
150155
) -> Result<()> {
151156
let inbox_item = release_inbox_item(&mut ctx.accounts.common.inbox_item, args.revert_on_delay)?;
157+
if inbox_item.is_none() {
158+
return Ok(());
159+
}
160+
let inbox_item = inbox_item.unwrap();
161+
assert!(inbox_item.release_status == ReleaseStatus::Released);
152162

153163
// NOTE: minting tokens is a two-step process:
154164
// 1. Mint tokens to the custody account
@@ -226,6 +236,11 @@ pub fn release_inbound_unlock<'info>(
226236
args: ReleaseInboundArgs,
227237
) -> Result<()> {
228238
let inbox_item = release_inbox_item(&mut ctx.accounts.common.inbox_item, args.revert_on_delay)?;
239+
if inbox_item.is_none() {
240+
return Ok(());
241+
}
242+
let inbox_item = inbox_item.unwrap();
243+
assert!(inbox_item.release_status == ReleaseStatus::Released);
229244

230245
onchain::invoke_transfer_checked(
231246
&ctx.accounts.common.token_program.key(),
@@ -243,14 +258,15 @@ pub fn release_inbound_unlock<'info>(
243258
)?;
244259
Ok(())
245260
}
246-
247-
fn release_inbox_item(inbox_item: &mut InboxItem, revert_on_delay: bool) -> Result<&mut InboxItem> {
261+
fn release_inbox_item(
262+
inbox_item: &mut InboxItem,
263+
revert_on_delay: bool,
264+
) -> Result<Option<&mut InboxItem>> {
248265
if inbox_item.try_release()? {
249-
assert!(inbox_item.release_status == ReleaseStatus::Released);
250-
Ok(inbox_item)
266+
Ok(Some(inbox_item))
251267
} else if revert_on_delay {
252268
Err(NTTError::CantReleaseYet.into())
253269
} else {
254-
Ok(inbox_item)
270+
Ok(None)
255271
}
256272
}

0 commit comments

Comments
 (0)