-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerateblock.go
103 lines (88 loc) · 2.61 KB
/
generateblock.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
94
95
96
97
98
99
100
101
102
103
package generateblock
import (
"context"
"github.com/cryptogarageinc/generate-block-for-testing/internal/domain/service"
"github.com/cryptogarageinc/generate-block-for-testing/internal/handler"
"github.com/cryptogarageinc/generate-block-for-testing/internal/infrastructure/repository"
"github.com/cryptogarageinc/generate-block-for-testing/internal/usecase"
)
type Connection struct {
Host string
RpcUserID string
RpcPassword string
}
type Generator struct {
handle handler.Handler
network string
ignoreEmptyMempool bool
hasCheckInitialBlkDl bool
}
func NewGenerator(
nodeInfo *Connection,
network string,
) *Generator {
return &Generator{
handle: newHandler(nodeInfo.Host, nodeInfo.RpcUserID, nodeInfo.RpcPassword),
network: network,
}
}
func (g *Generator) WithIgnoreEmptyMempool(ignoreEmptyMempool bool) *Generator {
g.ignoreEmptyMempool = ignoreEmptyMempool
return g
}
func (g *Generator) WithCheckInitialBlockDownload(hasCheckInitialBlkDl bool) *Generator {
g.hasCheckInitialBlkDl = hasCheckInitialBlkDl
return g
}
func (g *Generator) GenerateBlock(
ctx context.Context,
address string,
generateCount uint,
) error {
return g.handle.GenerateBlock(
ctx, g.network, "", []string{}, address, generateCount,
g.ignoreEmptyMempool, g.hasCheckInitialBlkDl)
}
func (g *Generator) GenerateElementsDynafedBlock(
ctx context.Context,
fedpegScript string,
pakEntries []string,
generateCount uint,
) error {
return g.handle.GenerateBlock(
ctx, g.network, fedpegScript, pakEntries, "", generateCount,
g.ignoreEmptyMempool, g.hasCheckInitialBlkDl)
}
func GenerateBlock(
ctx context.Context,
nodeInfo *Connection,
network string,
address string,
generateCount uint,
) error {
handle := newHandler(nodeInfo.Host, nodeInfo.RpcUserID, nodeInfo.RpcPassword)
return handle.GenerateBlock(ctx, network, "", []string{}, address,
generateCount, false, false)
}
func GenerateElementsDynafedBlock(
ctx context.Context,
nodeInfo *Connection,
network string,
fedpegScript string,
pakEntries []string,
generateCount uint,
) error {
handle := newHandler(nodeInfo.Host, nodeInfo.RpcUserID, nodeInfo.RpcPassword)
return handle.GenerateBlock(ctx, network, fedpegScript, pakEntries, "",
generateCount, false, false)
}
func newHandler(
host, rpcUserID, rpcPassword string,
) handler.Handler {
blockchainConfig := repository.NewBlockchainRpcConfig(
host, rpcUserID, rpcPassword)
blockchainRepo := repository.NewBlockchainRpc(blockchainConfig)
genBlockService := service.NewGenerateBlock(blockchainRepo)
genBlockUsecase := usecase.NewGenerateBlock(genBlockService)
return handler.NewHandler(genBlockUsecase)
}