Skip to content

Commit af41987

Browse files
Karthik/5591/protos for ttp (stellar#5596)
* Ignore generated checksums file * Commit protos, generated code, helper code, and Makefile target * go mod tidy * Change address proto to be an enum + strkey representation of address * Update location of proto files from protos/ to protos/ingest to be consistent with where the generated code should appear This also helps simply the Makefile target Right now, yes, the protos that we need to work on need to be put in the /ingest path. Tomorrow, we may need to have generated go files in some other path for some other source code. At that time, redoing protos might be hard. * Add README.md * remove address helper * Add unit tests for ser-deser of Asset proto * newline * Test cases for token transfer event * Rework test fixture * variable names
1 parent 082069d commit af41987

15 files changed

Lines changed: 1624 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ debug
2121
*.db
2222
*.conf
2323
*.lock
24+
.proto_checksums

Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,48 @@ xdr-clean:
7373
rm $(DOWNLOADABLE_XDRS) || true
7474

7575
xdr-update: xdr-clean xdr
76+
77+
78+
##############
79+
PROTO_DIR := protos
80+
GEN_SUFFIX := .pb.go
81+
PROTO_FILES := $(shell find $(PROTO_DIR) -name "*.proto")
82+
PROTO_CHECKSUM := .proto_checksums
83+
84+
generate-proto:
85+
@echo "Regenerating proto files..."
86+
@touch $(PROTO_CHECKSUM)
87+
@current_checksum=$$(sha256sum $(PROTO_FILES) | sha256sum | awk '{print $$1}'); \
88+
stored_checksum=$$(cat $(PROTO_CHECKSUM)); \
89+
if [ "$${current_checksum}" != "$${stored_checksum}" ]; then \
90+
echo "Changes detected. Regenerating all proto files..."; \
91+
MAP_OPTS=$$(for file in $(PROTO_FILES); do \
92+
rel_path=$$(echo $$file | sed 's|$(PROTO_DIR)/||'); \
93+
pkg_path=$$(dirname $$rel_path); \
94+
go_pkg="github.com/stellar/go/$$pkg_path"; \
95+
printf "M%s=%s," "$$rel_path" "$$go_pkg"; \
96+
done); \
97+
MAP_OPTS=$${MAP_OPTS%,}; \
98+
echo "Running protoc with options:"; \
99+
echo " --go_out=."; \
100+
echo " --go_opt=paths=source_relative"; \
101+
echo " --go_opt=$$MAP_OPTS"; \
102+
echo "Proto Files: $(PROTO_FILES)"; \
103+
protoc -I=$(PROTO_DIR) \
104+
--go_out=. --go_opt=paths=source_relative \
105+
--go_opt=$$MAP_OPTS \
106+
$(PROTO_FILES); \
107+
echo "$${current_checksum}" > $(PROTO_CHECKSUM); \
108+
else \
109+
echo "No changes detected in proto files."; \
110+
fi
111+
112+
113+
regenerate-proto: $(PROTO_CHECKSUM)
114+
rm -f $(PROTO_CHECKSUM)
115+
$(MAKE) generate-proto
116+
117+
$(PROTO_CHECKSUM):
118+
@touch $(PROTO_CHECKSUM)
119+
120+
.PHONY: generate-proto regenerate-proto

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ In addition to the other top-level packages, there are a few special directories
4545
* **support/scripts** contains single-file go programs and bash scripts used to support the development of this repo.
4646
* **services** contains packages that compile to applications that are long-running processes (such as API servers).
4747
* **tools** contains packages that compile to command line applications.
48+
* **protos** contains the protobuf definitions for data-models that we want to generate for use with external stakeholders. Refer to [protos/README.md](./protos/README.md) for more information about code structure in `protos` directory
4849

4950
Each of these directories have their own README file that explain further the nature of their contents.
5051

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ require (
178178
google.golang.org/appengine v1.6.8 // indirect
179179
google.golang.org/genproto v0.0.0-20240528184218-531527333157 // indirect
180180
google.golang.org/grpc v1.64.1 // indirect
181-
google.golang.org/protobuf v1.34.2 // indirect
181+
google.golang.org/protobuf v1.34.2
182182
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
183183
gopkg.in/yaml.v3 v3.0.1 // indirect
184184
)

ingest/address/address.pb.go

Lines changed: 206 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ingest/asset/asset.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package asset
2+
3+
// NewNativeAsset creates an Asset representing the native token (XLM).
4+
func NewNativeAsset() *Asset {
5+
return &Asset{AssetType: &Asset_Native{Native: true}}
6+
}
7+
8+
// NewIssuedAsset creates an Asset with an asset code and issuer.
9+
func NewIssuedAsset(assetCode, issuer string) *Asset {
10+
return &Asset{
11+
AssetType: &Asset_IssuedAsset{
12+
IssuedAsset: &IssuedAsset{
13+
AssetCode: assetCode,
14+
Issuer: issuer,
15+
},
16+
},
17+
}
18+
}

0 commit comments

Comments
 (0)