Skip to content

Commit

Permalink
Add random XDR generator
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirms committed Apr 2, 2021
1 parent 339647f commit 4e09c0a
Show file tree
Hide file tree
Showing 17 changed files with 17,394 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ commands:
name: Check generated code
command: ./gogenerate.sh

# checkgoxdr validates that any goxdr generated code has been updated if needed.
checkgoxdr:
steps:
- checkout
- run:
name: Check goxdr generated code
command: ./checkgoxdr.sh

# govet does govet checks in the entire codebase.
govet:
steps:
Expand Down Expand Up @@ -240,6 +248,7 @@ jobs:
- check_go_deps
- gofmt
- gogenerate
- checkgoxdr
- govet
- staticcheck
- build_packages
Expand Down
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 $@~ $@
8 changes: 8 additions & 0 deletions checkgoxdr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash
set -e

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 make gxdr/xdr_generated.go. Run make gxdr/xdr_generated.go locally and update generated files." && exit 1)
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
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

0 comments on commit 4e09c0a

Please sign in to comment.