Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ISA for Restricted NFT/Account addresses #1743

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions sdk/src/client/api/block_builder/input_selection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use self::{burn::Burn, error::Error, requirement::Requirement};
use crate::{
client::{api::types::RemainderData, secret::types::InputSigningData},
types::block::{
address::{AccountAddress, Address, AnchorAddress, NftAddress},
address::{AccountAddress, Address, NftAddress},
input::INPUT_COUNT_RANGE,
output::{
AccountOutput, ChainId, FoundryOutput, NativeTokensBuilder, NftOutput, Output, OutputId, OUTPUT_COUNT_RANGE,
Expand Down Expand Up @@ -63,15 +63,16 @@ impl InputSelection {
.output
.required_and_unlocked_address(self.slot_index, input.output_id())?
.0;
let required_address = if let Address::Restricted(restricted) = &required_address {
restricted.address()
} else {
&required_address
};

match required_address {
Address::Ed25519(_) => Ok(None),
Address::Account(account_address) => Ok(Some(Requirement::Account(*account_address.account_id()))),
Address::Nft(nft_address) => Ok(Some(Requirement::Nft(*nft_address.nft_id()))),
Address::Anchor(_) => Err(Error::UnsupportedAddressType(AnchorAddress::KIND)),
Address::ImplicitAccountCreation(_) => Ok(None),
Address::Restricted(_) => Ok(None),
_ => todo!("What do we do here?"),
_ => Ok(None),
}
}

Expand Down Expand Up @@ -236,12 +237,17 @@ impl InputSelection {
// PANIC: safe to unwrap as non basic/account/foundry/nft outputs are already filtered out.
.unwrap()
.0;
let required_address = if let Address::Restricted(restricted) = &required_address {
restricted.address()
} else {
&required_address
};

match required_address {
Address::Anchor(_) => false,
Address::ImplicitAccountCreation(implicit_account_creation) => self
.addresses
.contains(&Address::from(*implicit_account_creation.ed25519_address())),
Address::Restricted(restricted) => self.addresses.contains(restricted.address()),
_ => self.addresses.contains(&required_address),
}
})
Expand Down
2 changes: 1 addition & 1 deletion sdk/tests/client/input_selection/basic_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,7 @@ fn restricted_account() {
let restricted = Address::from(RestrictedAddress::new(account_address.clone()).unwrap());

let inputs = build_inputs([
Basic(2_000_000, restricted, None, None, None, None, None, None),
Basic(3_000_000, restricted, None, None, None, None, None, None),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't working before, or why did it change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was working but without triggering the part of the code I actually wanted to test

Account(
2_000_000,
account_id_1,
Expand Down
Loading