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

elrond.esdt.common.TokenIdentifier Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package elrond.esdt.common;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;

import java.nio.charset.StandardCharsets;

public class TokenIdentifier {
    private TokenIdentifier() {
    }

    private String hexTokenIdentifier;

    public static TokenIdentifier fromString(String tokenIdentifier) {
        TokenIdentifier ti = new TokenIdentifier();
        ti.hexTokenIdentifier = Utils.castToPaddedHex(tokenIdentifier);

        return ti;
    }

    public static TokenIdentifier fromHex(String hexTokenIdentifier) {
        TokenIdentifier ti = new TokenIdentifier();
        ti.hexTokenIdentifier = hexTokenIdentifier;

        return ti;
    }

    public String toRegularString() throws DecoderException {
        byte[] bytes = Hex.decodeHex(this.hexTokenIdentifier.toCharArray());

        return new String(bytes, StandardCharsets.UTF_8);
    }

    public String toHexString() {
        return this.hexTokenIdentifier;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy