mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-12 03:28:13 -07:00
43 lines
973 B
JavaScript
43 lines
973 B
JavaScript
import { readNumber, readObject, readString } from "../../read.js";
|
|
|
|
/**
|
|
* @typedef {import("../../scan/index.js").WalletAddress} WalletAddress
|
|
*
|
|
* @typedef {Object} WalletUtxo
|
|
* @property {WalletAddress} address
|
|
* @property {string} txid
|
|
* @property {number} vout
|
|
* @property {number} value
|
|
* @property {boolean} confirmed
|
|
*/
|
|
|
|
/**
|
|
* @param {unknown} utxo
|
|
*/
|
|
function isConfirmed(utxo) {
|
|
return readObject(readObject(utxo)?.status)?.confirmed === true;
|
|
}
|
|
|
|
/**
|
|
* @param {WalletAddress} address
|
|
* @param {unknown} utxo
|
|
* @returns {WalletUtxo | undefined}
|
|
*/
|
|
export function readWalletUtxo(address, utxo) {
|
|
const txid = readString(readObject(utxo)?.txid);
|
|
const vout = readNumber(readObject(utxo)?.vout);
|
|
const value = readNumber(readObject(utxo)?.value);
|
|
|
|
if (txid === undefined || vout === undefined || value === undefined) {
|
|
return undefined;
|
|
}
|
|
|
|
return {
|
|
address,
|
|
txid,
|
|
vout,
|
|
value,
|
|
confirmed: isConfirmed(utxo),
|
|
};
|
|
}
|