diff --git a/api/api.go b/api/api.go
index 70f72814d..f2b38f670 100644
--- a/api/api.go
+++ b/api/api.go
@@ -105,6 +105,7 @@ type FullNode interface {
StateMinerProvingSet(context.Context, address.Address) ([]*SectorInfo, error)
StateMinerPower(context.Context, address.Address, *types.TipSet) (MinerPower, error)
StateMinerWorker(context.Context, address.Address, *types.TipSet) (address.Address, error)
+ StateMinerPeerID(ctx context.Context, m address.Address, ts *types.TipSet) (peer.ID, error)
// if tipset is nil, we'll use heaviest
StateCall(context.Context, *types.Message, *types.TipSet) (*types.MessageReceipt, error)
StateGetActor(ctx context.Context, actor address.Address, ts *types.TipSet) (*types.Actor, error)
diff --git a/api/struct.go b/api/struct.go
index 005c70965..553586dc5 100644
--- a/api/struct.go
+++ b/api/struct.go
@@ -79,6 +79,7 @@ type FullNodeStruct struct {
StateMinerProvingSet func(context.Context, address.Address) ([]*SectorInfo, error) `perm:"read"`
StateMinerPower func(context.Context, address.Address, *types.TipSet) (MinerPower, error) `perm:"read"`
StateMinerWorker func(context.Context, address.Address, *types.TipSet) (address.Address, error) `perm:"read"`
+ StateMinerPeerID func(ctx context.Context, m address.Address, ts *types.TipSet) (peer.ID, error)`perm:"read"`
StateCall func(context.Context, *types.Message, *types.TipSet) (*types.MessageReceipt, error) `perm:"read"`
StateGetActor func(context.Context, address.Address, *types.TipSet) (*types.Actor, error) `perm:"read"`
StateReadState func(context.Context, *types.Actor, *types.TipSet) (*ActorState, error) `perm:"read"`
@@ -293,6 +294,10 @@ func (c *FullNodeStruct) StateMinerWorker(ctx context.Context, m address.Address
return c.Internal.StateMinerWorker(ctx, m, ts)
}
+func (c *FullNodeStruct) StateMinerPeerID(ctx context.Context, m address.Address, ts *types.TipSet) (peer.ID, error) {
+ return c.Internal.StateMinerPeerID(ctx, m, ts)
+}
+
func (c *FullNodeStruct) StateCall(ctx context.Context, msg *types.Message, ts *types.TipSet) (*types.MessageReceipt, error) {
return c.Internal.StateCall(ctx, msg, ts)
}
diff --git a/lotuspond/front/src/Client.js b/lotuspond/front/src/Client.js
index 1bfe1981c..698badada 100644
--- a/lotuspond/front/src/Client.js
+++ b/lotuspond/front/src/Client.js
@@ -49,6 +49,23 @@ class Client extends React.Component {
console.log("deal cid: ", dealcid)
}
+ retrieve = (deal) => async () => {
+ console.log(deal)
+ let client = await this.props.client.call('Filecoin.WalletDefaultAddress', [])
+
+ let order = {
+ Root: deal.PieceRef,
+ Size: deal.Size,
+ // TODO: support offset
+ Total: "900",
+
+ Client: client,
+ Miner: deal.Miner
+ }
+
+ await this.props.client.call('Filecoin.ClientRetrieve', [order, '/dev/null'])
+ }
+
render() {
let ppb = Math.round(this.state.total / this.state.blocks * 100) / 100
let ppmbb = Math.round(ppb / (this.state.kbs / 1000) * 100) / 100
@@ -67,6 +84,7 @@ class Client extends React.Component {
let deals = this.state.deals.map((deal, i) =>
- {i}. Proposal: {deal.ProposalCid['/'].substr(0, 18)}... : {dealStates[deal.State]}
+ {dealStates[deal.State] === 'Complete' ? [Retrieve] : }
- Data: {deal.PieceRef['/']}, {deal.Size}B; Duration: {deal.Duration}Blocks
- Total: {deal.TotalPrice}FIL; Per Block: {Math.round(deal.TotalPrice / deal.Duration * 100) / 100}FIL; PerMbyteByteBlock: {Math.round(deal.TotalPrice / deal.Duration / (deal.Size / 1000000) * 100) / 100}FIL
diff --git a/node/impl/client/client.go b/node/impl/client/client.go
index 374014b88..cefc25797 100644
--- a/node/impl/client/client.go
+++ b/node/impl/client/client.go
@@ -241,6 +241,15 @@ func (a *API) ClientListImports(ctx context.Context) ([]api.Import, error) {
}
func (a *API) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, path string) error {
+ if order.MinerPeerID == "" {
+ pid, err := a.StateMinerPeerID(ctx, order.Miner, nil)
+ if err != nil {
+ return err
+ }
+
+ order.MinerPeerID = pid
+ }
+
outFile, err := os.OpenFile(path, os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0777)
if err != nil {
return err
diff --git a/node/impl/full/state.go b/node/impl/full/state.go
index acdc8ee6b..2b25ca4be 100644
--- a/node/impl/full/state.go
+++ b/node/impl/full/state.go
@@ -5,24 +5,24 @@ import (
"fmt"
"strconv"
+ "github.com/ipfs/go-hamt-ipld"
+ cbor "github.com/ipfs/go-ipld-cbor"
+ "github.com/libp2p/go-libp2p-core/peer"
+ "go.uber.org/fx"
+ "golang.org/x/xerrors"
+
+ "github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/chain"
+ "github.com/filecoin-project/go-lotus/chain/actors"
+ "github.com/filecoin-project/go-lotus/chain/address"
"github.com/filecoin-project/go-lotus/chain/gen"
+ "github.com/filecoin-project/go-lotus/chain/state"
"github.com/filecoin-project/go-lotus/chain/stmgr"
"github.com/filecoin-project/go-lotus/chain/store"
"github.com/filecoin-project/go-lotus/chain/types"
"github.com/filecoin-project/go-lotus/chain/vm"
"github.com/filecoin-project/go-lotus/chain/wallet"
"github.com/filecoin-project/go-lotus/lib/bufbstore"
- "golang.org/x/xerrors"
-
- "github.com/filecoin-project/go-lotus/api"
- "github.com/filecoin-project/go-lotus/chain/actors"
- "github.com/filecoin-project/go-lotus/chain/address"
- "github.com/filecoin-project/go-lotus/chain/state"
-
- "github.com/ipfs/go-hamt-ipld"
- cbor "github.com/ipfs/go-ipld-cbor"
- "go.uber.org/fx"
)
type StateAPI struct {
@@ -186,6 +186,23 @@ func (a *StateAPI) StateMinerWorker(ctx context.Context, m address.Address, ts *
return w, nil
}
+func (a *StateAPI) StateMinerPeerID(ctx context.Context, m address.Address, ts *types.TipSet) (peer.ID, error) {
+ ret, err := a.StateManager.Call(ctx, &types.Message{
+ From: m,
+ To: m,
+ Method: actors.MAMethods.GetPeerID,
+ }, ts)
+ if err != nil {
+ return "", xerrors.Errorf("failed to get miner worker addr: %w", err)
+ }
+
+ if ret.ExitCode != 0 {
+ return "", xerrors.Errorf("failed to get miner worker addr (exit code %d)", ret.ExitCode)
+ }
+
+ return peer.IDFromBytes(ret.Return)
+}
+
func (a *StateAPI) StateCall(ctx context.Context, msg *types.Message, ts *types.TipSet) (*types.MessageReceipt, error) {
return a.StateManager.Call(ctx, msg, ts)
}
diff --git a/retrieval/client.go b/retrieval/client.go
index 4874c76c7..47ed70cbc 100644
--- a/retrieval/client.go
+++ b/retrieval/client.go
@@ -33,8 +33,8 @@ type Client struct {
payapi payapi.PaychAPI
}
-func NewClient(h host.Host) *Client {
- return &Client{h: h}
+func NewClient(h host.Host, pmgr *paych.Manager, payapi payapi.PaychAPI) *Client {
+ return &Client{h: h, pmgr: pmgr, payapi: payapi}
}
func (c *Client) Query(ctx context.Context, p discovery.RetrievalPeer, data cid.Cid) api.QueryOffer {