2020-09-12 03:07:52 +00:00
|
|
|
package adt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/cbor"
|
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
2020-09-24 00:01:40 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
2020-09-23 22:36:56 +00:00
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
adt0 "github.com/filecoin-project/specs-actors/actors/util/adt"
|
2020-09-23 22:36:56 +00:00
|
|
|
adt1 "github.com/filecoin-project/specs-actors/v2/actors/util/adt"
|
2020-09-12 03:07:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Map interface {
|
|
|
|
Root() (cid.Cid, error)
|
|
|
|
|
|
|
|
Put(k abi.Keyer, v cbor.Marshaler) error
|
|
|
|
Get(k abi.Keyer, v cbor.Unmarshaler) (bool, error)
|
|
|
|
Delete(k abi.Keyer) error
|
|
|
|
|
|
|
|
ForEach(v cbor.Unmarshaler, fn func(key string) error) error
|
|
|
|
}
|
|
|
|
|
2020-09-24 00:01:40 +00:00
|
|
|
func AsMap(store Store, root cid.Cid, version actors.Version) (Map, error) {
|
2020-09-14 22:43:12 +00:00
|
|
|
switch version {
|
2020-09-24 00:01:40 +00:00
|
|
|
case actors.Version0:
|
2020-09-18 21:59:27 +00:00
|
|
|
return adt0.AsMap(store, root)
|
2020-09-24 00:01:40 +00:00
|
|
|
case actors.Version1:
|
2020-09-23 22:36:56 +00:00
|
|
|
return adt1.AsMap(store, root)
|
2020-09-12 03:07:52 +00:00
|
|
|
}
|
|
|
|
return nil, xerrors.Errorf("unknown network version: %d", version)
|
|
|
|
}
|
|
|
|
|
2020-09-24 00:01:40 +00:00
|
|
|
func NewMap(store Store, version actors.Version) (Map, error) {
|
2020-09-14 22:43:12 +00:00
|
|
|
switch version {
|
2020-09-24 00:01:40 +00:00
|
|
|
case actors.Version0:
|
2020-09-18 21:59:27 +00:00
|
|
|
return adt0.MakeEmptyMap(store), nil
|
2020-09-24 00:01:40 +00:00
|
|
|
case actors.Version1:
|
2020-09-23 22:36:56 +00:00
|
|
|
return adt1.MakeEmptyMap(store), nil
|
2020-09-12 03:07:52 +00:00
|
|
|
}
|
|
|
|
return nil, xerrors.Errorf("unknown network version: %d", version)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Array interface {
|
|
|
|
Root() (cid.Cid, error)
|
|
|
|
|
|
|
|
Set(idx uint64, v cbor.Marshaler) error
|
|
|
|
Get(idx uint64, v cbor.Unmarshaler) (bool, error)
|
|
|
|
Delete(idx uint64) error
|
|
|
|
Length() uint64
|
|
|
|
|
2020-09-14 11:14:06 +00:00
|
|
|
ForEach(v cbor.Unmarshaler, fn func(idx int64) error) error
|
2020-09-12 03:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func AsArray(store Store, root cid.Cid, version network.Version) (Array, error) {
|
2020-09-24 00:01:40 +00:00
|
|
|
switch actors.VersionForNetwork(version) {
|
|
|
|
case actors.Version0:
|
2020-09-18 21:59:27 +00:00
|
|
|
return adt0.AsArray(store, root)
|
2020-09-24 00:01:40 +00:00
|
|
|
case actors.Version1:
|
2020-09-23 22:36:56 +00:00
|
|
|
return adt1.AsArray(store, root)
|
2020-09-12 03:07:52 +00:00
|
|
|
}
|
|
|
|
return nil, xerrors.Errorf("unknown network version: %d", version)
|
|
|
|
}
|
2020-09-22 18:09:56 +00:00
|
|
|
|
2020-09-24 00:01:40 +00:00
|
|
|
func NewArray(store Store, version actors.Version) (Array, error) {
|
2020-09-22 18:09:56 +00:00
|
|
|
switch version {
|
2020-09-24 00:01:40 +00:00
|
|
|
case actors.Version0:
|
2020-09-22 18:09:56 +00:00
|
|
|
return adt0.MakeEmptyArray(store), nil
|
2020-09-24 00:01:40 +00:00
|
|
|
case actors.Version1:
|
2020-09-23 22:36:56 +00:00
|
|
|
return adt1.MakeEmptyArray(store), nil
|
2020-09-22 18:09:56 +00:00
|
|
|
}
|
|
|
|
return nil, xerrors.Errorf("unknown network version: %d", version)
|
|
|
|
}
|