Skip to content

Commit

Permalink
Fix ISA for Restricted NFT/Account addresses (#1743)
Browse files Browse the repository at this point in the history
* Fix ISA for Restricted NFT/Account addresses

* Remove warning
  • Loading branch information
thibault-martinez committed Dec 5, 2023
1 parent a46a224 commit 677c2f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
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),
Account(
2_000_000,
account_id_1,
Expand Down

0 comments on commit 677c2f5

Please sign in to comment.