Skip to content

Commit

Permalink
fix: add burnPercent field to FeeCalculator (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines authored Jun 26, 2019
1 parent 636a17d commit f784b94
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
5 changes: 4 additions & 1 deletion module.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===
Expand Down
24 changes: 13 additions & 11 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ const GetTotalSupplyRpcResult = jsonRpcResult('number');
const GetRecentBlockhash = jsonRpcResult([
'string',
struct({
burnPercent: 'number',
lamportsPerSignature: 'number',
maxLamportsPerSignature: 'number',
minLamportsPerSignature: 'number',
Expand All @@ -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',
}),
]);

Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions test/mockrpc/get-recent-blockhash.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export function mockGetRecentBlockhash() {
recentBlockhash.publicKey.toBase58(),
{
lamportsPerSignature: 42,
burnPercent: 50,
maxLamportsPerSignature: 42,
minLamportsPerSignature: 42,
targetLamportsPerSignature: 42,
targetSignaturesPerSlot: 42,
},
],
},
Expand Down

0 comments on commit f784b94

Please sign in to comment.