Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xdr: Add random XDR generator #3523

Merged
merged 4 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Docker build targets use an optional "TAG" environment
# variable can be set to use custom tag name. For example:
# TAG=my-registry.example.com/keystore:dev make keystore
XDRS = xdr/Stellar-SCP.x \
xdr/Stellar-ledger-entries.x \
xdr/Stellar-ledger.x \
xdr/Stellar-overlay.x \
xdr/Stellar-transaction.x \
xdr/Stellar-types.x

keystore:
$(MAKE) -C services/keystore/ docker-build
Expand All @@ -18,4 +24,8 @@ recoverysigner:
$(MAKE) -C exp/services/recoverysigner/ docker-build

regulated-assets-approval-server:
$(MAKE) -C services/regulated-assets-approval-server/ docker-build
$(MAKE) -C services/regulated-assets-approval-server/ docker-build

gxdr/xdr_generated.go: $(XDRS)
go run github.com/xdrpp/goxdr/cmd/goxdr -p gxdr -enum-comments -o $@~ $(XDRS)
cmp $@~ $@ 2> /dev/null || mv -f $@~ $@
1 change: 1 addition & 0 deletions go.list
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ github.com/stretchr/testify v1.5.1
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.1.0
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 Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ 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.1.0
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 Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ 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.1.0 h1:464WVKpe16VazriMaPxuGZtU/oE0Bxr5q5hLGs2I0rs=
github.com/xdrpp/goxdr v0.1.0/go.mod h1:sIkGTrelHHneJXYd+dJGuziv4dWDofbdMl+onW+E3x8=
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 Down
3 changes: 3 additions & 0 deletions gogenerate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ command -v go-bindata >/dev/null 2>&1 || (
printf "Running go generate...\n"
go generate ./...

printf "Running make gxdr/xdr_generated.go...\n"
make gxdr/xdr_generated.go

printf "Checking for no diff...\n"
git diff --exit-code || (echo "Files changed after running go generate. Run go generate ./... locally and update generated files." && exit 1)
25 changes: 25 additions & 0 deletions gxdr/dump.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gxdr

import (
"bytes"
"encoding"

goxdr "github.com/xdrpp/goxdr/xdr"
)

// Dump serializes the given goxdr value into binary.
func Dump(v goxdr.XdrType) []byte {
var buf bytes.Buffer
writer := goxdr.XdrOut{Out: &buf}
writer.Marshal("", v)
return buf.Bytes()
}

// Convert serializes the given goxdr value into another destination value
// which supports binary unmarshalling.
//
// This function can be used to convert github.com/xdrpp/goxdr/xdr values into
// equivalent https://github.com/stellar/go-xdr values.
func Convert(src goxdr.XdrType, dest encoding.BinaryUnmarshaler) error {
return dest.UnmarshalBinary(Dump(src))
}
Loading