From 604eeaa36bdf9e12135ab9fe995ad20f86a8a292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 6 Sep 2019 19:42:31 +0200 Subject: [PATCH] pond: Basic storage client --- lotuspond/api.go | 19 +++++++++++++++++++ lotuspond/front/src/ChainExplorer.js | 3 +++ lotuspond/front/src/FullNode.js | 9 +++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lotuspond/api.go b/lotuspond/api.go index 321e0b0e1..6b547e7a4 100644 --- a/lotuspond/api.go +++ b/lotuspond/api.go @@ -1,6 +1,7 @@ package main import ( + "crypto/rand" "fmt" "github.com/filecoin-project/go-lotus/lib/jsonrpc" "io" @@ -203,6 +204,24 @@ func (api *api) SpawnStorage(fullNodeRepo string) (nodeInfo, error) { return info, nil } +func (api *api) CreateRandomFile(size int64) (string, error) { + tf, err := ioutil.TempFile(os.TempDir(), "pond-random-") + if err != nil { + return "", err + } + + _, err = io.CopyN(tf, rand.Reader, size) + if err != nil { + return "", err + } + + if err := tf.Close(); err != nil { + return "", err + } + + return tf.Name(), nil +} + type client struct { Nodes func() []nodeInfo } diff --git a/lotuspond/front/src/ChainExplorer.js b/lotuspond/front/src/ChainExplorer.js index 8347317f8..d9609614f 100644 --- a/lotuspond/front/src/ChainExplorer.js +++ b/lotuspond/front/src/ChainExplorer.js @@ -58,6 +58,9 @@ class ChainExplorer extends React.Component { } async fetch(h, cache, msgcache) { + if (h < 0) { + return + } const cids = cache[h + 1].Blocks.map(b => b.Parents).reduce((acc, val) => acc.concat(val), []) const blocks = await Promise.all(cids.map(cid => this.props.client.call('Filecoin.ChainGetBlock', [cid]))) diff --git a/lotuspond/front/src/FullNode.js b/lotuspond/front/src/FullNode.js index 09dc12b96..94970c4b4 100644 --- a/lotuspond/front/src/FullNode.js +++ b/lotuspond/front/src/FullNode.js @@ -1,10 +1,10 @@ import React from 'react'; -import { Client } from 'rpc-websockets' import Cristal from 'react-cristal' import { BlockLinks } from "./BlockLink"; import StorageNodeInit from "./StorageNodeInit"; import Address from "./Address"; import ChainExplorer from "./ChainExplorer"; +import Client from "./Client"; class FullNode extends React.Component { constructor(props) { @@ -18,6 +18,7 @@ class FullNode extends React.Component { this.startStorageMiner = this.startStorageMiner.bind(this) this.add1k = this.add1k.bind(this) this.explorer = this.explorer.bind(this) + this.client = this.client.bind(this) this.loadInfo() setInterval(this.loadInfo, 2050) @@ -86,6 +87,10 @@ class FullNode extends React.Component { this.props.mountWindow((onClose) => ) } + client() { + this.props.mountWindow((onClose) => ) + } + render() { let runtime =
@@ -96,7 +101,7 @@ class FullNode extends React.Component {
Head: { - } H:{this.state.tipset.Height} [Explore] + } H:{this.state.tipset.Height} [Explore] [Client]
) }