forked from OffchainLabs/nitro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage_service.go
45 lines (36 loc) · 1.01 KB
/
storage_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE
package das
import (
"context"
"errors"
"fmt"
"strings"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/offchainlabs/nitro/arbstate/daprovider"
)
var ErrNotFound = errors.New("not found")
type StorageService interface {
daprovider.DASReader
Put(ctx context.Context, data []byte, expirationTime uint64) error
Sync(ctx context.Context) error
Closer
fmt.Stringer
HealthCheck(ctx context.Context) error
}
const defaultStorageRetention = time.Hour * 24 * 21 // 6 days longer than the batch poster default
func EncodeStorageServiceKey(key common.Hash) string {
return key.Hex()[2:]
}
func DecodeStorageServiceKey(input string) (common.Hash, error) {
if !strings.HasPrefix(input, "0x") {
input = "0x" + input
}
key, err := hexutil.Decode(input)
if err != nil {
return common.Hash{}, err
}
return common.BytesToHash(key), nil
}