fix: deprecate getTotalSupply

This commit is contained in:
Tyera Eulberg 2021-04-14 02:28:40 -06:00 committed by Tyera Eulberg
parent fe4c39a26a
commit a4474f1d94
2 changed files with 12 additions and 5 deletions

View File

@ -2308,15 +2308,16 @@ export class Connection {
/** /**
* Fetch the current total currency supply of the cluster in lamports * 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<number> { async getTotalSupply(commitment?: Commitment): Promise<number> {
const args = this._buildArgs([], commitment); const args = this._buildArgs([], commitment);
const unsafeRes = await this._rpcRequest('getTotalSupply', args); const unsafeRes = await this._rpcRequest('getSupply', args);
const res = create(unsafeRes, jsonRpcResult(number())); const res = create(unsafeRes, GetSupplyRpcResult);
if ('error' in res) { if ('error' in res) {
throw new Error('failed to get total supply: ' + res.error.message); throw new Error('failed to get total supply: ' + res.error.message);
} }
return res.result; return res.result.value.total;
} }
/** /**

View File

@ -492,9 +492,15 @@ describe('Connection', () => {
it('get total supply', async () => { it('get total supply', async () => {
await mockRpcResponse({ await mockRpcResponse({
method: 'getTotalSupply', method: 'getSupply',
params: [], params: [],
value: 1000000, value: {
total: 1000000,
circulating: 100000,
nonCirculating: 900000,
nonCirculatingAccounts: [new Account().publicKey.toBase58()],
},
withContext: true,
}); });
const count = await connection.getTotalSupply(); const count = await connection.getTotalSupply();