2020-01-24 21:44:28 +00:00
|
|
|
import React from 'react'
|
|
|
|
import Address from './Address'
|
|
|
|
import Window from './Window'
|
|
|
|
import Fil from './Fil'
|
2019-09-10 14:48:54 +00:00
|
|
|
|
|
|
|
const dealStates = [
|
2020-01-24 21:44:28 +00:00
|
|
|
'Unknown',
|
|
|
|
'ProposalNotFound',
|
|
|
|
'ProposalRejected',
|
|
|
|
'ProposalAccepted',
|
|
|
|
'Staged',
|
|
|
|
'Sealing',
|
|
|
|
'ProposalSigned',
|
|
|
|
'Published',
|
|
|
|
'Committed',
|
|
|
|
'Active',
|
|
|
|
'Failing',
|
|
|
|
'Recovering',
|
|
|
|
'Expired',
|
|
|
|
'NotFound',
|
|
|
|
|
|
|
|
'Validating',
|
|
|
|
'Transferring',
|
|
|
|
'VerifyData',
|
|
|
|
'Publishing',
|
|
|
|
'Error'
|
2019-09-10 14:48:54 +00:00
|
|
|
]
|
|
|
|
|
2019-09-06 17:43:24 +00:00
|
|
|
class Client extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
this.state = {
|
2020-01-24 21:44:28 +00:00
|
|
|
miners: ['t0101'],
|
|
|
|
ask: { Price: '1000000000' }, // 2x min default ask to account for bin packing (could also do the math correctly below, but..)
|
2019-10-25 12:44:53 +00:00
|
|
|
|
2019-09-06 17:43:24 +00:00
|
|
|
kbs: 1,
|
|
|
|
blocks: 12,
|
2019-09-06 22:35:31 +00:00
|
|
|
total: 36000,
|
2020-01-24 21:44:28 +00:00
|
|
|
miner: 't0101',
|
2019-09-10 14:48:54 +00:00
|
|
|
|
2019-10-25 12:44:53 +00:00
|
|
|
deals: [],
|
|
|
|
|
2020-01-24 21:44:28 +00:00
|
|
|
blockDelay: 10
|
2019-09-06 17:43:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 12:44:53 +00:00
|
|
|
async componentDidMount() {
|
|
|
|
let ver = await this.props.client.call('Filecoin.Version', [])
|
2020-01-24 21:44:28 +00:00
|
|
|
this.setState({ blockDelay: ver.BlockDelay })
|
2019-10-25 12:44:53 +00:00
|
|
|
|
2019-09-10 14:48:54 +00:00
|
|
|
this.getDeals()
|
|
|
|
setInterval(this.getDeals, 1325)
|
|
|
|
}
|
|
|
|
|
|
|
|
getDeals = async () => {
|
2020-01-24 21:44:28 +00:00
|
|
|
let miners = await this.props.client.call('Filecoin.StateListMiners', [
|
|
|
|
null
|
|
|
|
])
|
2019-09-10 14:48:54 +00:00
|
|
|
let deals = await this.props.client.call('Filecoin.ClientListDeals', [])
|
2019-10-25 12:44:53 +00:00
|
|
|
miners.sort()
|
2020-01-24 21:44:28 +00:00
|
|
|
this.setState({ deals, miners })
|
2019-09-10 14:48:54 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 21:44:28 +00:00
|
|
|
update = name => e => this.setState({ [name]: e.target.value })
|
2019-09-06 17:43:24 +00:00
|
|
|
|
|
|
|
makeDeal = async () => {
|
2020-01-24 21:44:28 +00:00
|
|
|
let perBlk =
|
|
|
|
((this.state.ask.Price * this.state.kbs * 1000) / (1 << 30)) * 2
|
2019-10-25 12:44:53 +00:00
|
|
|
|
2020-01-24 21:44:28 +00:00
|
|
|
let file = await this.props.pondClient.call('Pond.CreateRandomFile', [
|
|
|
|
this.state.kbs * 1000
|
|
|
|
]) // 1024 won't fit in 1k blocks :(
|
2020-03-03 04:13:08 +00:00
|
|
|
let cid = await this.props.client.call('Filecoin.ClientImport', [
|
|
|
|
{
|
|
|
|
Path: file,
|
|
|
|
IsCar: false
|
|
|
|
}
|
|
|
|
])
|
2020-01-24 21:44:28 +00:00
|
|
|
let dealcid = await this.props.client.call('Filecoin.ClientStartDeal', [
|
|
|
|
cid,
|
|
|
|
this.state.miner,
|
|
|
|
`${Math.round(perBlk)}`,
|
|
|
|
Number(this.state.blocks)
|
|
|
|
])
|
|
|
|
console.log('deal cid: ', dealcid)
|
2019-09-06 17:43:24 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 21:44:28 +00:00
|
|
|
retrieve = deal => async () => {
|
2019-09-16 20:11:17 +00:00
|
|
|
console.log(deal)
|
2020-01-24 21:44:28 +00:00
|
|
|
let client = await this.props.client.call(
|
|
|
|
'Filecoin.WalletDefaultAddress',
|
|
|
|
[]
|
|
|
|
)
|
2019-09-16 20:11:17 +00:00
|
|
|
|
|
|
|
let order = {
|
|
|
|
Root: deal.PieceRef,
|
|
|
|
Size: deal.Size,
|
|
|
|
// TODO: support offset
|
2019-09-16 21:25:23 +00:00
|
|
|
Total: String(deal.Size * 2),
|
2019-09-16 20:11:17 +00:00
|
|
|
|
|
|
|
Client: client,
|
|
|
|
Miner: deal.Miner
|
|
|
|
}
|
|
|
|
|
2020-01-24 21:44:28 +00:00
|
|
|
await this.props.client.call('Filecoin.ClientRetrieve', [
|
|
|
|
order,
|
2020-03-03 04:13:08 +00:00
|
|
|
{
|
|
|
|
Path: '/dev/null',
|
|
|
|
IsCAR: false
|
|
|
|
}
|
2020-01-24 21:44:28 +00:00
|
|
|
])
|
2019-09-16 20:11:17 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 17:43:24 +00:00
|
|
|
render() {
|
2019-10-25 12:44:53 +00:00
|
|
|
let perBlk = this.state.ask.Price * this.state.kbs * 1000
|
|
|
|
let total = perBlk * this.state.blocks
|
|
|
|
let days = (this.state.blocks * this.state.blockDelay) / 60 / 60 / 24
|
2019-09-06 17:43:24 +00:00
|
|
|
|
2020-01-24 21:44:28 +00:00
|
|
|
let dealMaker = (
|
|
|
|
<div hidden={!this.props.pondClient}>
|
|
|
|
<div>
|
|
|
|
<span>Make Deal: </span>
|
|
|
|
<select>
|
|
|
|
{this.state.miners.map(m => (
|
|
|
|
<option key={m} value={m}>
|
|
|
|
{m}
|
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
<span>
|
|
|
|
{' '}
|
|
|
|
Ask:{' '}
|
|
|
|
<b>
|
|
|
|
<Fil>{this.state.ask.Price}</Fil>
|
|
|
|
</b>{' '}
|
|
|
|
Fil/Byte/Block
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
Data Size:{' '}
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
placeholder="KBs"
|
|
|
|
defaultValue={1}
|
|
|
|
onChange={this.update('kbs')}
|
|
|
|
style={{ width: '5em' }}
|
|
|
|
/>
|
|
|
|
KB; Duration:
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
placeholder="blocks"
|
|
|
|
defaultValue={12}
|
|
|
|
onChange={this.update('blocks')}
|
|
|
|
style={{ width: '5em' }}
|
|
|
|
/>
|
|
|
|
Blocks
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
Total: <Fil>{total}</Fil>; {days} Days
|
|
|
|
</div>
|
|
|
|
<button onClick={this.makeDeal}>Deal!</button>
|
2019-10-25 12:44:53 +00:00
|
|
|
</div>
|
2020-01-24 21:44:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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.Provider}
|
|
|
|
mountWindow={this.props.mountWindow}
|
|
|
|
/>
|
|
|
|
: <b>{dealStates[deal.State]}</b>
|
|
|
|
{dealStates[deal.State] === 'Complete' ? (
|
|
|
|
<span>
|
|
|
|
|
|
|
|
<a href="#" onClick={this.retrieve(deal)}>
|
|
|
|
[Retrieve]
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<span />
|
|
|
|
)}
|
|
|
|
<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>
|
2019-09-10 14:48:54 +00:00
|
|
|
</div>
|
2020-01-24 21:44:28 +00:00
|
|
|
))
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Window
|
|
|
|
title={'Client - Node ' + this.props.node.ID}
|
|
|
|
onClose={this.props.onClose}
|
|
|
|
initialSize={{ width: 600, height: 400 }}
|
|
|
|
>
|
|
|
|
<div className="Client">
|
|
|
|
<div>{dealMaker}</div>
|
|
|
|
<div>{deals}</div>
|
|
|
|
</div>
|
|
|
|
</Window>
|
|
|
|
)
|
2019-09-06 17:43:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Client
|