From 5752a65a0d39ddd665e4abfcdbfa68eeb53dc0a8 Mon Sep 17 00:00:00 2001 From: Alex Benedetto Date: Mon, 13 Jul 2020 14:12:03 -0700 Subject: [PATCH] New method: getEternalReport --- CHANGELOG.md | 5 ++++ package.json | 2 +- src/interfaces/DragonchainClientInterfaces.ts | 9 +++++++ .../dragonchain-client/DragonchainClient.ts | 27 +++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02e051d..e9f058f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 4.3.5 + +- **Development:** + - Add in getEternalReport method + ## 4.3.4 - **Development:** diff --git a/package.json b/package.json index f206b35..49d120c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dragonchain-sdk", - "version": "4.3.4", + "version": "4.3.5", "description": "Dragonchain SDK for Node.JS and the Browser", "license": "Apache-2.0", "homepage": "https://github.com/dragonchain/dragonchain-sdk-javascript#readme", diff --git a/src/interfaces/DragonchainClientInterfaces.ts b/src/interfaces/DragonchainClientInterfaces.ts index ea49cfd..3daef93 100644 --- a/src/interfaces/DragonchainClientInterfaces.ts +++ b/src/interfaces/DragonchainClientInterfaces.ts @@ -1236,3 +1236,12 @@ export interface PermissionsDocument { }; }; } + +export interface EternalReportV1 { + l1Transaction: L1DragonchainTransactionFull; + l1Block: BlockSchemaType; + l2Verifications: L2BlockAtRest[]; + l3Verifications: L3BlockAtRest[]; + l4Verifications: L4BlockAtRest[]; + l5Verifications: L5BlockAtRest[]; +} diff --git a/src/services/dragonchain-client/DragonchainClient.ts b/src/services/dragonchain-client/DragonchainClient.ts index ece0f29..6ff5504 100644 --- a/src/services/dragonchain-client/DragonchainClient.ts +++ b/src/services/dragonchain-client/DragonchainClient.ts @@ -57,6 +57,7 @@ import { CustomTagFieldOptions, SmartContractLogs, PermissionsDocument, + EternalReportV1, } from '../../interfaces/DragonchainClientInterfaces'; import { CredentialService, HmacAlgorithm } from '../credential-service/CredentialService'; import { getDragonchainId, getDragonchainEndpoint } from '../config-service'; @@ -1437,6 +1438,32 @@ export class DragonchainClient { return (await this.post('/v1/public-blockchain-transaction', body)) as Response; }; + /** + * Get/Generate an Eternal-type report given a transaction ID + */ + public getEternalReport = async (options: { + /** + * the transaction ID of the transaction to generate report for + */ + transactionId: string; + }) => { + if (!options.transactionId) throw new FailureByDesign('PARAM_ERROR', 'Parameter `transactionId` is required'); + const transaction = await this.getTransaction({ transactionId: options.transactionId }); + if (transaction && !transaction.ok) throw new FailureByDesign('NOT_FOUND', 'transaction not found'); + const blockId = transaction.response.header.block_id; + const block = await this.getBlock({ blockId }); + if (block && !block.ok) throw new FailureByDesign('NOT_FOUND', 'block not found'); + const verifications = await this.getVerifications({ blockId }); + return { + l1Transaction: transaction.response, + l1Block: block.response, + l2Verifications: verifications.response && verifications.response['2'], + l3Verifications: verifications.response && verifications.response['3'], + l4Verifications: verifications.response && verifications.response['4'], + l5Verifications: verifications.response && verifications.response['5'], + } as EternalReportV1; + }; + /** * @hidden */