-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-contract.ts
52 lines (42 loc) · 1.17 KB
/
test-contract.ts
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
import { Bool, Field, PublicKey, SmartContract, State, UInt64, method, provablePure, state } from "o1js";
class TestContract extends SmartContract {
@state(Bool) boolState = State<Bool>();
events = {
simpleEvent: PublicKey,
complexEvent: provablePure({
publicKey: PublicKey,
field: Field,
bool: Bool,
uint64: UInt64,
}),
};
@method init() {
super.init();
this.boolState.set(Bool(true));
}
@method update(value: Bool) {
this.boolState.set(value);
}
@method failIfFalse(value: Bool) {
value.assertEquals(true, "custom error message");
}
@method payout(amount: UInt64) {
this.send({ to: this.sender, amount });
}
@method payoutTwice(amount: UInt64) {
this.send({ to: this.sender, amount }); // Purposedly doing it twice to check if it detects them
this.send({ to: this.sender, amount });
}
@method eventEmittingMethod() {
this.emitEvent('simpleEvent', this.sender);
}
@method complexEventEmittingMethod() {
this.emitEvent('complexEvent', {
publicKey: this.sender,
field: Field.from(0),
bool: Bool(true),
uint64: UInt64.from(0),
});
}
}
export { TestContract };