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

Sample protos build #5582

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ debug
*.db
*.conf
*.lock
.proto_checksums
45 changes: 45 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,48 @@ xdr-clean:
rm $(DOWNLOADABLE_XDRS) || true

xdr-update: xdr-clean xdr


##############
PROTO_DIR := protos
GEN_SUFFIX := .pb.go
PROTO_FILES := $(shell find $(PROTO_DIR) -name "*.proto")
PROTO_CHECKSUM := .proto_checksums

generate-proto:
@echo "Regenerating proto files..."
@touch $(PROTO_CHECKSUM)
@current_checksum=$$(sha256sum $(PROTO_FILES) | sha256sum | awk '{print $$1}'); \
stored_checksum=$$(cat $(PROTO_CHECKSUM)); \
if [ "$${current_checksum}" != "$${stored_checksum}" ]; then \
echo "Changes detected. Regenerating all proto files..."; \
MAP_OPTS=$$(for file in $(PROTO_FILES); do \
rel_path=$$(echo $$file | sed 's|$(PROTO_DIR)/||'); \
pkg_path=$$(dirname $$rel_path); \
go_pkg="github.com/stellar/go/ingest/$$pkg_path"; \
printf "M%s=%s," "$$rel_path" "$$go_pkg"; \
done); \
MAP_OPTS=$${MAP_OPTS%,}; \
echo "Running protoc with options:"; \
echo " --go_out=ingest"; \
echo " --go_opt=paths=source_relative"; \
echo " --go_opt=$$MAP_OPTS"; \
echo "Proto Files: $(PROTO_FILES)"; \
protoc -I=$(PROTO_DIR) \
--go_out=ingest --go_opt=paths=source_relative \
--go_opt=$$MAP_OPTS \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use -go_opt with the M flag to indicate what the package location/path inside the generated proto should look like

$(PROTO_FILES); \
echo "$${current_checksum}" > $(PROTO_CHECKSUM); \
else \
echo "No changes detected in proto files."; \
fi


regenerate-proto: $(PROTO_CHECKSUM)
rm -f $(PROTO_CHECKSUM)
$(MAKE) generate-proto

$(PROTO_CHECKSUM):
@touch $(PROTO_CHECKSUM)

.PHONY: generate-proto regenerate-proto
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ require (
github.com/docker/docker v27.3.1+incompatible
github.com/docker/go-connections v0.5.0
github.com/fsouza/fake-gcs-server v1.49.2
google.golang.org/protobuf v1.34.2
)

require (
Expand All @@ -85,6 +86,7 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gobuffalo/packd v1.0.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/renameio/v2 v2.0.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
Expand Down Expand Up @@ -134,7 +136,6 @@ require (
github.com/fatih/structs v1.0.0 // indirect
github.com/gavv/monotime v0.0.0-20161010190848-47d58efa6955 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-querystring v0.0.0-20160401233042-9235644dd9e5 // indirect
github.com/googleapis/gax-go/v2 v2.12.4 // indirect
Expand Down Expand Up @@ -178,7 +179,6 @@ require (
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/grpc v1.64.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
213 changes: 213 additions & 0 deletions ingest/address/address.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions ingest/address/address_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package address

import (
"fmt"
)

func (a *Address) BetterString() string {
switch addr := a.AddressType.(type) {
case *Address_SmartContractAddress:
return fmt.Sprintf("Smart Contract Address: %s", addr.SmartContractAddress)
case *Address_AccountAddress:
return fmt.Sprintf("Account Address: %s", addr.AccountAddress)
case *Address_LiquidityPoolHash:
return fmt.Sprintf("Liquidity Pool Hash: %s", addr.LiquidityPoolHash)
case *Address_ClaimableBalanceId:
return fmt.Sprintf("Claimable Balance ID: %s", addr.ClaimableBalanceId)
default:
return "Unknown Address Type"
}
}
Loading
Loading