Skip to content

Commit

Permalink
Jxiao/fix log truncation (#121)
Browse files Browse the repository at this point in the history
* Initial implementation of log truncation fix

* Add new files

* refactor bubblegum pda

* amend me

* update basic ts sdk

* better bgum convenience

* addProof modifies instructions to add proof fluently

* better bg init

* fix rebase issues

* fix sugar shack tests

* use convenience initializer

* revert maxSeq change, update smokeTest

Co-authored-by: Noah Gundotra <[email protected]>
  • Loading branch information
jarry-xiao and Noah Gundotra authored Jun 30, 2022
1 parent 409aae7 commit 2ee6d5a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
28 changes: 25 additions & 3 deletions contracts/programs/bubblegum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ use {
NewNFTEvent,
NFTDecompressionEvent,
},
gummyroll::{program::Gummyroll, Node},
gummyroll::{
program::Gummyroll,
Node,
state::CandyWrapper,
utils::wrap_event,
},
crate::error::BubblegumError,
crate::utils::{append_leaf,
replace_leaf,
Expand Down Expand Up @@ -54,6 +59,7 @@ pub struct CreateTree<'info> {
#[account(mut)]
pub payer: Signer<'info>,
pub tree_creator: Signer<'info>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub system_program: Program<'info, System>,
pub gummyroll_program: Program<'info, Gummyroll>,
#[account(zero)]
Expand All @@ -72,6 +78,7 @@ pub struct MintV1<'info> {
/// CHECK: This account is neither written to nor read from.
#[account(mut)]
pub authority: Account<'info, Nonce>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub gummyroll_program: Program<'info, Gummyroll>,
/// CHECK: This account is neither written to nor read from.
pub owner: AccountInfo<'info>,
Expand All @@ -90,6 +97,7 @@ pub struct Burn<'info> {
)]
/// CHECK: This account is neither written to nor read from.
pub authority: Account<'info, Nonce>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub gummyroll_program: Program<'info, Gummyroll>,
/// CHECK: This account is checked in the instruction
pub owner: UncheckedAccount<'info>,
Expand All @@ -114,6 +122,7 @@ pub struct Transfer<'info> {
pub delegate: UncheckedAccount<'info>,
/// CHECK: This account is neither written to nor read from.
pub new_owner: UncheckedAccount<'info>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub gummyroll_program: Program<'info, Gummyroll>,
#[account(mut)]
/// CHECK: This account is modified in the downstream program
Expand All @@ -133,6 +142,7 @@ pub struct Delegate<'info> {
pub previous_delegate: UncheckedAccount<'info>,
/// CHECK: This account is neither written to nor read from.
pub new_delegate: UncheckedAccount<'info>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub gummyroll_program: Program<'info, Gummyroll>,
#[account(mut)]
/// CHECK: This account is modified in the downstream program
Expand All @@ -154,6 +164,7 @@ pub struct Redeem<'info> {
)]
/// CHECK: This account is neither written to nor read from.
pub authority: Account<'info, Nonce>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub gummyroll_program: Program<'info, Gummyroll>,
#[account(mut)]
pub owner: Signer<'info>,
Expand Down Expand Up @@ -185,6 +196,7 @@ pub struct CancelRedeem<'info> {
)]
/// CHECK: This account is neither written to nor read from.
pub authority: Account<'info, Nonce>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub gummyroll_program: Program<'info, Gummyroll>,
#[account(mut)]
/// CHECK: unsafe
Expand Down Expand Up @@ -286,6 +298,7 @@ pub struct Compress<'info> {
pub token_metadata_program: UncheckedAccount<'info>,
/// CHECK:
pub token_program: UncheckedAccount<'info>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub gummyroll_program: Program<'info, Gummyroll>,
}

Expand Down Expand Up @@ -343,6 +356,7 @@ pub mod bubblegum {
authority: ctx.accounts.authority.to_account_info(),
append_authority: ctx.accounts.tree_creator.to_account_info(),
merkle_roll: merkle_slab,
candy_wrapper: ctx.accounts.candy_wrapper.to_account_info(),
},
authority_pda_signer,
);
Expand Down Expand Up @@ -380,11 +394,13 @@ pub mod bubblegum {
data_hash.to_bytes(),
creator_hash.to_bytes(),
);
emit!(NewNFTEvent {
let new_nft = NewNFTEvent {
version: Version::V1,
metadata: message,
nonce: nonce.count
});
};
emit!(new_nft);
wrap_event(new_nft.try_to_vec()?, &ctx.accounts.candy_wrapper)?;
emit!(leaf.to_event());
nonce.count = nonce.count.saturating_add(1);
append_leaf(
Expand All @@ -394,6 +410,7 @@ pub mod bubblegum {
&ctx.accounts.authority.to_account_info(),
&ctx.accounts.mint_authority.to_account_info(),
&ctx.accounts.merkle_slab.to_account_info(),
&ctx.accounts.candy_wrapper.to_account_info(),
leaf.to_node(),
)
}
Expand Down Expand Up @@ -438,6 +455,7 @@ pub mod bubblegum {
&ctx.accounts.gummyroll_program.to_account_info(),
&ctx.accounts.authority.to_account_info(),
&ctx.accounts.merkle_slab.to_account_info(),
&ctx.accounts.candy_wrapper.to_account_info(),
ctx.remaining_accounts,
root,
previous_leaf.to_node(),
Expand Down Expand Up @@ -476,6 +494,7 @@ pub mod bubblegum {
&ctx.accounts.gummyroll_program.to_account_info(),
&ctx.accounts.authority.to_account_info(),
&ctx.accounts.merkle_slab.to_account_info(),
&ctx.accounts.candy_wrapper.to_account_info(),
ctx.remaining_accounts,
root,
previous_leaf.to_node(),
Expand Down Expand Up @@ -513,6 +532,7 @@ pub mod bubblegum {
&ctx.accounts.gummyroll_program.to_account_info(),
&ctx.accounts.authority.to_account_info(),
&ctx.accounts.merkle_slab.to_account_info(),
&ctx.accounts.candy_wrapper.to_account_info(),
ctx.remaining_accounts,
root,
previous_leaf.to_node(),
Expand Down Expand Up @@ -543,6 +563,7 @@ pub mod bubblegum {
&ctx.accounts.gummyroll_program.to_account_info(),
&ctx.accounts.authority.to_account_info(),
&ctx.accounts.merkle_slab.to_account_info(),
&ctx.accounts.candy_wrapper.to_account_info(),
ctx.remaining_accounts,
root,
previous_leaf.to_node(),
Expand Down Expand Up @@ -576,6 +597,7 @@ pub mod bubblegum {
&ctx.accounts.gummyroll_program.to_account_info(),
&ctx.accounts.authority.to_account_info(),
&ctx.accounts.merkle_slab.to_account_info(),
&ctx.accounts.candy_wrapper.to_account_info(),
ctx.remaining_accounts,
root,
[0; 32],
Expand Down
4 changes: 4 additions & 0 deletions contracts/programs/bubblegum/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn replace_leaf<'info>(
gummyroll_program: &AccountInfo<'info>,
authority: &AccountInfo<'info>,
merkle_roll: &AccountInfo<'info>,
candy_wrapper: &AccountInfo<'info>,
remaining_accounts: &[AccountInfo<'info>],
root_node: Node,
previous_leaf: Node,
Expand All @@ -28,6 +29,7 @@ pub fn replace_leaf<'info>(
gummyroll::cpi::accounts::Modify {
authority: authority.clone(),
merkle_roll: merkle_roll.clone(),
candy_wrapper: candy_wrapper.clone(),
},
authority_pda_signer,
)
Expand All @@ -42,6 +44,7 @@ pub fn append_leaf<'info>(
authority: &AccountInfo<'info>,
append_authority: &AccountInfo<'info>,
merkle_roll: &AccountInfo<'info>,
candy_wrapper: &AccountInfo<'info>,
leaf_node: Node,
) -> Result<()> {
let seeds = &[seed.as_ref(), &[bump]];
Expand All @@ -52,6 +55,7 @@ pub fn append_leaf<'info>(
authority: authority.clone(),
append_authority: append_authority.clone(),
merkle_roll: merkle_roll.clone(),
candy_wrapper: candy_wrapper.clone(),
},
authority_pda_signer,
);
Expand Down

0 comments on commit 2ee6d5a

Please sign in to comment.