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

software.crldev.elrondspringbootstarterreactive.domain.esdt.ESDTUpgrade 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.common.TokenIdentifier;
import software.crldev.elrondspringbootstarterreactive.domain.esdt.common.TokenProperty;
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.error.ErrorMessage;
import software.crldev.elrondspringbootstarterreactive.interactor.transaction.TransactionRequest;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
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_UPGRADE_CALL;

/**
 * Value object for ESDT upgrading
 *
 * @author carlo_stanciu
 */
public final class ESDTUpgrade implements ESDTTransaction {
    @NonNull
    private final TokenIdentifier tokenIdentifier;
    private final GasLimit gasLimit;
    private final Set properties;

    private PayloadData processPayloadData() {
        if (properties.isEmpty()) throw new IllegalArgumentException(ErrorMessage.TOKEN_PROPERTY.getValue());
        return PayloadData.fromString(format("%s@%s%s", ESDT_UPGRADE_CALL, tokenIdentifier.getHex(), properties.stream().map(p -> "@" + p.getNameHex() + "@" + p.getValueHex()).collect(Collectors.joining())));
    }

    @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();
    }

    private static Set $default$properties() {
        return new HashSet<>();
    }

    ESDTUpgrade(@NonNull final TokenIdentifier tokenIdentifier, final GasLimit gasLimit, final Set properties) {
        if (tokenIdentifier == null) {
            throw new NullPointerException("tokenIdentifier is marked non-null but is null");
        }
        this.tokenIdentifier = tokenIdentifier;
        this.gasLimit = gasLimit;
        this.properties = properties;
    }


    public static class ESDTUpgradeBuilder {
        private TokenIdentifier tokenIdentifier;
        private boolean gasLimit$set;
        private GasLimit gasLimit$value;
        private boolean properties$set;
        private Set properties$value;

        ESDTUpgradeBuilder() {
        }

        /**
         * @return {@code this}.
         */
        public ESDTUpgrade.ESDTUpgradeBuilder 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 ESDTUpgrade.ESDTUpgradeBuilder gasLimit(final GasLimit gasLimit) {
            this.gasLimit$value = gasLimit;
            gasLimit$set = true;
            return this;
        }

        /**
         * @return {@code this}.
         */
        public ESDTUpgrade.ESDTUpgradeBuilder properties(final Set properties) {
            this.properties$value = properties;
            properties$set = true;
            return this;
        }

        public ESDTUpgrade build() {
            GasLimit gasLimit$value = this.gasLimit$value;
            if (!this.gasLimit$set) gasLimit$value = ESDTUpgrade.$default$gasLimit();
            Set properties$value = this.properties$value;
            if (!this.properties$set) properties$value = ESDTUpgrade.$default$properties();
            return new ESDTUpgrade(this.tokenIdentifier, gasLimit$value, properties$value);
        }

        @Override
        public String toString() {
            return "ESDTUpgrade.ESDTUpgradeBuilder(tokenIdentifier=" + this.tokenIdentifier + ", gasLimit$value=" + this.gasLimit$value + ", properties$value=" + this.properties$value + ")";
        }
    }

    public static ESDTUpgrade.ESDTUpgradeBuilder builder() {
        return new ESDTUpgrade.ESDTUpgradeBuilder();
    }

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

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

    public Set getProperties() {
        return this.properties;
    }

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

    @Override
    public String toString() {
        return "ESDTUpgrade(tokenIdentifier=" + this.getTokenIdentifier() + ", gasLimit=" + this.getGasLimit() + ", properties=" + this.getProperties() + ")";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy