-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from migalabs/feature/add_eth2_deposits_table
Feature/add eth2 deposits table
- Loading branch information
Showing
10 changed files
with
163 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package db | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ClickHouse/ch-go/proto" | ||
"github.com/migalabs/goteth/pkg/spec" | ||
) | ||
|
||
var ( | ||
depositsTable = "t_deposits" | ||
insertDepositQuery = ` | ||
INSERT INTO %s ( | ||
f_slot, | ||
f_public_key, | ||
f_withdrawal_credentials, | ||
f_amount, | ||
f_signature, | ||
f_index | ||
) | ||
VALUES` | ||
|
||
deleteDepositsQuery = ` | ||
DELETE FROM %s | ||
WHERE f_slot = $1;` | ||
) | ||
|
||
func depositsInput(depositss []spec.Deposit) proto.Input { | ||
// one object per column | ||
var ( | ||
f_slot proto.ColUInt64 | ||
f_public_key proto.ColStr | ||
f_withdrawal_credentials proto.ColStr | ||
f_amount proto.ColUInt64 | ||
f_signature proto.ColStr | ||
f_index proto.ColUInt8 | ||
) | ||
|
||
for _, deposit := range depositss { | ||
|
||
f_slot.Append(uint64(deposit.Slot)) | ||
f_public_key.Append(deposit.PublicKey.String()) | ||
f_withdrawal_credentials.Append(fmt.Sprintf("%#x", deposit.WithdrawalCredentials)) | ||
f_amount.Append(uint64(deposit.Amount)) | ||
f_signature.Append(deposit.Signature.String()) | ||
f_index.Append(uint8(deposit.Index)) | ||
} | ||
|
||
return proto.Input{ | ||
{Name: "f_slot", Data: f_slot}, | ||
{Name: "f_public_key", Data: f_public_key}, | ||
{Name: "f_withdrawal_credentials", Data: f_withdrawal_credentials}, | ||
{Name: "f_amount", Data: f_amount}, | ||
{Name: "f_signature", Data: f_signature}, | ||
{Name: "f_index", Data: f_index}, | ||
} | ||
} | ||
|
||
func (p *DBService) PersistDeposits(data []spec.Deposit) error { | ||
persistObj := PersistableObject[spec.Deposit]{ | ||
input: depositsInput, | ||
table: depositsTable, | ||
query: insertDepositQuery, | ||
} | ||
|
||
for _, item := range data { | ||
persistObj.Append(item) | ||
} | ||
|
||
err := p.Persist(persistObj.ExportPersist()) | ||
if err != nil { | ||
log.Errorf("error persisting deposits: %s", err.Error()) | ||
} | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS t_deposits; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE t_deposits( | ||
f_slot UInt64, | ||
f_public_key TEXT, | ||
f_withdrawal_credentials TEXT, | ||
f_amount UInt64, | ||
f_signature TEXT, | ||
f_index UInt8, | ||
) | ||
ENGINE = ReplacingMergeTree() | ||
ORDER BY (f_slot, f_index); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package spec | ||
|
||
import ( | ||
"github.com/attestantio/go-eth2-client/spec/phase0" | ||
) | ||
|
||
type Deposit struct { | ||
Slot phase0.Slot | ||
PublicKey phase0.BLSPubKey | ||
WithdrawalCredentials []byte | ||
Amount phase0.Gwei | ||
Signature phase0.BLSSignature | ||
Index uint8 | ||
} | ||
|
||
func (f Deposit) Type() ModelType { | ||
return DepositModel | ||
} | ||
|
||
func (f Deposit) ToArray() []interface{} { | ||
rows := []interface{}{ | ||
f.Slot, | ||
f.PublicKey, | ||
f.WithdrawalCredentials, | ||
f.Amount, | ||
f.Signature, | ||
f.Index, | ||
} | ||
return rows | ||
} |