2018-05-03 15:22:28 +00:00
|
|
|
package sharding
|
|
|
|
|
2018-05-03 15:48:25 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
)
|
2018-05-03 15:22:28 +00:00
|
|
|
|
|
|
|
type shardBackend struct {
|
2018-05-03 15:48:25 +00:00
|
|
|
kv map[common.Hash][]byte
|
2018-05-03 15:22:28 +00:00
|
|
|
}
|
|
|
|
|
2018-05-03 15:48:25 +00:00
|
|
|
func (sb *shardBackend) Get(k common.Hash) ([]byte, error) {
|
|
|
|
v := sb.kv[k]
|
|
|
|
if v == nil {
|
|
|
|
return nil, fmt.Errorf("Key Not Found")
|
|
|
|
}
|
|
|
|
return v, nil
|
2018-05-03 15:22:28 +00:00
|
|
|
}
|
|
|
|
|
2018-05-03 15:48:25 +00:00
|
|
|
func (sb *shardBackend) Put(k common.Hash, v []byte) {
|
2018-05-03 15:22:28 +00:00
|
|
|
sb.kv[k] = v
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-05-03 15:48:25 +00:00
|
|
|
func (sb *shardBackend) Delete(k common.Hash) {
|
2018-05-03 15:22:28 +00:00
|
|
|
delete(sb.kv, k)
|
|
|
|
return
|
|
|
|
}
|