-
Notifications
You must be signed in to change notification settings - Fork 113
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
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 4055e58
Fixing and adding tests
Nana-EC d1d6863
Added TransactionsHandlerTests
Nana-EC c9b9afd
Updated transaction handler tests and Added repository tests
Nana-EC fb322f8
Fixed transaction handler tests
Nana-EC 68db9fe
Fixing merge conflicts with alpha5
Nana-EC 93c9d48
Added caching to token and token_account repo calls
Nana-EC 4923866
Removed tokenBalance domain and repo and added tokenUpdate test
Nana-EC 6ec96df
Added tests to increase coverage
Nana-EC 327505d
Addressed initial round of feedback
Nana-EC d17c1e9
Addresed feedback 2 around EntityRecordItemListener
Nana-EC cbfde0c
Updating to have all TokenId's and AccountId's be passed to OnEntityId
Nana-EC f7b5f6a
Cleaned up and added logs message where missing token or token_account
Nana-EC 67738e1
Pulled in TokenBalance changes and addressed feedback
Nana-EC 8057dde
Add Importer Logic to Persist HTS transactions
Nana-EC d1b1530
Fixing and adding tests
Nana-EC bdb3417
Added TransactionsHandlerTests
Nana-EC 13a3db3
Updated transaction handler tests and Added repository tests
Nana-EC 837657f
Fixed transaction handler tests
Nana-EC 34bc078
Fixing merge conflicts with alpha5
Nana-EC f11b443
Added caching to token and token_account repo calls
Nana-EC 878f7d7
Removed tokenBalance domain and repo and added tokenUpdate test
Nana-EC ed01943
Added tests to increase coverage
Nana-EC 85b2ba5
Addressed initial round of feedback
Nana-EC c26d0c6
Addresed feedback 2 around EntityRecordItemListener
Nana-EC 80d726b
Cleaned up and added logs message where missing token or token_account
Nana-EC 814c1fb
Fixed mad merge
Nana-EC 6c61ddd
Removed merge artifcats and toggle methods
Nana-EC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
hedera-mirror-importer/src/main/java/com/hedera/mirror/importer/domain/Token.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
@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; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
hedera-mirror-importer/src/main/java/com/hedera/mirror/importer/domain/TokenAccount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...irror-importer/src/main/java/com/hedera/mirror/importer/domain/TokenFreezeStatusEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
35 changes: 35 additions & 0 deletions
35
...a-mirror-importer/src/main/java/com/hedera/mirror/importer/domain/TokenKycStatusEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 translateswipeKeyEd25519Hex
towipe_key_ed25519hex
.If we want to avoid manual mapping we either set the schema to
wipe_key_ed25519hex
or rename the member to bewipeKeyHexEd25519
and schema to bewipe_key_hex_ed25519