chaingate
Version:
A complete TypeScript library for connecting to and making transactions on different blockchains
156 lines • 6.01 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UtxoCurrencyUtils = void 0;
const CurrencyUtils_1 = require("../../CurrencyUtils");
const Client_1 = require("../../../../Client");
const Utils_1 = require("../../../../InternalUtils/Utils");
const NumberLike_1 = require("../../../../InternalUtils/NumberLike");
class UtxoCurrencyUtils extends CurrencyUtils_1.CurrencyUtils {
network;
networkParams;
signHeader;
constructor(client, currencyInfo, markets, network, networkParams, signHeader) {
super(client, currencyInfo, markets);
this.network = network;
this.networkParams = networkParams;
this.signHeader = signHeader;
}
async addressUtxos(address, page = 0) {
const response = await (0, Client_1.utxoUtxosByAddress)({
client: this.client,
path: { network: this.network },
query: { address, page },
});
return {
page: response.data.page,
utxos: response.data.utxos.map((utxo) => ({
txid: utxo.txid,
script: (0, Utils_1.hexToBytes)(utxo.script),
amount: this.buildAmount(utxo.amount),
n: utxo.n,
})),
};
}
async addressBalance(address) {
const result = await (0, Client_1.utxoAddressBalance)({
client: this.client,
path: { network: this.network },
query: { address },
});
return {
confirmed: this.buildAmount(result.data.confirmed),
unconfirmed: this.buildAmount(result.data.unconfirmed),
};
}
async addressHistory(address, page = 0) {
const respose = await (0, Client_1.utxoAddressHistory)({
client: this.client,
path: { network: this.network },
query: { address, page },
});
return {
transactions: respose.data.transactions.map((t) => ({
amount: this.buildAmount(t.amount),
addressBalance: this.buildAmount(t.addressBalance),
txid: t.txid,
height: t.height,
})),
page: respose.data.page,
};
}
async broadcastTransaction(transactionRaw) {
const result = await (0, Client_1.utxoBroadcastTransaction)({
client: this.client,
path: { network: this.network },
body: {
transactionRaw: transactionRaw instanceof Uint8Array
? (0, Utils_1.bytesToHex)(transactionRaw, false)
: transactionRaw,
},
});
return { transactionId: result.data.txId };
}
async transactionDetails(transactionId) {
const result = await (0, Client_1.utxoTransactionDetails)({
client: this.client,
path: { network: this.network },
query: { transactionId },
});
return {
blockHeight: result.data.blockHeight ?? null,
fee: this.buildAmount(result.data.fee),
feePerKb: this.buildAmount(result.data.feePerKb),
timestamp: result.data.timestamp,
inputs: result.data.inputs.map((input) => ({
address: input.address,
amount: this.buildAmount(input.amount),
n: (0, NumberLike_1.toDecimal)(input.n),
script: input.script ? (0, Utils_1.hexToBytes)(input.script) : null,
scriptSig: input.scriptSig ? (0, Utils_1.hexToBytes)(input.scriptSig) : null,
})),
outputs: result.data.outputs.map((output) => ({
address: output.address,
amount: this.buildAmount(output.amount),
n: (0, NumberLike_1.toDecimal)(output.n),
script: output.script ? (0, Utils_1.hexToBytes)(output.script) : null,
})),
rawTransaction: result.data.rawTransaction,
};
}
async getFeeRate() {
const result = await (0, Client_1.utxoFeeRate)({
client: this.client,
path: { network: this.network },
});
return {
low: {
feePerKb: this.buildAmount(result.data.low.feePerKb),
confirmationTimeSecs: Number(result.data.low.confirmationTimeSecs),
},
normal: {
feePerKb: this.buildAmount(result.data.normal.feePerKb),
confirmationTimeSecs: Number(result.data.normal.confirmationTimeSecs),
},
high: {
feePerKb: this.buildAmount(result.data.high.feePerKb),
confirmationTimeSecs: Number(result.data.high.confirmationTimeSecs),
},
maximum: {
feePerKb: this.buildAmount(result.data.maximum.feePerKb),
confirmationTimeSecs: Number(result.data.maximum.confirmationTimeSecs),
},
};
}
async latestBlock() {
const result = await (0, Client_1.utxoLatestBlock)({
client: this.client,
path: { network: this.network },
});
return result.data;
}
async mempoolTransactions() {
const result = await (0, Client_1.utxoMempool)({
client: this.client,
path: { network: this.network },
});
return result.data;
}
async blockByHeight(blockHeight) {
const result = await (0, Client_1.utxoBlockByHeight)({
client: this.client,
path: { network: this.network },
query: { blockHeight },
});
return result.data;
}
async blocByHash(blockHash) {
const result = await (0, Client_1.utxoBlockByHash)({
client: this.client,
path: { network: this.network },
query: { blockHash },
});
return result.data;
}
}
exports.UtxoCurrencyUtils = UtxoCurrencyUtils;
//# sourceMappingURL=UtxoCurrencyUtils.js.map