diff --git a/cashtab/src/utils/__mocks__/registerNewAliasMocks.js b/cashtab/src/utils/__mocks__/registerNewAliasMocks.js deleted file mode 100644 --- a/cashtab/src/utils/__mocks__/registerNewAliasMocks.js +++ /dev/null @@ -1,608 +0,0 @@ -// @generated - -export const aliasRegisteringWallet = { - mnemonic: - 'cheese purpose sphere member afford orbit aisle bundle shoe save delay poverty', - name: '[burned]aliasRegTest', - Path245: { - publicKey: - '033a8335572ad5877fb4691d702dc276e965e3dfc61b7ddb1266e56ee9e63b07c7', - hash160: '260ad4f88031bf90191db87956a141a4caee41b9', - cashAddress: 'ecash:qqnq448csqcmlyqerku8j44pgxjv4mjphyvf4q7ku5', - fundingWif: 'L2z9MWRYBdajS1JUvry8ef3H4dMoJiQpL7H9gh9QY9uN4tTW5sty', - }, - Path145: { - publicKey: - '03bb8d0f9b479bbbf17025f1c58c34c9831ad4ac16f1707fb3e19bf4a990eed517', - hash160: '7774bdf6dc5f88dcbafc9876ddda68d6ef9f5079', - cashAddress: 'ecash:qpmhf00km30c3h96ljv8dhw6drtwl86s0ysn32vngq', - fundingWif: 'Kwhw5NivkPBigRCsRFeab2W62yWHH3aNAK8PBAeK4cW13Sk3NM98', - }, - Path1899: { - publicKey: - '036ea648569566fa0843b914f67e54ebcfa6921208acd6408d2881488809403ac6', - hash160: '20edc8389101aed204b9c17b7d64a00ead0e8cfc', - cashAddress: 'ecash:qqswmjpcjyq6a5syh8qhklty5q826r5vlsh7a7uqtq', - fundingWif: 'L3NFW2e1T92cF6YZydoEtpmYSm1hhmUzJ9fXgBAzF8ts4Eugno2D', - }, - state: { - balances: { - totalBalanceInSatoshis: '10000000', - totalBalance: '100000', - }, - slpUtxos: [], - nonSlpUtxos: [ - { - outpoint: { - txid: '879e64ba90c09d957f6b7043776cd5c171ee2c7c82e728bd1fe97899f42d9c04', - outIdx: 0, - }, - blockHeight: 790294, - isCoinbase: false, - value: '10000000', - network: 'XEC', - address: 'ecash:qqswmjpcjyq6a5syh8qhklty5q826r5vlsh7a7uqtq', - }, - ], - tokens: [], - parsedTxHistory: [ - { - txid: '879e64ba90c09d957f6b7043776cd5c171ee2c7c82e728bd1fe97899f42d9c04', - version: 2, - inputs: [ - { - prevOut: { - txid: '88fec8beeda59c72b06b6d5d9531a03e4ecb46a0097501565361900f9dcc280a', - outIdx: 1, - }, - inputScript: - '47304402206bb74db30b624d62b51e00f1f4a309ad7c037c55c45ac38425a63e4b168e92ad022034e464b5f6136bb63345a32e40aa0c3224fcfb6ad4bb7449094b84f36a331e294121020d867a730bb6b55078d4eaf36fbf06d2a3867f81c20ad54925bcdd02ec914cbb', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - value: '8849259', - sequenceNo: 4294967295, - }, - { - prevOut: { - txid: '1c0b5e632601d041a4423e05aa9824c8d368eb01c8a9aaefc506233879349404', - outIdx: 3, - }, - inputScript: - '4730440220097633057fd28fb098c11012e63e05850b4f172f37dd58373c14ef80fdc790cb02203f0d5f44b92f3e659c605faac2c6743eacf223f695d1ce7cfd07796ff0a241694121020d867a730bb6b55078d4eaf36fbf06d2a3867f81c20ad54925bcdd02ec914cbb', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - value: '5000', - sequenceNo: 4294967295, - }, - { - prevOut: { - txid: '179f65e21f4bb3ee3bf9d0433b7a6df7ed6e5a795b2c1aea47902e1fb0e39fe3', - outIdx: 1, - }, - inputScript: - '473044022062f6dcddca0d477dedd0024cabf0b4e22f2b213231f385e0b68e9e5f41eb04e602201597c7df3495bab6093612d2628b8c30554c27a24d452bc11e3a51fd37727f264121020d867a730bb6b55078d4eaf36fbf06d2a3867f81c20ad54925bcdd02ec914cbb', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - value: '1100674', - sequenceNo: 4294967295, - }, - { - prevOut: { - txid: '9da7445bb061944175710efcb5a22118aceb6c23c8bc82d4afeddddd410ea2b5', - outIdx: 2, - }, - inputScript: - '47304402207d591fe5f8f6d71e120634be09674e36074122c3291c00c18e6807397ecac323022021e7e9c2c0fb724e99a74e0dd5dba453d292a1cd32f55e18a33fcf515b50e9784121020d867a730bb6b55078d4eaf36fbf06d2a3867f81c20ad54925bcdd02ec914cbb', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - value: '9998848', - sequenceNo: 4294967295, - }, - ], - outputs: [ - { - value: '10000000', - outputScript: - '76a91420edc8389101aed204b9c17b7d64a00ead0e8cfc88ac', - }, - { - value: '9952434', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - }, - ], - lockTime: 0, - block: { - height: 790294, - hash: '0000000000000000084fe051052cbbe8778135f254076b3e20e9f08387654b2f', - timestamp: '1683047794', - }, - timeFirstSeen: '1683047404', - size: 666, - isCoinbase: false, - network: 'XEC', - parsed: { - incoming: true, - xecAmount: '100000', - isEtokenTx: false, - airdropFlag: false, - airdropTokenId: '', - opReturnMessage: '', - isCashtabMessage: false, - isEncryptedMessage: false, - decryptionSuccess: false, - replyAddress: - 'ecash:qplkmuz3rx480u6vc4xgc0qxnza42p0e7vll6p90wr', - aliasFlag: false, - }, - }, - ], - }, -}; -export const aliasRegisteringWalletAfterTx = { - mnemonic: - 'cheese purpose sphere member afford orbit aisle bundle shoe save delay poverty', - name: '[burned]aliasRegTest', - Path245: { - publicKey: - '033a8335572ad5877fb4691d702dc276e965e3dfc61b7ddb1266e56ee9e63b07c7', - hash160: '260ad4f88031bf90191db87956a141a4caee41b9', - cashAddress: 'ecash:qqnq448csqcmlyqerku8j44pgxjv4mjphyvf4q7ku5', - fundingWif: 'L2z9MWRYBdajS1JUvry8ef3H4dMoJiQpL7H9gh9QY9uN4tTW5sty', - }, - Path145: { - publicKey: - '03bb8d0f9b479bbbf17025f1c58c34c9831ad4ac16f1707fb3e19bf4a990eed517', - hash160: '7774bdf6dc5f88dcbafc9876ddda68d6ef9f5079', - cashAddress: 'ecash:qpmhf00km30c3h96ljv8dhw6drtwl86s0ysn32vngq', - fundingWif: 'Kwhw5NivkPBigRCsRFeab2W62yWHH3aNAK8PBAeK4cW13Sk3NM98', - }, - Path1899: { - publicKey: - '036ea648569566fa0843b914f67e54ebcfa6921208acd6408d2881488809403ac6', - hash160: '20edc8389101aed204b9c17b7d64a00ead0e8cfc', - cashAddress: 'ecash:qqswmjpcjyq6a5syh8qhklty5q826r5vlsh7a7uqtq', - fundingWif: 'L3NFW2e1T92cF6YZydoEtpmYSm1hhmUzJ9fXgBAzF8ts4Eugno2D', - }, - state: { - balances: { - totalBalanceInSatoshis: '9998994', - totalBalance: '99989.94', - }, - slpUtxos: [], - nonSlpUtxos: [ - { - outpoint: { - txid: '1272c4a9bf5829c9dba1efb252e753ed20e3cdd49b6e75a778befc7a87eaf7d0', - outIdx: 2, - }, - blockHeight: 790297, - isCoinbase: false, - value: '9998994', - network: 'XEC', - address: 'ecash:qqswmjpcjyq6a5syh8qhklty5q826r5vlsh7a7uqtq', - }, - ], - tokens: [], - parsedTxHistory: [ - { - txid: '1272c4a9bf5829c9dba1efb252e753ed20e3cdd49b6e75a778befc7a87eaf7d0', - version: 2, - inputs: [ - { - prevOut: { - txid: '879e64ba90c09d957f6b7043776cd5c171ee2c7c82e728bd1fe97899f42d9c04', - outIdx: 0, - }, - inputScript: - '483045022100dd79c2a3e8773e7d4963ad3f6f03b54aca569e8e383c5cdc285afa601ee50829022058dfcdc905ec8f45d7418644ccfdf45cd8db41aade2d57d455c50e1a181cf7bb4121036ea648569566fa0843b914f67e54ebcfa6921208acd6408d2881488809403ac6', - outputScript: - '76a91420edc8389101aed204b9c17b7d64a00ead0e8cfc88ac', - value: '10000000', - sequenceNo: 4294967295, - }, - ], - outputs: [ - { - value: '0', - outputScript: - '6a042e78656300086e65777465737431150020edc8389101aed204b9c17b7d64a00ead0e8cfc', - }, - { - value: '551', - outputScript: - '76a914638568e36d0b5d7d49a6e99854caa27d9772b09388ac', - }, - { - value: '9998994', - outputScript: - '76a91420edc8389101aed204b9c17b7d64a00ead0e8cfc88ac', - }, - ], - lockTime: 0, - block: { - height: 790297, - hash: '000000000000000016920644c8c4abcf1681a6ca9068e532410554e901848d41', - timestamp: '1683049955', - }, - timeFirstSeen: '1683049080', - size: 273, - isCoinbase: false, - network: 'XEC', - parsed: { - incoming: false, - xecAmount: '5.51', - isEtokenTx: false, - airdropFlag: false, - airdropTokenId: '', - opReturnMessage: '', - isCashtabMessage: false, - isEncryptedMessage: false, - decryptionSuccess: false, - replyAddress: - 'ecash:qqswmjpcjyq6a5syh8qhklty5q826r5vlsh7a7uqtq', - aliasFlag: true, - }, - }, - { - txid: '879e64ba90c09d957f6b7043776cd5c171ee2c7c82e728bd1fe97899f42d9c04', - version: 2, - inputs: [ - { - prevOut: { - txid: '88fec8beeda59c72b06b6d5d9531a03e4ecb46a0097501565361900f9dcc280a', - outIdx: 1, - }, - inputScript: - '47304402206bb74db30b624d62b51e00f1f4a309ad7c037c55c45ac38425a63e4b168e92ad022034e464b5f6136bb63345a32e40aa0c3224fcfb6ad4bb7449094b84f36a331e294121020d867a730bb6b55078d4eaf36fbf06d2a3867f81c20ad54925bcdd02ec914cbb', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - value: '8849259', - sequenceNo: 4294967295, - }, - { - prevOut: { - txid: '1c0b5e632601d041a4423e05aa9824c8d368eb01c8a9aaefc506233879349404', - outIdx: 3, - }, - inputScript: - '4730440220097633057fd28fb098c11012e63e05850b4f172f37dd58373c14ef80fdc790cb02203f0d5f44b92f3e659c605faac2c6743eacf223f695d1ce7cfd07796ff0a241694121020d867a730bb6b55078d4eaf36fbf06d2a3867f81c20ad54925bcdd02ec914cbb', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - value: '5000', - sequenceNo: 4294967295, - }, - { - prevOut: { - txid: '179f65e21f4bb3ee3bf9d0433b7a6df7ed6e5a795b2c1aea47902e1fb0e39fe3', - outIdx: 1, - }, - inputScript: - '473044022062f6dcddca0d477dedd0024cabf0b4e22f2b213231f385e0b68e9e5f41eb04e602201597c7df3495bab6093612d2628b8c30554c27a24d452bc11e3a51fd37727f264121020d867a730bb6b55078d4eaf36fbf06d2a3867f81c20ad54925bcdd02ec914cbb', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - value: '1100674', - sequenceNo: 4294967295, - }, - { - prevOut: { - txid: '9da7445bb061944175710efcb5a22118aceb6c23c8bc82d4afeddddd410ea2b5', - outIdx: 2, - }, - inputScript: - '47304402207d591fe5f8f6d71e120634be09674e36074122c3291c00c18e6807397ecac323022021e7e9c2c0fb724e99a74e0dd5dba453d292a1cd32f55e18a33fcf515b50e9784121020d867a730bb6b55078d4eaf36fbf06d2a3867f81c20ad54925bcdd02ec914cbb', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - value: '9998848', - sequenceNo: 4294967295, - }, - ], - outputs: [ - { - value: '10000000', - outputScript: - '76a91420edc8389101aed204b9c17b7d64a00ead0e8cfc88ac', - spentBy: { - txid: '1272c4a9bf5829c9dba1efb252e753ed20e3cdd49b6e75a778befc7a87eaf7d0', - outIdx: 0, - }, - }, - { - value: '9952434', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - }, - ], - lockTime: 0, - block: { - height: 790294, - hash: '0000000000000000084fe051052cbbe8778135f254076b3e20e9f08387654b2f', - timestamp: '1683047794', - }, - timeFirstSeen: '1683047404', - size: 666, - isCoinbase: false, - network: 'XEC', - parsed: { - incoming: true, - xecAmount: '100000', - isEtokenTx: false, - airdropFlag: false, - airdropTokenId: '', - opReturnMessage: '', - isCashtabMessage: false, - isEncryptedMessage: false, - decryptionSuccess: false, - replyAddress: - 'ecash:qplkmuz3rx480u6vc4xgc0qxnza42p0e7vll6p90wr', - aliasFlag: false, - }, - }, - ], - }, -}; -export const aliasRegisteringWalletAfterTwoTxs = { - mnemonic: - 'cheese purpose sphere member afford orbit aisle bundle shoe save delay poverty', - name: '[burned]aliasRegTest', - Path245: { - publicKey: - '033a8335572ad5877fb4691d702dc276e965e3dfc61b7ddb1266e56ee9e63b07c7', - hash160: '260ad4f88031bf90191db87956a141a4caee41b9', - cashAddress: 'ecash:qqnq448csqcmlyqerku8j44pgxjv4mjphyvf4q7ku5', - fundingWif: 'L2z9MWRYBdajS1JUvry8ef3H4dMoJiQpL7H9gh9QY9uN4tTW5sty', - }, - Path145: { - publicKey: - '03bb8d0f9b479bbbf17025f1c58c34c9831ad4ac16f1707fb3e19bf4a990eed517', - hash160: '7774bdf6dc5f88dcbafc9876ddda68d6ef9f5079', - cashAddress: 'ecash:qpmhf00km30c3h96ljv8dhw6drtwl86s0ysn32vngq', - fundingWif: 'Kwhw5NivkPBigRCsRFeab2W62yWHH3aNAK8PBAeK4cW13Sk3NM98', - }, - Path1899: { - publicKey: - '036ea648569566fa0843b914f67e54ebcfa6921208acd6408d2881488809403ac6', - hash160: '20edc8389101aed204b9c17b7d64a00ead0e8cfc', - cashAddress: 'ecash:qqswmjpcjyq6a5syh8qhklty5q826r5vlsh7a7uqtq', - fundingWif: 'L3NFW2e1T92cF6YZydoEtpmYSm1hhmUzJ9fXgBAzF8ts4Eugno2D', - }, - state: { - balances: { - totalBalanceInSatoshis: '9997988', - totalBalance: '99979.88', - }, - slpUtxos: [], - nonSlpUtxos: [ - { - outpoint: { - txid: '912582a1dc11b568f14f8ebae15cbb0ce53bdb973e137e7dc7c9b261327e6cab', - outIdx: 2, - }, - blockHeight: 790312, - isCoinbase: false, - value: '9997988', - network: 'XEC', - address: 'ecash:qqswmjpcjyq6a5syh8qhklty5q826r5vlsh7a7uqtq', - }, - ], - tokens: [], - parsedTxHistory: [ - { - txid: '912582a1dc11b568f14f8ebae15cbb0ce53bdb973e137e7dc7c9b261327e6cab', - version: 2, - inputs: [ - { - prevOut: { - txid: '1272c4a9bf5829c9dba1efb252e753ed20e3cdd49b6e75a778befc7a87eaf7d0', - outIdx: 2, - }, - inputScript: - '47304402205cf1941bd0ed8c49319189973feebd14e8d7faf6c5a3cdc6c16f676bd62c63ac022068c10726326e37f960433a92894609f7f0b65946d8104038110e2104d973c8e24121036ea648569566fa0843b914f67e54ebcfa6921208acd6408d2881488809403ac6', - outputScript: - '76a91420edc8389101aed204b9c17b7d64a00ead0e8cfc88ac', - value: '9998994', - sequenceNo: 4294967295, - }, - ], - outputs: [ - { - value: '0', - outputScript: - '6a042e78656300157477656e74796f6e6562797465616c696173726567150020edc8389101aed204b9c17b7d64a00ead0e8cfc', - }, - { - value: '551', - outputScript: - '76a914638568e36d0b5d7d49a6e99854caa27d9772b09388ac', - }, - { - value: '9997988', - outputScript: - '76a91420edc8389101aed204b9c17b7d64a00ead0e8cfc88ac', - }, - ], - lockTime: 0, - block: { - height: 790312, - hash: '0000000000000000170185a5ef34ce2d9eaa9eebc540dadac15eb154c8c7aedd', - timestamp: '1683063775', - }, - timeFirstSeen: '1683063315', - size: 285, - isCoinbase: false, - network: 'XEC', - parsed: { - incoming: false, - xecAmount: '5.51', - isEtokenTx: false, - airdropFlag: false, - airdropTokenId: '', - opReturnMessage: '', - isCashtabMessage: false, - isEncryptedMessage: false, - decryptionSuccess: false, - replyAddress: - 'ecash:qqswmjpcjyq6a5syh8qhklty5q826r5vlsh7a7uqtq', - aliasFlag: true, - }, - }, - { - txid: '1272c4a9bf5829c9dba1efb252e753ed20e3cdd49b6e75a778befc7a87eaf7d0', - version: 2, - inputs: [ - { - prevOut: { - txid: '879e64ba90c09d957f6b7043776cd5c171ee2c7c82e728bd1fe97899f42d9c04', - outIdx: 0, - }, - inputScript: - '483045022100dd79c2a3e8773e7d4963ad3f6f03b54aca569e8e383c5cdc285afa601ee50829022058dfcdc905ec8f45d7418644ccfdf45cd8db41aade2d57d455c50e1a181cf7bb4121036ea648569566fa0843b914f67e54ebcfa6921208acd6408d2881488809403ac6', - outputScript: - '76a91420edc8389101aed204b9c17b7d64a00ead0e8cfc88ac', - value: '10000000', - sequenceNo: 4294967295, - }, - ], - outputs: [ - { - value: '0', - outputScript: - '6a042e78656300086e65777465737431150020edc8389101aed204b9c17b7d64a00ead0e8cfc', - }, - { - value: '551', - outputScript: - '76a914638568e36d0b5d7d49a6e99854caa27d9772b09388ac', - }, - { - value: '9998994', - outputScript: - '76a91420edc8389101aed204b9c17b7d64a00ead0e8cfc88ac', - spentBy: { - txid: '912582a1dc11b568f14f8ebae15cbb0ce53bdb973e137e7dc7c9b261327e6cab', - outIdx: 0, - }, - }, - ], - lockTime: 0, - block: { - height: 790297, - hash: '000000000000000016920644c8c4abcf1681a6ca9068e532410554e901848d41', - timestamp: '1683049955', - }, - timeFirstSeen: '1683049080', - size: 273, - isCoinbase: false, - network: 'XEC', - parsed: { - incoming: false, - xecAmount: '5.51', - isEtokenTx: false, - airdropFlag: false, - airdropTokenId: '', - opReturnMessage: '', - isCashtabMessage: false, - isEncryptedMessage: false, - decryptionSuccess: false, - replyAddress: - 'ecash:qqswmjpcjyq6a5syh8qhklty5q826r5vlsh7a7uqtq', - aliasFlag: true, - }, - }, - { - txid: '879e64ba90c09d957f6b7043776cd5c171ee2c7c82e728bd1fe97899f42d9c04', - version: 2, - inputs: [ - { - prevOut: { - txid: '88fec8beeda59c72b06b6d5d9531a03e4ecb46a0097501565361900f9dcc280a', - outIdx: 1, - }, - inputScript: - '47304402206bb74db30b624d62b51e00f1f4a309ad7c037c55c45ac38425a63e4b168e92ad022034e464b5f6136bb63345a32e40aa0c3224fcfb6ad4bb7449094b84f36a331e294121020d867a730bb6b55078d4eaf36fbf06d2a3867f81c20ad54925bcdd02ec914cbb', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - value: '8849259', - sequenceNo: 4294967295, - }, - { - prevOut: { - txid: '1c0b5e632601d041a4423e05aa9824c8d368eb01c8a9aaefc506233879349404', - outIdx: 3, - }, - inputScript: - '4730440220097633057fd28fb098c11012e63e05850b4f172f37dd58373c14ef80fdc790cb02203f0d5f44b92f3e659c605faac2c6743eacf223f695d1ce7cfd07796ff0a241694121020d867a730bb6b55078d4eaf36fbf06d2a3867f81c20ad54925bcdd02ec914cbb', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - value: '5000', - sequenceNo: 4294967295, - }, - { - prevOut: { - txid: '179f65e21f4bb3ee3bf9d0433b7a6df7ed6e5a795b2c1aea47902e1fb0e39fe3', - outIdx: 1, - }, - inputScript: - '473044022062f6dcddca0d477dedd0024cabf0b4e22f2b213231f385e0b68e9e5f41eb04e602201597c7df3495bab6093612d2628b8c30554c27a24d452bc11e3a51fd37727f264121020d867a730bb6b55078d4eaf36fbf06d2a3867f81c20ad54925bcdd02ec914cbb', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - value: '1100674', - sequenceNo: 4294967295, - }, - { - prevOut: { - txid: '9da7445bb061944175710efcb5a22118aceb6c23c8bc82d4afeddddd410ea2b5', - outIdx: 2, - }, - inputScript: - '47304402207d591fe5f8f6d71e120634be09674e36074122c3291c00c18e6807397ecac323022021e7e9c2c0fb724e99a74e0dd5dba453d292a1cd32f55e18a33fcf515b50e9784121020d867a730bb6b55078d4eaf36fbf06d2a3867f81c20ad54925bcdd02ec914cbb', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - value: '9998848', - sequenceNo: 4294967295, - }, - ], - outputs: [ - { - value: '10000000', - outputScript: - '76a91420edc8389101aed204b9c17b7d64a00ead0e8cfc88ac', - spentBy: { - txid: '1272c4a9bf5829c9dba1efb252e753ed20e3cdd49b6e75a778befc7a87eaf7d0', - outIdx: 0, - }, - }, - { - value: '9952434', - outputScript: - '76a9147f6df05119aa77f34cc54c8c3c0698bb5505f9f388ac', - }, - ], - lockTime: 0, - block: { - height: 790294, - hash: '0000000000000000084fe051052cbbe8778135f254076b3e20e9f08387654b2f', - timestamp: '1683047794', - }, - timeFirstSeen: '1683047404', - size: 666, - isCoinbase: false, - network: 'XEC', - parsed: { - incoming: true, - xecAmount: '100000', - isEtokenTx: false, - airdropFlag: false, - airdropTokenId: '', - opReturnMessage: '', - isCashtabMessage: false, - isEncryptedMessage: false, - decryptionSuccess: false, - replyAddress: - 'ecash:qplkmuz3rx480u6vc4xgc0qxnza42p0e7vll6p90wr', - aliasFlag: false, - }, - }, - ], - }, -}; diff --git a/cashtab/src/utils/__tests__/transactions.test.js b/cashtab/src/utils/__tests__/transactions.test.js --- a/cashtab/src/utils/__tests__/transactions.test.js +++ b/cashtab/src/utils/__tests__/transactions.test.js @@ -1,273 +1,12 @@ /* eslint-disable no-native-reassign */ -import sendBCHMock from '../__mocks__/sendBCH'; -import { - aliasRegisteringWallet, - aliasRegisteringWalletAfterTx, - aliasRegisteringWalletAfterTwoTxs, -} from '../__mocks__/registerNewAliasMocks'; import createTokenMock from '../__mocks__/createToken'; import { burnTokenWallet } from '../__mocks__/burnToken'; -import BigNumber from 'bignumber.js'; -import { fromSatoshisToXec } from 'utils/cashMethods'; import { ChronikClient } from 'chronik-client'; // for mocking purposes -import { - sendXec, - burnToken, - createToken, - getRecipientPublicKey, - registerNewAlias, -} from 'utils/transactions'; +import { burnToken, createToken } from 'utils/transactions'; import { explorer } from 'config/explorer'; -import { MockChronikClient } from '../../../../apps/mock-chronik-client'; import appConfig from 'config/app'; describe('Cashtab transaction broadcasting functions', () => { - it('sends XEC correctly', async () => { - const chronik = new ChronikClient( - 'https://FakeChronikUrlToEnsureMocksOnly.com', - ); - const { expectedTxId, utxos, wallet, destinationAddress, sendAmount } = - sendBCHMock; - - chronik.broadcastTx = jest - .fn() - .mockResolvedValue({ txid: expectedTxId }); - expect( - await sendXec( - chronik, - wallet, - utxos, - appConfig.defaultFee, - '', - false, - null, - destinationAddress, - sendAmount, - ), - ).toBe(`${explorer.blockExplorerUrl}/tx/${expectedTxId}`); - }); - - it('sends XEC correctly with an encrypted OP_RETURN message', async () => { - const chronik = new ChronikClient( - 'https://FakeChronikUrlToEnsureMocksOnly.com', - ); - const { expectedTxId, utxos, wallet, destinationAddress, sendAmount } = - sendBCHMock; - const expectedPubKey = - '03451a3e61ae8eb76b8d4cd6057e4ebaf3ef63ae3fe5f441b72c743b5810b6a389'; - - chronik.broadcastTx = jest - .fn() - .mockResolvedValue({ txid: expectedTxId }); - expect( - await sendXec( - chronik, - wallet, - utxos, - appConfig.defaultFee, - 'This is an encrypted opreturn message', - false, - null, - destinationAddress, - sendAmount, - true, // encryption flag for the OP_RETURN message - false, // airdrop flag - '', // airdrop token id - expectedPubKey, //optionalMockPubKeyResponse - ), - ).toBe(`${explorer.blockExplorerUrl}/tx/${expectedTxId}`); - }); - - it('sends one to many XEC correctly', async () => { - const chronik = new ChronikClient( - 'https://FakeChronikUrlToEnsureMocksOnly.com', - ); - const { expectedTxId, utxos, wallet } = sendBCHMock; - - const addressAndValueArray = [ - 'bitcoincash:qrzuvj0vvnsz5949h4axercl5k420eygavv0awgz05,6', - 'bitcoincash:qrzuvj0vvnsz5949h4axercl5k420eygavv0awgz05,6.8', - 'bitcoincash:qrzuvj0vvnsz5949h4axercl5k420eygavv0awgz05,7', - 'bitcoincash:qrzuvj0vvnsz5949h4axercl5k420eygavv0awgz05,6', - ]; - - chronik.broadcastTx = jest - .fn() - .mockResolvedValue({ txid: expectedTxId }); - expect( - await sendXec( - chronik, - wallet, - utxos, - appConfig.defaultFee, - '', - true, - addressAndValueArray, - ), - ).toBe(`${explorer.blockExplorerUrl}/tx/${expectedTxId}`); - }); - - it('Broadcasts a v0 alias registration tx for an 8-byte alias to a p2pkh address', async () => { - const mockedChronik = new MockChronikClient(); - - const mockTxid = - '1272c4a9bf5829c9dba1efb252e753ed20e3cdd49b6e75a778befc7a87eaf7d0'; - - mockedChronik.broadcastTx = jest - .fn() - .mockResolvedValue({ txid: mockTxid }); - - const expectedResult = { - explorerLink: - 'https://explorer.e.cash/tx/1272c4a9bf5829c9dba1efb252e753ed20e3cdd49b6e75a778befc7a87eaf7d0', - rawTxHex: - '0200000001049c2df49978e91fbd28e7827c2cee71c1d56c7743706b7f959dc090ba649e87000000006a4730440220764515ecd983bb0aa614d7c808dd02e95c28e2e4b6cac16664656ba553dbd7e802202bbf46a67c39f8e8e6555eceee084d247456a128ebbc02e7570722ccb04db3384121036ea648569566fa0843b914f67e54ebcfa6921208acd6408d2881488809403ac6ffffffff030000000000000000266a042e78656300086e65777465737431150020edc8389101aed204b9c17b7d64a00ead0e8cfc270200000000000017a914d37c4c809fe9840e7bfa77b86bd47163f6fb6c608792929800000000001976a91420edc8389101aed204b9c17b7d64a00ead0e8cfc88ac00000000', - txid: '1272c4a9bf5829c9dba1efb252e753ed20e3cdd49b6e75a778befc7a87eaf7d0', - }; - expect( - await registerNewAlias( - mockedChronik, - aliasRegisteringWallet, - appConfig.defaultFee, - 'newtest1', - 'ecash:qqswmjpcjyq6a5syh8qhklty5q826r5vlsh7a7uqtq', - 551, - ), - ).toStrictEqual(expectedResult); - }); - it('Broadcasts a v0 alias registration tx for a 21-byte alias to a p2pkh address', async () => { - const mockedChronik = new MockChronikClient(); - - const mockTxid = - '912582a1dc11b568f14f8ebae15cbb0ce53bdb973e137e7dc7c9b261327e6cab'; - - mockedChronik.broadcastTx = jest - .fn() - .mockResolvedValue({ txid: mockTxid }); - - const expectedResult = { - explorerLink: `${explorer.blockExplorerUrl}/tx/${mockTxid}`, - txid: mockTxid, - rawTxHex: - '0200000001d0f7ea877afcbe78a7756e9bd4cde320ed53e752b2efa1dbc92958bfa9c47212020000006a47304402200f6e3308c73fb1b3e6d891e07fb35dd83a01cef2cd3af3d427c0e35ae2214f80022074bcdfe52edea9300aff0ceff4898dda57a13581f2998a43a8b5ae9a62cba3654121036ea648569566fa0843b914f67e54ebcfa6921208acd6408d2881488809403ac6ffffffff030000000000000000336a042e78656300157477656e74796f6e6562797465616c696173726567150020edc8389101aed204b9c17b7d64a00ead0e8cfc270200000000000017a914d37c4c809fe9840e7bfa77b86bd47163f6fb6c6087a48e9800000000001976a91420edc8389101aed204b9c17b7d64a00ead0e8cfc88ac00000000', - }; - expect( - await registerNewAlias( - mockedChronik, - aliasRegisteringWalletAfterTx, - appConfig.defaultFee, - 'twentyonebytealiasreg', - 'ecash:qqswmjpcjyq6a5syh8qhklty5q826r5vlsh7a7uqtq', - 551, - ), - ).toStrictEqual(expectedResult); - }); - it('Broadcasts a v0 alias registration tx for a 16-byte alias to a p2pkh address', async () => { - const mockedChronik = new MockChronikClient(); - - const mockTxid = - '8783d7064ce22e8390c9fa94ef9a4d5bb0184e401ef5a9fbf60b68294e275c80'; - - mockedChronik.broadcastTx = jest - .fn() - .mockResolvedValue({ txid: mockTxid }); - - const expectedResult = { - explorerLink: `${explorer.blockExplorerUrl}/tx/${mockTxid}`, - txid: mockTxid, - rawTxHex: - '0200000001ab6c7e3261b2c9c77d7e133e97db3be50cbb5ce1ba8e4ff168b511dca1822591020000006b48304502210082cc73ce715e58291bb463b0533f0a3579e60fe307eea2198019ac5e59af639a02207cb4f5a4ddb79c019e3f6f9b4af78dbfadf9363a1912ec4fd6d83a254f51b4b74121036ea648569566fa0843b914f67e54ebcfa6921208acd6408d2881488809403ac6ffffffff0300000000000000002e6a042e78656300107768796e6f7474687265657465737473150020edc8389101aed204b9c17b7d64a00ead0e8cfc270200000000000017a914d37c4c809fe9840e7bfa77b86bd47163f6fb6c6087b68a9800000000001976a91420edc8389101aed204b9c17b7d64a00ead0e8cfc88ac00000000', - }; - expect( - await registerNewAlias( - mockedChronik, - aliasRegisteringWalletAfterTwoTxs, - appConfig.defaultFee, - 'whynotthreetests', - 'ecash:qqswmjpcjyq6a5syh8qhklty5q826r5vlsh7a7uqtq', - 551, - ), - ).toStrictEqual(expectedResult); - }); - - it(`Throws error if called trying to send one base unit ${appConfig.ticker} more than available in utxo set`, async () => { - const chronik = new ChronikClient( - 'https://FakeChronikUrlToEnsureMocksOnly.com', - ); - const { utxos, wallet, destinationAddress } = sendBCHMock; - - const expectedTxFeeInSats = 229; - - // tally up the total utxo values - let totalInputUtxoValue = new BigNumber(0); - for (let i = 0; i < utxos.length; i++) { - totalInputUtxoValue = totalInputUtxoValue.plus( - new BigNumber(utxos[i].value), - ); - } - - const oneBaseUnitMoreThanBalance = totalInputUtxoValue - .minus(expectedTxFeeInSats) - .plus(1) - .div(10 ** appConfig.cashDecimals) - .toString(); - - let errorThrown; - try { - await sendXec( - chronik, - wallet, - utxos, - appConfig.defaultFee, - '', - false, - null, - destinationAddress, - oneBaseUnitMoreThanBalance, - ); - } catch (err) { - errorThrown = err; - } - expect(errorThrown.message).toStrictEqual('Insufficient funds'); - - const nullValuesSendBch = sendXec( - chronik, - wallet, - utxos, - appConfig.defaultFee, - '', - false, - null, - destinationAddress, - null, - ); - - await expect(nullValuesSendBch).rejects.toThrow( - new Error('Invalid singleSendValue'), - ); - }); - - it('Throws error on attempt to send one satoshi less than backend dust limit', async () => { - const chronik = new ChronikClient( - 'https://FakeChronikUrlToEnsureMocksOnly.com', - ); - const { utxos, wallet, destinationAddress } = sendBCHMock; - const failedSendBch = sendXec( - chronik, - wallet, - utxos, - appConfig.defaultFee, - '', - false, - null, - destinationAddress, - new BigNumber(fromSatoshisToXec(appConfig.dustSats).toString()) - .minus(new BigNumber('0.00000001')) - .toString(), - ); - await expect(failedSendBch).rejects.toThrow(new Error('dust')); - }); - it("Throws error attempting to burn an eToken ID that is not within the wallet's utxo", async () => { const wallet = burnTokenWallet; const burnAmount = 10; @@ -290,88 +29,6 @@ expect(thrownError).toStrictEqual(new Error(expectedError)); }); - it('receives errors from the network and parses it', async () => { - const chronik = new ChronikClient( - 'https://FakeChronikUrlToEnsureMocksOnly.com', - ); - const { sendAmount, utxos, wallet, destinationAddress } = sendBCHMock; - chronik.broadcastTx = jest.fn().mockImplementation(async () => { - throw new Error('insufficient priority (code 66)'); - }); - const insufficientPriority = sendXec( - chronik, - wallet, - utxos, - appConfig.defaultFee, - '', - false, - null, - destinationAddress, - sendAmount, - ); - await expect(insufficientPriority).rejects.toThrow( - new Error('insufficient priority (code 66)'), - ); - - chronik.broadcastTx = jest.fn().mockImplementation(async () => { - throw new Error('txn-mempool-conflict (code 18)'); - }); - const txnMempoolConflict = sendXec( - chronik, - wallet, - utxos, - appConfig.defaultFee, - '', - false, - null, - destinationAddress, - sendAmount, - ); - await expect(txnMempoolConflict).rejects.toThrow( - new Error('txn-mempool-conflict (code 18)'), - ); - - chronik.broadcastTx = jest.fn().mockImplementation(async () => { - throw new Error('Network Error'); - }); - const networkError = sendXec( - chronik, - wallet, - utxos, - appConfig.defaultFee, - '', - false, - null, - destinationAddress, - sendAmount, - ); - await expect(networkError).rejects.toThrow(new Error('Network Error')); - - chronik.broadcastTx = jest.fn().mockImplementation(async () => { - const err = new Error( - 'too-long-mempool-chain, too many unconfirmed ancestors [limit: 25] (code 64)', - ); - throw err; - }); - - const tooManyAncestorsMempool = sendXec( - chronik, - wallet, - utxos, - appConfig.defaultFee, - '', - false, - null, - destinationAddress, - sendAmount, - ); - await expect(tooManyAncestorsMempool).rejects.toThrow( - new Error( - 'too-long-mempool-chain, too many unconfirmed ancestors [limit: 25] (code 64)', - ), - ); - }); - it('creates a token correctly', async () => { const { expectedTxId, wallet, configObj } = createTokenMock; const chronik = new ChronikClient( @@ -400,22 +57,4 @@ new Error('Invalid wallet'), ); }); - - it(`getRecipientPublicKey() correctly retrieves the public key of a cash address`, async () => { - const chronik = new ChronikClient( - 'https://FakeChronikUrlToEnsureMocksOnly.com', - ); - const expectedPubKey = - '03208c4f52229e021ddec5fc6e07a59fd66388ac52bc2a2c1e0f1afb24b0e275ac'; - const destinationAddress = - 'bitcoincash:qqvuj09f80sw9j7qru84ptxf0hyqffc38gstxfs5ru'; - - expect( - await getRecipientPublicKey( - chronik, - destinationAddress, - expectedPubKey, - ), - ).toBe(expectedPubKey); - }); }); diff --git a/cashtab/src/utils/transactions.js b/cashtab/src/utils/transactions.js --- a/cashtab/src/utils/transactions.js +++ b/cashtab/src/utils/transactions.js @@ -1,25 +1,12 @@ import { - fromXecToSatoshis, isValidStoredWallet, - generateOpReturnScript, - generateTxInput, - generateTxOutput, generateTokenTxInput, generateTokenTxOutput, signAndBuildTx, - getChangeAddressFromInputUtxos, - toHash160, - getMessageByteSize, - generateAliasOpReturnScript, - fromSatoshisToXec, - sumOneToManyXec, } from 'utils/cashMethods'; -import ecies from 'ecies-lite'; import * as utxolib from '@bitgo/utxo-lib'; import { explorer } from 'config/explorer'; import appConfig from 'config/app'; -import aliasSettings from 'config/alias'; -import BigNumber from 'bignumber.js'; const SEND_XEC_ERRORS = { INSUFFICIENT_FUNDS: 0, @@ -260,362 +247,3 @@ // return the explorer link for the broadcasted tx return `${explorer.blockExplorerUrl}/tx/${broadcastResponse.txid}`; }; - -export const getRecipientPublicKey = async ( - chronik, - recipientAddress, - optionalMockPubKeyResponse = false, -) => { - // Necessary because jest can't mock - // chronikTxHistoryAtAddress = await chronik.script('p2pkh', recipientAddressHash160).history(/*page=*/ 0, /*page_size=*/ 10); - if (optionalMockPubKeyResponse) { - return optionalMockPubKeyResponse; - } - - // get hash160 of address - let recipientAddressHash160; - try { - recipientAddressHash160 = toHash160(recipientAddress); - } catch (err) { - console.log( - `Error determining toHash160(${recipientAddress} in getRecipientPublicKey())`, - err, - ); - throw new Error( - `Error determining toHash160(${recipientAddress} in getRecipientPublicKey())`, - ); - } - - let chronikTxHistoryAtAddress; - try { - // Get 20 txs. If no outgoing txs in those 20 txs, just don't send the tx - chronikTxHistoryAtAddress = await chronik - .script('p2pkh', recipientAddressHash160) - .history(/*page=*/ 0, /*page_size=*/ 20); - } catch (err) { - console.log( - `Error getting await chronik.script('p2pkh', ${recipientAddressHash160}).history();`, - err, - ); - throw new Error('Error fetching tx history to parse for public key'); - } - let recipientPubKeyChronik; - - // Iterate over tx history to find an outgoing tx - for (let i = 0; i < chronikTxHistoryAtAddress.txs.length; i += 1) { - const { inputs } = chronikTxHistoryAtAddress.txs[i]; - for (let j = 0; j < inputs.length; j += 1) { - const thisInput = inputs[j]; - const thisInputSendingHash160 = thisInput.outputScript; - if (thisInputSendingHash160.includes(recipientAddressHash160)) { - // Then this is an outgoing tx, you can get the public key from this tx - // Get the public key - try { - recipientPubKeyChronik = - chronikTxHistoryAtAddress.txs[i].inputs[ - j - ].inputScript.slice(-66); - } catch (err) { - throw new Error( - 'Cannot send an encrypted message to a wallet with no outgoing transactions', - ); - } - return recipientPubKeyChronik; - } - } - } - // You get here if you find no outgoing txs in the chronik tx history - throw new Error( - 'Cannot send an encrypted message to a wallet with no outgoing transactions in the last 20 txs', - ); -}; - -export const registerNewAlias = async ( - chronik, - wallet, - feeInSatsPerByte, - aliasName, - aliasAddress, - registrationFeeSats, -) => { - try { - // Instantiate new txBuilder - let txBuilder = utxolib.bitgo.createTransactionBuilderForNetwork( - utxolib.networks.ecash, - ); - - // Create this transaction with nonSlpUtxos - const utxos = wallet.state.nonSlpUtxos; - - // Build opReturnData for alias tx per spec - const opReturnData = generateAliasOpReturnScript( - aliasName, - aliasAddress, - ); - - // Add opReturn as output with 0 satoshis of XEC spent - txBuilder.addOutput(opReturnData, 0); - - // generate the tx inputs and add to txBuilder instance - // returns the updated txBuilder, txFee, totalInputUtxoValue and inputUtxos - // Note that txBuilder is intentionally modified by this call - let txInputObj = generateTxInput( - false, // not a one to many tx - utxos, - txBuilder, - null, // no one-to-many array - registrationFeeSats, - feeInSatsPerByte, - ); - - // Get the change address - const changeAddress = getChangeAddressFromInputUtxos( - txInputObj.inputUtxos, - wallet, - ); - - // generate the tx outputs and add to txBuilder instance - // returns the updated txBuilder - txBuilder = generateTxOutput( - false, // not a one-to-many tx - fromSatoshisToXec(registrationFeeSats), // TODO fix this oversight param req in generateTxOutput - registrationFeeSats, - txInputObj.totalInputUtxoValue, - aliasSettings.aliasPaymentAddress, - null, // no one-to-many address array - changeAddress, - txInputObj.txFee, - txBuilder, - ); - - // sign the collated inputUtxos and build the raw tx hex - // returns the raw tx hex string - const rawTxHex = signAndBuildTx( - txInputObj.inputUtxos, - txBuilder, - wallet, - ); - - // Broadcast transaction to the network via the chronik client - // sample chronik.broadcastTx() response: - // {"txid":"0075130c9ecb342b5162bb1a8a870e69c935ea0c9b2353a967cda404401acf19"} - let broadcastResponse; - try { - broadcastResponse = await chronik.broadcastTx(rawTxHex); - if (!broadcastResponse) { - throw new Error('Empty chronik broadcast response'); - } - } catch (err) { - console.log('Error broadcasting tx to chronik client'); - throw err; - } - - const explorerLink = `${explorer.blockExplorerUrl}/tx/${broadcastResponse.txid}`; - // return the explorer link for the broadcasted tx - return { explorerLink, txid: broadcastResponse.txid, rawTxHex }; - } catch (err) { - if (err.error === 'insufficient priority (code 66)') { - err.code = SEND_XEC_ERRORS.INSUFFICIENT_PRIORITY; - } else if (err.error === 'txn-mempool-conflict (code 18)') { - err.code = SEND_XEC_ERRORS.DOUBLE_SPENDING; - } else if (err.error === 'Network Error') { - err.code = SEND_XEC_ERRORS.NETWORK_ERROR; - } else if ( - err.error === - 'too-long-mempool-chain, too many unconfirmed ancestors [limit: 25] (code 64)' - ) { - err.code = SEND_XEC_ERRORS.MAX_UNCONFIRMED_TXS; - } - console.log(`error: `, err); - throw err; - } -}; - -export const sendXec = async ( - chronik, - wallet, - utxos, - feeInSatsPerByte, - optionalOpReturnMsg, - isOneToMany, - destinationAddressAndValueArray, - destinationAddress, - sendAmount, - encryptionFlag, - airdropFlag, - airdropTokenId, - optionalMockPubKeyResponse = false, -) => { - try { - // Validation for missing sendAmount in one to one tx - // TODO clean this up and have separate functions for one-to-one and one-to-many sends - if (!isOneToMany && sendAmount === null) { - throw new Error('Invalid singleSendValue'); - } - - let txBuilder = utxolib.bitgo.createTransactionBuilderForNetwork( - utxolib.networks.ecash, - ); - - // parse the input value of XEC to send - // TODO deprecate BigNumber from the rest of the functions here and in Cashtab - const value = isOneToMany - ? new BigNumber(sumOneToManyXec(destinationAddressAndValueArray)) - : new BigNumber(sendAmount); - - // If you have a dust value, throw error here instead of broadcasting the tx and getting it from the node - if (value.lt(fromSatoshisToXec(appConfig.dustSats))) { - // Throw the same error given by the backend attempting to broadcast such a tx - throw new Error('dust'); - } - - const satoshisToSend = fromXecToSatoshis(value); - - // Throw validation error if fromXecToSatoshis returns false - if (!satoshisToSend) { - const error = new Error(`Invalid decimal places for send amount`); - throw error; - } - - let encryptedEj; // serialized encryption data object - - // if the user has opted to encrypt this message - if (encryptionFlag) { - try { - // get the pub key for the recipient address - let recipientPubKey = await getRecipientPublicKey( - chronik, - destinationAddress, - optionalMockPubKeyResponse, - ); - - // if the API can't find a pub key, it is due to the wallet having no outbound tx - if (recipientPubKey === 'not found') { - throw new Error( - 'Cannot send an encrypted message to a wallet with no outgoing transactions', - ); - } - - // encrypt the message - const pubKeyBuf = Buffer.from(recipientPubKey, 'hex'); - const bufferedFile = Buffer.from(optionalOpReturnMsg); - const structuredEj = await ecies.encrypt( - pubKeyBuf, - bufferedFile, - { compressEpk: true }, - ); - - // Serialize the encrypted data object - encryptedEj = Buffer.concat([ - structuredEj.epk, - structuredEj.iv, - structuredEj.ct, - structuredEj.mac, - ]); - } catch (err) { - console.log(`sendXec() encryption error.`); - throw err; - } - } - - // Start of building the OP_RETURN output. - // only build the OP_RETURN output if the user supplied it - if ( - (optionalOpReturnMsg && - typeof optionalOpReturnMsg !== 'undefined' && - optionalOpReturnMsg.trim() !== '') || - airdropFlag - ) { - const opReturnData = generateOpReturnScript( - optionalOpReturnMsg, - encryptionFlag, - airdropFlag, - airdropTokenId, - encryptedEj, - ); - txBuilder.addOutput(opReturnData, 0); - } - - let opReturnByteCount; - if (optionalOpReturnMsg) { - opReturnByteCount = getMessageByteSize( - optionalOpReturnMsg, - encryptionFlag, - encryptedEj, - ); - } - - // generate the tx inputs and add to txBuilder instance - // returns the updated txBuilder, txFee, totalInputUtxoValue and inputUtxos - let txInputObj = generateTxInput( - isOneToMany, - utxos, - txBuilder, - destinationAddressAndValueArray, - satoshisToSend, - feeInSatsPerByte, - opReturnByteCount, - ); - - const changeAddress = getChangeAddressFromInputUtxos( - txInputObj.inputUtxos, - wallet, - ); - txBuilder = txInputObj.txBuilder; // update the local txBuilder with the generated tx inputs - - // generate the tx outputs and add to txBuilder instance - // returns the updated txBuilder - const txOutputObj = generateTxOutput( - isOneToMany, - value, - satoshisToSend, - txInputObj.totalInputUtxoValue, - destinationAddress, - destinationAddressAndValueArray, - changeAddress, - txInputObj.txFee, - txBuilder, - ); - txBuilder = txOutputObj; // update the local txBuilder with the generated tx outputs - - // sign the collated inputUtxos and build the raw tx hex - // returns the raw tx hex string - const rawTxHex = signAndBuildTx( - txInputObj.inputUtxos, - txBuilder, - wallet, - ); - - // Broadcast transaction to the network via the chronik client - // sample chronik.broadcastTx() response: - // {"txid":"0075130c9ecb342b5162bb1a8a870e69c935ea0c9b2353a967cda404401acf19"} - let broadcastResponse; - try { - broadcastResponse = await chronik.broadcastTx(rawTxHex); - if (!broadcastResponse) { - throw new Error('Empty chronik broadcast response'); - } - } catch (err) { - console.log('Error broadcasting tx to chronik client'); - throw err; - } - - // return the explorer link for the broadcasted tx - return `${explorer.blockExplorerUrl}/tx/${broadcastResponse.txid}`; - } catch (err) { - if (err.error === 'insufficient priority (code 66)') { - err.code = SEND_XEC_ERRORS.INSUFFICIENT_PRIORITY; - } else if (err.error === 'txn-mempool-conflict (code 18)') { - err.code = SEND_XEC_ERRORS.DOUBLE_SPENDING; - } else if (err.error === 'Network Error') { - err.code = SEND_XEC_ERRORS.NETWORK_ERROR; - } else if ( - err.error === - 'too-long-mempool-chain, too many unconfirmed ancestors [limit: 25] (code 64)' - ) { - err.code = SEND_XEC_ERRORS.MAX_UNCONFIRMED_TXS; - } - console.log(`error: `, err); - throw err; - } -};