pond: List client deals

This commit is contained in:
Łukasz Magiera 2019-09-10 16:48:54 +02:00
parent 1fc7a48759
commit c121d9b8af
4 changed files with 66 additions and 6 deletions

View File

@ -2,7 +2,6 @@ package api
import ( import (
"context" "context"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/ipfs/go-filestore" "github.com/ipfs/go-filestore"
cbor "github.com/ipfs/go-ipld-cbor" cbor "github.com/ipfs/go-ipld-cbor"
@ -165,7 +164,14 @@ type Import struct {
type DealInfo struct { type DealInfo struct {
ProposalCid cid.Cid ProposalCid cid.Cid
State DealState State DealState
Miner peer.ID Miner address.Address
PieceRef cid.Cid
CommP []byte
Size uint64
TotalPrice types.BigInt
Duration uint64
} }
type MsgWait struct { type MsgWait struct {

View File

@ -48,6 +48,13 @@
display: inline-block; display: inline-block;
} }
.Client {
background: #f9be77;
user-select: text;
font-family: monospace;
display: inline-block;
}
.CristalScroll { .CristalScroll {
display: flex; display: flex;
min-width: 100%; min-width: 100%;

View File

@ -1,5 +1,18 @@
import React from 'react'; import React from 'react';
import Cristal from 'react-cristal' import Cristal from 'react-cristal'
import Address from "./Address";
const dealStates = [
"Unknown",
"Rejected",
"Accepted",
"Started",
"Failed",
"Staged",
"Sealing",
"Complete",
]
class Client extends React.Component { class Client extends React.Component {
constructor(props) { constructor(props) {
@ -9,16 +22,28 @@ class Client extends React.Component {
kbs: 1, kbs: 1,
blocks: 12, blocks: 12,
total: 36000, total: 36000,
miner: "t0101" miner: "t0101",
deals: []
} }
} }
componentDidMount() {
this.getDeals()
setInterval(this.getDeals, 1325)
}
getDeals = async () => {
let deals = await this.props.client.call('Filecoin.ClientListDeals', [])
this.setState({deals})
}
update = (name) => (e) => this.setState({ [name]: e.target.value }); update = (name) => (e) => this.setState({ [name]: e.target.value });
makeDeal = async () => { makeDeal = async () => {
let file = await this.props.pondClient.call('Pond.CreateRandomFile', [this.state.kbs * 1000]) // 1024 won't fit in 1k blocks :( let file = await this.props.pondClient.call('Pond.CreateRandomFile', [this.state.kbs * 1000]) // 1024 won't fit in 1k blocks :(
let cid = await this.props.client.call('Filecoin.ClientImport', [file]) let cid = await this.props.client.call('Filecoin.ClientImport', [file])
let dealcid = await this.props.client.call('Filecoin.ClientStartDeal', [cid, this.state.miner, `${Math.round(this.state.total / this.state.blocks)}`, this.state.blocks]) let dealcid = await this.props.client.call('Filecoin.ClientStartDeal', [cid, this.state.miner, `${Math.round(this.state.total / this.state.blocks)}`, Number(this.state.blocks)])
console.log("deal cid: ", dealcid) console.log("deal cid: ", dealcid)
} }
@ -37,8 +62,23 @@ class Client extends React.Component {
<button onClick={this.makeDeal}>Deal!</button> <button onClick={this.makeDeal}>Deal!</button>
</div> </div>
let deals = this.state.deals.map((deal, i) => <div key={i}>
<ul>
<li>{i}. Proposal: {deal.ProposalCid['/'].substr(0, 18)}... <Address nobalance={true} client={this.props.client} addr={deal.Miner} mountWindow={this.props.mountWindow}/>: <b>{dealStates[deal.State]}</b>
<ul>
<li>Data: {deal.PieceRef['/']}, <b>{deal.Size}</b>B; Duration: <b>{deal.Duration}</b>Blocks</li>
<li>Total: <b>{deal.TotalPrice}</b>FIL; Per Block: <b>{Math.round(deal.TotalPrice / deal.Duration * 100) / 100}</b>FIL; PerMbyteByteBlock: <b>{Math.round(deal.TotalPrice / deal.Duration / (deal.Size / 1000000) * 100) / 100}</b>FIL</li>
</ul>
</li>
</ul>
</div>)
return <Cristal title={"Client - Node " + this.props.node.ID}> return <Cristal title={"Client - Node " + this.props.node.ID}>
<div>{dealMaker}</div> <div className="Client">
<div>{dealMaker}</div>
<div>{deals}</div>
</div>
</Cristal> </Cristal>
} }
} }

View File

@ -128,7 +128,14 @@ func (a *ClientAPI) ClientListDeals(ctx context.Context) ([]api.DealInfo, error)
out[k] = api.DealInfo{ out[k] = api.DealInfo{
ProposalCid: v.ProposalCid, ProposalCid: v.ProposalCid,
State: v.State, State: v.State,
Miner: v.Miner, Miner: v.Proposal.MinerAddress,
PieceRef: v.Proposal.PieceRef,
CommP: v.Proposal.CommP,
Size: v.Proposal.Size,
TotalPrice: v.Proposal.TotalPrice,
Duration: v.Proposal.Duration,
} }
} }