You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import {
AccountUpdate,
assert,
Bool,
DeployArgs,
method,
Permissions,
Provable,
PublicKey,
SmartContract,
State,
state,
VerificationKey,
} from "o1js"
export type FungibleTokenAdminBase = SmartContract & {
canMint(accountUpdate: AccountUpdate): Promise<Bool>
canChangeAdmin(admin: PublicKey): Promise<Bool>
canPause(): Promise<Bool>
canResume(): Promise<Bool>
}
export interface FungibleTokenAdminDeployProps extends Exclude<DeployArgs, undefined> {
adminPublicKey: PublicKey
}
/** A contract that grants permissions for administrative actions on a token.
*
* We separate this out into a dedicated contract. That way, when issuing a token, a user can
* specify their own rules for administrative actions, without changing the token contract itself.
*
* The advantage is that third party applications that only use the token in a non-privileged way
* can integrate against the unchanged token contract.
*/
export class FungibleTokenAdmin extends SmartContract implements FungibleTokenAdminBase {
@state(PublicKey)
private adminPublicKey = State<PublicKey>()
async deploy(props: FungibleTokenAdminDeployProps) {
await super.deploy(props)
this.adminPublicKey.set(props.adminPublicKey)
this.account.permissions.set({
...Permissions.default(),
setVerificationKey: Permissions.VerificationKey.impossibleDuringCurrentVersion(),
setPermissions: Permissions.impossible(),
})
}
/** Update the verification key.
* Note that because we have set the permissions for setting the verification key to `impossibleDuringCurrentVersion()`, this will only be possible in case of a protocol update that requires an update.
*/
@method
async updateVerificationKey(vk: VerificationKey) {
this.account.verificationKey.set(vk)
}
private async ensureAdminSignature() {
const admin = await Provable.witnessAsync(PublicKey, async () => {
let pk = await this.adminPublicKey.fetch()
assert(pk !== undefined, "could not fetch admin public key")
return pk
})
this.adminPublicKey.requireEquals(admin)
return AccountUpdate.createSigned(admin)
}
@method.returns(Bool)
public async canMint(_accountUpdate: AccountUpdate) {
await this.ensureAdminSignature()
return Bool(true)
}
@method.returns(Bool)
public async canChangeAdmin(_admin: PublicKey) {
await this.ensureAdminSignature()
return Bool(true)
}
@method.returns(Bool)
public async canPause(): Promise<Bool> {
await this.ensureAdminSignature()
return Bool(true)
}
@method.returns(Bool)
public async canResume(): Promise<Bool> {
await this.ensureAdminSignature()
return Bool(true)
}
}
test sendToNonContractAddress: ok
test sendToContractAddress: error @@@@@@@@@
/Users/lkw/00_lkwProject/02_Project/mina-zkapp-bootcamp/local-code/mina-sz/contracts/node_modules/o1js/dist/node/bindings/compiled/_node_bindings/o1js_node.bc.cjs:6761
throw err;
^
Error: Transaction failed with errors:
- [[],[["Cancelled"]],[["Cancelled"]],[["Update_not_permitted_access"]]]
at file:///Users/lkw/00_lkwProject/02_Project/mina-zkapp-bootcamp/local-code/mina-sz/contracts/node_modules/o1js/dist/node/lib/mina/transaction.js:162:27
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async file:///Users/lkw/00_lkwProject/02_Project/mina-zkapp-bootcamp/local-code/mina-sz/contracts/build/src/issue-to-discussion/FungibleToken-local.js:71:16
Node.js v22.11.0
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
FungibleTokenAdmin.ts
:来自
https://github.com/coldstar1993/mina-sz/blob/main/contracts/src/others/learn-fungible-token/FungibleTokenAdmin.ts
FungibleToken.ts
也来自
https://github.com/coldstar1993/mina-sz/blob/main/contracts/src/others/learn-fungible-token/FungibleToken.ts
但增加了
sendToNonContractAddress()
和sendToContractAddress()
FungibleToken-local.ts
运行结果显示:
sendToNonContractAddress()
成功,sendToContractAddress()
失败,如下信息:Beta Was this translation helpful? Give feedback.
All reactions