swtc-chains
Version:
swtc chain information
108 lines • 3.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("./constants");
function funcGetChain(chain_or_token) {
const chains = constants_1.CHAINS.filter(chain => chain.code.toLowerCase() === chain_or_token.toLowerCase() ||
chain.currency.toUpperCase() === chain_or_token.toUpperCase());
return chains.length === 1 ? chains[0] : undefined;
}
exports.funcGetChain = funcGetChain;
function funcSeqEqual(arr1, arr2) {
if (arr1.length !== arr2.length) {
return false;
}
for (let i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i]) {
return false;
}
}
return true;
}
exports.funcSeqEqual = funcSeqEqual;
function isSequence(val) {
return val.length !== undefined;
}
function funcConcatArgs(...args) {
const ret = [];
args.forEach(arg => {
if (isSequence(arg)) {
for (const e of arg) {
ret.push(e);
}
}
else {
ret.push(arg);
}
});
return ret;
}
exports.funcConcatArgs = funcConcatArgs;
function funcHexToBytes(hex) {
const bytes = [];
for (let c = 0; c < hex.length; c += 2) {
bytes.push(parseInt(hex.substr(c, 2), 16));
}
return bytes;
}
exports.funcHexToBytes = funcHexToBytes;
function funcBytesToHex(bytes) {
const hex = [];
for (const byte of bytes) {
const current = byte < 0 ? byte + 256 : byte;
hex.push((current >>> 4).toString(16));
hex.push((current & 0xf).toString(16));
}
return hex.join("").toUpperCase();
}
exports.funcBytesToHex = funcBytesToHex;
function funcHexToString(h) {
const a = [];
let i = 0;
if (h.length % 2) {
a.push(String.fromCharCode(parseInt(h.substring(0, 1), 16)));
i = 1;
}
for (; i < h.length; i += 2) {
a.push(String.fromCharCode(parseInt(h.substring(i, i + 2), 16)));
}
return a.join("");
}
exports.funcHexToString = funcHexToString;
function funcStringToHex(s) {
let result = "";
for (const e of s) {
const b = e.charCodeAt(0);
result += b < 16 ? "0" + b.toString(16) : b.toString(16);
}
return result;
}
exports.funcStringToHex = funcStringToHex;
function funcString2Hex(s) {
let result = funcStringToHex(s);
if (result.length < 64) {
result += constants_1.ZERO.substr(result.length);
}
return result;
}
exports.funcString2Hex = funcString2Hex;
function funcNumber2Hex(n) {
n = n.toString(16);
return constants_1.ZERO.substr(0, 64 - n.length) + n;
}
exports.funcNumber2Hex = funcNumber2Hex;
function funcHex2Number(h) {
return parseInt(h, 16);
}
exports.funcHex2Number = funcHex2Number;
function funcIsEmpty(value) {
const type = typeof value;
if ((value !== null && type === "object") || type === "function") {
const properties = Object.keys(value);
if (properties.length === 0 || properties.size === 0) {
return true;
}
}
return !value;
}
exports.funcIsEmpty = funcIsEmpty;
//# sourceMappingURL=functions.js.map