mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
3ca4d6fd91
* new interface methods * support proposer slashings * add in the new buckets * all crud for propoer slashings * attester slashings complete * all slashings crud done * right comment * deposit contract tests pass * delete out of scope methods * conform old beacon DB * comment * deprecations * pass lint * Update deposit_contract.go
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/boltdb/bolt"
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"go.opencensus.io/trace"
|
|
)
|
|
|
|
// DepositContractAddress returns contract address is the address of
|
|
// the deposit contract on the proof of work chain.
|
|
func (k *Store) DepositContractAddress(ctx context.Context) ([]byte, error) {
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.DepositContractAddress")
|
|
defer span.End()
|
|
var addr []byte
|
|
// #nosec G104. Always returns nil.
|
|
k.db.View(func(tx *bolt.Tx) error {
|
|
chainInfo := tx.Bucket(chainMetadataBucket)
|
|
addr = chainInfo.Get(depositContractAddressKey)
|
|
return nil
|
|
})
|
|
return addr, nil
|
|
}
|
|
|
|
// SaveDepositContractAddress to the db. It returns an error if an address has been previously saved.
|
|
func (k *Store) SaveDepositContractAddress(ctx context.Context, addr common.Address) error {
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.VerifyContractAddress")
|
|
defer span.End()
|
|
|
|
return k.db.Update(func(tx *bolt.Tx) error {
|
|
chainInfo := tx.Bucket(chainMetadataBucket)
|
|
expectedAddress := chainInfo.Get(depositContractAddressKey)
|
|
if expectedAddress != nil {
|
|
return fmt.Errorf("cannot override deposit contract address: %v", expectedAddress)
|
|
}
|
|
return chainInfo.Put(depositContractAddressKey, addr.Bytes())
|
|
})
|
|
}
|