@@ -20,13 +20,7 @@ export class CheckpointTrie extends BaseTrie {
20
20
* After this is called, all changes can be reverted until `commit` is called.
21
21
*/
22
22
checkpoint ( ) {
23
- const wasCheckpoint = this . isCheckpoint
24
- this . db . checkpoints . push ( { root : this . root , operations : [ ] } )
25
-
26
- // Entering checkpoint mode is not necessary for nested checkpoints
27
- if ( ! wasCheckpoint && this . isCheckpoint ) {
28
- this . _enterCpMode ( )
29
- }
23
+ this . db . checkpoint ( this . root )
30
24
}
31
25
32
26
/**
@@ -40,13 +34,7 @@ export class CheckpointTrie extends BaseTrie {
40
34
}
41
35
42
36
await this . lock . wait ( )
43
-
44
- this . db . checkpoints . pop ( )
45
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
46
- if ( ! this . isCheckpoint ) {
47
- await this . _exitCpMode ( true )
48
- }
49
-
37
+ this . db . commit ( )
50
38
this . lock . signal ( )
51
39
}
52
40
@@ -56,16 +44,13 @@ export class CheckpointTrie extends BaseTrie {
56
44
* parent checkpoint as current.
57
45
*/
58
46
async revert ( ) : Promise < void > {
47
+ if ( ! this . isCheckpoint ) {
48
+ throw new Error ( 'trying to revert when not checkpointed' )
49
+ }
50
+
59
51
await this . lock . wait ( )
60
52
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
61
- if ( this . isCheckpoint ) {
62
- const { root } = this . db . checkpoints . pop ( ) !
63
- this . root = root
64
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
65
- if ( ! this . isCheckpoint ) {
66
- await this . _exitCpMode ( false )
67
- }
68
- }
53
+ this . root = this . db . revert ( )
69
54
this . lock . signal ( )
70
55
}
71
56
@@ -81,24 +66,4 @@ export class CheckpointTrie extends BaseTrie {
81
66
}
82
67
return trie
83
68
}
84
-
85
- /**
86
- * Enter into checkpoint mode.
87
- * @private
88
- */
89
- _enterCpMode ( ) { }
90
-
91
- /**
92
- * Exit from checkpoint mode.
93
- * @private
94
- */
95
- async _exitCpMode ( commitState : boolean ) : Promise < void > {
96
- return new Promise ( ( resolve ) => {
97
- /*if (commitState) {
98
- } else {
99
- }*/
100
- commitState = ! ! commitState // Temporary dummy line for linting
101
- resolve ( )
102
- } )
103
- }
104
69
}
0 commit comments