Skip to content

Commit

Permalink
fix: uintcv creation
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Jan 23, 2023
1 parent 4bd2812 commit 780b160
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/token-processor/queue/job/process-token-job.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { getAddressFromPrivateKey, makeRandomPrivKey } from '@stacks/transactions';
import { ClarityValueUInt, TransactionVersion } from 'stacks-encoding-native-js';
import { cvToHex, getAddressFromPrivateKey, makeRandomPrivKey, uintCV } from '@stacks/transactions';
import {
ClarityValueUInt,
decodeClarityValueToRepr,
TransactionVersion,
} from 'stacks-encoding-native-js';
import { logger } from '../../../logger';
import { PgNumeric } from '../../../pg/postgres-tools/types';
import {
Expand Down Expand Up @@ -111,7 +115,7 @@ export class ProcessTokenJob extends Job {

private async handleNft(client: StacksNodeRpcClient, token: DbToken) {
const uri = await client.readStringFromContract('get-token-uri', [
{ value: token.token_number.toString() } as ClarityValueUInt,
this.uIntCv(token.token_number),
]);
let metadataLocales: DbMetadataLocaleInsertBundle[] | undefined;
if (uri) {
Expand All @@ -128,7 +132,7 @@ export class ProcessTokenJob extends Job {
}

private async handleSft(client: StacksNodeRpcClient, token: DbToken) {
const arg = [{ value: token.token_number.toString() } as ClarityValueUInt];
const arg = [this.uIntCv(token.token_number)];

const uri = await client.readStringFromContract('get-token-uri', arg);

Expand Down Expand Up @@ -159,4 +163,14 @@ export class ProcessTokenJob extends Job {
};
await this.db.updateProcessedTokenWithMetadata({ id: token.id, values: tokenValues });
}

private uIntCv(n: bigint): ClarityValueUInt {
const cv = uintCV(n);
const hex = cvToHex(cv);
return {
value: n.toString(),
hex: hex,
repr: decodeClarityValueToRepr(hex),
} as ClarityValueUInt;
}
}

0 comments on commit 780b160

Please sign in to comment.