diff --git a/src/interfaces/network.interfaces.ts b/src/interfaces/network.interfaces.ts index e8be8e0..9139607 100644 --- a/src/interfaces/network.interfaces.ts +++ b/src/interfaces/network.interfaces.ts @@ -70,7 +70,6 @@ export enum IAPIRoute { FetchPending = '/fetch_pending' /* NOTE: Currently not available */, /* --------------------------- Storage Network Routes --------------------------- */ BlockchainEntry = '/blockchain_entry', - Transactions = '/transactions_by_key', /* ----------------------------- Intercom Routes ---------------------------- */ IntercomSet = '/set_data', IntercomGet = '/get_data', diff --git a/src/services/ablock.service.ts b/src/services/ablock.service.ts index 9cbac78..099e9bd 100644 --- a/src/services/ablock.service.ts +++ b/src/services/ablock.service.ts @@ -260,48 +260,6 @@ export class ABlockWallet { } as IClientResponse; } - /** - * @deprecated due to instability. - * - * Get all the addresses present on the ABlock network UTXO set - * - * @return {*} {Promise} - * @memberof ABlockWallet - */ - public async getUtxoAddressList(): Promise { - try { - if (!this.mempoolHost || !this.keyMgmt || !this.mempoolRoutesPoW) - throw new Error(IErrorInternal.ClientNotInitialized); - const headers = this.getRequestIdAndNonceHeadersForRoute( - this.mempoolRoutesPoW, - IAPIRoute.GetUtxoAddressList, - ); - return await axios - .get(`${this.mempoolHost}${IAPIRoute.GetUtxoAddressList}`, { - ...headers, - validateStatus: () => true, - }) - .then((response) => { - return { - status: castAPIStatus(response.data.status), - reason: response.data.reason, - content: { - fetchUtxoAddressesResponse: response.data.content, - }, - } as IClientResponse; - }) - .catch(async (error) => { - if (error instanceof Error) throw new Error(error.message); - else throw new Error(`${error}`); - }); - } catch (error) { - return { - status: 'error', - reason: `${error}`, - } as IClientResponse; - } - } - /** * Fetch balance for an address list from the UTXO set * @@ -313,18 +271,14 @@ export class ABlockWallet { try { if (!this.mempoolHost || !this.keyMgmt || !this.mempoolRoutesPoW) throw new Error(IErrorInternal.ClientNotInitialized); - const fetchBalanceBody = { - address_list: addressList, - }; const headers = this.getRequestIdAndNonceHeadersForRoute( this.mempoolRoutesPoW, IAPIRoute.FetchBalance, ); - return await axios .post( `${this.mempoolHost}${IAPIRoute.FetchBalance}`, - fetchBalanceBody, + addressList, { ...headers, validateStatus: () => true }, ) .then((response) => { @@ -367,7 +321,7 @@ export class ABlockWallet { ); return await axios .post( - `${this.storageHost}${IAPIRoute.Transactions}`, + `${this.storageHost}${IAPIRoute.BlockchainEntry}`, transactionHashes, { ...headers, validateStatus: () => true }, ) @@ -392,53 +346,6 @@ export class ABlockWallet { } } - /** - * Fetch pending DDE transaction from the mempool node - * - * @deprecated due to security concerns. - * - * @param {string[]} druids - A list of DRUID values - * @return {*} {Promise} - * @memberof ABlockWallet - */ - public async fetchPendingDDETransactions(druids: string[]): Promise { - try { - if (!this.mempoolHost || !this.keyMgmt || !this.mempoolRoutesPoW) - throw new Error(IErrorInternal.ClientNotInitialized); - const fetchPendingBody = { - druid_list: druids, - }; - const headers = this.getRequestIdAndNonceHeadersForRoute( - this.mempoolRoutesPoW, - IAPIRoute.FetchPending, - ); - return await axios - .post( - `${this.mempoolHost}${IAPIRoute.FetchPending}`, - fetchPendingBody, - { ...headers, validateStatus: () => true }, - ) - .then((response) => { - return { - status: castAPIStatus(response.data.status), - reason: response.data.reason, - content: { - fetchPendingDDEResponse: response.data.content, - }, - } as IClientResponse; - }) - .catch(async (error) => { - if (error instanceof Error) throw new Error(error.message); - else throw new Error(`${error}`); - }); - } catch (error) { - return { - status: 'error', - reason: `${error}`, - } as IClientResponse; - } - } - /** * Create item-assets for a provided address/key-pair * @@ -503,94 +410,6 @@ export class ABlockWallet { } } - /** - * Get the notary service's burn address - * - * @return {*} {Promise} - * @memberof ABlockWallet - */ - async getNotaryBurnAddress(): Promise { - try { - if (!this.keyMgmt) throw new Error(IErrorInternal.ClientNotInitialized); - if (!this.notaryHost) throw new Error(IErrorInternal.NotaryNotInitialized); - const headers = this.getRequestIdAndNonceHeadersForRoute( - new Map(), - IAPIRoute.GetNotaryBurnAddress, - ); - return await axios - .get(`${this.notaryHost}${IAPIRoute.GetNotaryBurnAddress}`, { - ...headers, - validateStatus: () => true, - }) - .then((response) => { - return { - status: castAPIStatus(response.data.status), - reason: response.data.reason, - content: response.data.content, - } as IClientResponse; - }) - .catch(async (error) => { - if (error instanceof Error) throw new Error(error.message); - else throw new Error(`${error}`); - }); - } catch (error) { - return { - status: 'error', - reason: `${error}`, - } as IClientResponse; - } - } - - /** - * Get the required signature from the notary to mint new Erc20 tokens - * - * @param {string} ethAddress - Ethereum address to mint tokens to - * @param {string} txHash - Transaction hash of the "burn" transaction - * @param {IGenericKeyPair} signatures - * @return {*} {Promise} - * @memberof ABlockWallet - */ - async getNotarySignature( - ethAddress: string, - txHash: string, - signatures: IGenericKeyPair, - ): Promise { - try { - if (!this.keyMgmt) throw new Error(IErrorInternal.ClientNotInitialized); - if (!this.notaryHost) throw new Error(IErrorInternal.NotaryNotInitialized); - const headers = this.getRequestIdAndNonceHeadersForRoute( - new Map(), - IAPIRoute.GetNotarySignature, - ); - const body = { - ethAddress, - txHash, - signatures, - }; - return await axios - .post(`${this.notaryHost}${IAPIRoute.GetNotarySignature}`, body, { - ...headers, - validateStatus: () => true, - }) - .then((response) => { - return { - status: castAPIStatus(response.data.status), - reason: response.data.reason, - content: response.data.content, - } as IClientResponse; - }) - .catch(async (error) => { - if (error instanceof Error) throw new Error(error.message); - else throw new Error(`${error}`); - }); - } catch (error) { - return { - status: 'error', - reason: `${error}`, - } as IClientResponse; - } - } - /** * Sign a given message with an array of key-pairs * @@ -1194,7 +1013,6 @@ export class ABlockWallet { /* -------------------------------------------------------------------------- */ /* Utils */ - /* -------------------------------------------------------------------------- */ /** @@ -1479,4 +1297,189 @@ export class ABlockWallet { }, }; } -} + + /* -------------------------------------------------------------------------- */ + /* Deprecated */ + /* -------------------------------------------------------------------------- */ + + /** + * Fetch pending DDE transaction from the mempool node + * + * @deprecated + * + * @param {string[]} druids - A list of DRUID values + * @return {*} {Promise} + * @memberof ABlockWallet + */ + public async fetchPendingDDETransactions(druids: string[]): Promise { + try { + if (!this.mempoolHost || !this.keyMgmt || !this.mempoolRoutesPoW) + throw new Error(IErrorInternal.ClientNotInitialized); + const fetchPendingBody = { + druid_list: druids, + }; + const headers = this.getRequestIdAndNonceHeadersForRoute( + this.mempoolRoutesPoW, + IAPIRoute.FetchPending, + ); + return await axios + .post( + `${this.mempoolHost}${IAPIRoute.FetchPending}`, + fetchPendingBody, + { ...headers, validateStatus: () => true }, + ) + .then((response) => { + return { + status: castAPIStatus(response.data.status), + reason: response.data.reason, + content: { + fetchPendingDDEResponse: response.data.content, + }, + } as IClientResponse; + }) + .catch(async (error) => { + if (error instanceof Error) throw new Error(error.message); + else throw new Error(`${error}`); + }); + } catch (error) { + return { + status: 'error', + reason: `${error}`, + } as IClientResponse; + } + } + + /** + * Get all the addresses present on the ABlock network UTXO set + * + * @deprecated + * + * @return {*} {Promise} + * @memberof ABlockWallet + */ + public async getUtxoAddressList(): Promise { + try { + if (!this.mempoolHost || !this.keyMgmt || !this.mempoolRoutesPoW) + throw new Error(IErrorInternal.ClientNotInitialized); + const headers = this.getRequestIdAndNonceHeadersForRoute( + this.mempoolRoutesPoW, + IAPIRoute.GetUtxoAddressList, + ); + return await axios + .get(`${this.mempoolHost}${IAPIRoute.GetUtxoAddressList}`, { + ...headers, + validateStatus: () => true, + }) + .then((response) => { + return { + status: castAPIStatus(response.data.status), + reason: response.data.reason, + content: { + fetchUtxoAddressesResponse: response.data.content, + }, + } as IClientResponse; + }) + .catch(async (error) => { + if (error instanceof Error) throw new Error(error.message); + else throw new Error(`${error}`); + }); + } catch (error) { + return { + status: 'error', + reason: `${error}`, + } as IClientResponse; + } + } + + /** + * Get the notary service's burn address + * + * @deprecated + * + * @return {*} {Promise} + * @memberof ABlockWallet + */ + async getNotaryBurnAddress(): Promise { + try { + if (!this.keyMgmt) throw new Error(IErrorInternal.ClientNotInitialized); + if (!this.notaryHost) throw new Error(IErrorInternal.NotaryNotInitialized); + const headers = this.getRequestIdAndNonceHeadersForRoute( + new Map(), + IAPIRoute.GetNotaryBurnAddress, + ); + return await axios + .get(`${this.notaryHost}${IAPIRoute.GetNotaryBurnAddress}`, { + ...headers, + validateStatus: () => true, + }) + .then((response) => { + return { + status: castAPIStatus(response.data.status), + reason: response.data.reason, + content: response.data.content, + } as IClientResponse; + }) + .catch(async (error) => { + if (error instanceof Error) throw new Error(error.message); + else throw new Error(`${error}`); + }); + } catch (error) { + return { + status: 'error', + reason: `${error}`, + } as IClientResponse; + } + } + + /** + * Get the required signature from the notary to mint new Erc20 tokens + * + * @deprecated + * + * @param {string} ethAddress - Ethereum address to mint tokens to + * @param {string} txHash - Transaction hash of the "burn" transaction + * @param {IGenericKeyPair} signatures + * @return {*} {Promise} + * @memberof ABlockWallet + */ + async getNotarySignature( + ethAddress: string, + txHash: string, + signatures: IGenericKeyPair, + ): Promise { + try { + if (!this.keyMgmt) throw new Error(IErrorInternal.ClientNotInitialized); + if (!this.notaryHost) throw new Error(IErrorInternal.NotaryNotInitialized); + const headers = this.getRequestIdAndNonceHeadersForRoute( + new Map(), + IAPIRoute.GetNotarySignature, + ); + const body = { + ethAddress, + txHash, + signatures, + }; + return await axios + .post(`${this.notaryHost}${IAPIRoute.GetNotarySignature}`, body, { + ...headers, + validateStatus: () => true, + }) + .then((response) => { + return { + status: castAPIStatus(response.data.status), + reason: response.data.reason, + content: response.data.content, + } as IClientResponse; + }) + .catch(async (error) => { + if (error instanceof Error) throw new Error(error.message); + else throw new Error(`${error}`); + }); + } catch (error) { + return { + status: 'error', + reason: `${error}`, + } as IClientResponse; + } + } +} \ No newline at end of file diff --git a/src/tests/__tests__/ablock.service.test.ts b/src/tests/__tests__/ablock.service.test.ts index 3352577..7473082 100644 --- a/src/tests/__tests__/ablock.service.test.ts +++ b/src/tests/__tests__/ablock.service.test.ts @@ -119,3 +119,42 @@ test('sign message with given keypairs', async () => { const result1 = ablockInstance.verifyMessage(MSG, signatures!, keypairs1); expect(result1.status).toBe('error'); }); + +test('fetch balance', async () => { + const config = { + mempoolHost: 'http://37.27.23.104:3003', + storageHost: 'http://37.27.23.104:3001', + passphrase: '', + }; + + await ablockInstance.initNew(config).then((res) => { + expect(res.status).toBe('success'); + }); + + const kp = ablockInstance.getNewKeypair([]).content?.newKeypairResponse; + const kpAddr = kp?.address; + + expect(kp).toBeDefined(); + expect(kpAddr).toBeDefined(); + + await ablockInstance.fetchBalance([kpAddr!]).then((res) => { + expect(res.status).toBe('success'); + }) + +}); + +test('fetch transaction', async () => { + const config = { + mempoolHost: 'http://37.27.23.104:3003', + storageHost: 'http://37.27.23.104:3001', + passphrase: '', + }; + + await ablockInstance.initNew(config).then((res) => { + expect(res.status).toBe('success'); + }); + + await ablockInstance.fetchTransactions(['000000']).then((res) => { + expect(res.status).toBe('success'); + }) +});