Search in sources :

Example 1 with NftAllowance

use of com.hederahashgraph.api.proto.java.NftAllowance in project hedera-services by hashgraph.

the class CryptoApproveAllowanceTransitionLogicTest method givenValidTxnCtxWithOwnerAsPayer.

private void givenValidTxnCtxWithOwnerAsPayer() {
    token1Model.setMaxSupply(5000L);
    token1Model.setType(TokenType.FUNGIBLE_COMMON);
    token2Model.setMaxSupply(5000L);
    token2Model.setType(TokenType.NON_FUNGIBLE_UNIQUE);
    final CryptoAllowance cryptoAllowance1 = CryptoAllowance.newBuilder().setSpender(spender1).setAmount(10L).build();
    final TokenAllowance tokenAllowance1 = TokenAllowance.newBuilder().setSpender(spender1).setAmount(10L).setTokenId(token1).build();
    final NftAllowance nftAllowance1 = NftAllowance.newBuilder().setSpender(spender1).setTokenId(token2).setApprovedForAll(BoolValue.of(true)).addAllSerialNumbers(List.of(1L, 10L)).build();
    cryptoAllowances.add(cryptoAllowance1);
    tokenAllowances.add(tokenAllowance1);
    nftAllowances.add(nftAllowance1);
    cryptoApproveAllowanceTxn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setCryptoApproveAllowance(CryptoApproveAllowanceTransactionBody.newBuilder().addAllCryptoAllowances(cryptoAllowances).addAllTokenAllowances(tokenAllowances).addAllNftAllowances(nftAllowances)).build();
    op = cryptoApproveAllowanceTxn.getCryptoApproveAllowance();
    payerAcccount.setNftAllowances(new HashMap<>());
    payerAcccount.setCryptoAllowances(new HashMap<>());
    payerAcccount.setFungibleTokenAllowances(new HashMap<>());
}
Also used : CryptoAllowance(com.hederahashgraph.api.proto.java.CryptoAllowance) NftAllowance(com.hederahashgraph.api.proto.java.NftAllowance) TokenAllowance(com.hederahashgraph.api.proto.java.TokenAllowance) FcTokenAllowance(com.hedera.services.state.submerkle.FcTokenAllowance)

Example 2 with NftAllowance

use of com.hederahashgraph.api.proto.java.NftAllowance in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerCryptoTest method customizeNftAllowances.

private List<NftAllowance> customizeNftAllowances(Timestamp consensusTimestamp, List<Nft> expectedNfts) {
    var delegatingSpender = recordItemBuilder.accountId();
    var owner = recordItemBuilder.accountId();
    var spender1 = recordItemBuilder.accountId();
    var spender2 = recordItemBuilder.accountId();
    var tokenId = recordItemBuilder.tokenId();
    var nft1 = Nft.builder().id(new NftId(1L, EntityId.of(tokenId))).accountId(EntityId.of(owner)).createdTimestamp(101L).modifiedTimestamp(101L).build();
    var nft2 = Nft.builder().id(new NftId(2L, EntityId.of(tokenId))).accountId(EntityId.of(owner)).createdTimestamp(102L).modifiedTimestamp(102L).build();
    var nft3 = Nft.builder().id(new NftId(3L, EntityId.of(tokenId))).accountId(EntityId.of(owner)).createdTimestamp(103L).modifiedTimestamp(103L).build();
    var timestamp = DomainUtils.timeStampInNanos(consensusTimestamp);
    List<NftAllowance> nftAllowances = new LinkedList<>();
    nftAllowances.add(NftAllowance.newBuilder().setDelegatingSpender(delegatingSpender).setOwner(owner).addSerialNumbers(1L).addSerialNumbers(2L).setSpender(spender1).setTokenId(tokenId).build());
    expectedNfts.add(nft1.toBuilder().delegatingSpender(EntityId.of(delegatingSpender)).modifiedTimestamp(timestamp).spender(EntityId.of(spender1)).build());
    nftAllowances.add(NftAllowance.newBuilder().setApprovedForAll(BoolValue.of(false)).setOwner(recordItemBuilder.accountId()).setSpender(recordItemBuilder.accountId()).setTokenId(recordItemBuilder.tokenId()).build());
    nftAllowances.add(NftAllowance.newBuilder().setApprovedForAll(BoolValue.of(true)).setOwner(recordItemBuilder.accountId()).setSpender(recordItemBuilder.accountId()).setTokenId(recordItemBuilder.tokenId()).build());
    nftAllowances.add(NftAllowance.newBuilder().setApprovedForAll(BoolValue.of(true)).setOwner(owner).addSerialNumbers(2L).addSerialNumbers(3L).setSpender(spender2).setTokenId(tokenId).build());
    // duplicate nft allowance
    nftAllowances.add(nftAllowances.get(nftAllowances.size() - 1));
    // serial number 2's allowance is granted twice, the allowance should be granted to spender2 since it appears
    // after the nft allowance to spender1
    expectedNfts.add(nft2.toBuilder().modifiedTimestamp(timestamp).spender(EntityId.of(spender2)).build());
    expectedNfts.add(nft3.toBuilder().modifiedTimestamp(timestamp).spender(EntityId.of(spender2)).build());
    nftRepository.saveAll(List.of(nft1, nft2, nft3));
    return nftAllowances;
}
Also used : NftAllowance(com.hederahashgraph.api.proto.java.NftAllowance) NftId(com.hedera.mirror.common.domain.token.NftId) LinkedList(java.util.LinkedList)

Example 3 with NftAllowance

use of com.hederahashgraph.api.proto.java.NftAllowance in project hedera-services by hashgraph.

the class ApproveAllowanceChecksTest method missingOwnerDefaultsToPayer.

@Test
void missingOwnerDefaultsToPayer() {
    setupNeeded();
    final CryptoAllowance cryptoAllowance1 = CryptoAllowance.newBuilder().setSpender(spender1).setAmount(10L).build();
    final TokenAllowance tokenAllowance1 = TokenAllowance.newBuilder().setSpender(spender1).setAmount(10L).setTokenId(token1).build();
    final NftAllowance nftAllowance1 = NftAllowance.newBuilder().setSpender(spender1).setTokenId(token2).setApprovedForAll(BoolValue.of(false)).addAllSerialNumbers(List.of(1L, 10L)).build();
    cryptoAllowances.clear();
    tokenAllowances.clear();
    nftAllowances.clear();
    cryptoAllowances.add(cryptoAllowance1);
    tokenAllowances.add(tokenAllowance1);
    nftAllowances.add(nftAllowance1);
    cryptoApproveAllowanceTxn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setCryptoApproveAllowance(CryptoApproveAllowanceTransactionBody.newBuilder().addAllCryptoAllowances(cryptoAllowances)).build();
    op = cryptoApproveAllowanceTxn.getCryptoApproveAllowance();
    assertEquals(OK, subject.validateCryptoAllowances(cryptoApproveAllowanceTxn.getCryptoApproveAllowance().getCryptoAllowancesList(), payerAccount));
    verify(accountStore, never()).loadAccount(any());
    cryptoApproveAllowanceTxn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setCryptoApproveAllowance(CryptoApproveAllowanceTransactionBody.newBuilder().addAllTokenAllowances(tokenAllowances)).build();
    op = cryptoApproveAllowanceTxn.getCryptoApproveAllowance();
    assertEquals(OK, subject.validateFungibleTokenAllowances(cryptoApproveAllowanceTxn.getCryptoApproveAllowance().getTokenAllowancesList(), payerAccount));
    verify(accountStore, never()).loadAccount(any());
    cryptoApproveAllowanceTxn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setCryptoApproveAllowance(CryptoApproveAllowanceTransactionBody.newBuilder().addAllNftAllowances(nftAllowances)).build();
    op = cryptoApproveAllowanceTxn.getCryptoApproveAllowance();
    assertEquals(OK, subject.validateNftAllowances(cryptoApproveAllowanceTxn.getCryptoApproveAllowance().getNftAllowancesList(), payerAccount));
    verify(accountStore, never()).loadAccount(any());
}
Also used : CryptoAllowance(com.hederahashgraph.api.proto.java.CryptoAllowance) NftAllowance(com.hederahashgraph.api.proto.java.NftAllowance) TokenAllowance(com.hederahashgraph.api.proto.java.TokenAllowance) Test(org.junit.jupiter.api.Test)

Example 4 with NftAllowance

use of com.hederahashgraph.api.proto.java.NftAllowance in project hedera-services by hashgraph.

the class CryptoAdjustAllowanceTransitionLogicTest method givenTxnCtxWithZeroAmount.

private void givenTxnCtxWithZeroAmount() {
    token1Model.setMaxSupply(5000L);
    token1Model.setType(TokenType.FUNGIBLE_COMMON);
    token2Model.setMaxSupply(5000L);
    token2Model.setType(TokenType.NON_FUNGIBLE_UNIQUE);
    List<Long> serials = new ArrayList<>();
    serials.add(-12L);
    serials.add(-10L);
    final CryptoAllowance cryptoAllowance = CryptoAllowance.newBuilder().setSpender(spender1).setAmount(-20L).build();
    final TokenAllowance tokenAllowance = TokenAllowance.newBuilder().setSpender(spender1).setAmount(-10L).setTokenId(token1).build();
    final NftAllowance nftAllowance = NftAllowance.newBuilder().setSpender(spender1).setTokenId(token2).setApprovedForAll(BoolValue.of(false)).addAllSerialNumbers(serials).build();
    cryptoAllowances.add(cryptoAllowance);
    tokenAllowances.add(tokenAllowance);
    nftAllowances.add(nftAllowance);
    cryptoAdjustAllowanceTxn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setCryptoAdjustAllowance(CryptoAdjustAllowanceTransactionBody.newBuilder().addAllCryptoAllowances(cryptoAllowances).addAllTokenAllowances(tokenAllowances).addAllNftAllowances(nftAllowances)).build();
    ownerAcccount.setNftAllowances(new HashMap<>());
    ownerAcccount.setCryptoAllowances(new HashMap<>());
    ownerAcccount.setFungibleTokenAllowances(new HashMap<>());
}
Also used : CryptoAllowance(com.hederahashgraph.api.proto.java.CryptoAllowance) NftAllowance(com.hederahashgraph.api.proto.java.NftAllowance) ArrayList(java.util.ArrayList) TokenAllowance(com.hederahashgraph.api.proto.java.TokenAllowance) FcTokenAllowance(com.hedera.services.state.submerkle.FcTokenAllowance)

Example 5 with NftAllowance

use of com.hederahashgraph.api.proto.java.NftAllowance in project hedera-services by hashgraph.

the class CryptoApproveAllowanceTransitionLogicTest method givenTxnCtxWithZeroAmount.

private void givenTxnCtxWithZeroAmount() {
    token1Model.setMaxSupply(5000L);
    token1Model.setType(TokenType.FUNGIBLE_COMMON);
    token2Model.setMaxSupply(5000L);
    token2Model.setType(TokenType.NON_FUNGIBLE_UNIQUE);
    final CryptoAllowance cryptoAllowance = CryptoAllowance.newBuilder().setOwner(ownerId).setSpender(spender1).setAmount(0L).build();
    final TokenAllowance tokenAllowance = TokenAllowance.newBuilder().setSpender(spender1).setAmount(0L).setTokenId(token1).setOwner(ownerId).build();
    final NftAllowance nftAllowance = NftAllowance.newBuilder().setSpender(spender1).setTokenId(token2).setApprovedForAll(BoolValue.of(false)).setOwner(ownerId).addAllSerialNumbers(List.of(1L, 10L)).build();
    cryptoAllowances.add(cryptoAllowance1);
    tokenAllowances.add(tokenAllowance1);
    nftAllowances.add(nftAllowance1);
    cryptoAllowances.add(cryptoAllowance);
    tokenAllowances.add(tokenAllowance);
    nftAllowances.add(nftAllowance);
    cryptoApproveAllowanceTxn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setCryptoApproveAllowance(CryptoApproveAllowanceTransactionBody.newBuilder().addAllCryptoAllowances(cryptoAllowances).addAllTokenAllowances(tokenAllowances).addAllNftAllowances(nftAllowances)).build();
    ownerAcccount.setNftAllowances(new HashMap<>());
    ownerAcccount.setCryptoAllowances(new HashMap<>());
    ownerAcccount.setFungibleTokenAllowances(new HashMap<>());
}
Also used : CryptoAllowance(com.hederahashgraph.api.proto.java.CryptoAllowance) NftAllowance(com.hederahashgraph.api.proto.java.NftAllowance) TokenAllowance(com.hederahashgraph.api.proto.java.TokenAllowance) FcTokenAllowance(com.hedera.services.state.submerkle.FcTokenAllowance)

Aggregations

NftAllowance (com.hederahashgraph.api.proto.java.NftAllowance)5 CryptoAllowance (com.hederahashgraph.api.proto.java.CryptoAllowance)4 TokenAllowance (com.hederahashgraph.api.proto.java.TokenAllowance)4 FcTokenAllowance (com.hedera.services.state.submerkle.FcTokenAllowance)3 NftId (com.hedera.mirror.common.domain.token.NftId)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Test (org.junit.jupiter.api.Test)1