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 101 102 103 104 105 | 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 1x 1x 1x 1x 1x 1x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x | import {
AccountUpdate,
Bool,
method,
PublicKey,
SmartContract,
state,
State,
Permissions,
DeployArgs,
} from "o1js";
import { NFTCollectionContractConstructor } from "./collection.js";
import { NFTState } from "./types.js";
export {
NFTUpdateBase,
NFTUpdateContractConstructor,
NFTStandardUpdate,
NFTUpdateDeployProps,
DefineUpdateFactory,
};
type DefineUpdateFactory = (params: {
collectionContract: () => NFTCollectionContractConstructor;
}) => NFTUpdateContractConstructor;
/**
* The `NFTUpdateBase` interface defines the update functionalities required for managing an NFT update
*/
type NFTUpdateBase = SmartContract & {
/**
* Checks if an NFT can be updated from its current state (`input`) to a new state (`output`).
*
* @param collectionAddress - The public key of the NFT collection address.
* @param nftAddress - The public key of the NFT.
* @param input - The current state of the NFT.
* @param output - The desired new state of the NFT.
* @returns A `Promise` resolving to a `Bool` indicating whether the update is permitted.
*/
canUpdate(
collectionAddress: PublicKey,
nftAddress: PublicKey,
input: NFTState,
output: NFTState
): Promise<Bool>;
};
/**
* Defines a constructor for contracts implementing `NFTUpdateBase`, accepting an `address` public key and returning an instance of `NFTUpdateBase`.
*
* @param address - The public key of the contract's owner.
* @returns An instance of `NFTUpdateBase`.
*/
type NFTUpdateContractConstructor = new (address: PublicKey) => NFTUpdateBase;
interface NFTUpdateDeployProps extends Exclude<DeployArgs, undefined> {
admin: PublicKey;
uri: string;
}
/**
* The **NFTStandardUpdate** contract is the default implementation of the `NFTUpdateBase` interface.
*/
class NFTStandardUpdate extends SmartContract implements NFTUpdateBase {
/**
* The public key of the contract's administrator.
*/
@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: NFTUpdateDeployProps) {
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;
}
@method.returns(Bool)
async canUpdate(
collectionAddress: PublicKey,
nftAddress: PublicKey,
input: NFTState,
output: NFTState
): Promise<Bool> {
await this.ensureOwnerSignature();
return Bool(true);
}
}
|