Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import {
AccountUpdate,
Bool,
method,
PublicKey,
SmartContract,
state,
State,
Permissions,
DeployArgs,
} from "o1js";
import { NFTCollectionContractConstructor } from "./collection.js";
import { TransferExtendedParams } from "./types.js";
export {
NFTApprovalBase,
NFTApprovalContractConstructor,
NFTStandardApproval,
NFTApprovalDeployProps,
DefineApprovalFactory,
};
type DefineApprovalFactory = (params: {
collectionContract: () => NFTCollectionContractConstructor;
}) => NFTApprovalContractConstructor;
/**
* The `NFTApprovalBase` interface defines the administrative functionalities required for managing an NFT transfer approval on the Mina Protocol.
*/
type NFTApprovalBase = SmartContract & {
/**
* Determines if an NFT can be transferred from one owner (`from`) to another (`to`) for a specific NFT contract address.
*
* @param params - The transfer details.
* @returns A `Promise` resolving to a `Bool` indicating whether the transfer is allowed.
*/
canTransfer(params: TransferExtendedParams): Promise<Bool>;
};
/**
* Defines a constructor for contracts implementing `NFTApprovalBase`, accepting an `address` public key and returning an instance of `NFTApprovalBase`.
*
* @param address - The public key of the contract's owner.
* @returns An instance of `NFTApprovalBase`.
*/
type NFTApprovalContractConstructor = new (
address: PublicKey
) => NFTApprovalBase;
interface NFTApprovalDeployProps extends Exclude<DeployArgs, undefined> {
admin: PublicKey;
uri: string;
}
/**
* The **NFTStandardApproval** contract is the default implementation of the `NFTApprovalBase` interface.
*/
class NFTStandardApproval extends SmartContract implements NFTApprovalBase {
/**
* The public key of the contract's administrator.
* This account has the authority to perform administrative actions such as pausing the contract or upgrading the verification key.
*/
@state(PublicKey) admin = State<PublicKey>();
/**
* Deploys the contract with initial settings.
* @param props - Deployment properties including admin, upgradeAuthority, uri, canPause, and isPaused.
*/
async deploy(props: NFTApprovalDeployProps) {
await super.deploy(props);
this.admin.set(props.admin);
this.account.zkappUri.set(props.uri);
this.account.permissions.set({
...Permissions.default(),
setVerificationKey: Permissions.VerificationKey.signature(),
setPermissions: Permissions.impossible(),
});
}
/**
* Ensures that the transaction is authorized by the contract owner.
* @returns A signed `AccountUpdate` from the admin.
*/
async ensureOwnerSignature(): Promise<AccountUpdate> {
const admin = this.admin.getAndRequireEquals();
const adminUpdate = AccountUpdate.createSigned(admin);
adminUpdate.body.useFullCommitment = Bool(true); // Prevent memo and fee change
return adminUpdate;
}
/**
* Determines if an NFT can be transferred.
*
* @param params - The transfer details.
* @returns A `Promise` resolving to a `Bool` indicating whether the transfer is allowed.
*/
@method.returns(Bool)
async canTransfer(params: TransferExtendedParams): Promise<Bool> {
await this.ensureOwnerSignature();
return Bool(true);
}
}
|