Skip to content

Commit f855afd

Browse files
authored
refactor: migrate Java XDR generator from xdrgen to SDK (#762)
1 parent 15ca931 commit f855afd

File tree

12 files changed

+1415
-21
lines changed

12 files changed

+1415
-21
lines changed

Makefile

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,16 @@ xdr/Stellar-internal.x \
1313
xdr/Stellar-contract-config-setting.x \
1414
xdr/Stellar-exporter.x
1515

16-
# xdrgen commit to use, see https://github.com/stellar/xdrgen
17-
XDRGEN_COMMIT=621d042b824f67ac65cc53d0e5e381e24aed4583
1816
# stellar-xdr commit to use, see https://github.com/stellar/stellar-xdr
1917
XDR_COMMIT=4b7a2ef7931ab2ca2499be68d849f38190b443ca
2018

2119
.PHONY: xdr xdr-clean xdr-update
2220

2321
xdr-generate: $(XDRS)
24-
docker run -it --rm -v $$PWD:/wd -w /wd ruby /bin/bash -c '\
25-
gem install specific_install -v 0.3.8 && \
26-
gem specific_install https://github.com/lightsail-network/xdrgen.git -b $(XDRGEN_COMMIT) && \
27-
xdrgen \
28-
--language java \
29-
--namespace org.stellar.sdk.xdr \
30-
--output src/main/java/org/stellar/sdk/xdr/ \
31-
$(XDRS)'
22+
docker run --rm -v $$PWD:/wd -w /wd ruby:3.4 /bin/bash -c '\
23+
cd xdr-generator && \
24+
bundle install --quiet && \
25+
bundle exec ruby generate.rb'
3226
./gradlew :spotlessApply
3327

3428
xdr/%.x:
@@ -38,4 +32,4 @@ xdr-clean:
3832
rm xdr/*.x || true
3933
find src/main/java/org/stellar/sdk/xdr -type f -name "*.java" ! -name "package-info.java" -delete
4034

41-
xdr-update: xdr-clean xdr-generate
35+
xdr-update: xdr-clean xdr-generate

src/main/java/org/stellar/sdk/xdr/Constants.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
public final class Constants {
77
private Constants() {}
88

9+
public static final int AUTH_MSG_FLAG_FLOW_CONTROL_BYTES_REQUESTED = 200;
10+
public static final int CONTRACT_COST_COUNT_LIMIT = 1024;
11+
public static final int LIQUIDITY_POOL_FEE_V18 = 30;
912
public static final int MASK_ACCOUNT_FLAGS = 0x7;
1013
public static final int MASK_ACCOUNT_FLAGS_V17 = 0xF;
11-
public static final int MAX_SIGNERS = 20;
14+
public static final int MASK_CLAIMABLE_BALANCE_FLAGS = 0x1;
15+
public static final int MASK_LEDGER_HEADER_FLAGS = 0x7;
16+
public static final int MASK_OFFERENTRY_FLAGS = 1;
1217
public static final int MASK_TRUSTLINE_FLAGS = 1;
1318
public static final int MASK_TRUSTLINE_FLAGS_V13 = 3;
1419
public static final int MASK_TRUSTLINE_FLAGS_V17 = 7;
15-
public static final int MASK_OFFERENTRY_FLAGS = 1;
16-
public static final int MASK_CLAIMABLE_BALANCE_FLAGS = 0x1;
17-
public static final int MASK_LEDGER_HEADER_FLAGS = 0x7;
18-
public static final int AUTH_MSG_FLAG_FLOW_CONTROL_BYTES_REQUESTED = 200;
19-
public static final int TX_ADVERT_VECTOR_MAX_SIZE = 1000;
20-
public static final int TX_DEMAND_VECTOR_MAX_SIZE = 1000;
2120
public static final int MAX_OPS_PER_TX = 100;
22-
public static final int LIQUIDITY_POOL_FEE_V18 = 30;
23-
public static final int SC_SPEC_DOC_LIMIT = 1024;
21+
public static final int MAX_SIGNERS = 20;
2422
public static final int SCSYMBOL_LIMIT = 32;
25-
public static final int CONTRACT_COST_COUNT_LIMIT = 1024;
23+
public static final int SC_SPEC_DOC_LIMIT = 1024;
24+
public static final int TX_ADVERT_VECTOR_MAX_SIZE = 1000;
25+
public static final int TX_DEMAND_VECTOR_MAX_SIZE = 1000;
2626
}

xdr-generator/Gemfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
source "https://rubygems.org"
2+
3+
gem "xdrgen", git: "https://github.com/stellar/xdrgen", branch: "master"
4+
5+
# Required for Ruby 3.4+ compatibility
6+
gem "base64"
7+
gem "benchmark"
8+
gem "bigdecimal"
9+
gem "logger"
10+
gem "mutex_m"

xdr-generator/Gemfile.lock

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
GIT
2+
remote: https://github.com/stellar/xdrgen
3+
revision: 9796d627a739533d0c158ce87fde349b5f764f8b
4+
branch: master
5+
specs:
6+
xdrgen (0.1.3)
7+
activesupport (~> 6)
8+
concurrent-ruby (<= 1.3.4)
9+
memoist (~> 0.11.0)
10+
slop (~> 3.4)
11+
treetop (~> 1.5.3)
12+
13+
GEM
14+
remote: https://rubygems.org/
15+
specs:
16+
activesupport (6.1.7.10)
17+
concurrent-ruby (~> 1.0, >= 1.0.2)
18+
i18n (>= 1.6, < 2)
19+
minitest (>= 5.1)
20+
tzinfo (~> 2.0)
21+
zeitwerk (~> 2.3)
22+
base64 (0.3.0)
23+
benchmark (0.5.0)
24+
bigdecimal (4.0.1)
25+
concurrent-ruby (1.3.4)
26+
i18n (1.14.8)
27+
concurrent-ruby (~> 1.0)
28+
logger (1.7.0)
29+
memoist (0.11.0)
30+
minitest (6.0.1)
31+
prism (~> 1.5)
32+
mutex_m (0.3.0)
33+
polyglot (0.3.5)
34+
prism (1.9.0)
35+
slop (3.6.0)
36+
treetop (1.5.3)
37+
polyglot (~> 0.3)
38+
tzinfo (2.0.6)
39+
concurrent-ruby (~> 1.0)
40+
zeitwerk (2.7.4)
41+
42+
PLATFORMS
43+
aarch64-linux
44+
ruby
45+
46+
DEPENDENCIES
47+
base64
48+
benchmark
49+
bigdecimal
50+
logger
51+
mutex_m
52+
xdrgen!
53+
54+
BUNDLED WITH
55+
2.6.9

xdr-generator/generate.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'xdrgen'
2+
require_relative 'generator/generator'
3+
4+
puts "Generating Java XDR classes..."
5+
6+
# Operate on the root directory of the repo.
7+
Dir.chdir("..")
8+
9+
# Compile the XDR files into Java.
10+
Xdrgen::Compilation.new(
11+
Dir.glob("xdr/*.x"),
12+
output_dir: "src/main/java/org/stellar/sdk/xdr/",
13+
generator: Generator,
14+
namespace: "org.stellar.sdk.xdr",
15+
).compile
16+
17+
puts "Done!"

0 commit comments

Comments
 (0)