diff --git a/exp/hubble/cmd/main.go b/exp/hubble/cmd/main.go index 2b8a8464c7..4d2556597a 100644 --- a/exp/hubble/cmd/main.go +++ b/exp/hubble/cmd/main.go @@ -1,3 +1,5 @@ +// +build go1.13 + package main import ( diff --git a/exp/hubble/pipeline.go b/exp/hubble/pipeline.go index 7f650bd8b7..aff9764b85 100644 --- a/exp/hubble/pipeline.go +++ b/exp/hubble/pipeline.go @@ -1,3 +1,5 @@ +// +build go1.13 + package hubble import ( diff --git a/exp/hubble/pretty_printers.go b/exp/hubble/pretty_printers.go deleted file mode 100644 index b5d8717058..0000000000 --- a/exp/hubble/pretty_printers.go +++ /dev/null @@ -1,158 +0,0 @@ -package hubble - -import ( - "fmt" - - "github.com/stellar/go/xdr" -) - -// TODO: Rather than hand serializing every struct, use Go reflection and other type tricks -// to set up custom printing rules for certain types (i.e., AccountId and Sequence). -// Then, we can replace this hand serialization with the JSON package methods. -func prettyPrintEntry(entry xdr.LedgerEntryChange, prefix string) string { - entryString := "" - entryString += fmt.Sprintf("Type: %s\n", entry.Type) - entryString += fmt.Sprintf("Created: %s\n", prettyPrintLedgerEntry(entry.Created, prefix)) - entryString += fmt.Sprintf("Updated: %s\n", prettyPrintLedgerEntry(entry.Updated, prefix)) - entryString += fmt.Sprintf("Removed: %v\n", prettyPrintLedgerKey(entry.Removed, prefix)) - entryString += fmt.Sprintf("State: %s\n", prettyPrintLedgerEntry(entry.State, prefix)) - entryString += "\n" // For extra spacing when printing multiple entries. - return entryString -} - -func prettyPrintLedgerEntry(entry *xdr.LedgerEntry, prefix string) string { - if entry == nil { - return "" - } - entryString := "\n" - newPrefix := prefix + prefix - entryString += fmt.Sprintf("%sLastModifiedLedgerSeq: %d\n", prefix, entry.LastModifiedLedgerSeq) - entryString += fmt.Sprintf("%sData: %s\n", prefix, prettyPrintLedgerEntryData(entry.Data, newPrefix)) - entryString += fmt.Sprintf("%sExt: %v", prefix, entry.Ext) - return entryString -} - -func prettyPrintLedgerKey(key *xdr.LedgerKey, prefix string) string { - if key == nil { - return "" - } - keyString := "\n" - newPrefix := prefix + prefix - keyString += fmt.Sprintf("%sType: %s\n", prefix, key.Type) - keyString += fmt.Sprintf("%sAccount: %s\n", prefix, prettyPrintLedgerKeyAccount(key.Account, newPrefix)) - keyString += fmt.Sprintf("%sTrustLine: %s\n", prefix, prettyPrintLedgerKeyTrustLine(key.TrustLine, newPrefix)) - keyString += fmt.Sprintf("%sOffer: %s\n", prefix, prettyPrintLedgerKeyOffer(key.Offer, newPrefix)) - keyString += fmt.Sprintf("%sData: %s", prefix, prettyPrintLedgerKeyData(key.Data, newPrefix)) - return keyString -} - -func prettyPrintLedgerKeyAccount(account *xdr.LedgerKeyAccount, prefix string) string { - if account == nil { - return "" - } - keyString := "\n" - keyString += fmt.Sprintf("%sAccountId: %s", prefix, account.AccountId.Address()) - return keyString -} - -func prettyPrintLedgerKeyTrustLine(trustline *xdr.LedgerKeyTrustLine, prefix string) string { - if trustline == nil { - return "" - } - keyString := "\n" - keyString += fmt.Sprintf("%sAccountId: %s\n", prefix, trustline.AccountId.Address()) - keyString += fmt.Sprintf("%sAsset: %s", prefix, trustline.Asset) - return keyString -} - -func prettyPrintLedgerKeyOffer(offer *xdr.LedgerKeyOffer, prefix string) string { - if offer == nil { - return "" - } - keyString := "\n" - keyString += fmt.Sprintf("%sSellerId: %s\n", prefix, offer.SellerId.Address()) - keyString += fmt.Sprintf("%sOfferId: %d", prefix, offer.OfferId) - return keyString -} - -func prettyPrintLedgerKeyData(data *xdr.LedgerKeyData, prefix string) string { - if data == nil { - return "" - } - keyString := "\n" - keyString += fmt.Sprintf("%sAccountId: %s\n", prefix, data.AccountId.Address()) - keyString += fmt.Sprintf("%sDataName: %s", prefix, data.DataName) - return keyString -} - -func prettyPrintLedgerEntryData(data xdr.LedgerEntryData, prefix string) string { - entryString := "\n" - newPrefix := prefix + prefix - entryString += fmt.Sprintf("%sType: %s\n", prefix, data.Type) - entryString += fmt.Sprintf("%sOffer: %s\n", prefix, prettyPrintOfferEntry(data.Offer, newPrefix)) - entryString += fmt.Sprintf("%sData: %s\n", prefix, prettyPrintDataEntry(data.Data, newPrefix)) - entryString += fmt.Sprintf("%sTrustLine: %s\n", prefix, prettyPrintTrustlineEntry(data.TrustLine, newPrefix)) - entryString += fmt.Sprintf("%sAccount: %s", prefix, prettyPrintAccountEntry(data.Account, newPrefix)) - return entryString -} - -func prettyPrintOfferEntry(offerEntry *xdr.OfferEntry, prefix string) string { - if offerEntry == nil { - return "" - } - entryString := "\n" - entryString += fmt.Sprintf("%sSellerId: %s\n", prefix, offerEntry.SellerId.Address()) - entryString += fmt.Sprintf("%sOfferId: %d\n", prefix, offerEntry.OfferId) - entryString += fmt.Sprintf("%sSelling: %s\n", prefix, offerEntry.Selling.String()) - entryString += fmt.Sprintf("%sBuying: %s\n", prefix, offerEntry.Buying.String()) - entryString += fmt.Sprintf("%sAmount: %d\n", prefix, offerEntry.Amount) - // TODO: Price may need custom rule to clarify numerator and denominator. - entryString += fmt.Sprintf("%sPrice: %v\n", prefix, offerEntry.Price) - entryString += fmt.Sprintf("%sFlags: %d\n", prefix, offerEntry.Flags) - entryString += fmt.Sprintf("%sExt: %v", prefix, offerEntry.Ext) - return entryString -} - -func prettyPrintDataEntry(dataEntry *xdr.DataEntry, prefix string) string { - if dataEntry == nil { - return "" - } - entryString := "\n" - entryString += fmt.Sprintf("%sAccountId: %s\n", prefix, dataEntry.AccountId.Address()) - entryString += fmt.Sprintf("%sDataName: %s\n", prefix, dataEntry.DataName) - entryString += fmt.Sprintf("%sDataValue: %x\n", prefix, dataEntry.DataValue) - entryString += fmt.Sprintf("%sExt: %v", prefix, dataEntry.Ext) - return entryString -} - -func prettyPrintTrustlineEntry(trustlineEntry *xdr.TrustLineEntry, prefix string) string { - if trustlineEntry == nil { - return "" - } - entryString := "\n" - entryString += fmt.Sprintf("%sAccountId: %s\n", prefix, trustlineEntry.AccountId.Address()) - entryString += fmt.Sprintf("%sAsset: %s\n", prefix, trustlineEntry.Asset.String()) - entryString += fmt.Sprintf("%sBalance: %d\n", prefix, trustlineEntry.Balance) - entryString += fmt.Sprintf("%sLimit: %d\n", prefix, trustlineEntry.Limit) - entryString += fmt.Sprintf("%sFlags: %d\n", prefix, trustlineEntry.Flags) - entryString += fmt.Sprintf("%sExt: %v", prefix, trustlineEntry.Ext) - return entryString -} - -func prettyPrintAccountEntry(accountEntry *xdr.AccountEntry, prefix string) string { - if accountEntry == nil { - return "" - } - entryString := "\n" - entryString += fmt.Sprintf("%sAccountId: %s\n", prefix, accountEntry.AccountId.Address()) - entryString += fmt.Sprintf("%sBalance: %d\n", prefix, accountEntry.Balance) - entryString += fmt.Sprintf("%sSeqNum: %d\n", prefix, accountEntry.SeqNum) - entryString += fmt.Sprintf("%sNumSubEntries: %d\n", prefix, accountEntry.NumSubEntries) - entryString += fmt.Sprintf("%sInflationDest: %s\n", prefix, accountEntry.InflationDest.Address()) - entryString += fmt.Sprintf("%sFlags: %d\n", prefix, accountEntry.Flags) - entryString += fmt.Sprintf("%sHomeDomain: %s\n", prefix, accountEntry.HomeDomain) - entryString += fmt.Sprintf("%sThresholds: %v\n", prefix, accountEntry.Thresholds) - entryString += fmt.Sprintf("%sSigners: %v\n", prefix, accountEntry.Signers) - entryString += fmt.Sprintf("%sExt: %v", prefix, accountEntry.Ext) - return entryString -} diff --git a/exp/hubble/processors.go b/exp/hubble/processors.go index d9a6966e38..7ad11b2aad 100644 --- a/exp/hubble/processors.go +++ b/exp/hubble/processors.go @@ -1,3 +1,5 @@ +// +build go1.13 + package hubble import ( @@ -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" ) @@ -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() @@ -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(): diff --git a/exp/hubble/serializers.go b/exp/hubble/serializers.go new file mode 100644 index 0000000000..5fdccbf6e2 --- /dev/null +++ b/exp/hubble/serializers.go @@ -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 +} diff --git a/go.list b/go.list index 7ee3f08b34..b69deeb330 100644 --- a/go.list +++ b/go.list @@ -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 @@ -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 diff --git a/go.mod b/go.mod index 634b4bba5c..fa5cc54189 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index a636208c97..dd0d37bb48 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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=