forked from Salvionied/apollo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backends.go
93 lines (77 loc) · 2.57 KB
/
backends.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package apollo
import (
"fmt"
"github.com/Salvionied/apollo/constants"
"github.com/Salvionied/apollo/txBuilding/Backend/BlockFrostChainContext"
"github.com/Salvionied/apollo/txBuilding/Backend/FixedChainContext"
"github.com/Salvionied/apollo/txBuilding/Backend/MaestroChainContext"
)
/*
*
NewEmptyBackend creates and returns an empty FixedChainContext instance,
which is iused for cases where no specific backend context is required.
Returns:
FixedChainContext.FixedChainContext: An empty FixedChainContext instance.
*/
func NewEmptyBackend() FixedChainContext.FixedChainContext {
return FixedChainContext.InitFixedChainContext()
}
/*
*
NewBlockfrostBackend creates a BlockFrostChainContext instance based
on the specified network and project ID.
Params:
projectId (string): The project ID to authenticate with BlockFrost.
network (Network): The network to configure the BlockFrost context for.
Returns:
BlockFrostChainContext.BlockFrostChainContext: A BlockFrostChainContext instance configured for the specified network.
*/
func NewBlockfrostBackend(
projectId string,
network constants.Network,
) (BlockFrostChainContext.BlockFrostChainContext, error) {
switch network {
case constants.MAINNET:
return BlockFrostChainContext.NewBlockfrostChainContext(
constants.BLOCKFROST_BASE_URL_MAINNET,
int(constants.MAINNET),
projectId,
), nil
case constants.TESTNET:
return BlockFrostChainContext.NewBlockfrostChainContext(
constants.BLOCKFROST_BASE_URL_TESTNET,
int(constants.TESTNET),
projectId,
), nil
case constants.PREVIEW:
return BlockFrostChainContext.NewBlockfrostChainContext(
constants.BLOCKFROST_BASE_URL_PREVIEW,
int(constants.TESTNET),
projectId,
), nil
case constants.PREPROD:
return BlockFrostChainContext.NewBlockfrostChainContext(
constants.BLOCKFROST_BASE_URL_PREPROD,
int(constants.TESTNET),
projectId,
), nil
default:
return BlockFrostChainContext.BlockFrostChainContext{}, fmt.Errorf("Invalid network")
}
}
// NewMaestroBackend
// NewMaestroBackend creates a MaestroChainContext instance based on the specified network and project ID.
// Params:
// projectId (string): The project ID to authenticate with Maestro.
// network (Network): The network to configure the Maestro context for.
// Returns:
// MaestroChainContext.MaestroChainContext: A MaestroChainContext instance configured for the specified network.
func NewMaestroBackend(
projectId string,
network constants.Network,
) (MaestroChainContext.MaestroChainContext, error) {
return MaestroChainContext.NewMaestroChainContext(
int(network),
projectId,
)
}