@aztec/kv-store 4.0.0-nightly.20260111 → 4.0.0-nightly.20260113
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,15 +1,29 @@
|
|
|
1
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import
|
|
1
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { type L2BlockTag, L2TipsStoreBase } from '@aztec/stdlib/block';
|
|
3
|
+
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
3
4
|
import type { AztecAsyncKVStore } from '../interfaces/store.js';
|
|
4
|
-
/**
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Persistent implementation of L2 tips store backed by a KV store.
|
|
7
|
+
* Used by nodes that need to persist chain state across restarts.
|
|
8
|
+
*/
|
|
9
|
+
export declare class L2TipsKVStore extends L2TipsStoreBase {
|
|
10
|
+
private store;
|
|
6
11
|
private readonly l2TipsStore;
|
|
7
12
|
private readonly l2BlockHashesStore;
|
|
13
|
+
private readonly l2BlockNumberToCheckpointNumberStore;
|
|
14
|
+
private readonly l2CheckpointStore;
|
|
8
15
|
constructor(store: AztecAsyncKVStore, namespace: string);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
protected getTip(tag: L2BlockTag): Promise<BlockNumber | undefined>;
|
|
17
|
+
protected setTip(tag: L2BlockTag, blockNumber: BlockNumber): Promise<void>;
|
|
18
|
+
protected getStoredBlockHash(blockNumber: BlockNumber): Promise<string | undefined>;
|
|
19
|
+
protected setBlockHash(blockNumber: BlockNumber, hash: string): Promise<void>;
|
|
20
|
+
protected deleteBlockHashesBefore(blockNumber: BlockNumber): Promise<void>;
|
|
21
|
+
protected getCheckpointNumberForBlock(blockNumber: BlockNumber): Promise<CheckpointNumber | undefined>;
|
|
22
|
+
protected setCheckpointNumberForBlock(blockNumber: BlockNumber, checkpointNumber: CheckpointNumber): Promise<void>;
|
|
23
|
+
protected deleteBlockToCheckpointBefore(blockNumber: BlockNumber): Promise<void>;
|
|
24
|
+
protected getCheckpoint(checkpointNumber: CheckpointNumber): Promise<PublishedCheckpoint | undefined>;
|
|
25
|
+
protected saveCheckpointData(checkpoint: PublishedCheckpoint): Promise<void>;
|
|
26
|
+
protected deleteCheckpointsBefore(checkpointNumber: CheckpointNumber): Promise<void>;
|
|
27
|
+
protected runInTransaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
14
28
|
}
|
|
15
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
29
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDJfdGlwc19zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N0b3Jlcy9sMl90aXBzX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxXQUFXLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNoRixPQUFPLEVBQUUsS0FBSyxVQUFVLEVBQUUsZUFBZSxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDdkUsT0FBTyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFHL0QsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUVoRTs7O0dBR0c7QUFDSCxxQkFBYSxhQUFjLFNBQVEsZUFBZTtJQU85QyxPQUFPLENBQUMsS0FBSztJQU5mLE9BQU8sQ0FBQyxRQUFRLENBQUMsV0FBVyxDQUF5QztJQUNyRSxPQUFPLENBQUMsUUFBUSxDQUFDLGtCQUFrQixDQUFxQztJQUN4RSxPQUFPLENBQUMsUUFBUSxDQUFDLG9DQUFvQyxDQUErQztJQUNwRyxPQ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BQUUsZ0JBQWdCLEdBQUcsT0FBTyxDQUFDLG1CQUFtQixHQUFHLFNBQVMsQ0FBQyxDQU0xRztJQUVELFNBQVMsQ0FBQyxrQkFBa0IsQ0FBQyxVQUFVLEVBQUUsbUJBQW1CLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUUzRTtJQUVELFVBQWdCLHVCQUF1QixDQUFDLGdCQUFnQixFQUFFLGdCQUFnQixHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FJekY7SUFFRCxTQUFTLENBQUMsZ0JBQWdCLENBQUMsQ0FBQyxFQUFFLEVBQUUsRUFBRSxNQUFNLE9BQU8sQ0FBQyxDQUFDLENBQUMsR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLENBRTlEO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"l2_tips_store.d.ts","sourceRoot":"","sources":["../../src/stores/l2_tips_store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"l2_tips_store.d.ts","sourceRoot":"","sources":["../../src/stores/l2_tips_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,KAAK,UAAU,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;GAGG;AACH,qBAAa,aAAc,SAAQ,eAAe;IAO9C,OAAO,CAAC,KAAK;IANf,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAyC;IACrE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAqC;IACxE,OAAO,CAAC,QAAQ,CAAC,oCAAoC,CAA+C;IACpG,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA0C;IAE5E,YACU,KAAK,EAAE,iB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
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
/**
|
|
1
|
+
import { L2TipsStoreBase } from '@aztec/stdlib/block';
|
|
2
|
+
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
3
|
+
/**
|
|
4
|
+
* Persistent implementation of L2 tips store backed by a KV store.
|
|
5
|
+
* Used by nodes that need to persist chain state across restarts.
|
|
6
|
+
*/ export class L2TipsKVStore extends L2TipsStoreBase {
|
|
7
|
+
store;
|
|
4
8
|
l2TipsStore;
|
|
5
9
|
l2BlockHashesStore;
|
|
10
|
+
l2BlockNumberToCheckpointNumberStore;
|
|
11
|
+
l2CheckpointStore;
|
|
6
12
|
constructor(store, namespace){
|
|
13
|
+
super(), this.store = store;
|
|
7
14
|
this.l2TipsStore = store.openMap([
|
|
8
15
|
namespace,
|
|
9
16
|
'l2_tips'
|
|
@@ -12,65 +19,65 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
|
12
19
|
namespace,
|
|
13
20
|
'l2_block_hashes'
|
|
14
21
|
].join('_'));
|
|
22
|
+
this.l2BlockNumberToCheckpointNumberStore = store.openMap([
|
|
23
|
+
namespace,
|
|
24
|
+
'l2_block_number_to_checkpoint_number'
|
|
25
|
+
].join('_'));
|
|
26
|
+
this.l2CheckpointStore = store.openMap([
|
|
27
|
+
namespace,
|
|
28
|
+
'l2_checkpoint_store'
|
|
29
|
+
].join('_'));
|
|
30
|
+
}
|
|
31
|
+
getTip(tag) {
|
|
32
|
+
return this.l2TipsStore.getAsync(tag);
|
|
33
|
+
}
|
|
34
|
+
setTip(tag, blockNumber) {
|
|
35
|
+
return this.l2TipsStore.set(tag, blockNumber);
|
|
15
36
|
}
|
|
16
|
-
|
|
17
|
-
return this.l2BlockHashesStore.getAsync(
|
|
37
|
+
getStoredBlockHash(blockNumber) {
|
|
38
|
+
return this.l2BlockHashesStore.getAsync(blockNumber);
|
|
18
39
|
}
|
|
19
|
-
|
|
20
|
-
return
|
|
21
|
-
latest: await this.getL2Tip('latest'),
|
|
22
|
-
finalized: await this.getL2Tip('finalized'),
|
|
23
|
-
proven: await this.getL2Tip('proven')
|
|
24
|
-
};
|
|
40
|
+
setBlockHash(blockNumber, hash) {
|
|
41
|
+
return this.l2BlockHashesStore.set(blockNumber, hash);
|
|
25
42
|
}
|
|
26
|
-
async
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
hash: GENESIS_BLOCK_HEADER_HASH.toString()
|
|
32
|
-
};
|
|
43
|
+
async deleteBlockHashesBefore(blockNumber) {
|
|
44
|
+
for await (const key of this.l2BlockHashesStore.keysAsync({
|
|
45
|
+
end: blockNumber
|
|
46
|
+
})){
|
|
47
|
+
await this.l2BlockHashesStore.delete(key);
|
|
33
48
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
}
|
|
50
|
+
getCheckpointNumberForBlock(blockNumber) {
|
|
51
|
+
return this.l2BlockNumberToCheckpointNumberStore.getAsync(blockNumber);
|
|
52
|
+
}
|
|
53
|
+
setCheckpointNumberForBlock(blockNumber, checkpointNumber) {
|
|
54
|
+
return this.l2BlockNumberToCheckpointNumberStore.set(blockNumber, checkpointNumber);
|
|
55
|
+
}
|
|
56
|
+
async deleteBlockToCheckpointBefore(blockNumber) {
|
|
57
|
+
for await (const key of this.l2BlockNumberToCheckpointNumberStore.keysAsync({
|
|
58
|
+
end: blockNumber
|
|
59
|
+
})){
|
|
60
|
+
await this.l2BlockNumberToCheckpointNumberStore.delete(key);
|
|
37
61
|
}
|
|
38
|
-
return {
|
|
39
|
-
number: blockNumber,
|
|
40
|
-
hash: blockHash
|
|
41
|
-
};
|
|
42
62
|
}
|
|
43
|
-
async
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const blocks = event.blocks.map((b)=>b.block);
|
|
48
|
-
for (const block of blocks){
|
|
49
|
-
await this.l2BlockHashesStore.set(block.number, (await block.hash()).toString());
|
|
50
|
-
}
|
|
51
|
-
await this.l2TipsStore.set('latest', blocks.at(-1).number);
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
case 'chain-pruned':
|
|
55
|
-
await this.saveTag('latest', event.block);
|
|
56
|
-
break;
|
|
57
|
-
case 'chain-proven':
|
|
58
|
-
await this.saveTag('proven', event.block);
|
|
59
|
-
break;
|
|
60
|
-
case 'chain-finalized':
|
|
61
|
-
await this.saveTag('finalized', event.block);
|
|
62
|
-
for await (const key of this.l2BlockHashesStore.keysAsync({
|
|
63
|
-
end: event.block.number
|
|
64
|
-
})){
|
|
65
|
-
await this.l2BlockHashesStore.delete(key);
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
63
|
+
async getCheckpoint(checkpointNumber) {
|
|
64
|
+
const buffer = await this.l2CheckpointStore.getAsync(checkpointNumber);
|
|
65
|
+
if (!buffer) {
|
|
66
|
+
return undefined;
|
|
68
67
|
}
|
|
68
|
+
return PublishedCheckpoint.fromBuffer(buffer);
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
saveCheckpointData(checkpoint) {
|
|
71
|
+
return this.l2CheckpointStore.set(checkpoint.checkpoint.number, checkpoint.toBuffer());
|
|
72
|
+
}
|
|
73
|
+
async deleteCheckpointsBefore(checkpointNumber) {
|
|
74
|
+
for await (const key of this.l2CheckpointStore.keysAsync({
|
|
75
|
+
end: checkpointNumber
|
|
76
|
+
})){
|
|
77
|
+
await this.l2CheckpointStore.delete(key);
|
|
74
78
|
}
|
|
75
79
|
}
|
|
80
|
+
runInTransaction(fn) {
|
|
81
|
+
return this.store.transactionAsync(fn);
|
|
82
|
+
}
|
|
76
83
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/kv-store",
|
|
3
|
-
"version": "4.0.0-nightly.
|
|
3
|
+
"version": "4.0.0-nightly.20260113",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/interfaces/index.js",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"./package.local.json"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aztec/constants": "4.0.0-nightly.
|
|
29
|
-
"@aztec/ethereum": "4.0.0-nightly.
|
|
30
|
-
"@aztec/foundation": "4.0.0-nightly.
|
|
31
|
-
"@aztec/native": "4.0.0-nightly.
|
|
32
|
-
"@aztec/stdlib": "4.0.0-nightly.
|
|
28
|
+
"@aztec/constants": "4.0.0-nightly.20260113",
|
|
29
|
+
"@aztec/ethereum": "4.0.0-nightly.20260113",
|
|
30
|
+
"@aztec/foundation": "4.0.0-nightly.20260113",
|
|
31
|
+
"@aztec/native": "4.0.0-nightly.20260113",
|
|
32
|
+
"@aztec/stdlib": "4.0.0-nightly.20260113",
|
|
33
33
|
"idb": "^8.0.0",
|
|
34
34
|
"lmdb": "^3.2.0",
|
|
35
35
|
"msgpackr": "^1.11.2",
|
|
@@ -1,81 +1,88 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
L2BlockId,
|
|
5
|
-
L2BlockStreamEvent,
|
|
6
|
-
L2BlockStreamEventHandler,
|
|
7
|
-
L2BlockStreamLocalDataProvider,
|
|
8
|
-
L2BlockTag,
|
|
9
|
-
L2Tips,
|
|
10
|
-
} from '@aztec/stdlib/block';
|
|
1
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { type L2BlockTag, L2TipsStoreBase } from '@aztec/stdlib/block';
|
|
3
|
+
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
11
4
|
|
|
12
5
|
import type { AztecAsyncMap } from '../interfaces/map.js';
|
|
13
6
|
import type { AztecAsyncKVStore } from '../interfaces/store.js';
|
|
14
7
|
|
|
15
|
-
/**
|
|
16
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Persistent implementation of L2 tips store backed by a KV store.
|
|
10
|
+
* Used by nodes that need to persist chain state across restarts.
|
|
11
|
+
*/
|
|
12
|
+
export class L2TipsKVStore extends L2TipsStoreBase {
|
|
17
13
|
private readonly l2TipsStore: AztecAsyncMap<L2BlockTag, BlockNumber>;
|
|
18
14
|
private readonly l2BlockHashesStore: AztecAsyncMap<BlockNumber, string>;
|
|
15
|
+
private readonly l2BlockNumberToCheckpointNumberStore: AztecAsyncMap<BlockNumber, CheckpointNumber>;
|
|
16
|
+
private readonly l2CheckpointStore: AztecAsyncMap<CheckpointNumber, Buffer>;
|
|
19
17
|
|
|
20
|
-
constructor(
|
|
18
|
+
constructor(
|
|
19
|
+
private store: AztecAsyncKVStore,
|
|
20
|
+
namespace: string,
|
|
21
|
+
) {
|
|
22
|
+
super();
|
|
21
23
|
this.l2TipsStore = store.openMap([namespace, 'l2_tips'].join('_'));
|
|
22
24
|
this.l2BlockHashesStore = store.openMap([namespace, 'l2_block_hashes'].join('_'));
|
|
25
|
+
this.l2BlockNumberToCheckpointNumberStore = store.openMap(
|
|
26
|
+
[namespace, 'l2_block_number_to_checkpoint_number'].join('_'),
|
|
27
|
+
);
|
|
28
|
+
this.l2CheckpointStore = store.openMap([namespace, 'l2_checkpoint_store'].join('_'));
|
|
23
29
|
}
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
return this.
|
|
31
|
+
protected getTip(tag: L2BlockTag): Promise<BlockNumber | undefined> {
|
|
32
|
+
return this.l2TipsStore.getAsync(tag);
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
return
|
|
31
|
-
latest: await this.getL2Tip('latest'),
|
|
32
|
-
finalized: await this.getL2Tip('finalized'),
|
|
33
|
-
proven: await this.getL2Tip('proven'),
|
|
34
|
-
};
|
|
35
|
+
protected setTip(tag: L2BlockTag, blockNumber: BlockNumber): Promise<void> {
|
|
36
|
+
return this.l2TipsStore.set(tag, blockNumber);
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
protected getStoredBlockHash(blockNumber: BlockNumber): Promise<string | undefined> {
|
|
40
|
+
return this.l2BlockHashesStore.getAsync(blockNumber);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
protected setBlockHash(blockNumber: BlockNumber, hash: string): Promise<void> {
|
|
44
|
+
return this.l2BlockHashesStore.set(blockNumber, hash);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected async deleteBlockHashesBefore(blockNumber: BlockNumber): Promise<void> {
|
|
48
|
+
for await (const key of this.l2BlockHashesStore.keysAsync({ end: blockNumber })) {
|
|
49
|
+
await this.l2BlockHashesStore.delete(key);
|
|
45
50
|
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected getCheckpointNumberForBlock(blockNumber: BlockNumber): Promise<CheckpointNumber | undefined> {
|
|
54
|
+
return this.l2BlockNumberToCheckpointNumberStore.getAsync(blockNumber);
|
|
55
|
+
}
|
|
46
56
|
|
|
47
|
-
|
|
57
|
+
protected setCheckpointNumberForBlock(blockNumber: BlockNumber, checkpointNumber: CheckpointNumber): Promise<void> {
|
|
58
|
+
return this.l2BlockNumberToCheckpointNumberStore.set(blockNumber, checkpointNumber);
|
|
48
59
|
}
|
|
49
60
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const blocks = event.blocks.map(b => b.block);
|
|
54
|
-
for (const block of blocks) {
|
|
55
|
-
await this.l2BlockHashesStore.set(block.number, (await block.hash()).toString());
|
|
56
|
-
}
|
|
57
|
-
await this.l2TipsStore.set('latest', blocks.at(-1)!.number);
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
case 'chain-pruned':
|
|
61
|
-
await this.saveTag('latest', event.block);
|
|
62
|
-
break;
|
|
63
|
-
case 'chain-proven':
|
|
64
|
-
await this.saveTag('proven', event.block);
|
|
65
|
-
break;
|
|
66
|
-
case 'chain-finalized':
|
|
67
|
-
await this.saveTag('finalized', event.block);
|
|
68
|
-
for await (const key of this.l2BlockHashesStore.keysAsync({ end: event.block.number })) {
|
|
69
|
-
await this.l2BlockHashesStore.delete(key);
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
61
|
+
protected async deleteBlockToCheckpointBefore(blockNumber: BlockNumber): Promise<void> {
|
|
62
|
+
for await (const key of this.l2BlockNumberToCheckpointNumberStore.keysAsync({ end: blockNumber })) {
|
|
63
|
+
await this.l2BlockNumberToCheckpointNumberStore.delete(key);
|
|
72
64
|
}
|
|
73
65
|
}
|
|
74
66
|
|
|
75
|
-
|
|
76
|
-
await this.
|
|
77
|
-
if (
|
|
78
|
-
|
|
67
|
+
protected async getCheckpoint(checkpointNumber: CheckpointNumber): Promise<PublishedCheckpoint | undefined> {
|
|
68
|
+
const buffer = await this.l2CheckpointStore.getAsync(checkpointNumber);
|
|
69
|
+
if (!buffer) {
|
|
70
|
+
return undefined;
|
|
79
71
|
}
|
|
72
|
+
return PublishedCheckpoint.fromBuffer(buffer);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
protected saveCheckpointData(checkpoint: PublishedCheckpoint): Promise<void> {
|
|
76
|
+
return this.l2CheckpointStore.set(checkpoint.checkpoint.number, checkpoint.toBuffer());
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
protected async deleteCheckpointsBefore(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
80
|
+
for await (const key of this.l2CheckpointStore.keysAsync({ end: checkpointNumber })) {
|
|
81
|
+
await this.l2CheckpointStore.delete(key);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
protected runInTransaction<T>(fn: () => Promise<T>): Promise<T> {
|
|
86
|
+
return this.store.transactionAsync(fn);
|
|
80
87
|
}
|
|
81
88
|
}
|