-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
126 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,43 @@ | ||
package modules | ||
|
||
import ( | ||
"context" | ||
"github.com/filecoin-project/go-lotus/chain" | ||
"github.com/filecoin-project/go-lotus/node/modules/helpers" | ||
"github.com/ipfs/go-bitswap" | ||
"github.com/ipfs/go-bitswap/network" | ||
blockstore "github.com/ipfs/go-ipfs-blockstore" | ||
exchange "github.com/ipfs/go-ipfs-exchange-interface" | ||
logging "github.com/ipfs/go-log" | ||
"github.com/libp2p/go-libp2p-core/host" | ||
"github.com/libp2p/go-libp2p-core/peerstore" | ||
"github.com/libp2p/go-libp2p-core/routing" | ||
record "github.com/libp2p/go-libp2p-record" | ||
"go.uber.org/fx" | ||
) | ||
|
||
var log = logging.Logger("modules") | ||
|
||
type Genesis *chain.BlockHeader | ||
|
||
// RecordValidator provides namesys compatible routing record validator | ||
func RecordValidator(ps peerstore.Peerstore) record.Validator { | ||
return record.NamespacedValidator{ | ||
"pk": record.PublicKeyValidator{}, | ||
} | ||
} | ||
|
||
func Bitswap(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, rt routing.Routing, bs blockstore.GCBlockstore) exchange.Interface { | ||
bitswapNetwork := network.NewFromIpfsHost(host, rt) | ||
exch := bitswap.New(helpers.LifecycleCtx(mctx, lc), bitswapNetwork, bs) | ||
lc.Append(fx.Hook{ | ||
OnStop: func(ctx context.Context) error { | ||
return exch.Close() | ||
}, | ||
}) | ||
return exch | ||
} | ||
|
||
func SetGenesis(cs *chain.ChainStore, g Genesis) error { | ||
return cs.SetGenesis(g) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package testing | ||
|
||
import ( | ||
"github.com/filecoin-project/go-lotus/chain" | ||
"github.com/filecoin-project/go-lotus/node/modules" | ||
blockstore "github.com/ipfs/go-ipfs-blockstore" | ||
) | ||
|
||
func MakeGenesis(bs blockstore.Blockstore, w *chain.Wallet) (modules.Genesis, error){ | ||
genb, err := chain.MakeGenesisBlock(bs, w) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return genb.Genesis, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package testing | ||
|
||
import ( | ||
"github.com/ipfs/go-datastore" | ||
dsync "github.com/ipfs/go-datastore/sync" | ||
blockstore "github.com/ipfs/go-ipfs-blockstore" | ||
) | ||
|
||
func MapBlockstore() blockstore.Blockstore { | ||
// TODO: proper datastore | ||
bds := dsync.MutexWrap(datastore.NewMapDatastore()) | ||
bs := blockstore.NewBlockstore(bds) | ||
return blockstore.NewIdStore(bs) | ||
} | ||
|
||
func MapDatastore() datastore.Batching { | ||
return dsync.MutexWrap(datastore.NewMapDatastore()) | ||
} |