Skip to content

Commit

Permalink
exp/hubble: print state changes using stx and goxdr (#1922)
Browse files Browse the repository at this point in the history
*** Condense above commits, from the Hubble initial commit.

* Serialize using goxdr and stx, add build tags.

* Update mod and sum.

* Actually add build tags.

* Update go list.

* Delete old pretty printers.

* Change panic to return error.
  • Loading branch information
debnil authored Nov 14, 2019
1 parent d4cc14e commit a7cdc7f
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 165 deletions.
2 changes: 2 additions & 0 deletions exp/hubble/cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build go1.13

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions exp/hubble/pipeline.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build go1.13

package hubble

import (
Expand Down
158 changes: 0 additions & 158 deletions exp/hubble/pretty_printers.go

This file was deleted.

11 changes: 8 additions & 3 deletions exp/hubble/processors.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build go1.13

package hubble

import (
Expand All @@ -7,6 +9,7 @@ import (

"github.com/stellar/go/exp/ingest/io"
supportPipeline "github.com/stellar/go/exp/support/pipeline"
"github.com/stellar/go/support/errors"
"github.com/stellar/go/xdr"
)

Expand All @@ -23,7 +26,6 @@ func (p *PrettyPrintEntryProcessor) ProcessState(ctx context.Context, store *sup
defer w.Close()
defer r.Close()

prefix := "\t"
entryTypeSet := make(map[string]bool)
for {
entry, err := r.Read()
Expand Down Expand Up @@ -54,8 +56,11 @@ func (p *PrettyPrintEntryProcessor) ProcessState(ctx context.Context, store *sup
} else {
entryTypeSet[entryType] = true
}

fmt.Println(prettyPrintEntry(entry, prefix))
bytes, err := serializeLedgerEntryChange(entry)
if err != nil {
return errors.Wrap(err, "converting ledgerentry to json")
}
fmt.Printf("%s\n", bytes)

select {
case <-ctx.Done():
Expand Down
26 changes: 26 additions & 0 deletions exp/hubble/serializers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// +build go1.13

package hubble

import (
"bytes"

"github.com/stellar/go/xdr"
goxdr "github.com/xdrpp/goxdr/xdr"
"github.com/xdrpp/stc/stcdetail"
"github.com/xdrpp/stc/stx"
)

func serializeLedgerEntryChange(lec xdr.LedgerEntryChange) ([]byte, error) {
stxlec := stx.LedgerEntryChange{}
lecbytes, err := lec.MarshalBinary()
if err != nil {
return []byte{}, err
}
stx.XDR_LedgerEntryChange(&stxlec).XdrMarshal(&goxdr.XdrIn{In: bytes.NewReader(lecbytes)}, "")
j, err := stcdetail.XdrToJson(&stxlec)
if err != nil {
return []byte{}, err
}
return j, nil
}
4 changes: 3 additions & 1 deletion go.list
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ github.com/stretchr/testify v1.4.0
github.com/tyler-smith/go-bip39 v0.0.0-20180618194314-52158e4697b8
github.com/valyala/bytebufferpool v1.0.0
github.com/valyala/fasthttp v0.0.0-20170109085056-0a7f0a797cd6
github.com/xdrpp/goxdr v0.0.0-20191113231906-019d11aacd2b
github.com/xdrpp/stc v0.0.0-20191113232203-b257d8ace4e0
github.com/xeipuuv/gojsonpointer v0.0.0-20151027082146-e0fe6f683076
github.com/xeipuuv/gojsonreference v0.0.0-20150808065054-e02fc20de94c
github.com/xeipuuv/gojsonschema v0.0.0-20161231055540-f06f290571ce
Expand All @@ -91,7 +93,7 @@ github.com/yudai/gojsondiff v0.0.0-20170107030110-7b1b7adf999d
github.com/yudai/golcs v0.0.0-20150405163532-d1c525dea8ce
github.com/yudai/pp v2.0.1+incompatible
github.com/ziutek/mymysql v1.5.4
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297
golang.org/x/sync v0.0.0-20190423024810-112230192c58
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ require (
github.com/tyler-smith/go-bip39 v0.0.0-20180618194314-52158e4697b8
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v0.0.0-20170109085056-0a7f0a797cd6 // indirect
github.com/xdrpp/goxdr v0.0.0-20191113231906-019d11aacd2b
github.com/xdrpp/stc v0.0.0-20191113232203-b257d8ace4e0
github.com/xeipuuv/gojsonpointer v0.0.0-20151027082146-e0fe6f683076 // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20150808065054-e02fc20de94c // indirect
github.com/xeipuuv/gojsonschema v0.0.0-20161231055540-f06f290571ce // indirect
Expand All @@ -83,7 +85,7 @@ require (
github.com/yudai/golcs v0.0.0-20150405163532-d1c525dea8ce // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
github.com/ziutek/mymysql v1.5.4 // indirect
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 // indirect
golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c // indirect
google.golang.org/appengine v1.6.1 // indirect
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v0.0.0-20170109085056-0a7f0a797cd6 h1:s0IDmR1jFyWvOK7jVIuAsmHQaGkXUuTas8NXFUOwuAI=
github.com/valyala/fasthttp v0.0.0-20170109085056-0a7f0a797cd6/go.mod h1:+g/po7GqyG5E+1CNgquiIxJnsXEi5vwFn5weFujbO78=
github.com/xdrpp/goxdr v0.0.0-20191113231906-019d11aacd2b h1:fZpzAs5CSbVHO2lBuENWmWzFQqgq35tWXJ+LeZgKncg=
github.com/xdrpp/goxdr v0.0.0-20191113231906-019d11aacd2b/go.mod h1:vklyPo9Sphl4lZx+IoQW0wPnqMMRmuCINPDfSzwtJVw=
github.com/xdrpp/stc v0.0.0-20191113232203-b257d8ace4e0 h1:4NdjufN0yEQL8PcEXWRIPw6x1ThKuSVgejbUqMoZSLM=
github.com/xdrpp/stc v0.0.0-20191113232203-b257d8ace4e0/go.mod h1:gl+ezqvAgwkHN6CbzPoWFnbpIETeDQdBLHws3TaNDo4=
github.com/xeipuuv/gojsonpointer v0.0.0-20151027082146-e0fe6f683076 h1:KM4T3G70MiR+JtqplcYkNVoNz7pDwYaBxWBXQK804So=
github.com/xeipuuv/gojsonpointer v0.0.0-20151027082146-e0fe6f683076/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonreference v0.0.0-20150808065054-e02fc20de94c h1:XZWnr3bsDQWAZg4Ne+cPoXRPILrNlPNQfxBuwLl43is=
Expand All @@ -188,8 +192,8 @@ github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A=
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708 h1:pXVtWnwHkrWD9ru3sDxY/qFK/bfc0egRovX91EjWjf4=
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down

0 comments on commit a7cdc7f

Please sign in to comment.