diff --git a/README.md b/README.md index 9573d96b..77c360ab 100644 --- a/README.md +++ b/README.md @@ -837,6 +837,9 @@ Running the unit tests require node.js v8.15+. # Change Log +### 0.27.8 +- Simplify BchdValidator behavior and API + ### 0.27.7 - Add BchdValidator class for leveraging BCHD SLP indexer diff --git a/lib/bchdtrustedvalidator.ts b/lib/bchdtrustedvalidator.ts index ace729f7..c855b1c0 100644 --- a/lib/bchdtrustedvalidator.ts +++ b/lib/bchdtrustedvalidator.ts @@ -1,10 +1,14 @@ import { IGrpcClient } from "grpc-bchrpc"; -import { SlpValidator } from ".."; +import { logger, SlpValidator } from ".."; export class BchdValidator implements SlpValidator { public client: IGrpcClient; - constructor(client: IGrpcClient) { + private logger?: { log: (s: string) => any; }; + constructor(client: IGrpcClient, logger?: logger) { this.client = client; + if (logger) { + this.logger = logger; + } } public async getRawTransactions(txid: string[]): Promise { const res = await this.client.getRawTransaction({hash: txid[0], reversedHashOrder: true}); @@ -12,19 +16,19 @@ export class BchdValidator implements SlpValidator { } public async isValidSlpTxid(txid: string): Promise { try { - console.log(`validate: ${txid}`); + this.log(`validate: ${txid}`); const res = await this.client.getTrustedSlpValidation({ txos: [{vout: 1, hash: txid}], reversedHashOrder: true }); } catch (error) { - if (!error.message.includes("Error")) { + if (! error.message.includes("txid is missing from slp validity set")) { throw error; } - console.log(`false (${txid})`); + this.log(`false (${txid})`); return false; } - console.log(`true (${txid})`); + this.log(`true (${txid})`); return true; } @@ -35,4 +39,10 @@ export class BchdValidator implements SlpValidator { } return res.filter((id: string) => id.length > 0); } + + private log(s: string) { + if (this.logger) { + this.logger.log(s); + } + } } diff --git a/package-lock.json b/package-lock.json index f2686fcb..2494ee81 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "slpjs", - "version": "0.27.7", + "version": "0.27.8", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 87827fa3..5f4d58c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "slpjs", - "version": "0.27.7", + "version": "0.27.8", "description": "Simple Ledger Protocol (SLP) JavaScript Library", "main": "index.js", "files": [