feat(builder): finish new FundManager setup
Finish setup of new FundManager and provide a migration for previously reserved funds
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/filecoin-project/go-multistore"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"go.uber.org/fx"
|
||||
@@ -26,6 +28,7 @@ import (
|
||||
"github.com/ipfs/go-datastore/namespace"
|
||||
"github.com/libp2p/go-libp2p-core/host"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/market"
|
||||
"github.com/filecoin-project/lotus/journal"
|
||||
"github.com/filecoin-project/lotus/lib/blockstore"
|
||||
"github.com/filecoin-project/lotus/markets"
|
||||
@@ -39,6 +42,36 @@ import (
|
||||
"github.com/filecoin-project/lotus/node/repo/retrievalstoremgr"
|
||||
)
|
||||
|
||||
func HandleMigrateClientFunds(lc fx.Lifecycle, ds dtypes.MetadataDS, wallet full.WalletAPI, fundMgr *market.FundManager) {
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
addr, err := wallet.WalletDefaultAddress(ctx)
|
||||
// nothing to be done if there is no default address
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
b, err := ds.Get(datastore.NewKey("/marketfunds/client"))
|
||||
if err != nil {
|
||||
if xerrors.Is(err, datastore.ErrNotFound) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
var value abi.TokenAmount
|
||||
if err = value.UnmarshalCBOR(bytes.NewReader(b)); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = fundMgr.Reserve(ctx, addr, addr, value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return ds.Delete(datastore.NewKey("/marketfunds/client"))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func ClientMultiDatastore(lc fx.Lifecycle, r repo.LockedRepo) (dtypes.ClientMultiDstore, error) {
|
||||
ds, err := r.Datastore("/client")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user