Skip to content

Commit

Permalink
Merge branch 'main' into 160-redundant-variable
Browse files Browse the repository at this point in the history
  • Loading branch information
felipe.fuerback authored Apr 10, 2024
2 parents 6fe5b6a + d60a0ec commit c99421a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 21 deletions.
9 changes: 9 additions & 0 deletions chain-api/src/types/TokenMintRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ export class TokenMintRequest extends RangedChainObject {
@IsNotEmpty()
public allowanceKey?: AllowanceKey;

public isTimeKeyValid(): boolean {
try {
new BigNumber(this.timeKey);
return true;
} catch (e) {
return false;
}
}

public requestId(): string {
const { collection, category, type, additionalKey, totalKnownMintsCount, requestor, owner, created } =
this;
Expand Down
9 changes: 9 additions & 0 deletions chain-api/src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,13 @@ export class MintRequestDto {
@Type(() => AllowanceKey)
@IsNotEmpty()
public allowanceKey?: AllowanceKey;

public isTimeKeyValid(): boolean {
try {
new BigNumber(this.timeKey);
return true;
} catch (e) {
return false;
}
}
}
2 changes: 1 addition & 1 deletion chaincode/src/burns/fetchBurns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export async function fetchKnownBurnCount(

// inverted timeKeys read most recent first; using unshift sorts a new array as oldest first.
// essentially, we rewind the tape and then play it forward.
// covering the following possible scensarios:
// covering the following possible scenarios:
// a) no results yet - empty array, start with zero below.
// b) no recent results. continue back toward the beginning of the ledger until we find at least one.
// c) recent results. Get all results within two past block spans to cover any missing timestamp gaps from concurrent recent transactions.
Expand Down
18 changes: 1 addition & 17 deletions chaincode/src/mint/fetchMintAllowanceSupply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function fetchMintAllowanceSupply(

// inverted timeKeys read most recent first; using unshift sorts a new array as oldest first.
// essentially, we rewind the tape and then play it forward.
// covering the following possible scensarios:
// covering the following possible scenarios:
// a) no results yet - empty array, start with zero below.
// b) no recent results. continue back toward the beginning of the ledger until we find at least one.
// c) recent results. Get all results within two past block spans to cover any missing timestamp gaps from concurrent recent transactions.
Expand Down Expand Up @@ -115,19 +115,3 @@ export async function fetchMintAllowanceSupply(

return updatedKnownMintAllowancesCount;
}

export async function fetchMintAllowanceSupplyForToken(ctx: GalaChainContext, data: TokenClassKeyProperties) {
const { collection, category, type, additionalKey } = data;

const keyList = [collection, category, type, additionalKey];
const compositeKey = ChainObject.getCompositeKeyFromParts(TokenClass.INDEX_KEY, keyList);
const tokenClass: TokenClass = await getObjectByKey(ctx, TokenClass, compositeKey);

const supply = await fetchMintAllowanceSupply(ctx, tokenClass);

const response = plainToInstance(FetchTokenSupplyResponse, {
supply
});

return response;
}
14 changes: 13 additions & 1 deletion chaincode/src/mint/fulfillMintAllowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function fulfillMintAllowanceRequest(
// todo: type this failures array and work it into response
const failures: any[] = [];

for (const [key, values] of Object.entries(reqIdx)) {
for (const [_, values] of Object.entries(reqIdx)) {
// Entries in the Request Index represent
// some number of mint requests for the same token, at the same running total height.
// Because our original GrantAllowance implementation allowed (potentially large) arrays,
Expand Down Expand Up @@ -84,6 +84,18 @@ export async function fulfillMintAllowanceRequest(

for (const req of values) {
// timeKeys are inverted timestamps, lowest = most recent, highest = oldest
if (req.isTimeKeyValid() === false) {
throw new Error(
`FulfillMintAllowance failure: Invalid timeKey value: ${
req.timeKey
}. The value of timeKey should be a valid BigNumber, ${inspect(req, {
depth: 4,
breakLength: Infinity,
compact: true
})}`
);
}

const reqTime = new BigNumber(req.timeKey);
if (reqTime.isLessThan(mostRecentTimeInversion)) {
mostRecentTimeInversion = reqTime;
Expand Down
3 changes: 1 addition & 2 deletions chaincode/src/mint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
indexedMintOperationsByTokenClass
} from "./batchMintToken";
import { constructVerifiedMints } from "./constructVerifiedMints";
import { fetchMintAllowanceSupply, fetchMintAllowanceSupplyForToken } from "./fetchMintAllowanceSupply";
import { fetchMintAllowanceSupply } from "./fetchMintAllowanceSupply";
import { fetchMintSupply } from "./fetchMintSupply";
import { fetchTokenClassesWithSupply } from "./fetchTokenClassWithSupply";
import { fulfillMintRequest } from "./fulfillMint";
Expand Down Expand Up @@ -52,7 +52,6 @@ export {
validateMintRequest,
fetchMintAllowanceSupply,
fetchMintSupply,
fetchMintAllowanceSupplyForToken,
fetchTokenClassesWithSupply,
mintTokenWithAllowance,
MintTokenWithAllowanceParams
Expand Down

0 comments on commit c99421a

Please sign in to comment.