All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.crldev.elrondspringbootstarterreactive.domain.esdt.NFTCreationRoleTransfer Maven / Gradle / Ivy

Go to download

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.account.Address;
import software.crldev.elrondspringbootstarterreactive.domain.common.Balance;
import software.crldev.elrondspringbootstarterreactive.domain.esdt.ESDTTransaction;
import software.crldev.elrondspringbootstarterreactive.domain.esdt.common.TokenIdentifier;
import software.crldev.elrondspringbootstarterreactive.domain.transaction.GasLimit;
import software.crldev.elrondspringbootstarterreactive.domain.transaction.PayloadData;
import software.crldev.elrondspringbootstarterreactive.domain.wallet.Wallet;
import software.crldev.elrondspringbootstarterreactive.interactor.transaction.TransactionRequest;
import static java.lang.String.format;
import static software.crldev.elrondspringbootstarterreactive.config.constants.ESDTConstants.ESDT_ISSUER_BECH32_ADDRESS;
import static software.crldev.elrondspringbootstarterreactive.config.constants.ESDTConstants.ESDT_NFT_CREATE_ROLE_TRANSFER_CALL;

/**
 * Value object for NFT create role transfer
 *
 * @author carlo_stanciu
 */
public final class NFTCreationRoleTransfer implements ESDTTransaction {
    @NonNull
    private final TokenIdentifier tokenIdentifier;
    @NonNull
    private final Address fromAddress;
    @NonNull
    private final Address toAddress;
    @NonNull
    private final GasLimit gasLimit;

    private PayloadData processPayloadData() {
        return PayloadData.fromString(format("%s@%s@%s@%s", ESDT_NFT_CREATE_ROLE_TRANSFER_CALL, tokenIdentifier.getHex(), fromAddress.getHex(), toAddress.getHex()));
    }

    @Override
    public TransactionRequest toTransactionRequest(Wallet wallet) {
        return TransactionRequest.builder().receiverAddress(Address.fromBech32(ESDT_ISSUER_BECH32_ADDRESS)).data(processPayloadData()).value(Balance.zero()).gasLimit(gasLimit).build();
    }

    private static GasLimit $default$gasLimit() {
        return GasLimit.defaultEsdtIssuance();
    }

    NFTCreationRoleTransfer(@NonNull final TokenIdentifier tokenIdentifier, @NonNull final Address fromAddress, @NonNull final Address toAddress, @NonNull final GasLimit gasLimit) {
        if (tokenIdentifier == null) {
            throw new NullPointerException("tokenIdentifier is marked non-null but is null");
        }
        if (fromAddress == null) {
            throw new NullPointerException("fromAddress is marked non-null but is null");
        }
        if (toAddress == null) {
            throw new NullPointerException("toAddress 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.fromAddress = fromAddress;
        this.toAddress = toAddress;
        this.gasLimit = gasLimit;
    }


    public static class NFTCreationRoleTransferBuilder {
        private TokenIdentifier tokenIdentifier;
        private Address fromAddress;
        private Address toAddress;
        private boolean gasLimit$set;
        private GasLimit gasLimit$value;

        NFTCreationRoleTransferBuilder() {
        }

        /**
         * @return {@code this}.
         */
        public NFTCreationRoleTransfer.NFTCreationRoleTransferBuilder 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 NFTCreationRoleTransfer.NFTCreationRoleTransferBuilder fromAddress(@NonNull final Address fromAddress) {
            if (fromAddress == null) {
                throw new NullPointerException("fromAddress is marked non-null but is null");
            }
            this.fromAddress = fromAddress;
            return this;
        }

        /**
         * @return {@code this}.
         */
        public NFTCreationRoleTransfer.NFTCreationRoleTransferBuilder toAddress(@NonNull final Address toAddress) {
            if (toAddress == null) {
                throw new NullPointerException("toAddress is marked non-null but is null");
            }
            this.toAddress = toAddress;
            return this;
        }

        /**
         * @return {@code this}.
         */
        public NFTCreationRoleTransfer.NFTCreationRoleTransferBuilder 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 NFTCreationRoleTransfer build() {
            GasLimit gasLimit$value = this.gasLimit$value;
            if (!this.gasLimit$set) gasLimit$value = NFTCreationRoleTransfer.$default$gasLimit();
            return new NFTCreationRoleTransfer(this.tokenIdentifier, this.fromAddress, this.toAddress, gasLimit$value);
        }

        @Override
        public String toString() {
            return "NFTCreationRoleTransfer.NFTCreationRoleTransferBuilder(tokenIdentifier=" + this.tokenIdentifier + ", fromAddress=" + this.fromAddress + ", toAddress=" + this.toAddress + ", gasLimit$value=" + this.gasLimit$value + ")";
        }
    }

    public static NFTCreationRoleTransfer.NFTCreationRoleTransferBuilder builder() {
        return new NFTCreationRoleTransfer.NFTCreationRoleTransferBuilder();
    }

    @NonNull
    public TokenIdentifier getTokenIdentifier() {
        return this.tokenIdentifier;
    }

    @NonNull
    public Address getFromAddress() {
        return this.fromAddress;
    }

    @NonNull
    public Address getToAddress() {
        return this.toAddress;
    }

    @NonNull
    public GasLimit getGasLimit() {
        return this.gasLimit;
    }

    @Override
    public boolean equals(final Object o) {
        if (o == this) return true;
        if (!(o instanceof NFTCreationRoleTransfer)) return false;
        final NFTCreationRoleTransfer other = (NFTCreationRoleTransfer) 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$fromAddress = this.getFromAddress();
        final Object other$fromAddress = other.getFromAddress();
        if (this$fromAddress == null ? other$fromAddress != null : !this$fromAddress.equals(other$fromAddress)) return false;
        final Object this$toAddress = this.getToAddress();
        final Object other$toAddress = other.getToAddress();
        if (this$toAddress == null ? other$toAddress != null : !this$toAddress.equals(other$toAddress)) 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 $fromAddress = this.getFromAddress();
        result = result * PRIME + ($fromAddress == null ? 43 : $fromAddress.hashCode());
        final Object $toAddress = this.getToAddress();
        result = result * PRIME + ($toAddress == null ? 43 : $toAddress.hashCode());
        final Object $gasLimit = this.getGasLimit();
        result = result * PRIME + ($gasLimit == null ? 43 : $gasLimit.hashCode());
        return result;
    }

    @Override
    public String toString() {
        return "NFTCreationRoleTransfer(tokenIdentifier=" + this.getTokenIdentifier() + ", fromAddress=" + this.getFromAddress() + ", toAddress=" + this.getToAddress() + ", gasLimit=" + this.getGasLimit() + ")";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy