Skip to content

Commit

Permalink
Added optional filtering by tokenId to validator
Browse files Browse the repository at this point in the history
  • Loading branch information
jcramer committed Mar 1, 2019
1 parent 94c3ccf commit a5ed737
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/localvalidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class LocalValidator implements SlpValidator {
throw Error("Transaction data not provided (null or undefined).")
}

async isValidSlpTxid(txid: string): Promise<boolean> {
async isValidSlpTxid(txid: string, tokenIdFilter?: string): Promise<boolean> {
if(txid && !this.cachedValidations[txid]) {
this.cachedValidations[txid] = { validity: null, parents: [], details: null, invalidReason: null }
await this.retrieveRawTransaction(txid);
Expand All @@ -98,11 +98,19 @@ export class LocalValidator implements SlpValidator {
let slpmsg: SlpTransactionDetails;
try {
slpmsg = this.cachedValidations[txid].details = this.slp.parseSlpOutputScript(txn.outputs[0]._scriptBuffer)
if(slpmsg.transactionType === SlpTransactionType.GENESIS)
slpmsg.tokenIdHex = txid;
} catch(e) {
this.cachedValidations[txid].invalidReason = "SLP OP_RETURN parsing error (" + e.message + ")."
return this.cachedValidations[txid].validity = false;
}

// Check for tokenId filter
if(tokenIdFilter && slpmsg.tokenIdHex !== tokenIdFilter) {
this.cachedValidations[txid].invalidReason = "Only tokenId " + tokenIdFilter + " was considered by validator.";
return this.cachedValidations[txid].validity = false;
}

// Check DAG validity
if(slpmsg.transactionType === SlpTransactionType.GENESIS) {
return this.cachedValidations[txid].validity = true;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slpjs",
"version": "0.15.0",
"version": "0.15.2",
"description": "Simple Ledger Protocol (SLP) JavaScript Library",
"main": "index.js",
"files": [
Expand Down

0 comments on commit a5ed737

Please sign in to comment.