-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into 9728-address-account-nonce-discrepancies-…
…mono
- Loading branch information
Showing
152 changed files
with
3,079 additions
and
4,331 deletions.
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
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
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
90 changes: 90 additions & 0 deletions
90
...-node/hedera-app/src/main/java/com/hedera/node/app/bbm/associations/TokenAssociation.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,90 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package com.hedera.node.app.bbm.associations; | ||
|
||
import com.hedera.hapi.node.state.token.TokenRelation; | ||
import com.hedera.node.app.service.mono.state.submerkle.EntityId; | ||
import com.hedera.node.app.service.mono.state.virtual.entities.OnDiskTokenRel; | ||
import com.hedera.node.app.service.mono.utils.EntityNumPair; | ||
import com.hedera.node.app.state.merkle.disk.OnDiskValue; | ||
import com.hederahashgraph.api.proto.java.AccountID; | ||
import com.hederahashgraph.api.proto.java.TokenID; | ||
import com.swirlds.base.utility.Pair; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import edu.umd.cs.findbugs.annotations.Nullable; | ||
|
||
record TokenAssociation( | ||
EntityId accountId, | ||
EntityId tokenId, | ||
long balance, | ||
boolean isFrozen, | ||
boolean isKycGranted, | ||
boolean isAutomaticAssociation, | ||
EntityId prev, | ||
EntityId next) { | ||
|
||
@NonNull | ||
static TokenAssociation fromMono(@NonNull final OnDiskTokenRel tokenRel) { | ||
final var at = toLongsPair(toPair(tokenRel.getKey())); | ||
|
||
return new TokenAssociation( | ||
entityIdFrom(at.left()), | ||
entityIdFrom(at.right()), | ||
tokenRel.getBalance(), | ||
tokenRel.isFrozen(), | ||
tokenRel.isKycGranted(), | ||
tokenRel.isAutomaticAssociation(), | ||
entityIdFrom(tokenRel.getPrev()), | ||
entityIdFrom(tokenRel.getNext())); | ||
} | ||
|
||
static TokenAssociation fromMod(@NonNull final OnDiskValue<TokenRelation> wrapper) { | ||
final var value = wrapper.getValue(); | ||
return new TokenAssociation( | ||
accountIdFromMod(value.accountId()), | ||
tokenIdFromMod(value.tokenId()), | ||
value.balance(), | ||
value.frozen(), | ||
value.kycGranted(), | ||
value.automaticAssociation(), | ||
tokenIdFromMod(value.previousToken()), | ||
tokenIdFromMod(value.nextToken())); | ||
} | ||
|
||
@NonNull | ||
static Pair<AccountID, TokenID> toPair(@NonNull final EntityNumPair enp) { | ||
final var at = enp.asAccountTokenRel(); | ||
return Pair.of(at.getLeft(), at.getRight()); | ||
} | ||
|
||
@NonNull | ||
static Pair<Long, Long> toLongsPair(@NonNull final Pair<AccountID, TokenID> pat) { | ||
return Pair.of(pat.left().getAccountNum(), pat.right().getTokenNum()); | ||
} | ||
|
||
static EntityId accountIdFromMod(@Nullable final com.hedera.hapi.node.base.AccountID accountId) { | ||
return null == accountId ? EntityId.MISSING_ENTITY_ID : new EntityId(0L, 0L, accountId.accountNumOrThrow()); | ||
} | ||
|
||
static EntityId tokenIdFromMod(@Nullable final com.hedera.hapi.node.base.TokenID tokenId) { | ||
return null == tokenId ? EntityId.MISSING_ENTITY_ID : new EntityId(0L, 0L, tokenId.tokenNum()); | ||
} | ||
|
||
static EntityId entityIdFrom(long num) { | ||
return new EntityId(0L, 0L, num); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ode/hedera-app/src/main/java/com/hedera/node/app/bbm/associations/TokenAssociationId.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,52 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package com.hedera.node.app.bbm.associations; | ||
|
||
import static com.hedera.node.app.bbm.associations.TokenAssociation.toLongsPair; | ||
import static com.hedera.node.app.bbm.associations.TokenAssociation.toPair; | ||
|
||
import com.google.common.collect.ComparisonChain; | ||
import com.hedera.node.app.bbm.utils.Writer; | ||
import com.hedera.node.app.service.mono.state.virtual.entities.OnDiskTokenRel; | ||
import com.hedera.node.app.state.merkle.disk.OnDiskKey; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
record TokenAssociationId(long accountId, long tokenId) implements Comparable<TokenAssociationId> { | ||
static TokenAssociationId fromMod(@NonNull final com.hedera.hapi.node.base.TokenAssociation association) { | ||
return new TokenAssociationId( | ||
association.accountId().accountNum(), association.tokenId().tokenNum()); | ||
} | ||
|
||
static TokenAssociationId fromMono(@NonNull final OnDiskKey<OnDiskTokenRel> tokenRel) { | ||
final var key = toLongsPair(toPair(tokenRel.getKey().getKey())); | ||
; | ||
return new TokenAssociationId(key.left(), key.right()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "%d%s%d".formatted(accountId, Writer.FIELD_SEPARATOR, tokenId); | ||
} | ||
|
||
@Override | ||
public int compareTo(TokenAssociationId o) { | ||
return ComparisonChain.start() | ||
.compare(this.accountId, o.accountId) | ||
.compare(this.tokenId, o.tokenId) | ||
.result(); | ||
} | ||
} |
Oops, something went wrong.