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

software.crldev.elrondspringbootstarterreactive.domain.esdt.NFTSFTGlobalOp 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.common.Nonce;
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.*;

/**
 * Value object for NFT \ SFT global operations
 *
 * @author carlo_stanciu
 */
public final class NFTSFTGlobalOp implements ESDTTransaction {
    @NonNull
    private final Type type;
    @NonNull
    private final TokenIdentifier tokenIdentifier;
    @NonNull
    private final Nonce nonce;
    @NonNull
    private final Address address;
    @NonNull
    private final GasLimit gasLimit;

    private PayloadData processPayloadData() {
        return PayloadData.fromString(format("%s@%s@%s@%s", processType(), tokenIdentifier.getHex(), nonce.getHex(), address.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 String processType() {
        switch (type) {
        case FREEZE: 
            return ESDT_NFT_FREEZE_CALL;
        case UNFREEZE: 
            return ESDT_NFT_UNFREEZE_CALL;
        case WIPE: 
            return ESDT_NFT_WIPE_CALL;
        default: 
            throw new IllegalArgumentException();
        }
    }


    public enum Type {
        FREEZE, UNFREEZE, WIPE;
    }

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

    NFTSFTGlobalOp(@NonNull final Type type, @NonNull final TokenIdentifier tokenIdentifier, @NonNull final Nonce nonce, @NonNull final Address address, @NonNull final GasLimit gasLimit) {
        if (type == null) {
            throw new NullPointerException("type is marked non-null but is null");
        }
        if (tokenIdentifier == null) {
            throw new NullPointerException("tokenIdentifier is marked non-null but is null");
        }
        if (nonce == null) {
            throw new NullPointerException("nonce is marked non-null but is null");
        }
        if (address == null) {
            throw new NullPointerException("address is marked non-null but is null");
        }
        if (gasLimit == null) {
            throw new NullPointerException("gasLimit is marked non-null but is null");
        }
        this.type = type;
        this.tokenIdentifier = tokenIdentifier;
        this.nonce = nonce;
        this.address = address;
        this.gasLimit = gasLimit;
    }


    public static class NFTSFTGlobalOpBuilder {
        private Type type;
        private TokenIdentifier tokenIdentifier;
        private Nonce nonce;
        private Address address;
        private boolean gasLimit$set;
        private GasLimit gasLimit$value;

        NFTSFTGlobalOpBuilder() {
        }

        /**
         * @return {@code this}.
         */
        public NFTSFTGlobalOp.NFTSFTGlobalOpBuilder type(@NonNull final Type type) {
            if (type == null) {
                throw new NullPointerException("type is marked non-null but is null");
            }
            this.type = type;
            return this;
        }

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

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

        /**
         * @return {@code this}.
         */
        public NFTSFTGlobalOp.NFTSFTGlobalOpBuilder 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 NFTSFTGlobalOp build() {
            GasLimit gasLimit$value = this.gasLimit$value;
            if (!this.gasLimit$set) gasLimit$value = NFTSFTGlobalOp.$default$gasLimit();
            return new NFTSFTGlobalOp(this.type, this.tokenIdentifier, this.nonce, this.address, gasLimit$value);
        }

        @Override
        public String toString() {
            return "NFTSFTGlobalOp.NFTSFTGlobalOpBuilder(type=" + this.type + ", tokenIdentifier=" + this.tokenIdentifier + ", nonce=" + this.nonce + ", address=" + this.address + ", gasLimit$value=" + this.gasLimit$value + ")";
        }
    }

    public static NFTSFTGlobalOp.NFTSFTGlobalOpBuilder builder() {
        return new NFTSFTGlobalOp.NFTSFTGlobalOpBuilder();
    }

    @NonNull
    public Type getType() {
        return this.type;
    }

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

    @NonNull
    public Nonce getNonce() {
        return this.nonce;
    }

    @NonNull
    public Address getAddress() {
        return this.address;
    }

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

    @Override
    public boolean equals(final Object o) {
        if (o == this) return true;
        if (!(o instanceof NFTSFTGlobalOp)) return false;
        final NFTSFTGlobalOp other = (NFTSFTGlobalOp) o;
        final Object this$type = this.getType();
        final Object other$type = other.getType();
        if (this$type == null ? other$type != null : !this$type.equals(other$type)) return false;
        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$nonce = this.getNonce();
        final Object other$nonce = other.getNonce();
        if (this$nonce == null ? other$nonce != null : !this$nonce.equals(other$nonce)) return false;
        final Object this$address = this.getAddress();
        final Object other$address = other.getAddress();
        if (this$address == null ? other$address != null : !this$address.equals(other$address)) 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 $type = this.getType();
        result = result * PRIME + ($type == null ? 43 : $type.hashCode());
        final Object $tokenIdentifier = this.getTokenIdentifier();
        result = result * PRIME + ($tokenIdentifier == null ? 43 : $tokenIdentifier.hashCode());
        final Object $nonce = this.getNonce();
        result = result * PRIME + ($nonce == null ? 43 : $nonce.hashCode());
        final Object $address = this.getAddress();
        result = result * PRIME + ($address == null ? 43 : $address.hashCode());
        final Object $gasLimit = this.getGasLimit();
        result = result * PRIME + ($gasLimit == null ? 43 : $gasLimit.hashCode());
        return result;
    }

    @Override
    public String toString() {
        return "NFTSFTGlobalOp(type=" + this.getType() + ", tokenIdentifier=" + this.getTokenIdentifier() + ", nonce=" + this.getNonce() + ", address=" + this.getAddress() + ", gasLimit=" + this.getGasLimit() + ")";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy