Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13711275
D14257.id41558.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
D14257.id41558.diff
View Options
diff --git a/modules/chronik-client/README.md b/modules/chronik-client/README.md
--- a/modules/chronik-client/README.md
+++ b/modules/chronik-client/README.md
@@ -50,8 +50,23 @@
const history = await chronik
.script('p2pk', GENESIS_PK)
.history(/*page=*/ 0, /*page_size=*/ 10);
+
// Get all UTXOs of the Genesis pubkey:
+// Note: As of v1.0.0, utxos() now returns the UTXOs separated by type (XEC / SLP)
const utxos = await chronik.script('p2pk', GENESIS_PK).utxos();
+// {
+// outputScript: ...,
+// xecUtxos: [{...}, {...}],
+// slpUtxos: [{...}, {...}],
+// }
+
+// Get XEC specific UTXOs of the Genesis pubkey:
+const xecUtxos = await chronik.script('p2pk', GENESIS_PK).xecUtxos();
+// [{...}, {...}], // XEC utxos only
+
+// Get SLP specific UTXOs of the Genesis pubkey:
+const slpUtxos = await chronik.script('p2pk', GENESIS_PK).slpUtxos();
+// [{...}, {...}], // SLP utxos only
// Listen to updates on scripts:
const ws = chronik.ws({
diff --git a/modules/chronik-client/index.ts b/modules/chronik-client/index.ts
--- a/modules/chronik-client/index.ts
+++ b/modules/chronik-client/index.ts
@@ -189,19 +189,43 @@
};
}
- /** Fetches the current UTXO set for this script.
+ /** Fetches the current UTXO set for this script, separated by XEC and SLP UTXOs.
* It is grouped by output script, in case a script type can match multiple
* different output scripts (e.g. Taproot on Lotus). */
- public async utxos(): Promise<ScriptUtxos[]> {
+ public async utxos(): Promise<ScriptUtxos> {
const data = await _get(
this._url,
`/script/${this._scriptType}/${this._scriptPayload}/utxos`,
);
const utxos = proto.Utxos.decode(data);
- return utxos.scriptUtxos.map(scriptUtxos => ({
- outputScript: toHex(scriptUtxos.outputScript),
- utxos: scriptUtxos.utxos.map(convertToUtxo),
- }));
+ const legacyScriptUtxos = utxos.scriptUtxos.map(scriptUtxos => {
+ const thisScriptUtxos = scriptUtxos.utxos.map(convertToUtxo);
+ return {
+ outputScript: toHex(scriptUtxos.outputScript),
+ xecUtxos: [...thisScriptUtxos.values()].filter(
+ item => !item.slpToken,
+ ),
+ slpUtxos: [...thisScriptUtxos.values()].filter(
+ item => item.slpToken,
+ ),
+ };
+ });
+ // The legacy `script().utxo()` API returns an array with one single entry for
+ // addresses with utxos. This was designed to handle multiple different
+ // output scripts in one query, however this is unique to the Lotus chain.
+ // In the case of eCash, the array length will always be 1, hence returning
+ // the first entry here directly.
+ return legacyScriptUtxos[0];
+ }
+
+ /** Specifically fetches the XEC UTXO set for this script. */
+ public async xecUtxos(): Promise<Utxo[]> {
+ return (await this.utxos()).xecUtxos;
+ }
+
+ /** Specifically fetches the SLP UTXO set for this script. */
+ public async slpUtxos(): Promise<Utxo[]> {
+ return (await this.utxos()).slpUtxos;
}
}
@@ -866,8 +890,10 @@
export interface ScriptUtxos {
/** Output script in hex. */
outputScript: string;
- /** UTXOs of the output script. */
- utxos: Utxo[];
+ /** XEC UTXOs of the output script. */
+ xecUtxos: Utxo[];
+ /** SLP UTXOs of the output script. */
+ slpUtxos: Utxo[];
}
/** Page of the transaction history. */
diff --git a/modules/chronik-client/package.json b/modules/chronik-client/package.json
--- a/modules/chronik-client/package.json
+++ b/modules/chronik-client/package.json
@@ -1,6 +1,6 @@
{
"name": "chronik-client",
- "version": "0.8.4",
+ "version": "1.0.0",
"description": "A client for accessing the Chronik Indexer API",
"main": "dist/index.js",
"types": "dist/index.d.ts",
diff --git a/modules/chronik-client/test/test.ts b/modules/chronik-client/test/test.ts
--- a/modules/chronik-client/test/test.ts
+++ b/modules/chronik-client/test/test.ts
@@ -441,12 +441,36 @@
describe('/script/:type/:payload/utxos', () => {
const chronik = new ChronikClient(TEST_URL);
- it('gives us the UTXOs', async () => {
+ it('gives us the UTXOs separated by type', async () => {
const script = chronik.script('p2pk', GENESIS_PK);
const utxos = await script.utxos();
- expect(utxos.length).to.equal(1);
- expect(utxos[0].outputScript).to.eql('41' + GENESIS_PK + 'ac');
- expect(utxos[0].utxos[0]).to.eql(GENESIS_UTXO);
+ expect(utxos.outputScript).to.eql('41' + GENESIS_PK + 'ac');
+ expect(utxos.xecUtxos.length).to.eql(2);
+ expect(utxos.xecUtxos[0]).to.eql(GENESIS_UTXO);
+ expect(utxos.slpUtxos.length).to.eql(0);
+ expect(utxos.slpUtxos).to.eql([]);
+ });
+});
+
+describe('/script/:type/:payload/xecUtxos', () => {
+ const chronik = new ChronikClient(TEST_URL);
+
+ it('gives us the XEC specific UTXOs', async () => {
+ const script = chronik.script('p2pk', GENESIS_PK);
+ const xecUtxos = await script.xecUtxos();
+ expect(xecUtxos.length).to.equal(2);
+ expect(xecUtxos[0]).to.eql(GENESIS_UTXO);
+ });
+});
+
+describe('/script/:type/:payload/slpUtxos', () => {
+ const chronik = new ChronikClient(TEST_URL);
+
+ it('gives us the SLP specific UTXOs', async () => {
+ const script = chronik.script('p2pk', GENESIS_PK);
+ const slpUtxos = await script.slpUtxos();
+ expect(slpUtxos.length).to.equal(0);
+ expect(slpUtxos).to.eql([]);
});
});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 26, 11:19 (11 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5573390
Default Alt Text
D14257.id41558.diff (5 KB)
Attached To
D14257: [Chronik-client] Implement new UTXO APIs
Event Timeline
Log In to Comment