
software.crldev.elrondspringbootstarterreactive.domain.esdt.NFTCreation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elrond-spring-boot-starter-reactive Show documentation
Show all versions of elrond-spring-boot-starter-reactive Show documentation
A SpringBoot Starter solution designed to ensure easy and efficient integration with the Elrond Network using a Reactive API layer.
The newest version!
package software.crldev.elrondspringbootstarterreactive.domain.esdt;
import lombok.NonNull;
import software.crldev.elrondspringbootstarterreactive.domain.common.Balance;
import software.crldev.elrondspringbootstarterreactive.domain.esdt.ESDTTransaction;
import software.crldev.elrondspringbootstarterreactive.domain.esdt.common.*;
import software.crldev.elrondspringbootstarterreactive.domain.transaction.GasLimit;
import software.crldev.elrondspringbootstarterreactive.domain.transaction.Hash;
import software.crldev.elrondspringbootstarterreactive.domain.transaction.PayloadData;
import software.crldev.elrondspringbootstarterreactive.domain.wallet.Wallet;
import software.crldev.elrondspringbootstarterreactive.interactor.transaction.TransactionRequest;
import java.math.BigInteger;
import java.util.Set;
import java.util.stream.Collectors;
import static java.lang.String.format;
import static software.crldev.elrondspringbootstarterreactive.config.constants.ESDTConstants.ESDT_NFT_CREATE_CALL;
/**
* Value object for NFT creation
*
* @author carlo_stanciu
*/
public final class NFTCreation implements ESDTTransaction {
@NonNull
private final TokenIdentifier tokenIdentifier;
private final TokenInitialSupply initialQuantity;
@NonNull
private final TokenName nftName;
@NonNull
private final TokenRoyalties tokenRoyalties;
@NonNull
private final Hash hash;
@NonNull
private final TokenAttributes tokenAttributes;
@NonNull
private final Set uris;
@NonNull
private final GasLimit gasLimit;
private PayloadData processPayloadData() {
return PayloadData.fromString(format("%s@%s@%s@%s@%s@%s@%s@%s", ESDT_NFT_CREATE_CALL, tokenIdentifier.getHex(), initialQuantity.getHex(), nftName.getHex(), tokenRoyalties.getHex(), processHash(), tokenAttributes.getHex(), processUris()));
}
private String processHash() {
return hash.isEmpty() ? "00" : hash.toString();
}
private String processUris() {
if (uris.isEmpty()) throw new IllegalArgumentException("List of URIs cannot be empty");
return uris.stream().map(ESDTUri::getHex).collect(Collectors.joining("@"));
}
@Override
public TransactionRequest toTransactionRequest(Wallet wallet) {
return TransactionRequest.builder().receiverAddress(wallet.getAddress()).data(processPayloadData()).value(Balance.zero()).gasLimit(gasLimit).build();
}
private static TokenInitialSupply $default$initialQuantity() {
return TokenInitialSupply.fromNumber(BigInteger.ONE);
}
private static Hash $default$hash() {
return Hash.empty();
}
private static GasLimit $default$gasLimit() {
return GasLimit.defaultNftCreate();
}
NFTCreation(@NonNull final TokenIdentifier tokenIdentifier, final TokenInitialSupply initialQuantity, @NonNull final TokenName nftName, @NonNull final TokenRoyalties tokenRoyalties, @NonNull final Hash hash, @NonNull final TokenAttributes tokenAttributes, @NonNull final Set uris, @NonNull final GasLimit gasLimit) {
if (tokenIdentifier == null) {
throw new NullPointerException("tokenIdentifier is marked non-null but is null");
}
if (nftName == null) {
throw new NullPointerException("nftName is marked non-null but is null");
}
if (tokenRoyalties == null) {
throw new NullPointerException("tokenRoyalties is marked non-null but is null");
}
if (hash == null) {
throw new NullPointerException("hash is marked non-null but is null");
}
if (tokenAttributes == null) {
throw new NullPointerException("tokenAttributes is marked non-null but is null");
}
if (uris == null) {
throw new NullPointerException("uris is marked non-null but is null");
}
if (gasLimit == null) {
throw new NullPointerException("gasLimit is marked non-null but is null");
}
this.tokenIdentifier = tokenIdentifier;
this.initialQuantity = initialQuantity;
this.nftName = nftName;
this.tokenRoyalties = tokenRoyalties;
this.hash = hash;
this.tokenAttributes = tokenAttributes;
this.uris = uris;
this.gasLimit = gasLimit;
}
public static class NFTCreationBuilder {
private TokenIdentifier tokenIdentifier;
private boolean initialQuantity$set;
private TokenInitialSupply initialQuantity$value;
private TokenName nftName;
private TokenRoyalties tokenRoyalties;
private boolean hash$set;
private Hash hash$value;
private TokenAttributes tokenAttributes;
private Set uris;
private boolean gasLimit$set;
private GasLimit gasLimit$value;
NFTCreationBuilder() {
}
/**
* @return {@code this}.
*/
public NFTCreation.NFTCreationBuilder tokenIdentifier(@NonNull final TokenIdentifier tokenIdentifier) {
if (tokenIdentifier == null) {
throw new NullPointerException("tokenIdentifier is marked non-null but is null");
}
this.tokenIdentifier = tokenIdentifier;
return this;
}
/**
* @return {@code this}.
*/
public NFTCreation.NFTCreationBuilder initialQuantity(final TokenInitialSupply initialQuantity) {
this.initialQuantity$value = initialQuantity;
initialQuantity$set = true;
return this;
}
/**
* @return {@code this}.
*/
public NFTCreation.NFTCreationBuilder nftName(@NonNull final TokenName nftName) {
if (nftName == null) {
throw new NullPointerException("nftName is marked non-null but is null");
}
this.nftName = nftName;
return this;
}
/**
* @return {@code this}.
*/
public NFTCreation.NFTCreationBuilder tokenRoyalties(@NonNull final TokenRoyalties tokenRoyalties) {
if (tokenRoyalties == null) {
throw new NullPointerException("tokenRoyalties is marked non-null but is null");
}
this.tokenRoyalties = tokenRoyalties;
return this;
}
/**
* @return {@code this}.
*/
public NFTCreation.NFTCreationBuilder hash(@NonNull final Hash hash) {
if (hash == null) {
throw new NullPointerException("hash is marked non-null but is null");
}
this.hash$value = hash;
hash$set = true;
return this;
}
/**
* @return {@code this}.
*/
public NFTCreation.NFTCreationBuilder tokenAttributes(@NonNull final TokenAttributes tokenAttributes) {
if (tokenAttributes == null) {
throw new NullPointerException("tokenAttributes is marked non-null but is null");
}
this.tokenAttributes = tokenAttributes;
return this;
}
/**
* @return {@code this}.
*/
public NFTCreation.NFTCreationBuilder uris(@NonNull final Set uris) {
if (uris == null) {
throw new NullPointerException("uris is marked non-null but is null");
}
this.uris = uris;
return this;
}
/**
* @return {@code this}.
*/
public NFTCreation.NFTCreationBuilder gasLimit(@NonNull final GasLimit gasLimit) {
if (gasLimit == null) {
throw new NullPointerException("gasLimit is marked non-null but is null");
}
this.gasLimit$value = gasLimit;
gasLimit$set = true;
return this;
}
public NFTCreation build() {
TokenInitialSupply initialQuantity$value = this.initialQuantity$value;
if (!this.initialQuantity$set) initialQuantity$value = NFTCreation.$default$initialQuantity();
Hash hash$value = this.hash$value;
if (!this.hash$set) hash$value = NFTCreation.$default$hash();
GasLimit gasLimit$value = this.gasLimit$value;
if (!this.gasLimit$set) gasLimit$value = NFTCreation.$default$gasLimit();
return new NFTCreation(this.tokenIdentifier, initialQuantity$value, this.nftName, this.tokenRoyalties, hash$value, this.tokenAttributes, this.uris, gasLimit$value);
}
@Override
public String toString() {
return "NFTCreation.NFTCreationBuilder(tokenIdentifier=" + this.tokenIdentifier + ", initialQuantity$value=" + this.initialQuantity$value + ", nftName=" + this.nftName + ", tokenRoyalties=" + this.tokenRoyalties + ", hash$value=" + this.hash$value + ", tokenAttributes=" + this.tokenAttributes + ", uris=" + this.uris + ", gasLimit$value=" + this.gasLimit$value + ")";
}
}
public static NFTCreation.NFTCreationBuilder builder() {
return new NFTCreation.NFTCreationBuilder();
}
@NonNull
public TokenIdentifier getTokenIdentifier() {
return this.tokenIdentifier;
}
public TokenInitialSupply getInitialQuantity() {
return this.initialQuantity;
}
@NonNull
public TokenName getNftName() {
return this.nftName;
}
@NonNull
public TokenRoyalties getTokenRoyalties() {
return this.tokenRoyalties;
}
@NonNull
public Hash getHash() {
return this.hash;
}
@NonNull
public TokenAttributes getTokenAttributes() {
return this.tokenAttributes;
}
@NonNull
public Set getUris() {
return this.uris;
}
@NonNull
public GasLimit getGasLimit() {
return this.gasLimit;
}
@Override
public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof NFTCreation)) return false;
final NFTCreation other = (NFTCreation) o;
final Object this$tokenIdentifier = this.getTokenIdentifier();
final Object other$tokenIdentifier = other.getTokenIdentifier();
if (this$tokenIdentifier == null ? other$tokenIdentifier != null : !this$tokenIdentifier.equals(other$tokenIdentifier)) return false;
final Object this$initialQuantity = this.getInitialQuantity();
final Object other$initialQuantity = other.getInitialQuantity();
if (this$initialQuantity == null ? other$initialQuantity != null : !this$initialQuantity.equals(other$initialQuantity)) return false;
final Object this$nftName = this.getNftName();
final Object other$nftName = other.getNftName();
if (this$nftName == null ? other$nftName != null : !this$nftName.equals(other$nftName)) return false;
final Object this$tokenRoyalties = this.getTokenRoyalties();
final Object other$tokenRoyalties = other.getTokenRoyalties();
if (this$tokenRoyalties == null ? other$tokenRoyalties != null : !this$tokenRoyalties.equals(other$tokenRoyalties)) return false;
final Object this$hash = this.getHash();
final Object other$hash = other.getHash();
if (this$hash == null ? other$hash != null : !this$hash.equals(other$hash)) return false;
final Object this$tokenAttributes = this.getTokenAttributes();
final Object other$tokenAttributes = other.getTokenAttributes();
if (this$tokenAttributes == null ? other$tokenAttributes != null : !this$tokenAttributes.equals(other$tokenAttributes)) return false;
final Object this$uris = this.getUris();
final Object other$uris = other.getUris();
if (this$uris == null ? other$uris != null : !this$uris.equals(other$uris)) return false;
final Object this$gasLimit = this.getGasLimit();
final Object other$gasLimit = other.getGasLimit();
if (this$gasLimit == null ? other$gasLimit != null : !this$gasLimit.equals(other$gasLimit)) return false;
return true;
}
@Override
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $tokenIdentifier = this.getTokenIdentifier();
result = result * PRIME + ($tokenIdentifier == null ? 43 : $tokenIdentifier.hashCode());
final Object $initialQuantity = this.getInitialQuantity();
result = result * PRIME + ($initialQuantity == null ? 43 : $initialQuantity.hashCode());
final Object $nftName = this.getNftName();
result = result * PRIME + ($nftName == null ? 43 : $nftName.hashCode());
final Object $tokenRoyalties = this.getTokenRoyalties();
result = result * PRIME + ($tokenRoyalties == null ? 43 : $tokenRoyalties.hashCode());
final Object $hash = this.getHash();
result = result * PRIME + ($hash == null ? 43 : $hash.hashCode());
final Object $tokenAttributes = this.getTokenAttributes();
result = result * PRIME + ($tokenAttributes == null ? 43 : $tokenAttributes.hashCode());
final Object $uris = this.getUris();
result = result * PRIME + ($uris == null ? 43 : $uris.hashCode());
final Object $gasLimit = this.getGasLimit();
result = result * PRIME + ($gasLimit == null ? 43 : $gasLimit.hashCode());
return result;
}
@Override
public String toString() {
return "NFTCreation(tokenIdentifier=" + this.getTokenIdentifier() + ", initialQuantity=" + this.getInitialQuantity() + ", nftName=" + this.getNftName() + ", tokenRoyalties=" + this.getTokenRoyalties() + ", hash=" + this.getHash() + ", tokenAttributes=" + this.getTokenAttributes() + ", uris=" + this.getUris() + ", gasLimit=" + this.getGasLimit() + ")";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy