public-awesome / cw-nfts

Examples and helpers to build NFT contracts on CosmWasm
Apache License 2.0
185 stars 181 forks source link

Add query for approval of 1 operator #107

Closed peara closed 1 year ago

peara commented 1 year ago

Fix #88. I added a new query Operator(owner, operator, include_expired) which returns an ApprovalResponse if there exists such valid operator for the given owner. Otherwise, it will return an NotFound error. This query should allow contracts such as Marketplace or GameManager check their required permission to manage users' NFTs easily.

peara commented 1 year ago

@larry0x @shanev @JakeHartnell Could you give some thought?

larry0x commented 1 year ago

I'm supportive of adding this query.

Regarding the response type, considering the other query methods have their own response types:

#[cw_serde]
pub struct ApprovalResponse {
    pub approval: Approval,
}

#[cw_serde]
pub struct ApprovalsResponse {
    pub approvals: Vec<Approval>,
}

#[cw_serde]
pub struct OperatorsResponse {
    pub operators: Vec<Approval>,
}

In order to be consistent, I think the Operator query should also have its own response type:

#[cw_serde]
pub struct OperatorResponse {
    pub approval: Approval,
}
larry0x commented 1 year ago

Off topic - I think the AllOperators query should be renamed to Operators to be consistent with the naming convention of other queries.

peara commented 1 year ago

Off topic - I think the AllOperators query should be renamed to Operators to be consistent with the naming convention of other queries.

Although, I agree with this, this is a breaking change. There are also AllNftInfo and AllTokens which should be considered as well.