mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-21 16:51:59 -07:00
fix(Transaction.get3()): Created Transaction.get3()
This commit is contained in:
Generated
+387
-841
File diff suppressed because it is too large
Load Diff
+6
-7
@@ -68,20 +68,19 @@
|
||||
"assert": "2.0.0",
|
||||
"chai": "4.1.2",
|
||||
"coveralls": "3.0.2",
|
||||
"eslint": "^8.1.0",
|
||||
"eslint-config-prettier": "6.0.0",
|
||||
"eslint-config-standard": "14.1.0",
|
||||
"eslint-plugin-node": "9.1.0",
|
||||
"eslint-plugin-prettier": "3.1.0",
|
||||
"eslint": "7.17.0",
|
||||
"eslint-config-prettier": "7.1.0",
|
||||
"eslint-config-standard": "16.0.3",
|
||||
"eslint-plugin-node": "11.1.0",
|
||||
"eslint-plugin-prettier": "3.3.1",
|
||||
"eslint-plugin-standard": "4.0.0",
|
||||
"husky": "^4.3.8",
|
||||
"lodash.clonedeep": "4.5.0",
|
||||
"mocha": "9.1.3",
|
||||
"node-mocks-http": "1.7.0",
|
||||
"nyc": "15.1.0",
|
||||
"prettier": "1.18.2",
|
||||
"semantic-release": "18.0.0",
|
||||
"sinon": "7.3.2",
|
||||
"sinon": "9.2.2",
|
||||
"standard": "^16.0.4"
|
||||
},
|
||||
"apidoc": {
|
||||
|
||||
+73
-216
@@ -225,8 +225,8 @@ class Transaction {
|
||||
}
|
||||
|
||||
/**
|
||||
* @api Transaction.get2() get2()
|
||||
* @apiName get2
|
||||
* @api Transaction.get3() get3()
|
||||
* @apiName get3
|
||||
* @apiGroup Transaction
|
||||
* @apiDescription
|
||||
* Returns an object of transaction data, including addresses for input UTXOs.
|
||||
@@ -248,195 +248,6 @@ class Transaction {
|
||||
* }
|
||||
* })()
|
||||
*/
|
||||
async get2 (txid) {
|
||||
try {
|
||||
if (typeof txid !== 'string') {
|
||||
throw new Error(
|
||||
'Input to Transaction.get() must be a string containing a TXID.'
|
||||
)
|
||||
}
|
||||
|
||||
const txDetails = await this.rawTransaction.getTxData(txid)
|
||||
// console.log(`txDetails: ${JSON.stringify(txDetails, null, 2)}`)
|
||||
|
||||
// Get the block height the transaction was mined in.
|
||||
const blockHeader = await this.blockchain.getBlockHeader(
|
||||
txDetails.blockhash
|
||||
)
|
||||
txDetails.blockheight = blockHeader.height
|
||||
|
||||
// First get the token information for the output. If that fails, then
|
||||
// this is not an SLP transaction, and this method can return false.
|
||||
let outTokenData
|
||||
try {
|
||||
outTokenData = await this.slpUtils.decodeOpReturn(txid)
|
||||
console.log(`outTokenData: ${JSON.stringify(outTokenData, null, 2)}`)
|
||||
|
||||
// Get Genesis data for this token.
|
||||
const genesisData = await this.slpUtils.decodeOpReturn(
|
||||
outTokenData.tokenId
|
||||
// decodeOpReturnCache
|
||||
// usrObj // pass user data when making an internal call.
|
||||
)
|
||||
console.log(`genesisData: ${JSON.stringify(genesisData, null, 2)}`)
|
||||
|
||||
// Add token information to the tx details object.
|
||||
txDetails.tokenTxType = outTokenData.txType
|
||||
txDetails.tokenId = outTokenData.tokenId
|
||||
txDetails.tokenTicker = genesisData.ticker
|
||||
txDetails.tokenName = genesisData.name
|
||||
txDetails.tokenDecimals = genesisData.decimals
|
||||
txDetails.tokenUri = genesisData.documentUri
|
||||
txDetails.tokenDocHash = genesisData.documentHash
|
||||
|
||||
let numOutputs = 1
|
||||
if (outTokenData.txType === 'SEND') {
|
||||
numOutputs = outTokenData.amounts.length
|
||||
}
|
||||
|
||||
// Add the token quantity to each output.
|
||||
for (let i = 0; i < numOutputs; i++) {
|
||||
let rawQty = 0
|
||||
if (outTokenData.txType === 'SEND') {
|
||||
rawQty = outTokenData.amounts[i]
|
||||
} else {
|
||||
rawQty = outTokenData.qty
|
||||
}
|
||||
|
||||
// const realQty = Number(rawQty) / Math.pow(10, txDetails.tokenDecimals)
|
||||
|
||||
// Calculate the real quantity using a BigNumber, then convert it to a
|
||||
// floating point number.
|
||||
let realQty = new BigNumber(rawQty).dividedBy(
|
||||
10 ** parseInt(txDetails.tokenDecimals)
|
||||
)
|
||||
realQty = realQty.toString()
|
||||
// realQty = parseFloat(realQty)
|
||||
|
||||
txDetails.vout[i + 1].tokenQtyStr = realQty
|
||||
txDetails.vout[i + 1].tokenQty = parseFloat(realQty)
|
||||
console.log(
|
||||
`thisVout ${i}: ${JSON.stringify(txDetails.vout[i + 1], null, 2)}`
|
||||
)
|
||||
}
|
||||
|
||||
// Add tokenQty = null to any outputs that don't have a value.
|
||||
for (let i = 0; i < txDetails.vout.length; i++) {
|
||||
const thisVout = txDetails.vout[i]
|
||||
|
||||
if (!thisVout.tokenQty && thisVout.tokenQty !== 0) {
|
||||
thisVout.tokenQty = null
|
||||
}
|
||||
}
|
||||
|
||||
// Loop through each input and retrieve the token data.
|
||||
for (let i = 0; i < txDetails.vin.length; i++) {
|
||||
const thisVin = txDetails.vin[i]
|
||||
// console.log(`thisVin: ${JSON.stringify(thisVin, null, 2)}`)
|
||||
|
||||
try {
|
||||
// If decodeOpReturn() throws an error, then this input is not
|
||||
// from an SLP transaction and can be ignored.
|
||||
const inTokenData = await this.slpUtils.decodeOpReturn(thisVin.txid)
|
||||
console.log(
|
||||
`vin[${i}] tokenData: ${JSON.stringify(inTokenData, null, 2)}`
|
||||
)
|
||||
|
||||
let tokenQty = 0
|
||||
|
||||
if (inTokenData.txType === 'SEND') {
|
||||
// Get the appropriate vout token amount. This may throw an error,
|
||||
// which means this Vin is not actually a token UTXO, it was just
|
||||
// associated with a previous token TX.
|
||||
tokenQty = inTokenData.amounts[thisVin.vout - 1]
|
||||
// console.log(`tokenQty: ${JSON.stringify(tokenQty, null, 2)}`)
|
||||
|
||||
//
|
||||
} else if (inTokenData.txType === 'GENESIS') {
|
||||
// Only vout[1] of a Genesis transaction represents the tokens.
|
||||
// Any other outputs in that transaction are normal BCH UTXOs.
|
||||
if (thisVin.vout === 1) {
|
||||
tokenQty = inTokenData.qty
|
||||
// console.log(`tokenQty: ${JSON.stringify(tokenQty, null, 2)}`)
|
||||
}
|
||||
} else if (inTokenData.txType === 'MINT') {
|
||||
// vout=1 (second output) recieves the newly minted tokens.
|
||||
if (thisVin.vout === 1) {
|
||||
tokenQty = inTokenData.qty
|
||||
} else if (thisVin.vout === inTokenData.mintBatonVout) {
|
||||
// Vin is a Mint baton
|
||||
thisVin.tokenQty = new BigNumber(0)
|
||||
thisVin.tokenQtyStr = '0'
|
||||
thisVin.tokenId = inTokenData.tokenId
|
||||
} else {
|
||||
tokenQty = null
|
||||
}
|
||||
|
||||
//
|
||||
} else {
|
||||
console.log(
|
||||
'Unexpected code path in Transaction.get2(). What is the txType?'
|
||||
)
|
||||
console.log(inTokenData)
|
||||
throw new Error('Unexpected code path')
|
||||
}
|
||||
|
||||
if (tokenQty) {
|
||||
// Calculate the real quantity using a BigNumber, then convert it to a
|
||||
// floating point number.
|
||||
let realQty = new BigNumber(tokenQty).dividedBy(
|
||||
10 ** parseInt(txDetails.tokenDecimals)
|
||||
)
|
||||
realQty = realQty.toString()
|
||||
// realQty = parseFloat(realQty)
|
||||
|
||||
thisVin.tokenQtyStr = realQty
|
||||
thisVin.tokenQty = parseFloat(realQty)
|
||||
// txDetails.vin[i].tokenQty = tokenQty
|
||||
|
||||
// Add token ID to input
|
||||
thisVin.tokenId = inTokenData.tokenId
|
||||
} else {
|
||||
thisVin.tokenQty = null
|
||||
thisVin.tokenQtyStr = null
|
||||
}
|
||||
} catch (err) {
|
||||
// If decodeOpReturn() throws an error, then this input is not
|
||||
// from an SLP transaction and can be ignored.
|
||||
// thisVin.tokenQty = null
|
||||
thisVin.tokenQty = null
|
||||
thisVin.tokenQtyStr = null
|
||||
continue
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
// console.log('Error: ', err)
|
||||
|
||||
// This case handles rate limit errors.
|
||||
if (err.response && err.response.data && err.response.data.error) {
|
||||
throw new Error(err.response.data.error)
|
||||
}
|
||||
|
||||
// If decoding the op_return fails, then it's not an SLP transaction,
|
||||
// and the non-hyrated TX details can be returned.
|
||||
return txDetails
|
||||
}
|
||||
|
||||
return txDetails
|
||||
} catch (err) {
|
||||
// console.error('Error in transactions.js/get(): ', err)
|
||||
|
||||
// This case handles rate limit errors.
|
||||
if (err.response && err.response.data && err.response.data.error) {
|
||||
throw new Error(err.response.data.error)
|
||||
}
|
||||
|
||||
if (err.error) throw new Error(err.error)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
// Refactoring code in a more structured way
|
||||
async get3 (txid) {
|
||||
try {
|
||||
if (typeof txid !== 'string') {
|
||||
@@ -454,13 +265,14 @@ class Transaction {
|
||||
txDetails.blockhash
|
||||
)
|
||||
txDetails.blockheight = blockHeader.height
|
||||
// console.log(`blockHeader: ${JSON.stringify(blockHeader, null, 2)}`)
|
||||
|
||||
// Set default as not an SLP tx
|
||||
txDetails.isSlpTx = false
|
||||
|
||||
// Get Token Data
|
||||
const txTokenData = await this.getTokenInfo(txid)
|
||||
console.log(`txTokenData: ${JSON.stringify(txTokenData, null, 2)}`)
|
||||
// console.log(`txTokenData: ${JSON.stringify(txTokenData, null, 2)}`)
|
||||
|
||||
// If not a token, return the tx data. Processing is complete.
|
||||
if (!txTokenData) return txDetails
|
||||
@@ -471,7 +283,7 @@ class Transaction {
|
||||
|
||||
// Get Genesis data
|
||||
const genesisData = await this.getTokenInfo(txTokenData.tokenId)
|
||||
console.log(`genesisData: ${JSON.stringify(genesisData, null, 2)}`)
|
||||
// console.log(`genesisData: ${JSON.stringify(genesisData, null, 2)}`)
|
||||
|
||||
// Add token information to the tx details object.
|
||||
txDetails.tokenTxType = txTokenData.txType
|
||||
@@ -489,7 +301,9 @@ class Transaction {
|
||||
for (let i = 0; i < txDetails.vout.length; i++) {
|
||||
const thisVout = txDetails.vout[i]
|
||||
if (txTokenData.txType === 'SEND') {
|
||||
console.log(`txTokenData: ${JSON.stringify(txTokenData, null, 2)}`)
|
||||
// console.log(
|
||||
// `output txTokenData: ${JSON.stringify(txTokenData, null, 2)}`
|
||||
// )
|
||||
|
||||
// First output is OP_RETURN, so tokenQty is null.
|
||||
if (i === 0) {
|
||||
@@ -518,11 +332,16 @@ class Transaction {
|
||||
txDetails.vout[i].tokenQtyStr = realQty
|
||||
txDetails.vout[i].tokenQty = parseFloat(realQty)
|
||||
|
||||
console.log(
|
||||
`thisVout ${i}: ${JSON.stringify(txDetails.vout[i], null, 2)}`
|
||||
)
|
||||
} else if (txTokenData.txType === 'GENESIS' || txTokenData.txType === 'MINT') {
|
||||
console.log(`txTokenData: ${JSON.stringify(txTokenData, null, 2)}`)
|
||||
// console.log(
|
||||
// `thisVout ${i}: ${JSON.stringify(txDetails.vout[i], null, 2)}`
|
||||
// )
|
||||
} else if (
|
||||
txTokenData.txType === 'GENESIS' ||
|
||||
txTokenData.txType === 'MINT'
|
||||
) {
|
||||
// console.log(
|
||||
// `output txTokenData: ${JSON.stringify(txTokenData, null, 2)}`
|
||||
// )
|
||||
|
||||
let tokenQty = 0 // Default value
|
||||
|
||||
@@ -530,7 +349,7 @@ class Transaction {
|
||||
// Any other outputs in that transaction are normal BCH UTXOs.
|
||||
if (i === 1) {
|
||||
tokenQty = txTokenData.qty
|
||||
console.log(`tokenQty: ${JSON.stringify(tokenQty, null, 2)}`)
|
||||
// console.log(`tokenQty: ${JSON.stringify(tokenQty, null, 2)}`)
|
||||
|
||||
// Calculate the real quantity using a BigNumber, then convert it to a
|
||||
// floating point number.
|
||||
@@ -542,7 +361,7 @@ class Transaction {
|
||||
|
||||
thisVout.tokenQtyStr = realQty
|
||||
thisVout.tokenQty = parseFloat(realQty)
|
||||
console.log(`thisVout[${i}]: ${JSON.stringify(thisVout, null, 2)}`)
|
||||
// console.log(`thisVout[${i}]: ${JSON.stringify(thisVout, null, 2)}`)
|
||||
} else if (i === txTokenData.mintBatonVout) {
|
||||
// Optional Mint baton
|
||||
thisVout.tokenQtyStr = '0'
|
||||
@@ -560,9 +379,12 @@ class Transaction {
|
||||
// Process TX inputs
|
||||
for (let i = 0; i < txDetails.vin.length; i++) {
|
||||
const thisVin = txDetails.vin[i]
|
||||
// console.log(`thisVin[${i}]: ${JSON.stringify(thisVin, null, 2)}`)
|
||||
|
||||
const vinTokenData = await this.getTokenInfo(thisVin.txid)
|
||||
console.log(`vinTokenData: ${JSON.stringify(vinTokenData, null, 2)}`)
|
||||
// console.log(
|
||||
// `vinTokenData ${i}: ${JSON.stringify(vinTokenData, null, 2)}`
|
||||
// )
|
||||
|
||||
// Corner case: Ensure the token ID is the same.
|
||||
const vinTokenIdIsTheSame = vinTokenData.tokenId === txDetails.tokenId
|
||||
@@ -577,7 +399,9 @@ class Transaction {
|
||||
}
|
||||
|
||||
if (vinTokenData.txType === 'SEND') {
|
||||
console.log(`vinTokenData: ${JSON.stringify(vinTokenData, null, 2)}`)
|
||||
// console.log(
|
||||
// `SEND vinTokenData ${i}: ${JSON.stringify(vinTokenData, null, 2)}`
|
||||
// )
|
||||
|
||||
const tokenQty = vinTokenData.amounts[thisVin.vout - 1]
|
||||
// console.log(`tokenQty: ${JSON.stringify(tokenQty, null, 2)}`)
|
||||
@@ -593,8 +417,49 @@ class Transaction {
|
||||
thisVin.tokenQtyStr = realQty
|
||||
thisVin.tokenQty = parseFloat(realQty)
|
||||
thisVin.tokenId = vinTokenData.tokenId
|
||||
} else if (vinTokenData.txType === 'GENESIS' || vinTokenData.txType === 'MINT') {
|
||||
console.log(`vinTokenData: ${JSON.stringify(vinTokenData, null, 2)}`)
|
||||
} else if (vinTokenData.txType === 'MINT') {
|
||||
// console.log(
|
||||
// `MINT vinTokenData ${i}: ${JSON.stringify(vinTokenData, null, 2)}`
|
||||
// )
|
||||
|
||||
let tokenQty = 0 // Default value
|
||||
|
||||
// Only vout[1] of a Genesis transaction represents the tokens.
|
||||
// Any other outputs in that transaction are normal BCH UTXOs.
|
||||
if (thisVin.vout === 1) {
|
||||
tokenQty = vinTokenData.qty
|
||||
// console.log(`tokenQty: ${JSON.stringify(tokenQty, null, 2)}`)
|
||||
|
||||
// Calculate the real quantity using a BigNumber, then convert it to a
|
||||
// floating point number.
|
||||
let realQty = new BigNumber(tokenQty).dividedBy(
|
||||
10 ** parseInt(txDetails.tokenDecimals)
|
||||
)
|
||||
realQty = realQty.toString()
|
||||
// realQty = parseFloat(realQty)
|
||||
|
||||
thisVin.tokenQtyStr = realQty
|
||||
thisVin.tokenQty = parseFloat(realQty)
|
||||
thisVin.tokenId = vinTokenData.tokenId
|
||||
} else if (thisVin.vout === vinTokenData.mintBatonVout) {
|
||||
// Optional Mint baton
|
||||
thisVin.tokenQtyStr = '0'
|
||||
thisVin.tokenQty = 0
|
||||
thisVin.tokenId = vinTokenData.tokenId
|
||||
thisVin.isMintBaton = true
|
||||
} else {
|
||||
thisVin.tokenQtyStr = '0'
|
||||
thisVin.tokenQty = 0
|
||||
thisVin.tokenId = null
|
||||
}
|
||||
} else if (vinTokenData.txType === 'GENESIS') {
|
||||
// console.log(
|
||||
// `GENESIS vinTokenData ${i}: ${JSON.stringify(
|
||||
// vinTokenData,
|
||||
// null,
|
||||
// 2
|
||||
// )}`
|
||||
// )
|
||||
|
||||
let tokenQty = 0 // Default value
|
||||
|
||||
@@ -627,21 +492,13 @@ class Transaction {
|
||||
thisVin.tokenId = null
|
||||
}
|
||||
} else {
|
||||
console.log(`vinTokenData: ${JSON.stringify(vinTokenData, null, 2)}`)
|
||||
console.log(
|
||||
`Unknown vinTokenData: ${JSON.stringify(vinTokenData, null, 2)}`
|
||||
)
|
||||
throw new Error('Unknown token type in input')
|
||||
}
|
||||
}
|
||||
|
||||
// if SEND
|
||||
// if GENSIS
|
||||
// if MINT
|
||||
// Update Inputs
|
||||
// if not SLP
|
||||
// Ensure tokenID matches
|
||||
// if SEND
|
||||
// if GENESIS
|
||||
// if MINT
|
||||
|
||||
return txDetails
|
||||
} catch (err) {
|
||||
console.error('Error in get3()')
|
||||
|
||||
@@ -664,6 +664,111 @@ const mintTestOpReturnData04 = {
|
||||
qty: '234123'
|
||||
}
|
||||
|
||||
const mintTestOpReturnData05 = {
|
||||
tokenType: 1,
|
||||
txType: 'GENESIS',
|
||||
ticker: 'Bubb2',
|
||||
name: 'the new bubbles!',
|
||||
tokenId: '938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8',
|
||||
documentUri: '',
|
||||
documentHash: '',
|
||||
decimals: 5,
|
||||
mintBatonVout: 2,
|
||||
qty: '4354534534'
|
||||
}
|
||||
|
||||
const genesisTestInputTx02 = {
|
||||
txid: '4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf',
|
||||
hash: '4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf',
|
||||
version: 1,
|
||||
size: 444,
|
||||
locktime: 571211,
|
||||
vin: [
|
||||
{
|
||||
txid: 'f3e056874846b6f491a1ccac3da81a3411c61d8466835446a52efa68c0d11804',
|
||||
vout: 0,
|
||||
scriptSig: {
|
||||
asm:
|
||||
'3044022022fb67bd9b35810db3fa04da4014cc93063c5ed15e8febeca09d32c03397068502206fbb86498919ca8a9be6940c904c944cd923691391a4a7d92e0c841605d46b2e[ALL|FORKID] 03fbe2c56094dc336f6244eac2e45d3d25a8e97059f2cc7de31cbf179e73dcc9bf',
|
||||
hex:
|
||||
'473044022022fb67bd9b35810db3fa04da4014cc93063c5ed15e8febeca09d32c03397068502206fbb86498919ca8a9be6940c904c944cd923691391a4a7d92e0c841605d46b2e412103fbe2c56094dc336f6244eac2e45d3d25a8e97059f2cc7de31cbf179e73dcc9bf'
|
||||
},
|
||||
sequence: 4294967294,
|
||||
address: 'bitcoincash:qz6rcxjw34yuy5fngu7fngnyy55t0v802cmsmjvsp2',
|
||||
value: 0.00001111
|
||||
},
|
||||
{
|
||||
txid: '87bf0efc1630f5179b73496f9f885b141cb4c8366432a91ba678298432b197ea',
|
||||
vout: 0,
|
||||
scriptSig: {
|
||||
asm:
|
||||
'3045022100d5fbab461c19c7b56245287eb15510c86872ceb405ede7322f5266efa6cc32ea022074b557bcef9a129fb31cb2e7c2ada9fe51d5cf924ae55d1d2a29368ca1f15ef2[ALL|FORKID] 03fbe2c56094dc336f6244eac2e45d3d25a8e97059f2cc7de31cbf179e73dcc9bf',
|
||||
hex:
|
||||
'483045022100d5fbab461c19c7b56245287eb15510c86872ceb405ede7322f5266efa6cc32ea022074b557bcef9a129fb31cb2e7c2ada9fe51d5cf924ae55d1d2a29368ca1f15ef2412103fbe2c56094dc336f6244eac2e45d3d25a8e97059f2cc7de31cbf179e73dcc9bf'
|
||||
},
|
||||
sequence: 4294967294,
|
||||
address: 'bitcoincash:qz6rcxjw34yuy5fngu7fngnyy55t0v802cmsmjvsp2',
|
||||
value: 0.007
|
||||
}
|
||||
],
|
||||
vout: [
|
||||
{
|
||||
value: 0,
|
||||
n: 0,
|
||||
scriptPubKey: {
|
||||
asm:
|
||||
'OP_RETURN 5262419 1 47454e45534953 5350494345 5370696365 7370696365736c7040676d61696c2e636f6d 0 8 0 016345785d8a0000',
|
||||
hex:
|
||||
'6a04534c500001010747454e45534953055350494345055370696365127370696365736c7040676d61696c2e636f6d4c0001084c0008016345785d8a0000',
|
||||
type: 'nulldata'
|
||||
}
|
||||
},
|
||||
{
|
||||
value: 0.00000546,
|
||||
n: 1,
|
||||
scriptPubKey: {
|
||||
asm:
|
||||
'OP_DUP OP_HASH160 70e5c384ae563b4fd6cfc5f7f8df43ea427d9e10 OP_EQUALVERIFY OP_CHECKSIG',
|
||||
hex: '76a91470e5c384ae563b4fd6cfc5f7f8df43ea427d9e1088ac',
|
||||
reqSigs: 1,
|
||||
type: 'pubkeyhash',
|
||||
addresses: ['bitcoincash:qpcwtsuy4etrkn7kelzl07xlg04yylv7zqru2cqwvm']
|
||||
}
|
||||
},
|
||||
{
|
||||
value: 0.0070012,
|
||||
n: 2,
|
||||
scriptPubKey: {
|
||||
asm:
|
||||
'OP_DUP OP_HASH160 df305a87d98cd64e1bee825d2167a16445ecdfdd OP_EQUALVERIFY OP_CHECKSIG',
|
||||
hex: '76a914df305a87d98cd64e1bee825d2167a16445ecdfdd88ac',
|
||||
reqSigs: 1,
|
||||
type: 'pubkeyhash',
|
||||
addresses: ['bitcoincash:qr0nqk58mxxdvnsma6p96gt859jytmxlm5t0v7de4q']
|
||||
}
|
||||
}
|
||||
],
|
||||
hex:
|
||||
'01000000020418d1c068fa2ea546548366841dc611341aa83daccca191f4b646488756e0f3000000006a473044022022fb67bd9b35810db3fa04da4014cc93063c5ed15e8febeca09d32c03397068502206fbb86498919ca8a9be6940c904c944cd923691391a4a7d92e0c841605d46b2e412103fbe2c56094dc336f6244eac2e45d3d25a8e97059f2cc7de31cbf179e73dcc9bffeffffffea97b132842978a61ba9326436c8b41c145b889f6f49739b17f53016fc0ebf87000000006b483045022100d5fbab461c19c7b56245287eb15510c86872ceb405ede7322f5266efa6cc32ea022074b557bcef9a129fb31cb2e7c2ada9fe51d5cf924ae55d1d2a29368ca1f15ef2412103fbe2c56094dc336f6244eac2e45d3d25a8e97059f2cc7de31cbf179e73dcc9bffeffffff0300000000000000003e6a04534c500001010747454e45534953055350494345055370696365127370696365736c7040676d61696c2e636f6d4c0001084c0008016345785d8a000022020000000000001976a91470e5c384ae563b4fd6cfc5f7f8df43ea427d9e1088acd8ae0a00000000001976a914df305a87d98cd64e1bee825d2167a16445ecdfdd88ac4bb70800',
|
||||
blockhash: '000000000000000002278c188c52b536d4ed84a1970d8ff59043e082cef7748a',
|
||||
confirmations: 141226,
|
||||
time: 1551042875,
|
||||
blocktime: 1551042875
|
||||
}
|
||||
|
||||
const genesisTestOpReturn03 = {
|
||||
tokenType: 1,
|
||||
txType: 'GENESIS',
|
||||
ticker: 'SPICE',
|
||||
name: 'Spice',
|
||||
tokenId: '4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf',
|
||||
documentUri: 'spiceslp@gmail.com',
|
||||
documentHash: '',
|
||||
decimals: 8,
|
||||
mintBatonVout: 0,
|
||||
qty: '100000000000000000'
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
nonSlpTxDetails,
|
||||
slpTxDetails,
|
||||
@@ -683,5 +788,8 @@ module.exports = {
|
||||
sendTestOpReturnData03,
|
||||
sendTestOpReturnData04,
|
||||
mintTestInputTx02,
|
||||
mintTestOpReturnData04
|
||||
mintTestOpReturnData04,
|
||||
mintTestOpReturnData05,
|
||||
genesisTestInputTx02,
|
||||
genesisTestOpReturn03
|
||||
}
|
||||
|
||||
+124
-15
@@ -363,7 +363,10 @@ describe('#TransactionLib', () => {
|
||||
// Assert that inputs have expected properties
|
||||
assert.equal(result.vin[0].tokenQtyStr, '998834')
|
||||
assert.equal(result.vin[0].tokenQty, 998834)
|
||||
assert.equal(result.vin[0].tokenId, '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7')
|
||||
assert.equal(
|
||||
result.vin[0].tokenId,
|
||||
'497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7'
|
||||
)
|
||||
assert.equal(result.vin[1].tokenQtyStr, '0')
|
||||
assert.equal(result.vin[1].tokenQty, 0)
|
||||
assert.equal(result.vin[1].tokenId, null)
|
||||
@@ -439,7 +442,10 @@ describe('#TransactionLib', () => {
|
||||
// Assert inputs have expected properties and values
|
||||
assert.equal(result.vin[0].tokenQty, 10000000)
|
||||
assert.equal(result.vin[0].tokenQtyStr, '10000000')
|
||||
assert.equal(result.vin[0].tokenId, '323a1e35ae0b356316093d20f2d9fbc995d19314b5c0148b78dc8d9c0dab9d35')
|
||||
assert.equal(
|
||||
result.vin[0].tokenId,
|
||||
'323a1e35ae0b356316093d20f2d9fbc995d19314b5c0148b78dc8d9c0dab9d35'
|
||||
)
|
||||
assert.equal(result.vin[1].tokenQty, 0)
|
||||
assert.equal(result.vin[1].tokenQtyStr, '0')
|
||||
assert.equal(result.vin[1].tokenId, null)
|
||||
@@ -492,10 +498,16 @@ describe('#TransactionLib', () => {
|
||||
// Assert expected input properties and values exist.
|
||||
assert.equal(result.vin[0].tokenQty, 43545.34534)
|
||||
assert.equal(result.vin[0].tokenQtyStr, '43545.34534')
|
||||
assert.equal(result.vin[0].tokenId, '938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8')
|
||||
assert.equal(
|
||||
result.vin[0].tokenId,
|
||||
'938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8'
|
||||
)
|
||||
assert.equal(result.vin[1].tokenQty, 2.34123)
|
||||
assert.equal(result.vin[1].tokenQtyStr, '2.34123')
|
||||
assert.equal(result.vin[1].tokenId, '938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8')
|
||||
assert.equal(
|
||||
result.vin[1].tokenId,
|
||||
'938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8'
|
||||
)
|
||||
assert.equal(result.vin[2].tokenQty, 0)
|
||||
assert.equal(result.vin[2].tokenQtyStr, '0')
|
||||
assert.equal(result.vin[2].tokenId, null)
|
||||
@@ -552,13 +564,19 @@ describe('#TransactionLib', () => {
|
||||
// Assert the inputs have expected properties and values.
|
||||
assert.equal(result.vin[0].tokenQty, 100000000)
|
||||
assert.equal(result.vin[0].tokenQtyStr, '100000000')
|
||||
assert.equal(result.vin[0].tokenId, '550d19eb820e616a54b8a73372c4420b5a0567d8dc00f613b71c5234dc884b35')
|
||||
assert.equal(
|
||||
result.vin[0].tokenId,
|
||||
'550d19eb820e616a54b8a73372c4420b5a0567d8dc00f613b71c5234dc884b35'
|
||||
)
|
||||
assert.equal(result.vin[1].tokenQty, 0)
|
||||
assert.equal(result.vin[1].tokenQtyStr, 0)
|
||||
assert.equal(result.vin[1].tokenId, null)
|
||||
assert.equal(result.vin[2].tokenQty, 99000000)
|
||||
assert.equal(result.vin[2].tokenQtyStr, '99000000')
|
||||
assert.equal(result.vin[2].tokenId, '550d19eb820e616a54b8a73372c4420b5a0567d8dc00f613b71c5234dc884b35')
|
||||
assert.equal(
|
||||
result.vin[2].tokenId,
|
||||
'550d19eb820e616a54b8a73372c4420b5a0567d8dc00f613b71c5234dc884b35'
|
||||
)
|
||||
|
||||
// Assert blockheight is added
|
||||
assert.equal(result.blockheight, 543957)
|
||||
@@ -578,22 +596,113 @@ describe('#TransactionLib', () => {
|
||||
.stub(bchjs.Transaction.slpUtils, 'decodeOpReturn')
|
||||
.onCall(0)
|
||||
.resolves(mockData.mintTestOpReturnData04)
|
||||
// .onCall(1)
|
||||
// .resolves(mockData.sendTestOpReturnData02)
|
||||
// .onCall(2)
|
||||
// .resolves(mockData.sendTestOpReturnData03)
|
||||
// .onCall(3)
|
||||
// .resolves(mockData.sendTestOpReturnData03)
|
||||
// .onCall(4)
|
||||
// .resolves(mockData.sendTestOpReturnData04)
|
||||
.onCall(1)
|
||||
.resolves(mockData.mintTestOpReturnData05)
|
||||
.onCall(2)
|
||||
.resolves(mockData.mintTestOpReturnData05)
|
||||
.onCall(3)
|
||||
.resolves(mockData.mintTestOpReturnData05)
|
||||
.onCall(4)
|
||||
.resolves(mockData.mintTestOpReturnData05)
|
||||
.onCall(5)
|
||||
.resolves(mockData.mintTestOpReturnData05)
|
||||
|
||||
const txid =
|
||||
'ee9d3cf5153599c134147e3fac9844c68e216843f4452a1ce15a29452af6db34'
|
||||
|
||||
const result = await bchjs.Transaction.get3(txid)
|
||||
console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
// Assert that there are stanardized properties.
|
||||
assert.property(result, 'txid')
|
||||
assert.property(result, 'vin')
|
||||
assert.property(result, 'vout')
|
||||
assert.property(result.vout[0], 'value')
|
||||
assert.property(result.vout[1].scriptPubKey, 'addresses')
|
||||
|
||||
// Assert outputs have expected properties and values
|
||||
assert.equal(result.vout[0].tokenQty, 0)
|
||||
assert.equal(result.vout[0].tokenQty, '0')
|
||||
assert.equal(result.vout[1].tokenQty, 2.34123)
|
||||
assert.equal(result.vout[1].tokenQty, '2.34123')
|
||||
assert.equal(result.vout[2].tokenQty, 0)
|
||||
assert.equal(result.vout[2].tokenQty, '0')
|
||||
assert.equal(result.vout[2].isMintBaton, true)
|
||||
assert.equal(result.vout[3].tokenQty, 0)
|
||||
assert.equal(result.vout[3].tokenQty, '0')
|
||||
|
||||
// Assert inputs have expected properties and values
|
||||
assert.equal(result.vin[0].tokenQty, 0)
|
||||
assert.equal(result.vin[0].tokenQtyStr, '0')
|
||||
assert.equal(result.vin[0].tokenId, null)
|
||||
assert.equal(result.vin[1].tokenQty, 0)
|
||||
assert.equal(result.vin[1].tokenQtyStr, '0')
|
||||
assert.equal(
|
||||
result.vin[1].tokenId,
|
||||
'938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8'
|
||||
)
|
||||
assert.equal(result.vin[1].isMintBaton, true)
|
||||
|
||||
// Assert added TX data exists.
|
||||
assert.equal(result.blockheight, 543614)
|
||||
assert.equal(result.isSlpTx, true)
|
||||
})
|
||||
|
||||
// It should process a GENESIS tx
|
||||
it('should process a GENESIS tx', async () => {
|
||||
// Mock dependencies
|
||||
sandbox
|
||||
.stub(bchjs.Transaction.rawTransaction, 'getTxData')
|
||||
.resolves(mockData.genesisTestInputTx02)
|
||||
sandbox
|
||||
.stub(bchjs.Transaction.blockchain, 'getBlockHeader')
|
||||
.resolves({ height: 571212 })
|
||||
sandbox
|
||||
.stub(bchjs.Transaction, 'getTokenInfo')
|
||||
.onCall(0)
|
||||
.resolves(mockData.genesisTestOpReturn03)
|
||||
.onCall(1)
|
||||
.resolves(mockData.genesisTestOpReturn03)
|
||||
.onCall(2)
|
||||
.resolves(false)
|
||||
.onCall(3)
|
||||
.resolves(false)
|
||||
.onCall(4)
|
||||
.resolves(false)
|
||||
|
||||
const txid =
|
||||
'4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf'
|
||||
|
||||
const result = await bchjs.Transaction.get3(txid)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
// Assert that there are stanardized properties.
|
||||
assert.property(result, 'txid')
|
||||
assert.property(result, 'vin')
|
||||
assert.property(result, 'vout')
|
||||
assert.property(result.vout[0], 'value')
|
||||
assert.property(result.vout[1].scriptPubKey, 'addresses')
|
||||
|
||||
// Assert output have expected properties and values
|
||||
assert.equal(result.vout[0].tokenQty, 0)
|
||||
assert.equal(result.vout[0].tokenQtyStr, '0')
|
||||
assert.equal(result.vout[0].isMintBaton, true)
|
||||
assert.equal(result.vout[1].tokenQty, 1000000000)
|
||||
assert.equal(result.vout[1].tokenQtyStr, '1000000000')
|
||||
assert.equal(result.vout[2].tokenQty, 0)
|
||||
assert.equal(result.vout[2].tokenQtyStr, '0')
|
||||
|
||||
// Assert input have expected properties and values
|
||||
assert.equal(result.vin[0].tokenQty, 0)
|
||||
assert.equal(result.vin[0].tokenQtyStr, '0')
|
||||
assert.equal(result.vin[0].tokenId, null)
|
||||
assert.equal(result.vin[1].tokenQty, 0)
|
||||
assert.equal(result.vin[1].tokenQtyStr, '0')
|
||||
assert.equal(result.vin[1].tokenId, null)
|
||||
|
||||
// Assert added TX data exists.
|
||||
assert.equal(result.blockheight, 571212)
|
||||
assert.equal(result.isSlpTx, true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user