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

HTS: Add support for token transactions to Importer #1089

Merged
merged 28 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
462dad7
Add Importer Logic to Persist HTS transactions
Nana-EC Sep 24, 2020
4055e58
Fixing and adding tests
Nana-EC Sep 26, 2020
d1d6863
Added TransactionsHandlerTests
Nana-EC Sep 28, 2020
c9b9afd
Updated transaction handler tests and Added repository tests
Nana-EC Sep 29, 2020
fb322f8
Fixed transaction handler tests
Nana-EC Sep 29, 2020
68db9fe
Fixing merge conflicts with alpha5
Nana-EC Sep 29, 2020
93c9d48
Added caching to token and token_account repo calls
Nana-EC Sep 30, 2020
4923866
Removed tokenBalance domain and repo and added tokenUpdate test
Nana-EC Sep 30, 2020
6ec96df
Added tests to increase coverage
Nana-EC Oct 1, 2020
327505d
Addressed initial round of feedback
Nana-EC Oct 3, 2020
d17c1e9
Addresed feedback 2 around EntityRecordItemListener
Nana-EC Oct 5, 2020
cbfde0c
Updating to have all TokenId's and AccountId's be passed to OnEntityId
Nana-EC Oct 5, 2020
f7b5f6a
Cleaned up and added logs message where missing token or token_account
Nana-EC Oct 5, 2020
67738e1
Pulled in TokenBalance changes and addressed feedback
Nana-EC Oct 6, 2020
8057dde
Add Importer Logic to Persist HTS transactions
Nana-EC Sep 24, 2020
d1b1530
Fixing and adding tests
Nana-EC Sep 26, 2020
bdb3417
Added TransactionsHandlerTests
Nana-EC Sep 28, 2020
13a3db3
Updated transaction handler tests and Added repository tests
Nana-EC Sep 29, 2020
837657f
Fixed transaction handler tests
Nana-EC Sep 29, 2020
34bc078
Fixing merge conflicts with alpha5
Nana-EC Sep 29, 2020
f11b443
Added caching to token and token_account repo calls
Nana-EC Sep 30, 2020
878f7d7
Removed tokenBalance domain and repo and added tokenUpdate test
Nana-EC Sep 30, 2020
ed01943
Added tests to increase coverage
Nana-EC Oct 1, 2020
85b2ba5
Addressed initial round of feedback
Nana-EC Oct 3, 2020
c26d0c6
Addresed feedback 2 around EntityRecordItemListener
Nana-EC Oct 5, 2020
80d726b
Cleaned up and added logs message where missing token or token_account
Nana-EC Oct 5, 2020
814c1fb
Fixed mad merge
Nana-EC Oct 6, 2020
6c61ddd
Removed merge artifcats and toggle methods
Nana-EC Oct 6, 2020
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
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ value, it is recommended to only populate overridden properties in the custom `a
| `hedera.mirror.importer.parser.record.entity.persist.files` | true | Persist all file data to the database |
| `hedera.mirror.importer.parser.record.entity.persist.nonFeeTransfers` | false | Persist non-fee transfers for transactions that explicitly request hbar transfers |
| `hedera.mirror.importer.parser.record.entity.persist.systemFiles` | true | Persist only system files (number lower than `1000`) to the database |
| `hedera.mirror.importer.parser.record.entity.persist.tokens` | true | Persist token data to the database |
| `hedera.mirror.importer.parser.record.entity.persist.transactionBytes` | false | Persist raw transaction bytes to the database |
| `hedera.mirror.importer.parser.record.entity.redis.enabled` | true | Whether to use Redis to send messages to the gRPC process. Requires `spring.redis.*` [properties](https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#data-properties) |
| `hedera.mirror.importer.parser.record.entity.repository.enabled` | false | Whether to use Spring Data JPA repositories to insert into the database (experimental) |
Expand Down
4 changes: 2 additions & 2 deletions docs/design/hts.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ public class AccountBalance implements Persistable<AccountBalance.Id> {
- `accountId`
- `associated`
- `createdTimestamp`
- `freeze_status` (FreezeNotApplicable = 0, Frozen = 1, Unfrozen = 2)
- `kyc_status` (KycNotApplicable = 0, Granted = 1, Revoked = 2)
- `freezeStatus` (FreezeNotApplicable = 0, Frozen = 1, Unfrozen = 2)
- `kycStatus` (KycNotApplicable = 0, Granted = 1, Revoked = 2)
- `modifiedTimestamp`
- `tokenId`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
import com.hedera.mirror.importer.util.EntityIdEndec;

/**
* Common encapsulation for accountID, fileID, contractID, and topicID.
* Common encapsulation for accountID, fileID, contractID, topicID and tokenID.
* <p>
* There is no valid entity in Hedera network with an id '0.0.0'. When AccountID/FileID/ContractID/TopicID are not set,
* their values default to '0.0.0'. If such an unset (default) instance is used to create EntityId using one of the
* of(..) functions, null is returned.
* There is no valid entity in Hedera network with an id '0.0.0'. When AccountID/FileID/ContractID/TopicID/TokenID are
* not set, their values default to '0.0.0'. If such an unset (default) instance is used to create EntityId using one of
* the of(..) functions, null is returned.
*/
@Value
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package com.hedera.mirror.importer.domain;

/*-
* ‌
* Hedera Mirror Node
* ​
* Copyright (C) 2019 - 2020 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 com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.extern.log4j.Log4j2;

import com.hedera.mirror.importer.converter.AccountIdConverter;
import com.hedera.mirror.importer.converter.EntityIdSerializer;
import com.hedera.mirror.importer.converter.TokenIdConverter;
import com.hedera.mirror.importer.util.Utility;

@Data
@Entity
@Log4j2
@NoArgsConstructor
public class Token {
@EmbeddedId
private Token.Id tokenId;

private long createdTimestamp;

private long decimals;

private boolean freezeDefault;

@ToString.Exclude
private byte[] freezeKey;

@Column(name = "freeze_key_ed25519_hex")
@ToString.Exclude
private String freezeKeyEd25519Hex;

private long initialSupply;

private long totalSupply; // Increment with initialSupply and mint amounts, decrement with burn amount

@ToString.Exclude
private byte[] kycKey;

@Column(name = "kyc_key_ed25519_hex")
@ToString.Exclude
private String kycKeyEd25519Hex;

private long modifiedTimestamp;

private String name;

@ToString.Exclude
private byte[] supplyKey;

@Column(name = "supply_key_ed25519_hex")
@ToString.Exclude
private String supplyKeyEd25519Hex;

private String symbol;

@Convert(converter = AccountIdConverter.class)
private EntityId treasuryAccountId;

@ToString.Exclude
private byte[] wipeKey;

@Column(name = "wipe_key_ed25519_hex")
Copy link
Member

Choose a reason for hiding this comment

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

Should we rename as wipe_key_ed_25519_hex so we don't have to manually map?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that would be cleaner

Copy link
Collaborator Author

@Nana-EC Nana-EC Oct 2, 2020

Choose a reason for hiding this comment

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

wipe_key_ed_25519_hex would actually still require a mapping as hibernate translates wipeKeyEd25519Hex to wipe_key_ed25519hex.
If we want to avoid manual mapping we either set the schema to wipe_key_ed25519hex or rename the member to be wipeKeyHexEd25519 and schema to be wipe_key_hex_ed25519

@ToString.Exclude
private String wipeKeyEd25519Hex;

public void setInitialSupply(Long initialSupply) {
this.initialSupply = initialSupply;

// default totalSupply to initial supply
totalSupply = initialSupply;
}

public void setFreezeKey(byte[] key) {
freezeKey = key;
freezeKeyEd25519Hex = Utility.protobufKeyToHexIfEd25519OrNull(key);
}

public void setKycKey(byte[] key) {
kycKey = key;
kycKeyEd25519Hex = Utility.protobufKeyToHexIfEd25519OrNull(key);
}

public void setSupplyKey(byte[] key) {
supplyKey = key;
supplyKeyEd25519Hex = Utility.protobufKeyToHexIfEd25519OrNull(key);
}

public void setWipeKey(byte[] key) {
wipeKey = key;
wipeKeyEd25519Hex = Utility.protobufKeyToHexIfEd25519OrNull(key);
}

/**
* Get initial freeze status for an account being associated with this token. If the token does not have a
* freezeKey, FreezeNotApplicable is returned, if it does account frozen status is set based on freezeDefault.
* FreezeNotApplicable = 0, Frozen = 1, Unfrozen = 2
*
* @return Freeze status code
*/
public TokenFreezeStatusEnum getNewAccountFreezeStatus() {
if (freezeKey == null) {
return TokenFreezeStatusEnum.NOT_APPLICABLE;
}

return freezeDefault ? TokenFreezeStatusEnum.FROZEN : TokenFreezeStatusEnum.UNFROZEN;
}

/**
* Get initial kyc status for an account being associated with this token. If the token does not have a kycKey,
* KycNotApplicable is returned, if it does account should be set to Revoked as kyc must be performed.
* KycNotApplicable = 0, Granted = 1, Revoked = 2
*
* @return Kyc status code
*/
public TokenKycStatusEnum getNewAccountKycStatus() {
if (kycKey == null) {
return TokenKycStatusEnum.NOT_APPLICABLE;
}

return TokenKycStatusEnum.REVOKED;
}

@Data
@Embeddable
@AllArgsConstructor
@NoArgsConstructor
public static class Id implements Serializable {

private static final long serialVersionUID = -4595724698253758379L;

@Convert(converter = TokenIdConverter.class)
@JsonSerialize(using = EntityIdSerializer.class)
private EntityId tokenId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.hedera.mirror.importer.domain;

/*-
* ‌
* Hedera Mirror Node
* ​
* Copyright (C) 2019 - 2020 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 com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.io.Serializable;
import javax.persistence.Convert;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.log4j.Log4j2;

import com.hedera.mirror.importer.converter.AccountIdConverter;
import com.hedera.mirror.importer.converter.EntityIdSerializer;
import com.hedera.mirror.importer.converter.TokenIdConverter;

@Data
@Entity
@Log4j2
@NoArgsConstructor
public class TokenAccount {
@EmbeddedId
@JsonUnwrapped
private TokenAccount.Id id;

private boolean associated;

private long createdTimestamp;

@Enumerated(EnumType.ORDINAL)
private TokenFreezeStatusEnum freezeStatus;

@Enumerated(EnumType.ORDINAL)
private TokenKycStatusEnum kycStatus;

private long modifiedTimestamp;

public TokenAccount(EntityId tokenId, EntityId accountId) {
id = new TokenAccount.Id(tokenId, accountId);
}

@Data
@AllArgsConstructor
@NoArgsConstructor
@Embeddable
public static class Id implements Serializable {
private static final long serialVersionUID = -4069569824910871771L;

@Convert(converter = TokenIdConverter.class)
@JsonSerialize(using = EntityIdSerializer.class)
private EntityId tokenId;

@Convert(converter = AccountIdConverter.class)
@JsonSerialize(using = EntityIdSerializer.class)
private EntityId accountId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
@Entity
public class TokenBalance implements Persistable<TokenBalance.Id> {
Nana-EC marked this conversation as resolved.
Show resolved Hide resolved
private long balance;

@EmbeddedId
@JsonUnwrapped
private TokenBalance.Id id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.hedera.mirror.importer.domain;

/*-
* ‌
* Hedera Mirror Node
* ​
* Copyright (C) 2019 - 2020 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 lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum TokenFreezeStatusEnum {

NOT_APPLICABLE(0),
FROZEN(1),
UNFROZEN(2);

private final int id;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.hedera.mirror.importer.domain;

/*-
* ‌
* Hedera Mirror Node
* ​
* Copyright (C) 2019 - 2020 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 lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum TokenKycStatusEnum {

NOT_APPLICABLE(0),
GRANTED(1),
REVOKED(2);

private final int id;
}
Loading