use of com.hederahashgraph.api.proto.java.NftTransfer in project hedera-services by hashgraph.
the class RequestBuilder method getTokenTransferRequestToAlias.
public static Transaction getTokenTransferRequestToAlias(Long payerAccountNum, Long payerRealmNum, Long payerShardNum, Long nodeAccountNum, Long nodeRealmNum, Long nodeShardNum, long transactionFee, Timestamp timestamp, Duration transactionDuration, boolean generateRecord, String memo, Long senderActNum, Long tokenNum, Long amountSend, ByteString receivingAlias, Long amountReceived) {
AccountAmount a1 = AccountAmount.newBuilder().setAccountID(getAccountIdBuild(senderActNum, 0l, 0l)).setAmount(amountSend).build();
AccountAmount a2 = AccountAmount.newBuilder().setAccountID(getAccountIdBuild(receivingAlias, 0l, 0l)).setAmount(amountReceived).build();
NftTransfer a3 = NftTransfer.newBuilder().setReceiverAccountID(AccountID.newBuilder().setAlias(receivingAlias).build()).setSenderAccountID(getAccountIdBuild(senderActNum, 0l, 0l)).setSerialNumber(1).build();
TokenTransferList tokenTransferList = TokenTransferList.newBuilder().setToken(TokenID.newBuilder().setTokenNum(tokenNum).build()).addTransfers(a1).addTransfers(a2).addNftTransfers(a3).build();
return getTokenTransferRequest(payerAccountNum, payerRealmNum, payerShardNum, nodeAccountNum, nodeRealmNum, nodeShardNum, transactionFee, timestamp, transactionDuration, generateRecord, memo, tokenTransferList);
}
use of com.hederahashgraph.api.proto.java.NftTransfer in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method insertNonFungibleTokenTransfers.
private void insertNonFungibleTokenTransfers(long consensusTimestamp, TransactionBody body, TokenID tokenId, EntityId entityTokenId, EntityId payerAccountId, List<com.hederahashgraph.api.proto.java.NftTransfer> nftTransfersList) {
for (NftTransfer nftTransfer : nftTransfersList) {
long serialNumber = nftTransfer.getSerialNumber();
if (serialNumber == NftTransferId.WILDCARD_SERIAL_NUMBER) {
// treasury change
return;
}
EntityId receiverId = EntityId.of(nftTransfer.getReceiverAccountID());
EntityId senderId = EntityId.of(nftTransfer.getSenderAccountID());
var nftTransferDomain = new com.hedera.mirror.common.domain.token.NftTransfer();
nftTransferDomain.setId(new NftTransferId(consensusTimestamp, serialNumber, entityTokenId));
nftTransferDomain.setIsApproval(false);
nftTransferDomain.setReceiverAccountId(receiverId);
nftTransferDomain.setSenderAccountId(senderId);
nftTransferDomain.setPayerAccountId(payerAccountId);
var nftTransferInsideBody = findNftTransferInsideBody(nftTransfer, tokenId, body);
if (nftTransferInsideBody != null) {
nftTransferDomain.setIsApproval(nftTransferInsideBody.getIsApproval());
}
entityListener.onNftTransfer(nftTransferDomain);
if (!EntityId.isEmpty(receiverId)) {
transferNftOwnership(consensusTimestamp, serialNumber, entityTokenId, receiverId);
}
}
}
use of com.hederahashgraph.api.proto.java.NftTransfer in project hedera-mirror-node by hashgraph.
the class TokenUpdateTransactionHandler method updateTreasury.
private void updateTreasury(RecordItem recordItem) {
var payerAccountId = EntityId.of(recordItem.getTransactionBody().getTransactionID().getAccountID()).getId();
for (TokenTransferList tokenTransferList : recordItem.getRecord().getTokenTransferListsList()) {
for (NftTransfer nftTransfer : tokenTransferList.getNftTransfersList()) {
if (nftTransfer.getSerialNumber() == NftTransferId.WILDCARD_SERIAL_NUMBER) {
EntityId newTreasury = EntityId.of(nftTransfer.getReceiverAccountID());
EntityId previousTreasury = EntityId.of(nftTransfer.getSenderAccountID());
EntityId tokenId = EntityId.of(tokenTransferList.getToken());
nftRepository.updateTreasury(tokenId.getId(), previousTreasury.getId(), newTreasury.getId(), recordItem.getConsensusTimestamp(), payerAccountId, nftTransfer.getIsApproval());
}
}
}
}
use of com.hederahashgraph.api.proto.java.NftTransfer in project hedera-services by hashgraph.
the class SigRequirements method cryptoTransfer.
private <T> SigningOrderResult<T> cryptoTransfer(final AccountID payer, final CryptoTransferTransactionBody op, final SigningOrderResultFactory<T> factory, @Nullable final LinkedRefs linkedRefs) {
List<JKey> required = new ArrayList<>();
KeyOrderingFailure failure;
for (TokenTransferList xfers : op.getTokenTransfersList()) {
for (AccountAmount adjust : xfers.getTransfersList()) {
if ((failure = includeIfNecessary(payer, adjust, required, false, linkedRefs)) != NONE) {
return accountFailure(failure, factory);
}
}
final var token = xfers.getToken();
for (NftTransfer adjust : xfers.getNftTransfersList()) {
final var sender = adjust.getSenderAccountID();
if ((failure = nftIncludeIfNecessary(payer, sender, null, adjust.getIsApproval(), required, token, op, linkedRefs)) != NONE) {
return accountFailure(failure, factory);
}
final var receiver = adjust.getReceiverAccountID();
if ((failure = nftIncludeIfNecessary(payer, receiver, sender, false, required, token, op, linkedRefs)) != NONE) {
return (failure == MISSING_TOKEN) ? factory.forMissingToken() : accountFailure(failure, factory);
}
}
}
for (AccountAmount adjust : op.getTransfers().getAccountAmountsList()) {
if ((failure = includeIfNecessary(payer, adjust, required, true, linkedRefs)) != NONE) {
return accountFailure(failure, factory);
}
}
return factory.forValidOrder(required);
}
use of com.hederahashgraph.api.proto.java.NftTransfer in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerTokenTest method nftUpdateTreasury.
@Test
void nftUpdateTreasury() {
// given
createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0);
long mintTimestamp = 10L;
List<Long> serialNumbers = List.of(1L);
TokenTransferList mintTransfer = nftTransfer(TOKEN_ID, PAYER, DEFAULT_ACCOUNT_ID, serialNumbers);
Transaction mintTransaction = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, true, 0, serialNumbers);
insertAndParseTransaction(mintTimestamp, mintTransaction, builder -> {
builder.getReceiptBuilder().setNewTotalSupply(serialNumbers.size()).addAllSerialNumbers(serialNumbers);
builder.addTokenTransferLists(mintTransfer);
});
// when
long updateTimestamp = 15L;
TokenTransferList treasuryUpdateTransfer = nftTransfer(TOKEN_ID, PAYER2, PAYER, List.of(NftTransferId.WILDCARD_SERIAL_NUMBER));
insertAndParseTransaction(updateTimestamp, buildTransaction(builder -> builder.getTokenUpdateBuilder().setToken(TOKEN_ID).setTreasury(PAYER2)), builder -> builder.addTokenTransferLists(treasuryUpdateTransfer));
// then
assertThat(nftTransferRepository.findAll()).containsExactlyInAnyOrder(domainNftTransfer(mintTimestamp, PAYER, DEFAULT_ACCOUNT_ID, 1L, TOKEN_ID, PAYER), domainNftTransfer(updateTimestamp, PAYER2, PAYER, 1L, TOKEN_ID, PAYER));
}
Aggregations