Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.hedera.hashgraph.sdk.PrivateKey;
import com.hedera.hashgraph.sdk.TokenId;
import com.openelements.hiero.base.data.Account;

import java.util.List;
import java.util.Objects;
import org.jspecify.annotations.NonNull;

Expand Down Expand Up @@ -230,6 +232,91 @@ default void associateToken(@NonNull TokenId tokenId, @NonNull Account account)
associateToken(tokenId, account.accountId(), account.privateKey());
}

/**
* Associate an account with token.
*
* @param tokenIds list of the ID of the token
* @param accountId the accountId
* @param accountKey the account privateKey
* @throws HieroException if the account could not be associated with the token
*/
void associateToken(@NonNull List<TokenId> tokenIds, @NonNull AccountId accountId, @NonNull PrivateKey accountKey)
throws HieroException;

/**
* Associate an account with token.
*
* @param tokenIds list of the ID of the token
* @param account the account
* @throws HieroException if the account could not be associated with the token
*/
default void associateToken(@NonNull List<TokenId> tokenIds, @NonNull Account account) throws HieroException {
Objects.requireNonNull(account, "accountId must not be null");
associateToken(tokenIds, account.accountId(), account.privateKey());
};

/**
* Dissociate an account with token.
*
* @param tokenId the ID of the token
* @param accountId the accountId
* @param accountKey the account privateKey
* @throws HieroException if the account could not be associated with the token
*/
void dissociateToken(@NonNull TokenId tokenId, @NonNull AccountId accountId, @NonNull PrivateKey accountKey)
throws HieroException;

/**
* Dissociate an account with token.
*
* @param tokenId the ID of the token
* @param accountId the accountId
* @param accountKey the account privateKey
* @throws HieroException if the account could not be associated with the token
*/
default void dissociateToken(@NonNull String tokenId, @NonNull String accountId, @NonNull String accountKey)
throws HieroException {
Objects.requireNonNull(tokenId, "tokenId must not be null");
Objects.requireNonNull(accountId, "accountId must not be null");
Objects.requireNonNull(accountKey, "accountKey must not be null");
dissociateToken(TokenId.fromString(tokenId), AccountId.fromString(accountId), PrivateKey.fromString(accountKey));
};

/**
* Dissociate an account with token.
*
* @param tokenId the ID of the token
* @param account the account
* @throws HieroException if the account could not be associated with the token
*/
default void dissociateToken(@NonNull TokenId tokenId, @NonNull Account account) throws HieroException {
Objects.requireNonNull(account, "accountId must not be null");
dissociateToken(tokenId, account.accountId(), account.privateKey());
};

/**
* Dissociate an account with token.
*
* @param tokenIds list of the ID of the token
* @param accountId the accountId
* @param accountKey the account privateKey
* @throws HieroException if the account could not be associated with the token
*/
void dissociateToken(@NonNull List<TokenId> tokenIds, @NonNull AccountId accountId, @NonNull PrivateKey accountKey)
throws HieroException;

/**
* Dissociate an account with token.
*
* @param tokenIds list of the ID of the token
* @param account the account
* @throws HieroException if the account could not be associated with the token
*/
default void dissociateToken(@NonNull List<TokenId> tokenIds, @NonNull Account account) throws HieroException {
Objects.requireNonNull(account, "accountId must not be null");
dissociateToken(tokenIds, account.accountId(), account.privateKey());
};

/**
* Mint a Token.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.List;
import java.util.Objects;
import java.util.Set;

import com.openelements.hiero.base.data.Token;
import org.jspecify.annotations.NonNull;

/**
Expand Down Expand Up @@ -203,6 +205,93 @@ default void associateNft(@NonNull TokenId tokenId, @NonNull Account account) th
associateNft(tokenId, account.accountId(), account.privateKey());
}

/**
* Associate an account with an NFT type. If an account is associated with an NFT type, the account can hold NFTs of
* that type. Otherwise, the account cannot hold NFTs of that type and tranfer NFTs of that type will fail.
*
* @param tokenIds the List of ID for NFT type
* @param accountId the accountId
* @param accountKey the account privateKey
* @throws HieroException if the account could not be associated with the NFT type
*/
void associateNft(@NonNull List<TokenId> tokenIds, @NonNull AccountId accountId, @NonNull PrivateKey accountKey)
throws HieroException;

/**
* Associate an account with an NFT type. If an account is associated with an NFT type, the account can hold NFTs of
* that type. Otherwise, the account cannot hold NFTs of that type and tranfer NFTs of that type will fail.
*
* @param tokenIds the List of ID for NFT type
* @param account the account
* @throws HieroException if the account could not be associated with the NFT type
*/
default void associateNft(@NonNull List<TokenId> tokenIds, @NonNull Account account) throws HieroException {
Objects.requireNonNull(account, "accountId must not be null");
associateNft(tokenIds, account.accountId(), account.privateKey());
};

/**
* Dissociate an account with an NFT type.
*
* @param tokenId the ID of the NFT type
* @param accountId the accountId
* @param accountKey the account privateKey
* @throws HieroException if the account could not be associated with the NFT type
*/
void dissociateNft(@NonNull TokenId tokenId, @NonNull AccountId accountId, @NonNull PrivateKey accountKey)
throws HieroException;

/**
* Dissociate an account with an NFT type.
*
* @param tokenId the ID of the NFT type
* @param accountId the accountId
* @param accountKey the account privateKey
* @throws HieroException if the account could not be associated with the NFT type
*/
default void dissociateNft(@NonNull String tokenId, @NonNull String accountId, @NonNull String accountKey)
throws HieroException {
Objects.requireNonNull(tokenId, "tokenId must not be null");
Objects.requireNonNull(accountId, "accountId must not be null");
Objects.requireNonNull(accountKey, "accountKey must not be null");
dissociateNft(TokenId.fromString(tokenId), AccountId.fromString(accountId), PrivateKey.fromString(accountKey));
};

/**
* Dissociate an account with an NFT type.
*
* @param tokenId the ID of the NFT type
* @param account the account
* @throws HieroException if the account could not be associated with the NFT type
*/
default void dissociateNft(@NonNull TokenId tokenId, @NonNull Account account) throws HieroException {
Objects.requireNonNull(account, "accountId must not be null");
dissociateNft(tokenId, account.accountId(), account.privateKey());
};

/**
* Dissociate an account with an NFT type.
*
* @param tokenIds the List of ID for NFT type
* @param accountId the accountId
* @param accountKey the account privateKey
* @throws HieroException if the account could not be associated with the NFT type
*/
void dissociateNft(@NonNull List<TokenId> tokenIds, @NonNull AccountId accountId, @NonNull PrivateKey accountKey)
throws HieroException;

/**
* Dissociate an account with an NFT type.
*
* @param tokenIds the List of ID for NFT type
* @param account the account
* @throws HieroException if the account could not be associated with the NFT type
*/
default void dissociateNft(@NonNull List<TokenId> tokenIds, @NonNull Account account) throws HieroException {
Objects.requireNonNull(account, "accountId must not be null");
dissociateNft(tokenIds, account.accountId(), account.privateKey());
};

/**
* Mint a new NFT of the given type. The NFT is minted by the operator account. The operator account is used as
* supply account for the NFT.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import com.hedera.hashgraph.sdk.TokenType;
import com.openelements.hiero.base.HieroException;
import com.openelements.hiero.base.data.Account;
import com.openelements.hiero.base.protocol.*;
import com.openelements.hiero.base.protocol.ProtocolLayerClient;
import com.openelements.hiero.base.protocol.data.TokenAssociateRequest;
import com.openelements.hiero.base.protocol.data.TokenDissociateRequest;
import com.openelements.hiero.base.protocol.data.TokenBurnRequest;
import com.openelements.hiero.base.protocol.data.TokenBurnResult;
import com.openelements.hiero.base.protocol.data.TokenCreateRequest;
Expand All @@ -18,6 +19,7 @@
import com.openelements.hiero.base.protocol.data.TokenTransferRequest;
import org.jspecify.annotations.NonNull;

import java.util.List;
import java.util.Objects;

public class FungibleTokenClientImpl implements FungibleTokenClient {
Expand Down Expand Up @@ -65,6 +67,39 @@ public void associateToken(@NonNull TokenId tokenId, @NonNull AccountId accountI
client.executeTokenAssociateTransaction(request);
}

@Override
public void associateToken(@NonNull List<TokenId> tokenIds, @NonNull AccountId accountId, @NonNull PrivateKey accountKey) throws HieroException {
Objects.requireNonNull(tokenIds, "tokenIds must not be null");
Objects.requireNonNull(accountId, "accountId must not be null");
Objects.requireNonNull(accountKey, "accountKey must not be null");
if (tokenIds.isEmpty()) {
throw new IllegalArgumentException("tokenIds must not be empty");
}
final TokenAssociateRequest request = TokenAssociateRequest.of(tokenIds, accountId, accountKey);
client.executeTokenAssociateTransaction(request);
}

@Override
public void dissociateToken(@NonNull TokenId tokenId, @NonNull AccountId accountId, @NonNull PrivateKey accountKey) throws HieroException {
Objects.requireNonNull(tokenId, "tokenId must not be null");
Objects.requireNonNull(accountId, "accountId must not be null");
Objects.requireNonNull(accountKey, "accountKey must not be null");
final TokenDissociateRequest request = TokenDissociateRequest.of(tokenId, accountId, accountKey);
client.executeTokenDissociateTransaction(request);
}

@Override
public void dissociateToken(@NonNull List<TokenId> tokenIds, @NonNull AccountId accountId, @NonNull PrivateKey accountKey) throws HieroException {
Objects.requireNonNull(tokenIds, "tokenIds must not be null");
Objects.requireNonNull(accountId, "accountId must not be null");
Objects.requireNonNull(accountKey, "accountKey must not be null");
if (tokenIds.isEmpty()) {
throw new IllegalArgumentException("tokenIds must not be empty");
}
final TokenDissociateRequest request = TokenDissociateRequest.of(tokenIds, accountId, accountKey);
client.executeTokenDissociateTransaction(request);
}

@Override
public long mintToken(@NonNull TokenId tokenId, long amount) throws HieroException {
return mintToken(tokenId, operationalAccount.privateKey(), amount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.openelements.hiero.base.NftClient;
import com.openelements.hiero.base.protocol.ProtocolLayerClient;
import com.openelements.hiero.base.protocol.data.TokenAssociateRequest;
import com.openelements.hiero.base.protocol.data.TokenDissociateRequest;
import com.openelements.hiero.base.protocol.data.TokenBurnRequest;
import com.openelements.hiero.base.protocol.data.TokenCreateRequest;
import com.openelements.hiero.base.protocol.data.TokenCreateResult;
Expand Down Expand Up @@ -67,6 +68,39 @@ public void associateNft(@NonNull final TokenId tokenId, @NonNull final AccountI
client.executeTokenAssociateTransaction(request);
}

@Override
public void associateNft(@NonNull List<TokenId> tokenIds, @NonNull AccountId accountId, @NonNull PrivateKey accountKey) throws HieroException {
Objects.requireNonNull(tokenIds, "tokenIds must not be null");
Objects.requireNonNull(accountId, "accountId must not be null");
Objects.requireNonNull(accountKey, "accountKey must not be null");
if (tokenIds.isEmpty()) {
throw new IllegalArgumentException("tokenIds must not be empty");
}
final TokenAssociateRequest request = TokenAssociateRequest.of(tokenIds, accountId, accountKey);
client.executeTokenAssociateTransaction(request);
}

@Override
public void dissociateNft(@NonNull TokenId tokenId, @NonNull AccountId accountId, @NonNull PrivateKey accountKey) throws HieroException {
Objects.requireNonNull(tokenId, "tokenId must not be null");
Objects.requireNonNull(accountId, "accountId must not be null");
Objects.requireNonNull(accountKey, "accountKey must not be null");
final TokenDissociateRequest request = TokenDissociateRequest.of(tokenId, accountId, accountKey);
client.executeTokenDissociateTransaction(request);
}

@Override
public void dissociateNft(@NonNull List<TokenId> tokenIds, @NonNull AccountId accountId, @NonNull PrivateKey accountKey) throws HieroException {
Objects.requireNonNull(tokenIds, "tokenIds must not be null");
Objects.requireNonNull(accountId, "accountId must not be null");
Objects.requireNonNull(accountKey, "accountKey must not be null");
if (tokenIds.isEmpty()) {
throw new IllegalArgumentException("tokenIds must not be empty");
}
final TokenDissociateRequest request = TokenDissociateRequest.of(tokenIds, accountId, accountKey);
client.executeTokenDissociateTransaction(request);
}

@Override
public long mintNft(@NonNull TokenId tokenId, @NonNull byte[] metadata) throws HieroException {
return mintNft(tokenId, operationalAccount.privateKey(), metadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.hedera.hashgraph.sdk.Query;
import com.hedera.hashgraph.sdk.SubscriptionHandle;
import com.hedera.hashgraph.sdk.TokenAssociateTransaction;
import com.hedera.hashgraph.sdk.TokenDissociateTransaction;
import com.hedera.hashgraph.sdk.TokenBurnTransaction;
import com.hedera.hashgraph.sdk.TokenCreateTransaction;
import com.hedera.hashgraph.sdk.TokenMintTransaction;
Expand Down Expand Up @@ -67,6 +68,8 @@
import com.openelements.hiero.base.protocol.ProtocolLayerClient;
import com.openelements.hiero.base.protocol.data.TokenAssociateRequest;
import com.openelements.hiero.base.protocol.data.TokenAssociateResult;
import com.openelements.hiero.base.protocol.data.TokenDissociateRequest;
import com.openelements.hiero.base.protocol.data.TokenDissociateResult;
import com.openelements.hiero.base.protocol.data.TokenBurnRequest;
import com.openelements.hiero.base.protocol.data.TokenBurnResult;
import com.openelements.hiero.base.protocol.data.TokenCreateRequest;
Expand Down Expand Up @@ -452,7 +455,7 @@ public TokenAssociateResult executeTokenAssociateTransaction(@NonNull final Toke
final TokenAssociateTransaction transaction = new TokenAssociateTransaction()
.setMaxTransactionFee(request.maxTransactionFee())
.setTransactionValidDuration(request.transactionValidDuration())
.setTokenIds(List.of(request.tokenId()))
.setTokenIds(request.tokenIds())
.setAccountId(request.accountId());
sign(transaction, request.accountPrivateKey());
final TransactionReceipt receipt = executeTransactionAndWaitOnReceipt(transaction);
Expand All @@ -462,6 +465,24 @@ public TokenAssociateResult executeTokenAssociateTransaction(@NonNull final Toke
}
}

@Override
public @NonNull TokenDissociateResult executeTokenDissociateTransaction(@NonNull TokenDissociateRequest request)
throws HieroException {
Objects.requireNonNull(request, "request must not be null");
try {
final TokenDissociateTransaction transaction = new TokenDissociateTransaction()
.setMaxTransactionFee(request.maxTransactionFee())
.setTransactionValidDuration(request.transactionValidDuration())
.setAccountId(request.accountId())
.setTokenIds(request.tokenIds());
sign(transaction, request.accountKey());
final TransactionReceipt receipt = executeTransactionAndWaitOnReceipt(transaction);
return new TokenDissociateResult(receipt.transactionId, receipt.status);
} catch (final Exception e) {
throw new HieroException("Failed to execute dissociate token transaction", e);
}
}

public TokenBurnResult executeBurnTokenTransaction(@NonNull final TokenBurnRequest request) throws HieroException {
Objects.requireNonNull(request, "request must not be null");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.openelements.hiero.base.protocol.data.FileUpdateResult;
import com.openelements.hiero.base.protocol.data.TokenAssociateRequest;
import com.openelements.hiero.base.protocol.data.TokenAssociateResult;
import com.openelements.hiero.base.protocol.data.TokenDissociateRequest;
import com.openelements.hiero.base.protocol.data.TokenDissociateResult;
import com.openelements.hiero.base.protocol.data.TokenBurnRequest;
import com.openelements.hiero.base.protocol.data.TokenBurnResult;
import com.openelements.hiero.base.protocol.data.TokenCreateRequest;
Expand Down Expand Up @@ -197,6 +199,17 @@ AccountCreateResult executeAccountCreateTransaction(@NonNull final AccountCreate
TokenAssociateResult executeTokenAssociateTransaction(@NonNull final TokenAssociateRequest request)
throws HieroException;

/**
* Executes a token dissociate transaction.
*
* @param request the request containing the details of the token dissociate transaction
* @return the result of the token dissociate transaction
* @throws HieroException if the transaction could not be executed
*/
@NonNull
TokenDissociateResult executeTokenDissociateTransaction(@NonNull final TokenDissociateRequest request)
throws HieroException;

/**
* Executes a token mint transaction.
*
Expand Down
Loading
Loading