ecash-quicksend
Version:
A unified transaction manager for eCash (XEC), SLP, and ALP token transactions
106 lines • 4.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.send = exports.sendXec = exports.sendAlp = exports.sendSlp = exports.TransactionManager = void 0;
const tokensend_1 = require("./send/tokensend");
const xecsend_1 = require("./send/xecsend");
/**
* 统一交易管理器
* 支持 SLP、ALP 和 XEC 交易类型
*/
class TransactionManager {
/**
* 发送 SLP 代币
* @param recipients - 接收方数组
* @param options - 交易选项(可包含助记词和chronik实例)
*/
async sendSlp(recipients, options) {
return await (0, tokensend_1.createRawSlpTransaction)(recipients, options);
}
/**
* 发送 ALP 代币
* @param recipients - 接收方数组
* @param options - 交易选项(可包含助记词和chronik实例)
*/
async sendAlp(recipients, options) {
return await (0, tokensend_1.createRawAlpTransaction)(recipients, options);
}
/**
* 发送 XEC (eCash)
* @param recipients - 接收方数组
* @param options - UTXO选择策略字符串或包含utxoStrategy、addressIndex、mnemonic和chronik的选项对象
*/
async sendXec(recipients, options = 'all') {
// 如果options是对象,提取相关参数;否则直接使用options作为策略
let utxoStrategy;
let addressIndex;
let mnemonic;
let chronikClient; // 新增:chronik客户端
if (typeof options === 'object' && options !== null) {
utxoStrategy = options.utxoStrategy || 'all';
addressIndex = options.addressIndex || 0;
mnemonic = options.mnemonic;
chronikClient = options.chronik; // 提取chronik客户端
}
else {
utxoStrategy = options;
addressIndex = 0;
mnemonic = undefined;
chronikClient = undefined;
}
return await (0, xecsend_1.createRawXecTransaction)(recipients, utxoStrategy, addressIndex, mnemonic, chronikClient);
}
/**
* 通用发送方法
* @param type - 交易类型
* @param recipients - 接收方数组
* @param options - 交易选项(可包含助记词和chronik实例)
*/
async send(type, recipients, options = {}) {
switch (type.toLowerCase()) {
case 'slp':
if (!options.tokenId || !options.tokenDecimals) {
throw new Error('SLP transactions require tokenId and tokenDecimals');
}
return await this.sendSlp(recipients, {
tokenId: options.tokenId,
tokenDecimals: options.tokenDecimals,
addressIndex: options.addressIndex,
feeStrategy: options.feeStrategy,
tokenStrategy: options.tokenStrategy,
mnemonic: options.mnemonic,
chronik: options.chronik // 传递chronik客户端
});
case 'alp':
if (!options.tokenId || !options.tokenDecimals) {
throw new Error('ALP transactions require tokenId and tokenDecimals');
}
return await this.sendAlp(recipients, {
tokenId: options.tokenId,
tokenDecimals: options.tokenDecimals,
addressIndex: options.addressIndex,
feeStrategy: options.feeStrategy,
tokenStrategy: options.tokenStrategy,
mnemonic: options.mnemonic,
chronik: options.chronik // 传递chronik客户端
});
case 'xec':
const xecOptions = {
utxoStrategy: options.utxoStrategy,
addressIndex: options.addressIndex,
mnemonic: options.mnemonic,
chronik: options.chronik // 传递chronik客户端
};
return await this.sendXec(recipients, xecOptions);
default:
throw new Error(`Unsupported transaction type: ${type}`);
}
}
}
exports.TransactionManager = TransactionManager;
// 创建单例实例
const quick = new TransactionManager();
// 导出实例和类
exports.default = quick;
// 便捷方法导出
exports.sendSlp = quick.sendSlp, exports.sendAlp = quick.sendAlp, exports.sendXec = quick.sendXec, exports.send = quick.send;
//# sourceMappingURL=index.js.map