1
1
import { DependencyFactory } from "@proto-kit/common" ;
2
2
import { Mina } from "o1js" ;
3
+ import { match } from "ts-pattern" ;
3
4
4
5
import { MinaIncomingMessageAdapter } from "../../settlement/messages/MinaIncomingMessageAdapter" ;
5
6
import { SequencerModule } from "../../sequencer/builder/SequencerModule" ;
@@ -9,11 +10,21 @@ import { WithdrawalQueue } from "../../settlement/messages/WithdrawalQueue";
9
10
import { BaseLayer } from "./BaseLayer" ;
10
11
11
12
export interface MinaBaseLayerConfig {
12
- network : {
13
- local : boolean ;
14
- graphql ?: string ;
15
- archive ?: string ;
16
- } ;
13
+ network :
14
+ | {
15
+ type : "local" ;
16
+ }
17
+ | {
18
+ type : "lightnet" ;
19
+ graphql : string ;
20
+ archive : string ;
21
+ accountManager ?: string ;
22
+ }
23
+ | {
24
+ type : "remote" ;
25
+ graphql : string ;
26
+ archive : string ;
27
+ } ;
17
28
}
18
29
19
30
export class MinaBaseLayer
@@ -22,6 +33,8 @@ export class MinaBaseLayer
22
33
{
23
34
public network ?: Parameters < typeof Mina . setActiveInstance > [ 0 ] ;
24
35
36
+ public originalNetwork ?: Parameters < typeof Mina . setActiveInstance > [ 0 ] ;
37
+
25
38
public dependencies ( ) {
26
39
return {
27
40
IncomingMessageAdapter : {
@@ -39,27 +52,36 @@ export class MinaBaseLayer
39
52
}
40
53
41
54
public isLocalBlockChain ( ) : boolean {
42
- return this . config . network . local ;
55
+ return this . config . network . type === " local" ;
43
56
}
44
57
45
58
public async start ( ) : Promise < void > {
46
59
const { network } = this . config ;
47
60
48
- if (
49
- ! network . local &&
50
- ( network . graphql === undefined || network . archive === undefined )
51
- ) {
52
- throw new Error (
53
- "The API endpoints have to be defined, if the network is remote"
54
- ) ;
55
- }
61
+ this . originalNetwork = Mina . activeInstance ;
56
62
57
- const Network = this . config . network . local
58
- ? await Mina . LocalBlockchain ( { proofsEnabled : false } )
59
- : Mina . Network ( {
60
- mina : network . graphql ! ,
61
- archive : network . archive ! ,
63
+ const Network = await match ( network )
64
+ . with (
65
+ { type : "local" } ,
66
+ async ( ) => await Mina . LocalBlockchain ( { proofsEnabled : false } )
67
+ )
68
+ . with ( { type : "lightnet" } , async ( lightnet ) => {
69
+ const net = Mina . Network ( {
70
+ mina : lightnet . graphql ,
71
+ archive : lightnet . archive ,
72
+ lightnetAccountManager : lightnet . accountManager ,
62
73
} ) ;
74
+ net . proofsEnabled = false ;
75
+ return net ;
76
+ } )
77
+ . with ( { type : "remote" } , async ( remote ) =>
78
+ Mina . Network ( {
79
+ mina : remote . graphql ,
80
+ archive : remote . archive ,
81
+ } )
82
+ )
83
+ . exhaustive ( ) ;
84
+
63
85
Mina . setActiveInstance ( Network ) ;
64
86
this . network = Network ;
65
87
}
0 commit comments