-
Notifications
You must be signed in to change notification settings - Fork 461
/
utils.go
37 lines (29 loc) · 855 Bytes
/
utils.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
package chain
import (
"context"
blockstoreutil "github.com/filecoin-project/venus/venus-shared/blockstore"
"github.com/filecoin-project/venus/venus-shared/types"
blockFormat "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
)
type storable interface {
ToStorageBlock() (blockFormat.Block, error)
}
func PutMessage(ctx context.Context, bs blockstoreutil.Blockstore, m storable) (cid.Cid, error) {
b, err := m.ToStorageBlock()
if err != nil {
return cid.Undef, err
}
if err := bs.Put(ctx, b); err != nil {
return cid.Undef, err
}
return b.Cid(), nil
}
// Reverse reverses the order of the slice `chain`.
func Reverse(chain []*types.TipSet) {
// https://github.com/golang/go/wiki/SliceTricks#reversing
for i := len(chain)/2 - 1; i >= 0; i-- {
opp := len(chain) - 1 - i
chain[i], chain[opp] = chain[opp], chain[i]
}
}