<commit_before>import {Account} from "./account";
import {xdr, Keypair, encodeBase58Check} from "stellar-base";

/**
* Currency class represents a currency, either the native currency ("XLM")
* or a currency code / issuer address pair.
* @class Currency
*/
export class Currency {

    /**
    * Returns a currency object for the native currency.
    */
    static native() {
        return new Currency("XLM");
    }

    /**
    * Returns a currency object from its XDR object representation.
    * @param {xdr.Currency.iso4217} xdr - The currency xdr object.
    */
    static fromOperation(xdr) {
        if (xdr._switch.name == "currencyTypeNative") {
            return this.native();
        } else {
            let code = xdr._value._attributes.currencyCode;
            let issuer = encodeBase58Check("accountId", xdr._value._attributes.issuer);
            return new this(code, issuer);
        }
    }

    /**
    * A currency code describes a currency and issuer pair. In the case of the native
    * currency XLM, the issuer will be null.
    * @constructor
    * @param {string} code - The currency code.
    * @param {string} issuer - The address of the issuer.
    */
    constructor(code, issuer) {
        if (code.length != 3 && code.length != 4) {
            throw new Error("Currency code must be 3 or 4 characters");
        }
        if (code !== "XLM" && !issuer) {
            throw new Error("Issuer cannot be null");
        }
        // pad code with null byte if necessary
        this.code = code.length == 3 ? code + "\0" : code;
        this.issuer = issuer;
    }

    /**
    * Returns the xdr object for this currency.
    */
    toXdrObject() {
        if (this.isNative()) {
            return xdr.Currency.currencyTypeNative();
        } else {
            // need to pad the currency code with the null byte
            var currencyType = new xdr.CurrencyAlphaNum({
                currencyCode: this.code,
                issuer: Keypair.fromAddress(this.issuer).publicKey()
            });
            var currency = xdr.Currency.currencyTypeAlphanum();
            currency.set("currencyTypeAlphanum", currencyType);

            return currency;
        }
    }

    /**
    * Returns true if this currency object is the native currency.
    */
    isNative() {
        return this.code === "XLM\0";
    }

    /**
    * Returns true if this currency equals the given currency.
    */
    equals(currency) {
        return this.code == currency.code && this.issuer == currency.issuer;
    }
}<commit_msg>check lowercase code<commit_after>import {Account} from "./account";
import {xdr, Keypair, encodeBase58Check} from "stellar-base";

/**
* Currency class represents a currency, either the native currency ("XLM")
* or a currency code / issuer address pair.
* @class Currency
*/
export class Currency {

    /**
    * Returns a currency object for the native currency.
    */
    static native() {
        return new Currency("XLM");
    }

    /**
    * Returns a currency object from its XDR object representation.
    * @param {xdr.Currency.iso4217} xdr - The currency xdr object.
    */
    static fromOperation(xdr) {
        if (xdr._switch.name == "currencyTypeNative") {
            return this.native();
        } else {
            let code = xdr._value._attributes.currencyCode;
            let issuer = encodeBase58Check("accountId", xdr._value._attributes.issuer);
            return new this(code, issuer);
        }
    }

    /**
    * A currency code describes a currency and issuer pair. In the case of the native
    * currency XLM, the issuer will be null.
    * @constructor
    * @param {string} code - The currency code.
    * @param {string} issuer - The address of the issuer.
    */
    constructor(code, issuer) {
        if (code.length != 3 && code.length != 4) {
            throw new Error("Currency code must be 3 or 4 characters");
        }
        if (code.toLowerCase() !== "xlm" && !issuer) {
            throw new Error("Issuer cannot be null");
        }
        // pad code with null byte if necessary
        this.code = code.length == 3 ? code + "\0" : code;
        this.issuer = issuer;
    }

    /**
    * Returns the xdr object for this currency.
    */
    toXdrObject() {
        if (this.isNative()) {
            return xdr.Currency.currencyTypeNative();
        } else {
            // need to pad the currency code with the null byte
            var currencyType = new xdr.CurrencyAlphaNum({
                currencyCode: this.code,
                issuer: Keypair.fromAddress(this.issuer).publicKey()
            });
            var currency = xdr.Currency.currencyTypeAlphanum();
            currency.set("currencyTypeAlphanum", currencyType);

            return currency;
        }
    }

    /**
    * Returns true if this currency object is the native currency.
    */
    isNative() {
        return !this.issuer;
    }

    /**
    * Returns true if this currency equals the given currency.
    */
    equals(currency) {
        return this.code == currency.code && this.issuer == currency.issuer;
    }
}
{'fraction_non_alphanumeric': 0.1114587407117716, 'fraction_numerical': 0.005670707860774345, 'mean_word_length': 2.0428316478286734, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6489939', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1415, 'n_words': 455}