psf-multisig-approval 2.0.10 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +75 -17
- package/lib/nfts.js +1 -1
- package/lib/util.js +1 -1
- package/package.json +3 -2
- package/test/integration/main-index-integration.js +3 -3
- package/test/unit/main-index-unit.js +6 -6
- package/test/unit/mocks/main-index-mocks.js +13 -1
- package/test/unit/mocks/util-mocks.js +1 -1
- package/test/unit/nfts-unit.js +6 -9
- package/test/unit/util-unit.js +6 -6
package/index.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// global libraries
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import bitcore from '@chris.troutner/bitcore-lib-cash'
|
|
8
|
+
import axios from 'axios'
|
|
9
9
|
|
|
10
10
|
// Local libraries
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
import NFTs from './lib/nfts.js'
|
|
12
|
+
import UtilLib from './lib/util.js'
|
|
13
13
|
|
|
14
14
|
class MultisigApproval {
|
|
15
15
|
constructor (localConfig = {}) {
|
|
@@ -41,7 +41,7 @@ class MultisigApproval {
|
|
|
41
41
|
this.getUpdateTx = this.getUpdateTx.bind(this)
|
|
42
42
|
this.getCidData = this.getCidData.bind(this)
|
|
43
43
|
this.validateApproval = this.validateApproval.bind(this)
|
|
44
|
-
this.
|
|
44
|
+
this.getAllApprovalTxs = this.getAllApprovalTxs.bind(this)
|
|
45
45
|
|
|
46
46
|
// Create a transaction details cache, to reduce the number of API calls.
|
|
47
47
|
this.txCache = {}
|
|
@@ -340,21 +340,79 @@ class MultisigApproval {
|
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
//
|
|
344
|
-
//
|
|
345
|
-
//
|
|
346
|
-
//
|
|
347
|
-
//
|
|
348
|
-
//
|
|
349
|
-
|
|
350
|
-
|
|
343
|
+
// Given a BCH address, scan its transaction history to find all the
|
|
344
|
+
// APPROVAL transactions. This function returns an array of objects. Each
|
|
345
|
+
// object represents an APPROVAL transaction.
|
|
346
|
+
// If no APPROVAL transaction can be found, then function returns null.
|
|
347
|
+
// An optional input, filterTxids, is an array of transaction IDs to ignore. This can
|
|
348
|
+
// be used to ignore/skip any known, fake approval transactions.
|
|
349
|
+
async getAllApprovalTxs (inObj = {}) {
|
|
350
|
+
try {
|
|
351
|
+
let address = inObj.address
|
|
352
|
+
const { filterTxids } = inObj
|
|
351
353
|
|
|
352
|
-
|
|
354
|
+
const approvalTxs = []
|
|
353
355
|
|
|
354
|
-
|
|
356
|
+
// Input validation
|
|
357
|
+
if (address.includes('simpleledger:')) {
|
|
358
|
+
address = this.bchjs.SLP.Address.toCashAddress(address)
|
|
359
|
+
}
|
|
360
|
+
if (!address.includes('bitcoincash:')) {
|
|
361
|
+
throw new Error('Input address must start with bitcoincash: or simpleledger:')
|
|
362
|
+
}
|
|
355
363
|
|
|
356
|
-
|
|
364
|
+
// Get the transaction history for the address
|
|
365
|
+
const txHistory = await this.wallet.getTransactions(address)
|
|
366
|
+
// console.log('txHistory: ', JSON.stringify(txHistory, null, 2))
|
|
367
|
+
|
|
368
|
+
// Loop through the transaction history
|
|
369
|
+
for (let i = 0; i < txHistory.length; i++) {
|
|
370
|
+
const thisTxid = txHistory[i]
|
|
371
|
+
|
|
372
|
+
// const height = thisTxid.height
|
|
373
|
+
const txid = thisTxid.tx_hash
|
|
374
|
+
|
|
375
|
+
// Skip the txid if it is in the filter list.
|
|
376
|
+
if (Array.isArray(filterTxids)) {
|
|
377
|
+
const txidFound = filterTxids.find(x => x === txid)
|
|
378
|
+
// console.log('txidFound: ', txidFound)
|
|
379
|
+
if (txidFound) {
|
|
380
|
+
continue
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// Get the transaction details for the transaction
|
|
385
|
+
const txDetails = await this.util.getTxData(txid)
|
|
386
|
+
// console.log('txDetails: ', JSON.stringify(txDetails, null, 2))
|
|
387
|
+
// console.log(`txid: ${txid}`)
|
|
388
|
+
|
|
389
|
+
const out2ascii = Buffer.from(txDetails.vout[0].scriptPubKey.hex, 'hex').toString('ascii')
|
|
390
|
+
// console.log('out2ascii: ', out2ascii)
|
|
391
|
+
|
|
392
|
+
// If the first output is not an OP_RETURN, then the tx can be discarded.
|
|
393
|
+
if (!out2ascii.includes('APPROVE')) {
|
|
394
|
+
continue
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const updateTxid = out2ascii.slice(10)
|
|
398
|
+
// console.log('updateTxid: ', updateTxid)
|
|
399
|
+
|
|
400
|
+
const outObj = {
|
|
401
|
+
approvalTxid: txid,
|
|
402
|
+
updateTxid,
|
|
403
|
+
approvalTxDetails: txDetails,
|
|
404
|
+
opReturn: out2ascii
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
approvalTxs.push(outObj)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
return approvalTxs
|
|
411
|
+
} catch (err) {
|
|
412
|
+
console.error('Error in getAllApprovalTxs(): ', err)
|
|
413
|
+
throw err
|
|
414
|
+
}
|
|
357
415
|
}
|
|
358
416
|
}
|
|
359
417
|
|
|
360
|
-
|
|
418
|
+
export default MultisigApproval
|
package/lib/nfts.js
CHANGED
package/lib/util.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "psf-multisig-approval",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Utility library implementing the PS009 specification",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "index.js",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"start": "node index.js",
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
"chai": "4.3.7",
|
|
41
42
|
"husky": "8.0.3",
|
|
42
43
|
"lodash.clonedeep": "4.5.0",
|
|
43
|
-
"minimal-slp-wallet": "
|
|
44
|
+
"minimal-slp-wallet": "7.1.3",
|
|
44
45
|
"mocha": "10.2.0",
|
|
45
46
|
"nyc": "15.1.0",
|
|
46
47
|
"semantic-release": "19.0.5",
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
// Global npm libraries
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import SlpWallet from 'minimal-slp-wallet'
|
|
7
|
+
import { assert } from 'chai'
|
|
8
8
|
|
|
9
9
|
// Local libraries
|
|
10
|
-
|
|
10
|
+
import MultisigApproval from '../../index.js'
|
|
11
11
|
|
|
12
12
|
describe('#psf-multisig-approval', () => {
|
|
13
13
|
let uut
|
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
// npm libraries
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
import { assert } from 'chai'
|
|
7
|
+
import sinon from 'sinon'
|
|
8
|
+
import cloneDeep from 'lodash.clonedeep'
|
|
9
|
+
import SlpWallet from 'minimal-slp-wallet'
|
|
10
10
|
|
|
11
11
|
// Mocking data libraries.
|
|
12
12
|
|
|
13
13
|
// Local libraries
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
import MultisigApproval from '../../index.js'
|
|
15
|
+
import mockDataLib from './mocks/main-index-mocks.js'
|
|
16
16
|
|
|
17
17
|
describe('#MultisigApproval.js', () => {
|
|
18
18
|
let sandbox
|
|
@@ -277,7 +277,19 @@ const updateObj01 = {
|
|
|
277
277
|
txDetails: updateTxDetails01
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
|
|
280
|
+
export {
|
|
281
|
+
pubkeys01,
|
|
282
|
+
txHistory01,
|
|
283
|
+
txHistory02,
|
|
284
|
+
approvalTxDetails01,
|
|
285
|
+
updateTxDetails01,
|
|
286
|
+
tokenHolderInfo01,
|
|
287
|
+
updateData01,
|
|
288
|
+
approvalObj01,
|
|
289
|
+
updateObj01
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export default {
|
|
281
293
|
pubkeys01,
|
|
282
294
|
txHistory01,
|
|
283
295
|
txHistory02,
|
package/test/unit/nfts-unit.js
CHANGED
|
@@ -3,19 +3,16 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
// npm libraries
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// Locally global variables.
|
|
12
|
-
const assert = chai.assert
|
|
6
|
+
import { assert } from 'chai'
|
|
7
|
+
import sinon from 'sinon'
|
|
8
|
+
// import cloneDeep from 'lodash.clonedeep'
|
|
9
|
+
import SlpWallet from 'minimal-slp-wallet'
|
|
13
10
|
|
|
14
11
|
// Mocking data libraries.
|
|
15
|
-
//
|
|
12
|
+
// import mockDataLib from './mocks/util-mocks.js'
|
|
16
13
|
|
|
17
14
|
// Unit under test
|
|
18
|
-
|
|
15
|
+
import NftsLib from '../../lib/nfts.js'
|
|
19
16
|
|
|
20
17
|
describe('#NFTs', () => {
|
|
21
18
|
let sandbox
|
package/test/unit/util-unit.js
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
// npm libraries
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
6
|
+
import { assert } from 'chai'
|
|
7
|
+
import sinon from 'sinon'
|
|
8
|
+
// import cloneDeep from 'lodash.clonedeep'
|
|
9
|
+
import SlpWallet from 'minimal-slp-wallet'
|
|
10
10
|
|
|
11
11
|
// Local libraries
|
|
12
|
-
//
|
|
12
|
+
// import mockDataLib from './mocks/util-mocks.js'
|
|
13
13
|
|
|
14
14
|
// Unit under test
|
|
15
|
-
|
|
15
|
+
import UtilLib from '../../lib/util.js'
|
|
16
16
|
|
|
17
17
|
describe('#Util', () => {
|
|
18
18
|
let sandbox
|