Skip to content

Commit

Permalink
fix: build fail after updating protobufs (#1830)
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Lebedev <[email protected]>
  • Loading branch information
thenswan authored May 29, 2024
1 parent 094eeb8 commit f98bf9c
Show file tree
Hide file tree
Showing 18 changed files with 759 additions and 14 deletions.
21 changes: 20 additions & 1 deletion scripts/update_protobufs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import subprocess
import sys
import re


print(">>> Usage: `" + sys.argv[0] + " branch`")
Expand Down Expand Up @@ -83,12 +84,28 @@ def go_to_script_dir():
"option java_package = \"com.hedera.hashgraph.sdk.proto.mirror\";")
)

PROTO_REPLACEMENTS_IMPORTS = (
# Match any import statement and captures just the part after the last /
# for example, `import "state/common.proto"` -> `import "common.proto"`
(r'import ".*\/(.*\.proto)"',
r'import "\1"'),
)

def do_replacements(s, replacements):
for r in replacements:
s = s.replace(r[0], r[1])
return s

def do_replacements_proto_imports(s, replacements):
for r in replacements:
# Check if the replacement should be skipped
# Skip statements like `import "google/protobuf/wrappers.proto"`
# to update imports ONLY referred to hedera protobufs
if 'google' in s:
continue
s = re.sub(r[0], r[1], s)
return s




Expand Down Expand Up @@ -220,7 +237,9 @@ def do_generate_modified_protos(in_path, out_path):
# for name in os.listdir(in_path):
in_file = open(os.path.join(root, name), "r")
out_file = open(os.path.join(out_path, name), "w")
out_file.write(do_replacements(in_file.read(), PROTO_REPLACEMENTS))
file_contents_after_proto_replacements = do_replacements(in_file.read(), PROTO_REPLACEMENTS)
file_contents_after_proto_import_replacements = do_replacements_proto_imports(file_contents_after_proto_replacements, PROTO_REPLACEMENTS_IMPORTS)
out_file.write(file_contents_after_proto_import_replacements)
in_file.close()
out_file.close()

Expand Down
30 changes: 29 additions & 1 deletion sdk/src/main/java/com/hedera/hashgraph/sdk/RequestType.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,27 @@ public enum RequestType {
/**
* Update the metadata of one or more NFT's of a specific token type.
*/
TOKEN_UPDATE_NFTS(HederaFunctionality.TokenUpdateNfts);
TOKEN_UPDATE_NFTS(HederaFunctionality.TokenUpdateNfts),

/**
* Create a node
*/
NODE_CREATE(HederaFunctionality.NodeCreate),

/**
* Update a node
*/
NODE_UPDATE(HederaFunctionality.NodeUpdate),

/**
* Delete a node
*/
NODE_DELETE(HederaFunctionality.NodeDelete),

/**
* Get Node information
*/
NODE_GET_INFO(HederaFunctionality.NodeGetInfo);

final HederaFunctionality code;

Expand Down Expand Up @@ -482,6 +502,10 @@ static RequestType valueOf(HederaFunctionality code) {
case UtilPrng -> PRNG;
case TransactionGetFastRecord -> TRANSACTION_GET_FAST_RECORD;
case TokenUpdateNfts -> TOKEN_UPDATE_NFTS;
case NodeCreate -> NODE_CREATE;
case NodeUpdate -> NODE_UPDATE;
case NodeDelete -> NODE_DELETE;
case NodeGetInfo -> NODE_GET_INFO;
default -> throw new IllegalStateException("(BUG) unhandled HederaFunctionality");
};
}
Expand Down Expand Up @@ -564,6 +588,10 @@ public String toString() {
case PRNG -> "PRNG";
case TRANSACTION_GET_FAST_RECORD -> "TRANSACTION_GET_FAST_RECORD";
case TOKEN_UPDATE_NFTS -> "TOKEN_UPDATE_NFTS";
case NODE_CREATE -> "NODE_CREATE";
case NODE_UPDATE -> "NODE_UPDATE";
case NODE_DELETE -> "NODE_DELETE";
case NODE_GET_INFO -> "NODE_GET_INFO";
};
}
}
57 changes: 56 additions & 1 deletion sdk/src/main/java/com/hedera/hashgraph/sdk/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,53 @@ public enum Status {
/**
* Admin key is not set on token
*/
TOKEN_HAS_NO_ADMIN_KEY(ResponseCodeEnum.TOKEN_HAS_NO_ADMIN_KEY);
TOKEN_HAS_NO_ADMIN_KEY(ResponseCodeEnum.TOKEN_HAS_NO_ADMIN_KEY),

/**
* The node has been marked as deleted
*/
NODE_DELETED(ResponseCodeEnum.NODE_DELETED),

/**
* A node is not found during update and delete node transaction
*/
INVALID_NODE_ID(ResponseCodeEnum.INVALID_NODE_ID),

/**
* gossip_endpoint has a fully qualified domain name instead of ip
*/
INVALID_GOSSIP_ENDPOINT(ResponseCodeEnum.INVALID_GOSSIP_ENDPOINT),

/**
* The node account_id is invalid
*/
INVALID_NODE_ACCOUNT_ID(ResponseCodeEnum.INVALID_NODE_ACCOUNT_ID),

/**
* The node description is invalid
*/
INVALID_NODE_DESCRIPTION(ResponseCodeEnum.INVALID_NODE_DESCRIPTION),

/**
* service_endpoint is invalid
*/
INVALID_SERVICE_ENDPOINT(ResponseCodeEnum.INVALID_SERVICE_ENDPOINT),

/**
* gossip_ca_certificate is invalid
*/
INVALID_GOSSIP_CAE_CERTIFICATE(ResponseCodeEnum.INVALID_GOSSIP_CAE_CERTIFICATE),

/**
* grpc_certificate_hash is invalid
*/
INVALID_GRPC_CERTIFICATE(ResponseCodeEnum.INVALID_GRPC_CERTIFICATE),

/**
* The maximum automatic associations value is not valid.<br/>
* The most common cause for this error is a value less than `-1`.
*/
INVALID_MAX_AUTO_ASSOCIATIONS(ResponseCodeEnum.INVALID_MAX_AUTO_ASSOCIATIONS);

final ResponseCodeEnum code;

Expand Down Expand Up @@ -1855,6 +1901,15 @@ static Status valueOf(ResponseCodeEnum code) {
case MISSING_TOKEN_METADATA -> MISSING_TOKEN_METADATA;
case MISSING_SERIAL_NUMBERS -> MISSING_SERIAL_NUMBERS;
case TOKEN_HAS_NO_ADMIN_KEY -> TOKEN_HAS_NO_ADMIN_KEY;
case NODE_DELETED -> NODE_DELETED;
case INVALID_NODE_ID -> INVALID_NODE_ID;
case INVALID_GOSSIP_ENDPOINT -> INVALID_GOSSIP_ENDPOINT;
case INVALID_NODE_ACCOUNT_ID -> INVALID_NODE_ACCOUNT_ID;
case INVALID_NODE_DESCRIPTION -> INVALID_NODE_DESCRIPTION;
case INVALID_SERVICE_ENDPOINT -> INVALID_SERVICE_ENDPOINT;
case INVALID_GOSSIP_CAE_CERTIFICATE -> INVALID_GOSSIP_CAE_CERTIFICATE;
case INVALID_GRPC_CERTIFICATE -> INVALID_GRPC_CERTIFICATE;
case INVALID_MAX_AUTO_ASSOCIATIONS -> INVALID_MAX_AUTO_ASSOCIATIONS;
case UNRECOGNIZED ->
// NOTE: Protobuf deserialization will not give us the code on the wire
throw new IllegalArgumentException(
Expand Down
65 changes: 65 additions & 0 deletions sdk/src/main/proto/address_book_service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
syntax = "proto3";

package proto;

/*
* Hedera Network Services Protobuf
*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

option java_package = "com.hedera.hashgraph.sdk.proto";
// <<<pbj.java_package = "com.hedera.hapi.node.addressbook">>> This comment is special code for setting PBJ Compiler java package

import "query.proto";
import "response.proto";
import "transaction_response.proto";
import "transaction.proto";

/**
* Transactions for the AddressBook Service, those HAPI APIs facilitate changes to the nodes used across the Hedera network.
* All those transactions needs to be signed by the Hedera Council. Steps needed below:
* 1. The node operator creates and signs the transaction with their key (the key on the node operator account)
* 2. The node operator hands this transaction to Alex, who then gives it to the council to sign
* 3. When signed and submitted, the server will verify that account 2 keys have signed, and the keys on the operator account have signed.
* Hedera council should have ability to make all edits in addition to add/remove nodes
*/
service AddressBookService {
/**
* Prepare to add a new node to the network.
* When a valid council member initiates a HAPI transaction to add a new node,
* then the network should acknowledge the transaction and update the network’s Address Book within 24 hours.
* The added node will not be active until the network is upgraded.
*/
rpc createNode (Transaction) returns (TransactionResponse);

/**
* Prepare to delete the node to the network.
* The deleted node will not be deleted until the network is upgraded.
* Such a deleted node can never be reused.
*/
rpc deleteNode (Transaction) returns (TransactionResponse);

/**
* Prepare to update the node to the network.
* The node will not be updated until the network is upgraded.
*/
rpc updateNode (Transaction) returns (TransactionResponse);

/**
* Retrieves the node information by node Id.
*/
rpc getNodeInfo (Query) returns (Response);
}
41 changes: 34 additions & 7 deletions sdk/src/main/proto/basic_types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ message Key {
* contractID key, which also requires the code in the active message frame belong to the
* the contract with the given id.)
*/
ContractID delegatable_contract_id = 8;
ContractID delegatable_contract_id = 8;
}
}

Expand Down Expand Up @@ -1188,9 +1188,29 @@ enum HederaFunctionality {
TransactionGetFastRecord = 87;

/**
* Update the metadata of one or more NFT's of a specific token type.
*/
* Update the metadata of one or more NFT's of a specific token type.
*/
TokenUpdateNfts = 88;

/**
* Create a node
*/
NodeCreate = 89;

/**
* Update a node
*/
NodeUpdate = 90;

/**
* Delete a node
*/
NodeDelete = 91;

/**
* Get Node information
*/
NodeGetInfo = 92;
}

/**
Expand Down Expand Up @@ -1268,7 +1288,7 @@ message TransactionFeeSchedule {
/**
* Resource price coefficients
*/
FeeData feeData = 2 [deprecated=true];
FeeData feeData = 2 [deprecated = true];

/**
* Resource price coefficients. Supports subtype price definition.
Expand Down Expand Up @@ -1353,6 +1373,13 @@ message ServiceEndpoint {
* The port of the node
*/
int32 port = 2;

/**
* A node domain name
* This MUST be the fully qualified domain name of the node.
* This value MUST NOT be more than 253 characters.
*/
string domain_name = 3;
}

/**
Expand All @@ -1370,18 +1397,18 @@ message NodeAddress {
* The IP address of the Node with separator & octets encoded in UTF-8. Usage is deprecated,
* ServiceEndpoint is preferred to retrieve a node's list of IP addresses and ports
*/
bytes ipAddress = 1 [deprecated=true];
bytes ipAddress = 1 [deprecated = true];

/**
* The port number of the grpc server for the node. Usage is deprecated, ServiceEndpoint is
* preferred to retrieve a node's list of IP addresses and ports
*/
int32 portno = 2 [deprecated=true];
int32 portno = 2 [deprecated = true];

/**
* Usage is deprecated, nodeAccountId is preferred to retrieve a node's account ID
*/
bytes memo = 3 [deprecated=true];
bytes memo = 3 [deprecated = true];

/**
* The node's X509 RSA public key used to sign stream files (e.g., record stream
Expand Down
8 changes: 6 additions & 2 deletions sdk/src/main/proto/crypto_create.proto
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ message CryptoCreateTransactionBody {
string memo = 13;

/**
* The maximum number of tokens that an Account can be implicitly associated with. Defaults to 0
* and up to a maximum value of 1000.
* The maximum number of tokens that can be auto-associated with the account.<br/>
* If this is less than or equal to `used_auto_associations`, or 0, then this account
* MUST manually associate with a token before transacting in that token.<br/>
* This value MAY also be `-1` to indicate no limit.<br/>
* This value MUST NOT be less than `-1`.<br/>
* By default this value is 0 for accounts except for auto-created accounts which default -1.
*/
int32 max_automatic_token_associations = 14;

Expand Down
8 changes: 6 additions & 2 deletions sdk/src/main/proto/crypto_update.proto
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ message CryptoUpdateTransactionBody {
google.protobuf.StringValue memo = 14;

/**
* The maximum number of tokens that an Account can be implicitly associated with. Up to a 1000
* including implicit and explicit associations.
* If set, modify the maximum number of tokens that can be auto-associated with the
* account.<br/>
* If this is set and less than or equal to `used_auto_associations`, or 0, then this account
* MUST manually associate with a token before transacting in that token.<br/>
* This value MAY also be `-1` to indicate no limit.<br/>
* This value MUST NOT be less than `-1`.
*/
google.protobuf.Int32Value max_automatic_token_associations = 15;

Expand Down
Loading

0 comments on commit f98bf9c

Please sign in to comment.