From 2cacdaf22d1202356b5cec7c86552fcf0d8e9625 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Mon, 29 Apr 2019 17:19:59 -0400 Subject: [PATCH] support new protobufs, stop using victor's wallet server --- go.mod | 4 ++-- go.sum | 4 ++++ reflector/blocklist.go | 49 ++++++++++++++++++++++++++++-------------- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index ed74811..a59d6a4 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/go-ini/ini v1.41.0 github.com/go-sql-driver/mysql v0.0.0-20180719071942-99ff426eb706 github.com/golang/mock v1.2.0 // indirect - github.com/golang/protobuf v1.2.0 + github.com/golang/protobuf v1.3.1 github.com/gorilla/context v1.1.1 github.com/gorilla/mux v1.6.2 github.com/gorilla/rpc v1.1.0 @@ -34,7 +34,7 @@ require ( github.com/kkdai/bstream v0.0.0-20181106074824-b3251f7901ec // indirect github.com/lbryio/errors.go v0.0.0-20180223142025-ad03d3cc6a5c github.com/lbryio/lbry.go v0.0.0-20190109223729-30c312501602 - github.com/lbryio/types v0.0.0-20181001180206-594241d24e00 + github.com/lbryio/types v0.0.0-20190422033210-321fb2abda9c github.com/lyoshenka/bencode v0.0.0-20180323155644-b7abd7672df5 github.com/miekg/dns v1.0.8 github.com/mitchellh/mapstructure v1.1.2 // indirect diff --git a/go.sum b/go.sum index 7e219d2..e8f4ee1 100644 --- a/go.sum +++ b/go.sum @@ -45,6 +45,8 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk= @@ -102,6 +104,8 @@ github.com/lbryio/types v0.0.0-20171215152337-0a913ba650dd h1:5wQgwcaLqLMaFIPju2 github.com/lbryio/types v0.0.0-20171215152337-0a913ba650dd/go.mod h1:CG3wsDv5BiVYQd5i1Jp7wGsaVyjZTJshqXeWMVKsISE= github.com/lbryio/types v0.0.0-20181001180206-594241d24e00 h1:1qRpd8lcyVigX+kYkwQL13gpOURyytgvxZtuIQfPPX8= github.com/lbryio/types v0.0.0-20181001180206-594241d24e00/go.mod h1:CG3wsDv5BiVYQd5i1Jp7wGsaVyjZTJshqXeWMVKsISE= +github.com/lbryio/types v0.0.0-20190422033210-321fb2abda9c h1:m3O7561xBQ00lfUVayW4c6SnpVbUDQtPUwGcGYSUYQA= +github.com/lbryio/types v0.0.0-20190422033210-321fb2abda9c/go.mod h1:CG3wsDv5BiVYQd5i1Jp7wGsaVyjZTJshqXeWMVKsISE= github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5/go.mod h1:c2mYKRyMb1BPkO5St0c/ps62L4S0W2NAkaTXj9qEI+0= github.com/lusis/slack-test v0.0.0-20180109053238-3c758769bfa6/go.mod h1:sFlOUpQL1YcjhFVXhg1CG8ZASEs/Mf1oVb6H75JL/zg= github.com/lyoshenka/bencode v0.0.0-20180323155644-b7abd7672df5 h1:mG83tLXWSRdcXMWfkoumVwhcCbf3jHF9QKv/m37BkM0= diff --git a/reflector/blocklist.go b/reflector/blocklist.go index 2b06d43..54f7646 100644 --- a/reflector/blocklist.go +++ b/reflector/blocklist.go @@ -12,7 +12,8 @@ import ( "github.com/lbryio/reflector.go/wallet" "github.com/lbryio/lbry.go/extras/errors" - types "github.com/lbryio/types/go" + types1 "github.com/lbryio/types/v1/go" + types2 "github.com/lbryio/types/v2/go" "github.com/golang/protobuf/proto" log "github.com/sirupsen/logrus" @@ -96,9 +97,8 @@ func sdHashesForOutpoints(outpoints []string) (map[string]valOrErr, error) { node := wallet.NewNode() defer node.Shutdown() err := node.Connect([]string{ - "victor.lbry.tech:50001", - //"lbryumx1.lbry.io:50001", // cant use real servers until victor pushes bugfix - //"lbryumx2.lbry.io:50001", + "lbryumx1.lbry.io:50001", + "lbryumx2.lbry.io:50001", }, nil) if err != nil { return nil, err @@ -135,22 +135,39 @@ func sdHashesForOutpoints(outpoints []string) (map[string]valOrErr, error) { if err != nil { values[outpoint] = valOrErr{Err: err} continue - } - - claim := &types.Claim{} - err = proto.Unmarshal(value, claim) - if err != nil { - values[outpoint] = valOrErr{Err: err} + } else if value == nil { + values[outpoint] = valOrErr{Err: errors.Err("outpoint not found")} continue } - if claim.GetStream().GetSource().GetSourceType() != types.Source_lbry_sd_hash { - values[outpoint] = valOrErr{Err: errors.Err("source is nil or source type is not lbry_sd_hash")} - continue - } - - values[outpoint] = valOrErr{Value: hex.EncodeToString(claim.GetStream().GetSource().GetSource())} + hash, err := hashFromClaim(value) + values[outpoint] = valOrErr{Value: hash, Err: err} } return values, nil } + +func hashFromClaim(value []byte) (string, error) { + claim := &types1.Claim{} + err := proto.Unmarshal(value, claim) + if err != nil { + return "", err + } + + if claim.GetStream().GetSource().GetSourceType() == types1.Source_lbry_sd_hash && claim.GetStream().GetSource().GetSource() != nil { + return hex.EncodeToString(claim.GetStream().GetSource().GetSource()), nil + } + + claim2 := &types2.Claim{} + err = proto.Unmarshal(value, claim2) + if err != nil { + return "", err + } + + stream, ok := claim2.GetType().(*types2.Claim_Stream) + if !ok || stream == nil { + return "", errors.Err("not a stream claim") + } + + return hex.EncodeToString(claim2.GetStream().GetSource().GetSdHash()), nil +}