From 684605fd5c3f6b2a0c1e427733eeac706a3f8113 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Wed, 26 Jun 2019 13:49:29 -0700 Subject: [PATCH] fix: add burnPercent field to FeeCalculator (#381) --- web3.js/module.flow.js | 5 +++- web3.js/src/connection.js | 24 +++++++++++--------- web3.js/test/mockrpc/get-recent-blockhash.js | 5 ++++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/web3.js/module.flow.js b/web3.js/module.flow.js index 6e5db261901523..1daf312b552926 100644 --- a/web3.js/module.flow.js +++ b/web3.js/module.flow.js @@ -34,9 +34,12 @@ declare module '@solana/web3.js' { // === src/fee-calculator.js === declare export type FeeCalculator = { + burnPercent: number, lamportsPerSignature: number, - targetSignaturesPerSlot: number, + maxLamportsPerSignature: number, + minLamportsPerSignature: number, targetLamportsPerSignature: number, + targetSignaturesPerSlot: number, }; // === src/budget-program.js === diff --git a/web3.js/src/connection.js b/web3.js/src/connection.js index 23ffc07036af01..797643183cf854 100644 --- a/web3.js/src/connection.js +++ b/web3.js/src/connection.js @@ -225,6 +225,7 @@ const GetTotalSupplyRpcResult = jsonRpcResult('number'); const GetRecentBlockhash = jsonRpcResult([ 'string', struct({ + burnPercent: 'number', lamportsPerSignature: 'number', maxLamportsPerSignature: 'number', minLamportsPerSignature: 'number', @@ -235,10 +236,14 @@ const GetRecentBlockhash = jsonRpcResult([ /** * @ignore */ -const GetRecentBlockhash_015 = jsonRpcResult([ +const GetRecentBlockhash_016 = jsonRpcResult([ 'string', struct({ lamportsPerSignature: 'number', + maxLamportsPerSignature: 'number', + minLamportsPerSignature: 'number', + targetLamportsPerSignature: 'number', + targetSignaturesPerSlot: 'number', }), ]); @@ -548,22 +553,19 @@ export class Connection { async getRecentBlockhash(): Promise { const unsafeRes = await this._rpcRequest('getRecentBlockhash', []); - // Legacy v0.15 response. TODO: Remove in August 2019 + // Legacy v0.16 response. TODO: Remove in September 2019 try { - const res_015 = GetRecentBlockhash_015(unsafeRes); - if (res_015.error) { - throw new Error(res_015.error.message); + const res_016 = GetRecentBlockhash_016(unsafeRes); + if (res_016.error) { + throw new Error(res_016.error.message); } - const [blockhash, feeCalculator] = res_015.result; - feeCalculator.targetSignaturesPerSlot = 42; - feeCalculator.targetLamportsPerSignature = - feeCalculator.lamportsPerSignature; - + const [blockhash, feeCalculator] = res_016.result; + feeCalculator.burnPercent = 0; return [blockhash, feeCalculator]; } catch (e) { // Not legacy format } - // End Legacy v0.15 response + // End Legacy v0.16 response const res = GetRecentBlockhash(unsafeRes); if (res.error) { diff --git a/web3.js/test/mockrpc/get-recent-blockhash.js b/web3.js/test/mockrpc/get-recent-blockhash.js index 013d6a44ebfedf..138f17c8175369 100644 --- a/web3.js/test/mockrpc/get-recent-blockhash.js +++ b/web3.js/test/mockrpc/get-recent-blockhash.js @@ -19,6 +19,11 @@ export function mockGetRecentBlockhash() { recentBlockhash.publicKey.toBase58(), { lamportsPerSignature: 42, + burnPercent: 50, + maxLamportsPerSignature: 42, + minLamportsPerSignature: 42, + targetLamportsPerSignature: 42, + targetSignaturesPerSlot: 42, }, ], },