Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove param muteQueryLimitError and fix all the calls #53

Merged
merged 5 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chaincode/src/__test__/TestGalaContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ export default class TestGalaContract extends GalaContract {
})
);

return getObjectsByPartialCompositeKey(ctx, Superhero.INDEX_KEY, [], Superhero, false);
return getObjectsByPartialCompositeKey(ctx, Superhero.INDEX_KEY, [], Superhero);
}
}
3 changes: 1 addition & 2 deletions chaincode/src/allowances/fetchAllowances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export async function fetchAllowances(
ctx,
TokenAllowance.INDEX_KEY,
queryParams,
TokenAllowance,
true // TODO: may lead to incomplete results
TokenAllowance
);

const results = filterByGrantedBy(getObjectsResponse, data.grantedBy);
Expand Down
6 changes: 2 additions & 4 deletions chaincode/src/allowances/fullAllowanceCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export async function fullAllowanceCheck(
ctx,
TokenBalance.INDEX_KEY,
queryParams,
TokenBalance,
true // TODO: may lead to incomplete results
TokenBalance
);

// For each relevant balance, fetch relevant allowance(s)
Expand All @@ -69,8 +68,7 @@ export async function fullAllowanceCheck(
ctx,
TokenAllowance.INDEX_KEY,
allowanceParams,
TokenAllowance,
true // TODO: may lead to incomplete results
TokenAllowance
);

const expiredAllowances = allowanceResults.filter((allowance) => {
Expand Down
9 changes: 3 additions & 6 deletions chaincode/src/allowances/grantAllowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
import { refreshAllowances } from "./refreshAllowances";

// this determines how many balances is enough to warrant optimization of allowance fetch
const BALANCE_COUNT_THRESHOLD = 50;

Check warning on line 62 in chaincode/src/allowances/grantAllowance.ts

View workflow job for this annotation

GitHub Actions / CI

'BALANCE_COUNT_THRESHOLD' is assigned a value but never used

async function grantAllowanceByPartialKey(
ctx: GalaChainContext,
Expand Down Expand Up @@ -99,8 +99,7 @@
ctx,
TokenAllowance.INDEX_KEY,
allowanceQueryParamsForBalance,
TokenAllowance,
true // TODO: may lead to incomplete results
TokenAllowance
)
);
}
Expand All @@ -122,8 +121,7 @@
ctx,
TokenAllowance.INDEX_KEY,
allowanceQueryParamsForBalance,
TokenAllowance,
true // TODO: may lead to incomplete results
TokenAllowance
)
);
}
Expand Down Expand Up @@ -571,8 +569,7 @@
ctx,
TokenAllowance.INDEX_KEY,
chainKeys,
TokenAllowance,
true // TODO: may lead to incomplete results
TokenAllowance
);

for (const existingAllowance of results) {
Expand Down
3 changes: 1 addition & 2 deletions chaincode/src/balances/fetchBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ export async function fetchBalances(
ctx,
TokenBalance.INDEX_KEY,
queryParams,
TokenBalance,
true // TODO: may lead to incomplete results
TokenBalance
).catch((e) => {
throw ChainError.map(e, ErrorCode.NOT_FOUND, new BalanceNotFoundError(data.owner));
});
Expand Down
8 changes: 1 addition & 7 deletions chaincode/src/burns/fetchBurns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ export async function fetchBurns(ctx: GalaChainContext, data: FetchBurnParams):
data.created?.toString()
);

let results = await getObjectsByPartialCompositeKey(
ctx,
TokenBurn.INDEX_KEY,
queryParams,
TokenBurn,
false
);
let results = await getObjectsByPartialCompositeKey(ctx, TokenBurn.INDEX_KEY, queryParams, TokenBurn);

// Sort the items ascending by date
results = results.sort((a: TokenBurn, b: TokenBurn): number => (a.created < b.created ? -1 : 1));
Expand Down
3 changes: 1 addition & 2 deletions chaincode/src/mint/validateMintRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ export async function validateMintRequest(
ctx,
TokenAllowance.INDEX_KEY,
queryParams,
TokenAllowance,
true // TODO may lead to incomplete results!
TokenAllowance
);

results.sort((a: TokenAllowance, b: TokenAllowance): number => (a.created < b.created ? -1 : 1));
Expand Down
10 changes: 2 additions & 8 deletions chaincode/src/utils/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ export async function getObjectsByPartialCompositeKey<T extends ChainObject>(
ctx: GalaChainContext,
objectType: string,
attributes: string[],
constructor: ClassConstructor<Inferred<T, ChainObject>>,
muteQueryLimitError: boolean
constructor: ClassConstructor<Inferred<T, ChainObject>>
): Promise<Array<T>> {
const iterator = ctx.stub.getCachedStateByPartialCompositeKey(objectType, attributes);

Expand All @@ -84,12 +83,7 @@ export async function getObjectsByPartialCompositeKey<T extends ChainObject>(
`It means your results would be probably incomplete. ` +
`Please narrow your query or use pagination.`;

if (muteQueryLimitError) {
ctx.logger.warn(message);
} else {
// why it is "forbidden" type of error: https://stackoverflow.com/a/15192643
throw new ForbiddenError(message, { objectType, attributes });
}
throw new ForbiddenError(message, { objectType, attributes });
}

// iterator will be automatically closed on exit from the loop
Expand Down
Loading