Skip to content

Commit 2e33783

Browse files
authored
Merge pull request #557 from code-payments/chore/proto-fetch-script
chore: add fetch-protos to aid in proto updates
2 parents b33cc11 + c3eeff9 commit 2e33783

19 files changed

Lines changed: 359 additions & 751 deletions

File tree

api/src/main/java/com/getcode/model/chat/MessageContent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@ sealed interface MessageContent {
340340
proto: MessageContentV1,
341341
): MessageContent? {
342342
return when (proto.typeCase) {
343-
ChatServiceV1.Content.TypeCase.LOCALIZED -> Localized(
343+
ChatServiceV1.Content.TypeCase.SERVER_LOCALIZED -> Localized(
344344
isFromSelf = false,
345-
value = proto.localized.keyOrText
345+
value = proto.serverLocalized.keyOrText
346346
)
347347

348348
ChatServiceV1.Content.TypeCase.EXCHANGE_DATA -> {

api/src/main/java/com/getcode/network/repository/TransactionRepository.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ class TransactionRepository @Inject constructor(
368368

369369
expected?.diff(produced)
370370
}
371-
TransactionService.ErrorDetails.TypeCase.INTENT_DENIED -> {
372-
errors.add("Denied: ${error.intentDenied.reason.name}")
371+
TransactionService.ErrorDetails.TypeCase.DENIED -> {
372+
errors.add("Denied: ${error.denied.reason}")
373373
}
374374
else -> Unit
375375
}
@@ -765,8 +765,8 @@ sealed class ErrorSubmitIntent(val value: Int) {
765765
return when (proto.code) {
766766
SubmitIntentResponse.Error.Code.DENIED -> {
767767
val reasons = proto.errorDetailsList.mapNotNull {
768-
if (!it.hasIntentDenied()) return@mapNotNull null
769-
DeniedReason.fromValue(it.intentDenied.reasonValue)
768+
if (!it.hasDenied()) return@mapNotNull null
769+
DeniedReason.fromValue(it.denied.codeValue)
770770
}
771771

772772
Denied(reasons)

api/src/main/java/com/getcode/network/repository/TransactionRepository_Swap.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ private suspend fun TransactionRepository.submit(intent: SwapIntent): Result<Swa
9191

9292
expected?.diff(produced)
9393
}
94-
TransactionService.ErrorDetails.TypeCase.INTENT_DENIED -> {
95-
errors.add("Denied: ${error.intentDenied.reason.name}")
94+
TransactionService.ErrorDetails.TypeCase.DENIED -> {
95+
errors.add("Denied: ${error.denied.reason}")
9696
}
9797
else -> Unit
9898
}

scripts/fetch-protos.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
root=$(pwd)
4+
REPO_URL="https://github.com/code-payments/code-protobuf-api"
5+
COMMIT_SHA=$1
6+
TEMP_DIR=$(mktemp -d)
7+
DEST_DIR="service/protos/src/main/proto"
8+
9+
# Clone the repository
10+
git clone "$REPO_URL" "$TEMP_DIR"
11+
12+
# Change to the cloned repository directory
13+
cd "$TEMP_DIR" || exit
14+
15+
# If a commit SHA is provided, checkout that commit
16+
if [ -n "$COMMIT_SHA" ]; then
17+
git checkout "$COMMIT_SHA"
18+
else
19+
git checkout main
20+
fi
21+
22+
# Create the destination directory if it doesn't exist
23+
mkdir -p "../../$DEST_DIR"
24+
25+
# Copy proto files
26+
if [ -d "proto" ]; then
27+
rsync -av --exclude='buf*' proto/ "${root}/$DEST_DIR/"
28+
echo "Proto files copied successfully."
29+
else
30+
echo "Error: 'proto' directory not found in the repository."
31+
exit 1
32+
fi
33+
34+
# Clean up: remove the temporary directory
35+
cd ../..
36+
rm -rf "$TEMP_DIR"
37+
38+
sh "${root}"/scripts/strip-proto-validation.sh

scripts/strip-proto-validation.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#
2+
# For all .proto files, strip the validation parameters & replace inline
3+
#
4+
5+
root=$(pwd)
6+
7+
# 1. hack: first add a couple newlines after all "];"
8+
find "${root}"/service/protos/src/main/proto -name "*.proto" -type f -exec sh -c "awk '{gsub(/];/, \"];\n\n\"); print}' {} > tmp && mv tmp {}" \;
9+
10+
# 2. strip everything between square brackets [...] ignoring lines starting with //
11+
find "${root}"/service/protos/src/main/proto -name "*.proto" -type f -exec sh -c "awk '!/^[[:space:]]*\/\// {gsub(/ \[.*\]/, \"\");} {print}' {} > tmp && mv tmp {}" \;
12+
13+
find "${root}"/service/protos/src/main/proto -name "*.proto" -type f | while read -r file; do
14+
awk '
15+
BEGIN { in_repeated = 0; buffer = "" }
16+
{
17+
if ($0 ~ /^[[:space:]]*(repeated|bytes|[A-Za-z0-9_]+).*=.*\[/) {
18+
in_repeated = 1
19+
buffer = $0
20+
} else if (in_repeated) {
21+
buffer = buffer " " $0
22+
}
23+
24+
if (in_repeated && $0 ~ /;/) {
25+
gsub(/\[.*\]/, "", buffer)
26+
print buffer
27+
in_repeated = 0
28+
buffer = ""
29+
} else if (!in_repeated && $0 !~ /^[[:space:]]*option[[:space:]]*\(validate\.required\)[[:space:]]*=[[:space:]]*true;/) {
30+
print $0
31+
}
32+
}
33+
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
34+
done
35+
36+
# 3. add a newline after all trailing } brackets
37+
#find "${root}"/service/protos/src/main/proto -name "*.proto" -type f -exec sh -c "awk '{gsub(/}/, \"}\n\"); print}' {} > tmp && mv tmp {}" \;
38+
39+
# 4. strip validate import statement
40+
find "${root}"/service/protos/src/main/proto -name "*.proto" -type f -exec sh -c "awk -v RS='' '{gsub(/import \"validate\/validate.proto\";/, \"\"); print}' {} > tmp && mv tmp {}" \;
41+
42+
# 5. add a newline after all trailing } brackets
43+
#find "${root}"/service/protos/src/main/proto -name "*.proto" -type f -exec sh -c "awk '{gsub(/}/, \"}\n\"); print}' {} > tmp && mv tmp {}" \;

service/protos/src/main/proto/badge/v1/badge_service.proto

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ service Badge {
88
// ResetBadgeCount resets an owner account's app icon badge count back to zero
99
rpc ResetBadgeCount(ResetBadgeCountRequest) returns (ResetBadgeCountResponse);
1010
}
11-
1211
message ResetBadgeCountRequest {
1312
// The owner account to clear badge count
1413
common.v1.SolanaAccountId owner = 1;
@@ -17,12 +16,9 @@ message ResetBadgeCountRequest {
1716
// mechanism to the RPC.
1817
common.v1.Signature signature = 2;
1918
}
20-
2119
message ResetBadgeCountResponse {
2220
Result result = 1;
2321
enum Result {
2422
OK = 0;
2523
}
26-
2724
}
28-

0 commit comments

Comments
 (0)