Skip to content

Commit

Permalink
Fixing borrow issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Sep 10, 2024
1 parent a893b18 commit 2473b25
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 16 deletions.
3 changes: 1 addition & 2 deletions auction-house/program/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@ pub fn pay_creator_fees<'a>(
is_native: bool,
) -> Result<u64> {
let data = &metadata_info.data.borrow_mut();
if metadata_info.data_is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8
{
if data.is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
return Err(AuctionHouseError::MetadataDoesntExist.into());
}
let metadata = Metadata::deserialize(&mut data.as_ref())?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ pub fn handle_remove_collection(ctx: Context<RemoveCollection>) -> Result<()> {
candy_machine.assert_not_minted(error!(CandyError::NoChangingCollectionDuringMint))?;

let data = &ctx.accounts.metadata.data.borrow_mut();
if ctx.accounts.metadata.data_is_empty()
|| data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8
{
if data.is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
return Err(CandyError::InvalidMetadataAccount.into());
}
let metadata = Metadata::deserialize(&mut data.as_ref())?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ pub struct SetCollection<'info> {
pub fn handle_set_collection(ctx: Context<SetCollection>) -> Result<()> {
let mint = ctx.accounts.mint.to_account_info();
let data = &ctx.accounts.metadata.data.borrow_mut();
if ctx.accounts.metadata.data_is_empty()
|| data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8
{
if data.is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
return Err(CandyError::InvalidMetadataAccount.into());
}
let metadata = Metadata::deserialize(&mut data.as_ref())?;
Expand Down
2 changes: 1 addition & 1 deletion fixed-price-sale/program/src/processor/buy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl<'info> Buy<'info> {
)?;

let data = &metadata.data.borrow_mut();
if metadata.data_is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
if data.is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
return Err(ErrorCode::InvalidMetadataAccount.into());
}
let metadata_data = Metadata::deserialize(&mut data.as_ref())?;
Expand Down
2 changes: 1 addition & 1 deletion fixed-price-sale/program/src/processor/claim_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'info> ClaimResource<'info> {

// Update primary sale flag
let data = &metadata.data.borrow_mut();
if metadata.data_is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
if data.is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
return Err(ErrorCode::InvalidMetadataAccount.into());
}
let metadata_state = mpl_token_metadata::state::Metadata::deserialize(&mut data.as_ref())?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'info> InitSellingResource<'info> {
)?;

let data = &metadata.data.borrow_mut();
if metadata.data_is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
if data.is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
return Err(ErrorCode::InvalidMetadataAccount.into());
}
let metadata = mpl_token_metadata::state::Metadata::deserialize(&mut data.as_ref())?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl<'info> SavePrimaryMetadataCreators<'info> {
let admin = &self.admin;
let secondary_metadata_creators = &mut self.primary_metadata_creators;
let data = &metadata.data.borrow_mut();
if metadata.data_is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
if data.is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
return Err(ErrorCode::InvalidMetadataAccount.into());
}
let metadata_state = mpl_token_metadata::state::Metadata::deserialize(&mut data.as_ref())?;
Expand Down
2 changes: 1 addition & 1 deletion fixed-price-sale/program/src/processor/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<'info> Withdraw<'info> {

// Obtain right creators according to sale type
let data = &metadata.data.borrow_mut();
if metadata.data_is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
if data.is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
return Err(ErrorCode::InvalidMetadataAccount.into());
}
let metadata = mpl_token_metadata::state::Metadata::deserialize(&mut data.as_ref())?;
Expand Down
4 changes: 1 addition & 3 deletions hydra/program/src/utils/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ pub fn assert_valid_metadata(
mint: &AccountInfo,
) -> Result<Metadata> {
let data = &metadata_account.data.borrow_mut();
if metadata_account.data_is_empty()
|| data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8
{
if data.is_empty() || data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {
return Err(HydraError::InvalidMetadata.into());
}
let meta = mpl_token_metadata::state::Metadata::deserialize(&mut data.as_ref())?;
Expand Down
46 changes: 46 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

function exists_in_list() {
LIST=$1
DELIMITER=$2
VALUE=$3
echo $LIST | tr "$DELIMITER" '\n' | grep -F -q -x "$VALUE"
}

input=$1

programs="auction-house auctioneer candy-machine fixed-price-sale gumdrop hydra token-entangler"

mkdir -p test-programs

if exists_in_list "$programs" " " $input; then
echo "testing $input"
cd $input/program
cargo test-bpf --bpf-out-dir ../../test-programs/
cd ../../

elif [[ $input = "all" ]]
then
echo "testing all programs"
for program in ${programs}; do
echo "testing $program"
cd $program/program
cargo test-bpf --bpf-out-dir ../../test-programs/
cd ../../
done
#echo "building testing-utils"
#cd core/rust/testing-utils
#cargo build-bpf --bpf-out-dir ../../../test-programs/
#cd ../../../
elif [[ $input = "token-auth-rules" ]]
then
solana program dump -u https://api.mainnet-beta.solana.com auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg ./test-programs/mpl_token_auth_rules.so
elif [[ $input = "rooster" ]]
then
solana program dump -u https://api.mainnet-beta.solana.com Roostrnex2Z9Y2XZC49sFAdZARP8E4iFpEnZC5QJWdz ./test-programs/rooster.so
else
echo "Invalid program name: $input"
exit 1
fi


0 comments on commit 2473b25

Please sign in to comment.