From da9834d2727d9f238276db0703dde5ab43d9e4ef Mon Sep 17 00:00:00 2001 From: softsimon Date: Thu, 30 Jun 2022 00:35:27 +0200 Subject: [PATCH] Label channel closes --- .../address-labels.component.ts | 3 ++- .../transactions-list.component.html | 4 ++-- .../transactions-list.component.ts | 2 +- frontend/src/app/services/api.service.ts | 4 ++-- .../src/api/explorer/channels.api.ts | 2 +- .../src/api/explorer/channels.routes.ts | 22 ++++++++++++++----- lightning-backend/src/database-migration.ts | 3 ++- 7 files changed, 26 insertions(+), 14 deletions(-) diff --git a/frontend/src/app/components/address-labels/address-labels.component.ts b/frontend/src/app/components/address-labels/address-labels.component.ts index f2018bfe5..ba03aada8 100644 --- a/frontend/src/app/components/address-labels/address-labels.component.ts +++ b/frontend/src/app/components/address-labels/address-labels.component.ts @@ -34,7 +34,8 @@ export class AddressLabelsComponent implements OnChanges { } handleChannel() { - this.label = `Channel open: ${this.channel.node_left.alias} <> ${this.channel.node_right.alias}`; + const type = this.vout ? 'open' : 'close'; + this.label = `Channel ${type}: ${this.channel.node_left.alias} <> ${this.channel.node_right.alias}`; } handleVin() { diff --git a/frontend/src/app/components/transactions-list/transactions-list.component.html b/frontend/src/app/components/transactions-list/transactions-list.component.html index 9119355f6..3e78f60a2 100644 --- a/frontend/src/app/components/transactions-list/transactions-list.component.html +++ b/frontend/src/app/components/transactions-list/transactions-list.component.html @@ -77,7 +77,7 @@ {{ vin.prevout.scriptpubkey_type?.toUpperCase() }}
- +
@@ -172,7 +172,7 @@
- +
diff --git a/frontend/src/app/components/transactions-list/transactions-list.component.ts b/frontend/src/app/components/transactions-list/transactions-list.component.ts index 0ea41a2bb..e1e9880c0 100644 --- a/frontend/src/app/components/transactions-list/transactions-list.component.ts +++ b/frontend/src/app/components/transactions-list/transactions-list.component.ts @@ -36,7 +36,7 @@ export class TransactionsListComponent implements OnInit, OnChanges { showDetails$ = new BehaviorSubject(false); outspends: Outspend[][] = []; assetsMinimal: any; - channels: any[]; + channels: { inputs: any[], outputs: any[] }; constructor( public stateService: StateService, diff --git a/frontend/src/app/services/api.service.ts b/frontend/src/app/services/api.service.ts index 1c439a755..f728e64d4 100644 --- a/frontend/src/app/services/api.service.ts +++ b/frontend/src/app/services/api.service.ts @@ -232,12 +232,12 @@ export class ApiService { return this.httpClient.get(this.apiBaseUrl + this.apiBasePath + `/api/v1/mining/reward-stats/${blockCount}`); } - getChannelByTxIds$(txIds: string[]): Observable { + getChannelByTxIds$(txIds: string[]): Observable<{ inputs: any[], outputs: any[] }> { let params = new HttpParams(); txIds.forEach((txId: string) => { params = params.append('txId[]', txId); }); - return this.httpClient.get(this.apiBaseUrl + this.apiBasePath + '/lightning/api/v1/channels/txids/', { params }); + return this.httpClient.get<{ inputs: any[], outputs: any[] }>(this.apiBaseUrl + this.apiBasePath + '/lightning/api/v1/channels/txids/', { params }); } lightningSearch$(searchText: string): Observable { diff --git a/lightning-backend/src/api/explorer/channels.api.ts b/lightning-backend/src/api/explorer/channels.api.ts index d2dd930c3..c72f93257 100644 --- a/lightning-backend/src/api/explorer/channels.api.ts +++ b/lightning-backend/src/api/explorer/channels.api.ts @@ -74,7 +74,7 @@ class ChannelsApi { public async $getChannelsByTransactionId(transactionIds: string[]): Promise { try { transactionIds = transactionIds.map((id) => '\'' + id + '\''); - const query = `SELECT n1.alias AS alias_left, n2.alias AS alias_right, channels.* FROM channels LEFT JOIN nodes AS n1 ON n1.public_key = channels.node1_public_key LEFT JOIN nodes AS n2 ON n2.public_key = channels.node2_public_key WHERE channels.transaction_id IN (${transactionIds.join(', ')})`; + const query = `SELECT n1.alias AS alias_left, n2.alias AS alias_right, channels.* FROM channels LEFT JOIN nodes AS n1 ON n1.public_key = channels.node1_public_key LEFT JOIN nodes AS n2 ON n2.public_key = channels.node2_public_key WHERE channels.transaction_id IN (${transactionIds.join(', ')}) OR channels.closing_transaction_id IN (${transactionIds.join(', ')})`; const [rows]: any = await DB.query(query); const channels = rows.map((row) => this.convertChannel(row)); return channels; diff --git a/lightning-backend/src/api/explorer/channels.routes.ts b/lightning-backend/src/api/explorer/channels.routes.ts index fd3b3fac0..ff9d166f9 100644 --- a/lightning-backend/src/api/explorer/channels.routes.ts +++ b/lightning-backend/src/api/explorer/channels.routes.ts @@ -67,17 +67,27 @@ class ChannelsRoutes { } } const channels = await channelsApi.$getChannelsByTransactionId(txIds); - const result: any[] = []; + const inputs: any[] = []; + const outputs: any[] = []; for (const txid of txIds) { - const foundChannel = channels.find((channel) => channel.transaction_id === txid); - if (foundChannel) { - result.push(foundChannel); + const foundChannelInputs = channels.find((channel) => channel.closing_transaction_id === txid); + if (foundChannelInputs) { + inputs.push(foundChannelInputs); } else { - result.push(null); + inputs.push(null); + } + const foundChannelOutputs = channels.find((channel) => channel.transaction_id === txid); + if (foundChannelOutputs) { + outputs.push(foundChannelOutputs); + } else { + outputs.push(null); } } - res.json(result); + res.json({ + inputs: inputs, + outputs: outputs, + }); } catch (e) { res.status(500).send(e instanceof Error ? e.message : e); } diff --git a/lightning-backend/src/database-migration.ts b/lightning-backend/src/database-migration.ts index 6717154aa..4b99a708f 100644 --- a/lightning-backend/src/database-migration.ts +++ b/lightning-backend/src/database-migration.ts @@ -236,7 +236,8 @@ class DatabaseMigration { KEY node2_public_key (node2_public_key), KEY status (status), KEY short_id (short_id), - KEY transaction_id (transaction_id) + KEY transaction_id (transaction_id), + KEY closing_transaction_id (closing_transaction_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`; }