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

Add NFT owner to API Server response #1858

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

OBorce
Copy link
Contributor

@OBorce OBorce commented Dec 24, 2024

  • Truck NFT owner changes in API Server
  • Add NFT owner to nft endpoint response

@OBorce OBorce force-pushed the feature/api-server-nft-owner branch from 93d2e5e to 8619f18 Compare December 24, 2024 14:59
@OBorce OBorce force-pushed the feature/api-server-nft-owner branch from 8619f18 to d42c687 Compare December 26, 2024 08:55
Comment on lines +836 to +845
if let Some(by_height) = self.nft_token_issuances.get_mut(&token_id) {
let last = by_height.values().last().expect("not empty");
let owner = (amount > Amount::ZERO).then_some(address.as_object().clone());
let new = NftWithOwner {
nft: last.nft.clone(),
owner,
};
by_height.insert(block_height, new);
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Let's add an assertion that the amount is either 0 or 1?
  2. You probably shouldn't update the map if the amount is zero. Currently this only works because update_tables_from_transaction_inputs is called before update_tables_from_transaction_outputs (as I can see), IMO it's not good for this function to depend on this.
  3. In update_tables_from_transaction_outputs, in the TxOutput::IssueNft case, set_nft_token_issuance is called after increase_address_amount. How is it supposed to work?

Copy link
Contributor Author

@OBorce OBorce Jan 6, 2025

Choose a reason for hiding this comment

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

  1. we are updating in both input (decrease_amount, i.e. amount 0 case) and output (increase_amount) as a nft utxo can be used as an input but not transferred anywhere or burned, in that case we set the owner to None.
  2. as the NFT id will not be in the database the update owner will do nothing. If the order is for some reason reversed the on conflict will just update the owner to the same owner.

Copy link
Contributor

Choose a reason for hiding this comment

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

2. we are updating in both input (decrease_amount, i.e. amount 0 case) and output (increase_amount) as a nft utxo can be used as an input but not transferred anywhere or burned, in that case we set the owner to None.

I see. A comment would be nice though.

But if calls to update_tables_from_transaction_outputs and update_tables_from_transaction_inputs are swapped, things would break, right? Asking this because I've just tried swapping them and all tests passed. Probably some tests are missing?

3. as the NFT id will not be in the database the update owner will do nothing. If the order is for some reason reversed the on conflict will just update the owner to the same owner.

Yeah I missed that, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we swap updating first the outputs then the inputs it will break only in a specific case where someone sends it from the same address to the same address. in that case the last decrease will set the owner to None. Will add a test for that just in case anyone swaps the processing order in the future.

Comment on lines +267 to +280
self.update_nft_owner(token_id, height, (amount > Amount::ZERO).then_some(address))
.await?;

Ok(())
}

async fn update_nft_owner(
&mut self,
token_id: TokenId,
height: i64,
owner: Option<&Address<Destination>>,
) -> Result<(), ApiServerStorageError> {
self.tx
.execute(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments as for the other update_nft_owner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants