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

Initial draft of PBJ types for token state #263

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ba1af89
Add HCS state proto
tinker-michaelj Mar 1, 2023
214df5f
Add running hash, delete EntityNumber
tinker-michaelj Mar 1, 2023
b39dec9
add account and token
Neeharika-Sompalli Mar 24, 2023
f624257
add account and token
Neeharika-Sompalli Mar 24, 2023
5f39ec7
add token
Neeharika-Sompalli Mar 24, 2023
a5db1cc
add tokenRelation
Neeharika-Sompalli Mar 24, 2023
a718906
Merge branch 'main' into 05111-use-pbj-for-token-state
Neeharika-Sompalli Mar 29, 2023
3bd2503
add some javadocs
Neeharika-Sompalli Mar 29, 2023
f7ac736
add some javadocs
Neeharika-Sompalli Mar 30, 2023
6a8cb7e
Merge branch 'main' into 05111-use-pbj-for-token-state
Neeharika-Sompalli Mar 30, 2023
435cea9
address review comments
Neeharika-Sompalli Mar 30, 2023
ffb79b3
fix missing import
Neeharika-Sompalli Mar 30, 2023
bc3564e
address comments
Neeharika-Sompalli Apr 4, 2023
1a71497
address review comments
Neeharika-Sompalli Apr 5, 2023
db3e917
Update services/state/token/account.proto
Neeharika-Sompalli Apr 11, 2023
04d9470
Update services/state/token/account.proto
Neeharika-Sompalli Apr 11, 2023
f2158c3
address some review comments
Neeharika-Sompalli Apr 11, 2023
36ceb52
move back under services
Neeharika-Sompalli Apr 11, 2023
b65ba3b
change package name
Neeharika-Sompalli Apr 12, 2023
1ebc222
some docs and revert java package name
Neeharika-Sompalli Apr 12, 2023
8f54afe
revert docs
Neeharika-Sompalli Apr 12, 2023
1939032
add javadocs
Neeharika-Sompalli Apr 12, 2023
a871898
add javadocs
Neeharika-Sompalli Apr 12, 2023
1236702
re-order the first 16
Neeharika-Sompalli Apr 12, 2023
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ must be paid in ℏ from a cryptocurrency account. The payer authorizes a
fee by signing an appropriate transaction with a sufficient subset of the
Ed25519 key(s) associated to their account.

## Overview of state
State directory and its subdirectories contain the protobuf files that define the state of the network.
The state is divided into the following subdirectories, based on the service modules:
1. [Token](services/state/token) - The state of the Token service.
2. [Consensus](services/state/consensus) - The state of the Consensus service.

The state directory and its subdirectories are in preview and are subject to change.

# For Developers

## Branching
Expand Down
185 changes: 185 additions & 0 deletions services/state/token/account.proto
Neeharika-Sompalli marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
syntax = "proto3";

package proto;

/*-
* ‌
* Hedera Network Services Protobuf
* ​
* Copyright (C) 2018 - 2023 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.
* ‍
*/

import "basic_types.proto";
import "crypto_approve_allowance.proto";

option java_package = "com.hederahashgraph.api.proto.java";
Neeharika-Sompalli marked this conversation as resolved.
Show resolved Hide resolved
// <<<pbj.java_package = "com.hedera.hapi.node.state.token">>> This comment is special code for setting PBJ Compiler java package
Neeharika-Sompalli marked this conversation as resolved.
Show resolved Hide resolved
option java_multiple_files = true;

/**
* First-draft representation of a Hedera Token Service account entity in the network Merkle tree.
*
* As with all network entities, account has an unique entity number represented as shard.realm.X.
* X can be an alias public key or an EVM address or a number.
*
*/

message Account {
/**
* The unique entity number of the account. The shard and realm numbers are implied, based on the network
* this entity came from.
*/
int64 account_number = 1;
/**
* The alias to use for this account, if any.
*/
bytes alias = 2;
/**
* (Optional) The key to be used to sign transactions from the account, if any.
Copy link
Member

Choose a reason for hiding this comment

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

We should describe a little better as to when having a key is optional and when it is not. Most accounts require it. Only special accounts like 0.0.800 permit an empty key. Maybe we should document that.

Copy link
Member Author

Choose a reason for hiding this comment

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

And hollow accounts ?

* This key will not be set for hollow accounts until the account is finalized.
* This key should be set on all the accounts, except for immutable accounts (0.0.800 and 0.0.801).
*/
Key key = 3;
/**
* The expiration time of the account, in seconds since the epoch.
*/
int64 expiry = 4;
/**
* The balance of the account, in tiny-bars.
*/
int64 tinybar_balance = 5;
Neeharika-Sompalli marked this conversation as resolved.
Show resolved Hide resolved
/**
* An optional description of the account with UTF-8 encoding up to 100 bytes.
*/
string memo = 6;
/**
* A boolean marking if the account has been deleted.
*/
bool deleted = 7;
/**
* The amount of hbars staked to the account.
*/
int64 staked_to_me = 8;
/**
* If this account stakes to another account, its value will be -1. It will
* be set to the time when the account starts staking to a node.
*/
int64 stake_period_start = 9;
/**
* The node number or the account number this account is staked to.
* It is negative if staking to a node and positive if staking to an account and 0 if not staking to anyone.
* When staking to a node, it is stored as -node-1 to differentiate node 0.
*/
int64 staked_number = 10;
/**
* A boolean marking if the account declines rewards.
*/
bool decline_reward = 11;
/**
* A boolean marking if the account requires a receiver signature.
*/
bool receiver_sig_required = 12;
/**
* The token ID of the head of the linked list from token relations map for the account.
*/
int64 head_token_number = 13;
/**
* The NftId of the head of the linked list from unique tokens map for the account.
*/
int64 head_nft_id = 14;
/**
* The serial number of the head NftId of the linked list from unique tokens map for the account.
*/
int64 head_nft_serial_number = 15;
/**
* The number of NFTs owned by the account.
*/
int64 number_owned_nfts = 16;
/**
* The maximum number of tokens that can be auto-associated with the account.
*/
int32 max_auto_associations = 17;
/**
* The number of used auto-association slots.
*/
int32 used_auto_associations = 18;
/**
* The number of tokens associated with the account. This number is used for
* fee calculation during renewal of the account.
*/
int32 number_associations = 19;
/**
* A boolean marking if the account is a smart contract.
*/
bool smart_contract = 20;
/**
* The number of tokens with a positive balance associated with the account.
* If the account has positive balance in a token, it can not be deleted.
*/
int32 number_positive_balances = 21;
/**
* The nonce of the account, used for Ethereum interoperability.
*/
int64 ethereum_nonce = 22;
/**
* The amount of hbars staked to the account at the start of the last rewarded period.
*/
int64 stake_at_start_of_last_rewarded_period = 23;
/**
* (Optional) The number of an auto-renew account, in the same shard and realm as the account, that
* has signed a transaction allowing the network to use its balance to automatically extend the account's
* expiration time when it passes.
*/
int64 auto_renew_account_number = 24;
/**
* The number of seconds the network should automatically extend the account's expiration by, if the
* account has a valid auto-renew account, and is not deleted upon expiration.
* If this is not provided in a allowed range on account creation, the transaction will fail with INVALID_AUTO_RENEWAL_PERIOD.
* The default values for the minimum period and maximum period are 30 days and 90 days, respectively.
*/
int64 auto_renew_secs = 25;
/**
* If this account is a smart-contract, number of key-value pairs stored on the contract.
* This is used to determine the storage rent for the contract.
*/
int32 contract_kv_pairs_number = 26;
/**
* (Optional) List of crypto allowances approved by the account.
*/
repeated CryptoAllowance crypto_allowances = 27;
/**
* (Optional) List of non-fungible token allowances approved by the account.
*/
repeated NftAllowance nft_allowances = 28;

/**
* (Optional) List of fungible token allowances approved by the account.
*/
repeated TokenAllowance token_allowances = 29;
/**
* The number of tokens for which this account is treasury
*/
uint32 number_treasury_titles = 30;
/**
* A flag indicating if the account is expired and pending removal.
* Only the entity expiration system task toggles this flag when it reaches this account
* and finds it expired. Before setting the flag the system task checks if the account has
* an auto-renew account with balance. This is done to prevent a zero-balance account with a funded
* auto-renew account from being treated as expired in the interval between its expiration
* and the time the system task actually auto-renews it.
*/
bool expired_and_pending_removal = 31;
}
164 changes: 164 additions & 0 deletions services/state/token/token.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
syntax = "proto3";

package proto;

/*-
* ‌
* Hedera Network Services Protobuf
* ​
* Copyright (C) 2018 - 2023 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.
* ‍
*/

import "basic_types.proto";
import "custom_fees.proto";

option java_package = "com.hederahashgraph.api.proto.java";
// <<<pbj.java_package = "com.hedera.hapi.node.state.token">>> This comment is special code for setting PBJ Compiler java package
option java_multiple_files = true;

/**
* First-draft representation of a Hedera Token Service token entity in the network Merkle tree.
*
* As with all network entities, a token has a unique entity number, which is usually given along
* with the network's shard and realm in the form of a shard.realm.number id.
*/

message Token {
Neeharika-Sompalli marked this conversation as resolved.
Show resolved Hide resolved
/**
* The unique entity number of this token.
*/
int64 token_number = 1;
/**
* The human-readable name of this token and its not necessarily unique. Maximum length allowed is 100 bytes.
*/
string name = 2;
/**
* The human-readable symbol for the token. It is not necessarily unique. Maximum length allowed is 100 bytes.
*/
string symbol = 3;
/**
* The number of decimal places of this token. If decimals are 8 or 11, then the number of whole
* tokens can be at most a few billions or millions, respectively. For example, it could match
* Bitcoin (21 million whole tokens with 8 decimals) or hbars (50 billion whole tokens with 8 decimals).
* It could even match Bitcoin with milli-satoshis (21 million whole tokens with 11 decimals).
*/
int32 decimals = 4;
/**
* The total supply of this token.
*/
int64 total_supply = 5;
/**
* The treasury account number of this token. This account receives the initial supply of
* tokens as-well as the tokens from the Token Mint operation once executed. The balance
* of the treasury account is decreased when the Token Burn operation is executed.
*/
int64 treasury_account_number = 6;
/**
* (Optional) The admin key of this token. If this key is set, the token is mutable.
* A mutable token can be modified.
* If this key is not set on token creation, it cannot be modified.
*/
Key admin_key = 7;
/**
* (Optional) The kyc key of this token.
* If this key is not set on token creation, it can only be set if the token has admin key set.
*/
Key kyc_key = 8;
/**
* (Optional) The freeze key of this token. This key is needed for freezing the token.
* If this key is not set on token creation, it can only be set if the token has admin key set.
*/
Key freeze_key = 9;
/**
* (Optional) The wipe key of this token. This key is needed for wiping the token.
* If this key is not set on token creation, it can only be set if the token has admin key set.
*/
Key wipe_key = 10;
/**
* (Optional) The supply key of this token. This key is needed for minting or burning token.
* If this key is not set on token creation, it can only be set if the token has admin key set.
*/
Key supply_key = 11;
/**
* (Optional) The fee schedule key of this token. This key should be set, in order to make any
* changes to the custom fee schedule.
* If this key is not set on token creation, it can only be set if the token has admin key set.
*/
Key fee_schedule_key = 12;
/**
* (Optional) The pause key of this token. This key is needed for pausing the token.
* If this key is not set on token creation, it can only be set if the token has admin key set.
*/
Key pause_key = 13;
/**
* The last used serial number of this token.
*/
int64 last_used_serial_number = 14;
/**
* The flag indicating if this token is deleted.
*/
bool deleted = 15;
/**
* The type of this token. A token can be either FUNGIBLE_COMMON or NON_FUNGIBLE_UNIQUE.
* If it has been omitted during token creation, FUNGIBLE_COMMON type is used.
*/
TokenType token_type = 16;
/**
* The supply type of this token.A token can have either INFINITE or FINITE supply type.
* If it has been omitted during token creation, INFINITE type is used.
*/
TokenSupplyType supply_type = 17;
/**
* The number of the account (if any) that the network will attempt to charge for the
* token's auto-renewal upon expiration.
*/
int64 auto_renew_account_number = 18;
/**
* The number of seconds the network should automatically extend the token's expiration by, if the
* token has a valid auto-renew account, and is not deleted upon expiration.
* If this is not provided in a allowed range on token creation, the transaction will fail with INVALID_AUTO_RENEWAL_PERIOD.
* The default values for the minimum period and maximum period are 30 days and 90 days, respectively.
*/
int64 auto_renew_secs = 19;
/**
* The expiration time of the token, in seconds since the epoch.
*/
int64 expiry = 20;
/**
* An optional description of the token with UTF-8 encoding up to 100 bytes.
*/
string memo = 21;
/**
* The maximum supply of this token.
*/
int64 max_supply = 22;
/**
* The flag indicating if this token is paused.
*/
bool paused = 23;
/**
* The flag indicating if this token has accounts associated to it that are frozen by default.
*/
bool accounts_frozen_by_default = 24;
/**
* The flag indicating if this token has accounts associated to it that are KYC granted by default.
*/
bool accounts_kyc_granted_by_default = 25;
/**
* (Optional) The custom fees of this token.
*/
repeated CustomFee custom_fees = 26;
}
Loading