-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
112 lines (90 loc) · 2.36 KB
/
types.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
104
105
106
107
108
109
110
111
112
package database
import (
"crypto/sha256"
"database/sql"
"embed"
"fmt"
"math/big"
"time"
migrate "github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/source/iofs"
"github.com/sirupsen/logrus"
)
var Content embed.FS
type DatabaseDriver string
// Database Parameters Needed To Setup The Network
type DatabaseOpts struct {
MaxConnections int
MaxIdleConnections int
MaxIdleTimeConnection time.Duration
}
type DatabaseInterface struct {
DB *sql.DB // Function so we have functions on top of it
Opts DatabaseOpts
Driver DatabaseDriver
Log logrus.Entry
URL string
}
func (database *DatabaseInterface) NewDatabaseOpts() {
database.DB.SetMaxOpenConns(database.Opts.MaxConnections)
database.DB.SetMaxIdleConns(database.Opts.MaxIdleConnections)
database.DB.SetConnMaxIdleTime(database.Opts.MaxIdleTimeConnection)
}
func (database *DatabaseInterface) DBMigrate() error {
migrationOpts, err := iofs.New(Content, "migrations/")
if err != nil {
database.Log.Fatal(err)
return err
}
migration, err := migrate.NewWithSourceInstance("iofs", migrationOpts, database.URL)
if err != nil {
database.Log.Fatal(err)
return err
}
defer migration.Close()
err = migration.Up()
if err != nil {
database.Log.Fatal("Database Migrate Error")
return err
}
database.Log.Info("Database Migrate Succesful")
return nil
}
type ValidatorDeliveredPayloadDatabase struct {
Slot uint64
ProposerPubkey string
BlockHash string
Payload []byte
}
type ValidatorReturnedBlockDatabase struct {
Signature string
Slot uint64
BlockHash string
ProposerPubkey string
}
type ValidatorDeliveredHeaderDatabase struct {
Slot uint64
BlockHash string
ProposerPubkey string
BidValue uint64
}
type BuilderBlockDatabase struct {
Slot uint64
BuilderPubkey string
BuilderBidHash string
BuilderSignature string
RPBS string
RpbsPublicKey string
TransactionByte string
BidValue big.Int
}
func (builderSubmission *BuilderBlockDatabase) Hash() string {
BuilderBid := fmt.Sprintf("%d,%s,%s,%s",
builderSubmission.Slot,
builderSubmission.BuilderPubkey,
builderSubmission.BuilderSignature,
builderSubmission.BidValue.String(),
)
BuilderSubmissionHash := sha256.Sum256([]byte(BuilderBid))
return fmt.Sprintf("%#x", BuilderSubmissionHash)
}