How to add a custom error in assertEquals?
Is there a require statement like in Solidity?
require(this.sender == owner, "CUSTOM ERROR" );
import {
Bool,
PublicKey,
State,
state,
SmartContract,
method,
AccountUpdate,
ProvablePure,
provablePure,
} from 'snarkyjs';
export { Ownable };
type IOwnable = {
transferOwnership: (newOwner: PublicKey) => void;
// events
events: {
OwnershipTransferred: ProvablePure<{
oldOwner: PublicKey;
newOwner: PublicKey;
}>;
};
};
class Ownable extends SmartContract implements IOwnable {
@state(PublicKey) owner = State<PublicKey>();
events = {
OwnershipTransferred: provablePure({
oldOwner: PublicKey,
newOwner: PublicKey,
}),
};
@method
public initialize(owner: PublicKey) {
const provedState = this.account.provedState.get();
this.account.provedState.assertEquals(provedState);
this.owner.set(owner);
}
@method onlyOwner(): Bool {
const owner = this.owner.get();
this.owner.assertEquals(owner);
const ownerAccountUpdate = AccountUpdate.create(owner);
ownerAccountUpdate.requireSignature();
return Bool(true);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
@method transferOwnership(newOwner: PublicKey) {
const owner = this.owner.get();
this.owner.assertEquals(owner);
this.sender.assertEquals(owner);
this.owner.set(newOwner);
this.emitEvent('OwnershipTransferred', {
oldOwner: owner,
newOwner: newOwner,
});
}
}