@okxweb3/coin-bitcoin
Version:
@okxweb3/coin-bitcoin is a Bitcoin SDK for building Web3 wallets and applications. It supports BTC, BSV, DOGE, LTC, and TBTC, enabling private key management, transaction signing, address generation, and inscriptions like BRC-20, Runes, CAT, and Atomicals
73 lines • 2.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.scaleConfig = exports.tokenUtxoParse = exports.feeUtxoParse = exports.tokenInfoParse = void 0;
const common_1 = require("../common");
const cat_smartcontracts_1 = require("@cat-protocol/cat-smartcontracts");
const utils_1 = require("./utils");
function tokenInfoParse(tokenStr, network) {
const token = JSON.parse(tokenStr);
const tokenInfo = JSON.parse(JSON.stringify(token.info));
if (tokenInfo.max) {
tokenInfo.max = BigInt(tokenInfo.max);
tokenInfo.premine = BigInt(tokenInfo.premine);
tokenInfo.limit = BigInt(tokenInfo.limit);
}
token.info = tokenInfo;
if (!token.tokenAddr) {
const minterP2TR = (0, utils_1.toP2tr)(token.minterAddr);
token.tokenAddr = (0, utils_1.p2tr2Address)((0, utils_1.getTokenContractP2TR)(minterP2TR).p2tr, network);
}
return token;
}
exports.tokenInfoParse = tokenInfoParse;
function feeUtxoParse(ecKey, utxos) {
return utxos.map((utxo) => {
let scriptPk = common_1.btc.Script.fromAddress(ecKey.getAddress()).toHex();
return {
txId: utxo.txId,
outputIndex: utxo.vOut,
script: scriptPk,
satoshis: utxo.amount,
};
});
}
exports.feeUtxoParse = feeUtxoParse;
function tokenUtxoParse(tokenUtxos) {
let utxos = JSON.parse(tokenUtxos);
if (!Array.isArray(utxos)) {
utxos = [utxos];
}
return utxos.map((c) => {
const protocolState = cat_smartcontracts_1.ProtocolState.fromStateHashList(c.txoStateHashes);
if (typeof c.utxo.satoshis === 'string') {
c.utxo.satoshis = parseInt(c.utxo.satoshis);
}
let ownerAddr = c.state.address;
try {
ownerAddr = (0, utils_1.toTokenAddress)(c.state.address);
}
catch {
}
const r = {
utxo: c.utxo,
state: {
protocolState,
data: {
ownerAddr: ownerAddr,
amount: BigInt(c.state.amount),
},
},
};
return r;
});
}
exports.tokenUtxoParse = tokenUtxoParse;
function scaleConfig(config) {
const clone = Object.assign({}, config);
clone.max = (0, utils_1.scaleByDecimals)(config.max, config.decimals);
clone.premine = (0, utils_1.scaleByDecimals)(config.premine, config.decimals);
clone.limit = (0, utils_1.scaleByDecimals)(config.limit, config.decimals);
return clone;
}
exports.scaleConfig = scaleConfig;
//# sourceMappingURL=paramsUtils.js.map