Skip to content

Commit

Permalink
updates for version 0.11.0 release:
Browse files Browse the repository at this point in the history
* includes improved control over token graph updates
* after each block detects burns caused by non-SLP txn
* cleaned up local logging
* minor breaking change: removed "block" property from GraphTxn and GraphTxnDbo objects
* bump db schema version to trigger graph rebuild
* use recursion in checkForMissingMempoolTxns()
  • Loading branch information
jcramer committed Apr 26, 2019
1 parent f7242f8 commit 9cf1370
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 111 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
![SLPDB](assets/slpdb_logo.png)

# SLPDB Readme
**Last Updated:** 2019-04-25
**Last Updated:** 2019-04-26

**Current SLPDB Version:** 0.10.1 (beta)
**Current SLPDB Version:** 0.11.0 (beta)



Expand Down Expand Up @@ -52,7 +52,7 @@ Users should utilize the [SlpServe](https://github.com/fountainhead-cash/slpserv

Some of the values used in SLP require 64 or more bits of precision, which is more precision than `number` type can provide. To ensure value precision is maintained values are stored in collections using the `Decimal128` type. `Decimal128` allows users to make database queries using query comparison operators like `$gte`.

However, when `SlpServe` or `SlpSockServer` query results are returned as a JSON object these `Decimal128` values are converted into `string` type to improve readability of the value for the query consumer, as opposed to being returned as a special (and odd looking) `$DecimalNumber` JSON object. The `string` type also maintains the original value precision. If a user wants to perform math operations on these `string` values the user will need to first convert them to a large number type like `BigNumber` or `Decimal128` (e.g., `Decimal128.fromString("1000.123124")` or using [bignumber.js](https://github.com/MikeMcl/bignumber.js/) npm library via `new BigNumber("1000.00000001")`).
The services `SlpServe` and `SlpSockServer` return query results as a JSON object with `Decimal128` values converted to `string` type so that readability is improved for the query consumer, as opposed to being returned as an awqward `$DecimalNumber` JSON object. The `string` type also maintains the original value precision. If a user wants to perform math operations on these `string` values the user will need to first convert them to a large number type like `BigNumber` or `Decimal128` (e.g., `Decimal128.fromString("1000.123124")` or using [bignumber.js](https://github.com/MikeMcl/bignumber.js/) npm library via `new BigNumber("1000.00000001")`).



Expand Down Expand Up @@ -341,7 +341,6 @@ Six MongoDB collections used to store these three categories of data, they are a
"graphTxn": {
txid: string;
details: SlpTransactionDetailsDbo;
block: number|null;
outputs: GraphTxnOutputDbo[];
};
}
Expand Down
2 changes: 1 addition & 1 deletion SlpGraphManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export class SlpGraphManager implements IZmqSubscriber {
}
}

if(graph.IsValid()) {
if(graph.IsValid) {
this._tokens.set(tokens[i].tokenIdHex, graph);
await this.db.tokeninsertreplace(this._tokens.get(tokens[i].tokenIdHex)!.toTokenDbObject());
await this.db.graphinsertreplace(this._tokens.get(tokens[i].tokenIdHex)!.toGraphDbObject(), tokens[i].tokenIdHex);
Expand Down
202 changes: 105 additions & 97 deletions SlpTokenGraph.ts

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions bit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,9 @@ export class Bit {
}
}

async checkForMissingMempoolTxns() {
let currentBchMempoolList = await this.rpc.getRawMempool();
async checkForMissingMempoolTxns(currentBchMempoolList?: string[]) {
if(!currentBchMempoolList)
currentBchMempoolList = await this.rpc.getRawMempool();
let cachedSlpMempoolTxs = Array.from(this.slpMempool.keys());

// add missing SLP transactions and process
Expand All @@ -414,6 +415,10 @@ export class Bit {
}
});

let residualMempoolList = (await this.rpc.getRawMempool()).filter(id => !this.slpMempoolIgnoreList.includes(id) && !Array.from(this.slpMempool.keys()).includes(id))
if(residualMempoolList.length > 0)
this.checkForMissingMempoolTxns(residualMempoolList)

console.log('[INFO] BCH mempool txn count:', currentBchMempoolList.length);
console.log("[INFO] SLP mempool txn count:", this.slpMempool.size);
}
Expand Down Expand Up @@ -524,6 +529,14 @@ export class Bit {
}
return result;
}
else if(!isSLP) {
// check transaction inputs for spending of SLP transactions
// if(txn && self._zmqSubscribers.length > 0) {
// await self.asyncForEach(txn!.inputs, async () => {
// console.log("[TEST] checking input");
// })
// }
}
}
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Config {
name: process.env.db_name ? process.env.db_name : 'slpdb',
name_testnet: process.env.db_name ? process.env.db_name + "_test" : 'slpdb_testnet',
url: process.env.db_url ? process.env.db_url : 'mongodb://localhost:27017',
schema_version: 64,
schema_version: 65,
index: {
tokens: {
keys: [ 'tokenDetails.tokenIdHex', 'tokenDetails.name', 'tokenDetails.symbol', 'tokenStats.qty_token_circulating_supply', 'tokenStats.qty_token_burned', 'tokenStats.qty_token_minted' ],
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slpdb",
"version": "0.10.1",
"version": "0.11.0",
"description": "Data storage layer for Simple Ledger Protocol",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export class Query {

if(!response.errors) {
let results: MintTxnQueryResult[] = ([].concat(<any>response.c).concat(<any>response.u));
if(results.length === 1) {
if(results.length > 0) {
let res: MintTxnQueryResult = results[0];
try {
let qtyBuf = Buffer.from(res.mintQty as any as string, 'hex');
Expand All @@ -330,7 +330,7 @@ export class Query {
return res;
}
else {
console.log("Assumed Token Burn: Could not find the spend transaction: " + txid + ":" + vout);
console.log("[INFO] Assumed Token Burn: Could not find the spend transaction: " + txid + ":" + vout);
return { tokenid: null, txid: null, block: null, timestamp: null, batonHex: null, mintQty: null, mintBchQty: null }
}
}
Expand All @@ -357,7 +357,7 @@ export class Query {

if(!response.errors) {
let results: SendTxnQueryResult[] = ([].concat(<any>response.c).concat(<any>response.u));
if(results.length === 1) {
if(results.length > 0) {
let res: any = results[0];
let sendOutputs: { tokenQty: BigNumber, satoshis: number }[] = [];
res.sendOutputs = sendOutputs;
Expand All @@ -376,7 +376,7 @@ export class Query {
return res;
}
else {
console.log("Assumed Token Burn: Could not find the spend transaction: " + txid + ":" + vout);
console.log("[INFO] Assumed Token Burn: Could not find the spend transaction: " + txid + ":" + vout);
return { tokenid: null, txid: null, block: null, timestamp: null, sendOutputs: [ { tokenQty: new BigNumber(0), satoshis: 0} ] }
}
}
Expand Down

0 comments on commit 9cf1370

Please sign in to comment.