From a4474f1d947ccf5713bde75d093b071aeacd86b9 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Wed, 14 Apr 2021 02:28:40 -0600 Subject: [PATCH] fix: deprecate getTotalSupply --- web3.js/src/connection.ts | 7 ++++--- web3.js/test/connection.test.ts | 10 ++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/web3.js/src/connection.ts b/web3.js/src/connection.ts index ed3d25131..1048cfa0e 100644 --- a/web3.js/src/connection.ts +++ b/web3.js/src/connection.ts @@ -2308,15 +2308,16 @@ export class Connection { /** * Fetch the current total currency supply of the cluster in lamports + * @deprecated Deprecated since v1.2.8. Use `Connection.getSupply()` instead. */ async getTotalSupply(commitment?: Commitment): Promise { const args = this._buildArgs([], commitment); - const unsafeRes = await this._rpcRequest('getTotalSupply', args); - const res = create(unsafeRes, jsonRpcResult(number())); + const unsafeRes = await this._rpcRequest('getSupply', args); + const res = create(unsafeRes, GetSupplyRpcResult); if ('error' in res) { throw new Error('failed to get total supply: ' + res.error.message); } - return res.result; + return res.result.value.total; } /** diff --git a/web3.js/test/connection.test.ts b/web3.js/test/connection.test.ts index 45403e432..2a335e640 100644 --- a/web3.js/test/connection.test.ts +++ b/web3.js/test/connection.test.ts @@ -492,9 +492,15 @@ describe('Connection', () => { it('get total supply', async () => { await mockRpcResponse({ - method: 'getTotalSupply', + method: 'getSupply', params: [], - value: 1000000, + value: { + total: 1000000, + circulating: 100000, + nonCirculating: 900000, + nonCirculatingAccounts: [new Account().publicKey.toBase58()], + }, + withContext: true, }); const count = await connection.getTotalSupply();