prysm-pulse/sharding/db.go
Raul Jordan d1aa843ea6 sharding: address review comments om #100, fix linter issues
Former-commit-id: 5febe72a5a1936ce643488067e0990da810f1f5e [formerly 74c85fc99b259d064b5181f91cddf945e3d7b988]
Former-commit-id: 0cc6d451b5eee6e459597ad114a85bacc7a953f1
2018-05-09 15:23:09 -04:00

38 lines
651 B
Go

package sharding
import (
"fmt"
"github.com/ethereum/go-ethereum/common"
)
type shardKV struct {
// Shard state storage is a mapping of hashes to RLP encoded values.
kv map[common.Hash][]byte
}
func makeShardKV() *shardKV {
return &shardKV{kv: make(map[common.Hash][]byte)}
}
func (sb *shardKV) Get(k common.Hash) ([]byte, error) {
v, ok := sb.kv[k]
if !ok {
return nil, fmt.Errorf("key not found: %v", k)
}
return v, nil
}
func (sb *shardKV) Has(k common.Hash) bool {
v := sb.kv[k]
return v != nil
}
func (sb *shardKV) Put(k common.Hash, v []byte) {
sb.kv[k] = v
}
func (sb *shardKV) Delete(k common.Hash) {
delete(sb.kv, k)
}