@unspent/psi
Advanced tools
Comparing version 0.2.3 to 0.2.4
import { BytecodePatternQueryI, HistoryI, HistoryQueryI } from "./interface.js"; | ||
export declare function getRecords(host: string, prefix?: string, limit?: number, offset?: number, exclude_pattern?: string, after?: number): Promise<any>; | ||
export declare function getRecords(host: string, prefix?: string, node?: string, limit?: number, offset?: number, exclude_pattern?: string, after?: number): Promise<any>; | ||
export declare function getChaingraphUnspentRecords(host: string, param: BytecodePatternQueryI): Promise<any>; | ||
@@ -4,0 +4,0 @@ export declare function getTransaction(host: string, txid: string): Promise<any>; |
@@ -5,5 +5,6 @@ import axios from 'axios'; | ||
import { binToHex } from "@bitauth/libauth"; | ||
export async function getRecords(host, prefix, limit = 25, offset = 0, exclude_pattern = "", after = 0) { | ||
export async function getRecords(host, prefix, node = "mainnet", limit = 25, offset = 0, exclude_pattern = "", after = 0) { | ||
let param = { | ||
prefix: prefix, | ||
node: node, | ||
limit: limit, | ||
@@ -32,5 +33,4 @@ offset: offset, | ||
delete param.after; | ||
//@ts-ignore | ||
if ("node" in param) | ||
delete param.node; | ||
if ("prefix" in param) | ||
param.prefix = param.prefix.substring(0, 20); | ||
const response = await axios({ | ||
@@ -42,2 +42,3 @@ url: host, | ||
$prefix: String! | ||
$node: String! | ||
$exclude_pattern: String | ||
@@ -55,2 +56,19 @@ $limit: Int | ||
{ locking_bytecode_pattern: { _nlike: $exclude_pattern } } | ||
{ | ||
_or: [ | ||
{ | ||
transaction: { | ||
block_inclusions: { | ||
block: { accepted_by: { node: { name: { _regex: $node } } } } | ||
} | ||
} | ||
} | ||
{ | ||
transaction: { | ||
node_validations: { node: { name: { _regex: $node } } } | ||
} | ||
} | ||
] | ||
} | ||
] | ||
@@ -60,3 +78,10 @@ } | ||
locking_bytecode_pattern, | ||
locking_bytecode | ||
locking_bytecode, | ||
transaction{ | ||
block_inclusions{ | ||
block{ | ||
height | ||
} | ||
} | ||
} | ||
} | ||
@@ -79,5 +104,9 @@ }`, | ||
const results = response.data.data.search_output_prefix.map((r) => { | ||
let height = r.transaction.block_inclusions[0]?.block.height; | ||
if (typeof height === "string") | ||
height = parseInt(height); | ||
if (r.locking_bytecode.slice(0, 2) === "\\x") { | ||
return { | ||
record: r.locking_bytecode.slice(2) | ||
record: r.locking_bytecode.slice(2), | ||
height: height | ||
}; | ||
@@ -87,3 +116,4 @@ } | ||
return { | ||
record: r.locking_bytecode | ||
record: r.locking_bytecode, | ||
height: height | ||
}; | ||
@@ -95,3 +125,4 @@ } | ||
"id": o.record, | ||
"data": parseOpReturn(o.record) | ||
"data": parseOpReturn(o.record), | ||
"height": o.height | ||
}; | ||
@@ -212,3 +243,3 @@ }); | ||
variables: { | ||
prefix: lockingBytecode, | ||
prefix: lockingBytecode.substring(0, 20), | ||
}, | ||
@@ -219,2 +250,3 @@ }, | ||
}); | ||
console.log(response); | ||
// raise errors from chaingraph | ||
@@ -338,3 +370,3 @@ if (response.data.error || response.data.errors) { | ||
...param, | ||
"lockingBytecode": `${lockingBytecode.substring(0, 24)}`, | ||
"lockingBytecode": `${lockingBytecode.substring(0, 20)}`, | ||
}, | ||
@@ -341,0 +373,0 @@ } |
{ | ||
"name": "@unspent/psi", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "A persistent storage IndexedDB wrapper for ₿∙ϕ contracts and data using Dexie.js", | ||
@@ -5,0 +5,0 @@ "author": "2qx", |
@@ -13,3 +13,3 @@ import { HistoryQueryI, BytecodePatternQueryDefaults, HistoryIDefaults, BytecodePatternQueryI } from "./interface.js" | ||
PROTOCOL_ID + | ||
"01520101025203010017a91496e199d7ea23fb779f5764b97196824002ef811a87"; | ||
"01520101023601010017a914e2c8cacae07977ccbbcd39c0099c6a5b6426e70887"; | ||
const contractStrings = await getRecords( | ||
@@ -16,0 +16,0 @@ host, |
@@ -17,2 +17,3 @@ import axios from 'axios'; | ||
prefix?: string, | ||
node = "mainnet", | ||
limit = 25, | ||
@@ -26,2 +27,3 @@ offset = 0, | ||
prefix: prefix, | ||
node: node, | ||
limit: limit, | ||
@@ -58,5 +60,5 @@ offset: offset, | ||
if ("after" in param) delete param.after | ||
//@ts-ignore | ||
if ("node" in param) delete param.node | ||
if ("prefix" in param) param.prefix = param.prefix!.substring(0, 20) | ||
const response = await axios({ | ||
@@ -68,2 +70,3 @@ url: host, | ||
$prefix: String! | ||
$node: String! | ||
$exclude_pattern: String | ||
@@ -81,2 +84,19 @@ $limit: Int | ||
{ locking_bytecode_pattern: { _nlike: $exclude_pattern } } | ||
{ | ||
_or: [ | ||
{ | ||
transaction: { | ||
block_inclusions: { | ||
block: { accepted_by: { node: { name: { _regex: $node } } } } | ||
} | ||
} | ||
} | ||
{ | ||
transaction: { | ||
node_validations: { node: { name: { _regex: $node } } } | ||
} | ||
} | ||
] | ||
} | ||
] | ||
@@ -86,3 +106,10 @@ } | ||
locking_bytecode_pattern, | ||
locking_bytecode | ||
locking_bytecode, | ||
transaction{ | ||
block_inclusions{ | ||
block{ | ||
height | ||
} | ||
} | ||
} | ||
} | ||
@@ -105,10 +132,13 @@ }`, | ||
const results = response.data.data.search_output_prefix.map((r: ChaingraphSearchOutputResult) => { | ||
let height = r.transaction.block_inclusions[0]?.block.height | ||
if (typeof height === "string") height = parseInt(height) | ||
if (r.locking_bytecode.slice(0, 2) === "\\x") { | ||
return { | ||
record: r.locking_bytecode.slice(2) | ||
record: r.locking_bytecode.slice(2), | ||
height: height | ||
} | ||
} else { | ||
return { | ||
record: r.locking_bytecode | ||
record: r.locking_bytecode, | ||
height: height | ||
} | ||
@@ -121,3 +151,4 @@ } | ||
"id": o.record, | ||
"data": parseOpReturn(o.record) | ||
"data": parseOpReturn(o.record), | ||
"height": o.height | ||
} | ||
@@ -245,3 +276,3 @@ }) | ||
variables: { | ||
prefix: lockingBytecode, | ||
prefix: lockingBytecode.substring(0, 20), | ||
}, | ||
@@ -253,2 +284,3 @@ }, | ||
console.log(response) | ||
// raise errors from chaingraph | ||
@@ -382,3 +414,3 @@ if (response.data.error || response.data.errors) { | ||
...param, | ||
"lockingBytecode": `${lockingBytecode.substring(0, 24)}`, | ||
"lockingBytecode": `${lockingBytecode.substring(0, 20)}`, | ||
}, | ||
@@ -385,0 +417,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
321179
2713