diff --git a/modules/chronik-client/package-lock.json b/modules/chronik-client/package-lock.json --- a/modules/chronik-client/package-lock.json +++ b/modules/chronik-client/package-lock.json @@ -1,12 +1,12 @@ { "name": "chronik-client", - "version": "0.24.0", + "version": "0.24.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "chronik-client", - "version": "0.24.0", + "version": "0.24.1", "license": "MIT", "dependencies": { "@types/ws": "^8.2.1", diff --git a/modules/chronik-client/package.json b/modules/chronik-client/package.json --- a/modules/chronik-client/package.json +++ b/modules/chronik-client/package.json @@ -1,6 +1,6 @@ { "name": "chronik-client", - "version": "0.24.0", + "version": "0.24.1", "description": "A client for accessing the Chronik Indexer API", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/modules/chronik-client/src/ChronikClientNode.ts b/modules/chronik-client/src/ChronikClientNode.ts --- a/modules/chronik-client/src/ChronikClientNode.ts +++ b/modules/chronik-client/src/ChronikClientNode.ts @@ -625,14 +625,12 @@ } function convertToTx(tx: proto.Tx): Tx_InNode { - return { + const convertedTx: Tx_InNode = { txid: toHexRev(tx.txid), version: tx.version, inputs: tx.inputs.map(convertToTxInput), outputs: tx.outputs.map(convertToTxOutput), lockTime: tx.lockTime, - block: - tx.block !== undefined ? convertToBlockMeta(tx.block) : undefined, timeFirstSeen: parseInt(tx.timeFirstSeen), size: tx.size, isCoinbase: tx.isCoinbase, @@ -642,6 +640,11 @@ ), tokenStatus: convertToTokenStatus(tx.tokenStatus), }; + if (typeof tx.block !== 'undefined') { + // Only include block if the tx is in a block + convertedTx.block = convertToBlockMeta(tx.block); + } + return convertedTx; } function convertToTxInput(input: proto.TxInput): TxInput_InNode { @@ -654,10 +657,6 @@ outIdx: input.prevOut.outIdx, }, inputScript: toHex(input.inputScript), - outputScript: - input.outputScript.length > 0 - ? toHex(input.outputScript) - : undefined, value: parseInt(input.value), sequenceNo: input.sequenceNo, }; @@ -665,6 +664,13 @@ // We only return a token key if we have token data for this input txInput.token = convertToTokenInNode(input.token); } + if ( + typeof input.outputScript !== 'undefined' && + input.outputScript.length > 0 + ) { + // Coinbase tx inputs do not have an outputScript + txInput.outputScript = toHex(input.outputScript); + } return txInput; } @@ -672,18 +678,18 @@ const txOutput: TxOutput_InNode = { value: parseInt(output.value), outputScript: toHex(output.outputScript), - spentBy: - output.spentBy !== undefined - ? { - txid: toHexRev(output.spentBy.txid), - outIdx: output.spentBy.inputIdx, - } - : undefined, }; if (typeof output.token !== 'undefined') { // We only return a token key if we have token data for this input txOutput.token = convertToTokenInNode(output.token); } + if (typeof output.spentBy !== 'undefined') { + // We only return a spentBy key if this output has been spent + txOutput.spentBy = { + txid: toHexRev(output.spentBy.txid), + outIdx: output.spentBy.inputIdx, + }; + } return txOutput; } @@ -915,8 +921,8 @@ genesisInfo: convertToGenesisInfo(tokenInfo.genesisInfo, tokenType), }; - // Only include block if the tx is confirmed if (typeof tokenInfo.block !== 'undefined') { + // Only include block if the tx is in a block returnedTokenInfo.block = convertToBlockMeta(tokenInfo.block); } @@ -1033,8 +1039,8 @@ outputs: TxOutput_InNode[]; /** `locktime` field of the transaction, tx is not valid before this time. */ lockTime: number; - /** Block data for this tx, or undefined if not mined yet. */ - block: BlockMetadata_InNode | undefined; + /** Block data for this tx, if it is in a block. */ + block?: BlockMetadata_InNode; /** * UNIX timestamp when this tx has first been seen in the mempool. * 0 if unknown -> make sure to check. @@ -1067,8 +1073,9 @@ /** * Script of the output, in hex encoding. * Aka. `scriptPubKey` in bitcoind parlance. + * Not present for coinbase txs */ - outputScript: string | undefined; + outputScript?: string; /** Value of the output spent by this input, in satoshis. */ value: number; /** `sequence` field of the input; can be used for relative time locking. */ @@ -1087,10 +1094,10 @@ */ outputScript: string; /** - * Transaction & input index spending this output, or undefined if - * unspent. + * Transaction & input index spending this output, if + * spent. */ - spentBy: OutPoint | undefined; + spentBy?: OutPoint; /** Token value attached to this output */ token?: Token_InNode; } diff --git a/modules/chronik-client/test/integration/token_alp.ts b/modules/chronik-client/test/integration/token_alp.ts --- a/modules/chronik-client/test/integration/token_alp.ts +++ b/modules/chronik-client/test/integration/token_alp.ts @@ -150,7 +150,6 @@ const BASE_TX_OUTPUT = { value: 546, outputScript: 'a914da1745e9b549bd0bfa1a569971c77eba30cd5a4b87', - spentBy: undefined, }; const BASE_TX_TOKEN_INFO_ALP = { tokenType: { diff --git a/modules/chronik-client/test/integration/token_slp_fungible.ts b/modules/chronik-client/test/integration/token_slp_fungible.ts --- a/modules/chronik-client/test/integration/token_slp_fungible.ts +++ b/modules/chronik-client/test/integration/token_slp_fungible.ts @@ -116,7 +116,6 @@ const BASE_TX_OUTPUT = { value: 2000, outputScript: 'a914da1745e9b549bd0bfa1a569971c77eba30cd5a4b87', - spentBy: undefined, }; const BASE_TX_TOKEN_INFO_SLP_FUNGIBLE = { tokenType: { diff --git a/modules/chronik-client/test/integration/token_slp_mint_vault.ts b/modules/chronik-client/test/integration/token_slp_mint_vault.ts --- a/modules/chronik-client/test/integration/token_slp_mint_vault.ts +++ b/modules/chronik-client/test/integration/token_slp_mint_vault.ts @@ -112,7 +112,6 @@ const BASE_TX_OUTPUT = { value: 10000, outputScript: 'a914da1745e9b549bd0bfa1a569971c77eba30cd5a4b87', - spentBy: undefined, }; const BASE_TX_TOKEN_INFO_SLP_V2 = { tokenType: { diff --git a/modules/chronik-client/test/integration/token_slp_nft1.ts b/modules/chronik-client/test/integration/token_slp_nft1.ts --- a/modules/chronik-client/test/integration/token_slp_nft1.ts +++ b/modules/chronik-client/test/integration/token_slp_nft1.ts @@ -120,7 +120,6 @@ const BASE_TX_OUTPUT = { value: 2000, outputScript: 'a914da1745e9b549bd0bfa1a569971c77eba30cd5a4b87', - spentBy: undefined, }; const BASE_TX_TOKEN_INFO_SLP_NFT = { tokenType: {