fountain: populate miner sector dropdown from specs-actors
This commit is contained in:
parent
d3a1261f1e
commit
4e0cf1644f
@ -4,9 +4,13 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -28,12 +32,47 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
lcli "github.com/filecoin-project/lotus/cli"
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logging.Logger("main")
|
var log = logging.Logger("main")
|
||||||
|
|
||||||
var sendPerRequest, _ = types.ParseFIL("50")
|
var sendPerRequest, _ = types.ParseFIL("50")
|
||||||
|
|
||||||
|
var supportedSectors struct {
|
||||||
|
SectorSizes []struct {
|
||||||
|
Name string
|
||||||
|
Value uint64
|
||||||
|
Default bool
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
for supportedSector, _ := range miner.SupportedProofTypes {
|
||||||
|
sectorSize, err := supportedSector.SectorSize()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
supportedSectors.SectorSizes = append(supportedSectors.SectorSizes, struct {
|
||||||
|
Name string
|
||||||
|
Value uint64
|
||||||
|
Default bool
|
||||||
|
}{
|
||||||
|
Name: sectorSize.ShortString(),
|
||||||
|
Value: uint64(sectorSize),
|
||||||
|
Default: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(supportedSectors.SectorSizes[:], func(i, j int) bool {
|
||||||
|
return supportedSectors.SectorSizes[i].Value < supportedSectors.SectorSizes[j].Value
|
||||||
|
})
|
||||||
|
|
||||||
|
supportedSectors.SectorSizes[0].Default = true
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
logging.SetLogLevel("*", "INFO")
|
logging.SetLogLevel("*", "INFO")
|
||||||
|
|
||||||
@ -125,6 +164,7 @@ var runCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
http.Handle("/", http.FileServer(rice.MustFindBox("site").HTTPBox()))
|
http.Handle("/", http.FileServer(rice.MustFindBox("site").HTTPBox()))
|
||||||
|
http.HandleFunc("/miner.html", h.minerhtml)
|
||||||
http.HandleFunc("/send", h.send)
|
http.HandleFunc("/send", h.send)
|
||||||
http.HandleFunc("/mkminer", h.mkminer)
|
http.HandleFunc("/mkminer", h.mkminer)
|
||||||
http.HandleFunc("/msgwait", h.msgwait)
|
http.HandleFunc("/msgwait", h.msgwait)
|
||||||
@ -153,6 +193,37 @@ type handler struct {
|
|||||||
defaultMinerPeer peer.ID
|
defaultMinerPeer peer.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *handler) minerhtml(w http.ResponseWriter, r *http.Request) {
|
||||||
|
f, err := rice.MustFindBox("site").Open("_miner.html")
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(500)
|
||||||
|
_, _ = w.Write([]byte(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := ioutil.ReadAll(f)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(500)
|
||||||
|
_, _ = w.Write([]byte(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var executedTmpl bytes.Buffer
|
||||||
|
|
||||||
|
t, err := template.New("miner.html").Parse(string(tmpl))
|
||||||
|
if err := t.Execute(&executedTmpl, supportedSectors); err != nil {
|
||||||
|
w.WriteHeader(500)
|
||||||
|
_, _ = w.Write([]byte(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := io.Copy(w, &executedTmpl); err != nil {
|
||||||
|
log.Errorf("failed to write template to string %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (h *handler) send(w http.ResponseWriter, r *http.Request) {
|
func (h *handler) send(w http.ResponseWriter, r *http.Request) {
|
||||||
to, err := address.NewFromString(r.FormValue("address"))
|
to, err := address.NewFromString(r.FormValue("address"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -15,8 +15,9 @@
|
|||||||
<span>Enter owner/worker address:</span>
|
<span>Enter owner/worker address:</span>
|
||||||
<input type='text' name='address' style="width: 300px" placeholder="t3...">
|
<input type='text' name='address' style="width: 300px" placeholder="t3...">
|
||||||
<select name="sectorSize">
|
<select name="sectorSize">
|
||||||
<option selected value="34359738368">32GiB sectors</option>
|
{{range .SectorSizes}}
|
||||||
<option value="68719476736">64GiB sectors</option>
|
<option {{if .Default}}selected{{end}} value="{{ .Value }}">{{ .Name }}</option>
|
||||||
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
<button type='submit'>Create Miner</button>
|
<button type='submit'>Create Miner</button>
|
||||||
</form>
|
</form>
|
Loading…
Reference in New Issue
Block a user