fix: add burnPercent field to FeeCalculator (#381)

This commit is contained in:
Michael Vines 2019-06-26 13:49:29 -07:00
parent 5d81280c97
commit 684605fd5c
3 changed files with 22 additions and 12 deletions

View File

@ -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 ===

View File

@ -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<BlockhashAndFeeCalculator> {
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) {

View File

@ -19,6 +19,11 @@ export function mockGetRecentBlockhash() {
recentBlockhash.publicKey.toBase58(),
{
lamportsPerSignature: 42,
burnPercent: 50,
maxLamportsPerSignature: 42,
minLamportsPerSignature: 42,
targetLamportsPerSignature: 42,
targetSignaturesPerSlot: 42,
},
],
},