From e46ae15dfd3b4d699c5a0e5cd26ccc522498de02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 29 Oct 2019 14:06:02 +0100 Subject: [PATCH] townhall: Don't hard-code stuff --- Makefile | 2 +- cmd/lotus-townhall/main.go | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 6c3a6049f..b30f8712f 100644 --- a/Makefile +++ b/Makefile @@ -100,7 +100,7 @@ townhall: rm -f townhall go build -o townhall ./cmd/lotus-townhall (cd ./cmd/lotus-townhall/townhall && npm i && npm run build) - go run github.com/GeertJohan/go.rice/rice append --exec townhall -i ./cmd/lotus-townhall + go run github.com/GeertJohan/go.rice/rice append --exec townhall -i ./cmd/lotus-townhall -i ./build .PHONY: townhall fountain: diff --git a/cmd/lotus-townhall/main.go b/cmd/lotus-townhall/main.go index 9be633147..e45b8e8e4 100644 --- a/cmd/lotus-townhall/main.go +++ b/cmd/lotus-townhall/main.go @@ -1,9 +1,14 @@ package main import ( + "bytes" "context" "encoding/json" "fmt" + "github.com/filecoin-project/lotus/build" + "github.com/ipfs/go-car" + "github.com/ipfs/go-datastore" + blockstore "github.com/ipfs/go-ipfs-blockstore" "net/http" "strings" @@ -14,11 +19,26 @@ import ( pnet "github.com/libp2p/go-libp2p-pnet" pubsub "github.com/libp2p/go-libp2p-pubsub" - "github.com/filecoin-project/lotus/lib/addrutil" "github.com/filecoin-project/lotus/node/modules/lp2p" ) -const topic = "/fil/headnotifs/bafy2bzacea77zxnepp7wuqqgpj7xcw2ywwmmcmtrbjghhv4g2dildogpv6roi" +var topic = "/fil/headnotifs/" + +func init() { + genBytes := build.MaybeGenesis() + bs := blockstore.NewBlockstore(datastore.NewMapDatastore()) + + c, err := car.LoadCar(bs, bytes.NewReader(genBytes)) + if err != nil { + panic(err) + } + if len(c.Roots) != 1 { + panic("expected genesis file to have one root") + } + + fmt.Printf("Genesis CID: %s\n", c.Roots[0]) + topic = topic + c.Roots[0].String() +} var upgrader = websocket.Upgrader{ WriteBufferSize: 1024, @@ -48,9 +68,7 @@ func main() { panic(err) } - pi, err := addrutil.ParseAddresses(ctx, []string{ - "/ip4/147.75.80.29/tcp/1347/p2p/12D3KooWGU8C1mFsEtz4bXmHUH3kQTnQnxVy8cigwGV94qCpYJw7", - }) + pi, err := build.BuiltinBootstrap() if err != nil { panic(err) }