mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 16:37:39 +00:00
78a865eb0b
* Replaced. Debugging missing strict dependencies... * Merge branch 'master' into bbolt-import * Update import path * Merge branch 'bbolt-import' of github.com:prysmaticlabs/prysm into bbolt-import * use forked prombbolt * Merge branch 'bbolt-import' of github.com:prysmaticlabs/prysm into bbolt-import * fix * remove old boltdb reference * Use correct bolt for pk manager * Merge branch 'bbolt-import' of github.com:prysmaticlabs/prysm into bbolt-import * fix for docker build * gaz, oops
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
bolt "go.etcd.io/bbolt"
|
|
"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())
|
|
})
|
|
}
|