From 5d84254408ba372c95f122e2465ae2f057d44523 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Wed, 11 Nov 2020 21:14:37 +0100 Subject: [PATCH] feat: integrate Stacking STX into database and provide through account API details, upgrade to nodejs v14 --- Dockerfile | 4 +- .../address/get-address-balances.example.json | 2 + .../address/get-address-balances.schema.json | 4 +- .../get-address-stx-balance.example.json | 2 + .../get-address-stx-balance.schema.json | 2 +- ...nce.schema.json => ft-balance.schema.json} | 2 +- docs/entities/balance/stx-balance.schema.json | 24 ++ docs/index.d.ts | 8 +- follower.Dockerfile | 22 +- package.json | 3 +- src/api/routes/address.ts | 20 +- src/datastore/common.ts | 10 +- src/datastore/postgres-store.ts | 264 ++++++++++++------ src/helpers.ts | 2 +- src/migrations/1588256295395_ft_events.ts | 2 +- src/rosetta-helpers.ts | 2 +- src/tests-rosetta/api.ts | 4 +- src/tests/api-tests.ts | 62 ++-- src/tests/core-rpc-tests.ts | 2 +- src/tests/datastore-tests.ts | 121 ++++---- src/tests/websocket-tests.ts | 30 +- tsconfig.json | 2 +- 22 files changed, 372 insertions(+), 222 deletions(-) rename docs/entities/balance/{balance.schema.json => ft-balance.schema.json} (91%) create mode 100644 docs/entities/balance/stx-balance.schema.json diff --git a/Dockerfile b/Dockerfile index a1a63dd0b4..9e70f04c46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ -FROM node:13-alpine +FROM node:14-alpine WORKDIR /app COPY . . RUN apk add --no-cache --virtual .build-deps alpine-sdk python git openjdk8-jre RUN echo "GIT_TAG=$(git tag --points-at HEAD)" >> .env -RUN npm config set unsafe-perm true && npm install --unsafe-perm && npm run build --unsafe-perm && npm prune --production +RUN npm config set unsafe-perm true && npm install && npm run build && npm prune --production RUN apk del .build-deps CMD npm run start diff --git a/docs/api/address/get-address-balances.example.json b/docs/api/address/get-address-balances.example.json index 310e323b02..d8dcfa2870 100644 --- a/docs/api/address/get-address-balances.example.json +++ b/docs/api/address/get-address-balances.example.json @@ -1,6 +1,8 @@ { "stx": { "balance": "1000000", + "locked": "50000", + "unlock_height": "256", "total_sent": "0", "total_received": "1000000" }, diff --git a/docs/api/address/get-address-balances.schema.json b/docs/api/address/get-address-balances.schema.json index eecac21e60..3db98797a6 100644 --- a/docs/api/address/get-address-balances.schema.json +++ b/docs/api/address/get-address-balances.schema.json @@ -6,13 +6,13 @@ "required": ["stx", "fungible_tokens", "non_fungible_tokens"], "properties": { "stx": { - "$ref": "../../entities/balance/balance.schema.json" + "$ref": "../../entities/balance/stx-balance.schema.json" }, "fungible_tokens": { "type": "object", "patternProperties": { "*": { - "$ref": "../../entities/balance/balance.schema.json" + "$ref": "../../entities/balance/ft-balance.schema.json" } } }, diff --git a/docs/api/address/get-address-stx-balance.example.json b/docs/api/address/get-address-stx-balance.example.json index c6fcfa58ed..757712cbd9 100644 --- a/docs/api/address/get-address-stx-balance.example.json +++ b/docs/api/address/get-address-stx-balance.example.json @@ -1,5 +1,7 @@ { "balance": "1000000", + "locked": "50000", + "unlock_height": "256", "total_sent": "0", "total_received": "1000000" } diff --git a/docs/api/address/get-address-stx-balance.schema.json b/docs/api/address/get-address-stx-balance.schema.json index e98389bb6a..f712c4c666 100644 --- a/docs/api/address/get-address-stx-balance.schema.json +++ b/docs/api/address/get-address-stx-balance.schema.json @@ -3,5 +3,5 @@ "description": "GET request that returns address balances", "title": "AddressStxBalanceResponse", "type": "object", - "$ref": "../../entities/balance/balance.schema.json" + "$ref": "../../entities/balance/stx-balance.schema.json" } diff --git a/docs/entities/balance/balance.schema.json b/docs/entities/balance/ft-balance.schema.json similarity index 91% rename from docs/entities/balance/balance.schema.json rename to docs/entities/balance/ft-balance.schema.json index ede84ab319..f07c1566cb 100644 --- a/docs/entities/balance/balance.schema.json +++ b/docs/entities/balance/ft-balance.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "description": "Balance", + "description": "FtBalance", "type": "object", "additionalProperties": false, "required": ["balance", "total_sent", "total_received"], diff --git a/docs/entities/balance/stx-balance.schema.json b/docs/entities/balance/stx-balance.schema.json new file mode 100644 index 0000000000..e4064cc18d --- /dev/null +++ b/docs/entities/balance/stx-balance.schema.json @@ -0,0 +1,24 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "description": "StxBalance", + "type": "object", + "additionalProperties": false, + "required": ["balance", "locked", "unlock_height", "total_sent", "total_received"], + "properties": { + "balance": { + "type": "string" + }, + "locked": { + "type": "string" + }, + "unlock_height": { + "type": "string" + }, + "total_sent": { + "type": "string" + }, + "total_received": { + "type": "string" + } + } +} diff --git a/docs/index.d.ts b/docs/index.d.ts index 2575fba9da..8fa45b8608 100644 --- a/docs/index.d.ts +++ b/docs/index.d.ts @@ -19,16 +19,18 @@ export interface AddressAssetsListResponse { */ export interface AddressBalanceResponse { /** - * Balance + * StxBalance */ stx: { balance: string; + locked: string; + unlock_height: string; total_sent: string; total_received: string; }; fungible_tokens: { /** - * Balance + * FtBalance * * This interface was referenced by `undefined`'s JSON-Schema definition * via the `patternProperty` "*". @@ -59,6 +61,8 @@ export interface AddressBalanceResponse { */ export interface AddressStxBalanceResponse { balance: string; + locked: string; + unlock_height: string; total_sent: string; total_received: string; } diff --git a/follower.Dockerfile b/follower.Dockerfile index bfcd45c9a4..8dc7ba12bf 100644 --- a/follower.Dockerfile +++ b/follower.Dockerfile @@ -1,12 +1,11 @@ ### Build blockstack-core-sidecar API -FROM node:13.14.0-buster as build +FROM node:14-alpine as build WORKDIR /app COPY . . -RUN apt-get update && apt-get install -y openjdk-11-jre-headless +RUN apk add --no-cache --virtual .build-deps alpine-sdk python git openjdk8-jre RUN echo "GIT_TAG=$(git tag --points-at HEAD)" >> .env -RUN npm install -RUN npm run build -RUN npm prune --production +# RUN npm config set unsafe-perm true && npm install --unsafe-perm && npm run build --unsafe-perm && npm prune --production +RUN npm config set unsafe-perm true && npm install && npm run build && npm prune --production ### Fetch stacks-node binary FROM blockstack/stacks-blockchain:v23.0.0.10-krypton-stretch as stacks-node-build @@ -20,6 +19,10 @@ SHELL ["/bin/bash", "-c"] RUN apt-get update RUN apt-get install -y sudo curl pslist +### Install nodejs +RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - +RUN apt-get install -y nodejs + ### Set noninteractive apt-get RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections @@ -34,15 +37,6 @@ USER stacky RUN sudo chown -R stacky:stacky $HOME RUN mkdir /home/stacky/.bashrc.d -### Node.js -ENV NODE_VERSION=13.14.0 -RUN curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash \ - && bash -c ". .nvm/nvm.sh \ - && nvm install $NODE_VERSION \ - && nvm alias default $NODE_VERSION" -ENV PATH=$PATH:/home/stacky/.nvm/versions/node/v${NODE_VERSION}/bin -RUN node -e 'console.log("Node.js runs")' - ### Setup stacks-node COPY --from=stacks-node-build /bin/stacks-node stacks-node/ ENV PATH="$PATH:$HOME/stacks-node" diff --git a/package.json b/package.json index ef551527c7..9c43d0f6f3 100644 --- a/package.json +++ b/package.json @@ -39,8 +39,9 @@ "homepage": "https://github.com/blockstack/stacks-blockchain-api#readme", "prettier": "@blockstack/prettier-config", "engines": { - "node": ">=13.11" + "node": ">=14" }, + "engineStrict" : true, "release": { "plugins": [ "@semantic-release/commit-analyzer", diff --git a/src/api/routes/address.ts b/src/api/routes/address.ts index 91d459c58f..343844ae39 100644 --- a/src/api/routes/address.ts +++ b/src/api/routes/address.ts @@ -41,11 +41,13 @@ export function createAddressRouter(db: DataStore): RouterWithAsync { return res.status(400).json({ error: `invalid STX address "${stxAddress}"` }); } // Get balance info for STX token - const { balance, totalSent, totalReceived } = await db.getStxBalance(stxAddress); + const stxBalanceResult = await db.getStxBalance(stxAddress); const result: AddressStxBalanceResponse = { - balance: balance.toString(), - total_sent: totalSent.toString(), - total_received: totalReceived.toString(), + balance: stxBalanceResult.balance.toString(), + locked: stxBalanceResult.locked.toString(), + unlock_height: stxBalanceResult.unlockHeight.toString(), + total_sent: stxBalanceResult.totalSent.toString(), + total_received: stxBalanceResult.totalReceived.toString(), }; res.json(result); }); @@ -57,7 +59,7 @@ export function createAddressRouter(db: DataStore): RouterWithAsync { return res.status(400).json({ error: `invalid STX address "${stxAddress}"` }); } // Get balance info for STX token - const { balance, totalSent, totalReceived } = await db.getStxBalance(stxAddress); + const stxBalanceResult = await db.getStxBalance(stxAddress); // Get balances for fungible tokens const ftBalancesResult = await db.getFungibleTokenBalances(stxAddress); @@ -81,9 +83,11 @@ export function createAddressRouter(db: DataStore): RouterWithAsync { const result: AddressBalanceResponse = { stx: { - balance: balance.toString(), - total_sent: totalSent.toString(), - total_received: totalReceived.toString(), + balance: stxBalanceResult.balance.toString(), + locked: stxBalanceResult.locked.toString(), + unlock_height: stxBalanceResult.unlockHeight.toString(), + total_sent: stxBalanceResult.totalSent.toString(), + total_received: stxBalanceResult.totalReceived.toString(), }, fungible_tokens: ftBalances, non_fungible_tokens: nftBalances, diff --git a/src/datastore/common.ts b/src/datastore/common.ts index d21885f59e..cf019c3a24 100644 --- a/src/datastore/common.ts +++ b/src/datastore/common.ts @@ -239,8 +239,16 @@ export interface DbSearchResult { entity_data?: DbBlock | DbMempoolTx | DbTx; } +export interface DbFtBalance { + balance: bigint; + totalSent: bigint; + totalReceived: bigint; +} + export interface DbStxBalance { balance: bigint; + locked: bigint; + unlockHeight: bigint; totalSent: bigint; totalReceived: bigint; } @@ -285,7 +293,7 @@ export interface DataStore extends DataStoreEventEmitter { getStxBalance(stxAddress: string): Promise; getStxBalanceAtBlock(stxAddress: string, blockHeight: number): Promise; - getFungibleTokenBalances(stxAddress: string): Promise>; + getFungibleTokenBalances(stxAddress: string): Promise>; getNonFungibleTokenCounts( stxAddress: string ): Promise>; diff --git a/src/datastore/postgres-store.ts b/src/datastore/postgres-store.ts index 759cb8c726..d20a56870a 100644 --- a/src/datastore/postgres-store.ts +++ b/src/datastore/postgres-store.ts @@ -16,6 +16,7 @@ import { logError, FoundOrNot, getOrAdd, + assertNotNullish, } from '../helpers'; import { DataStore, @@ -38,6 +39,7 @@ import { DbSearchResult, DbStxBalance, DbStxLockEvent, + DbFtBalance, } from './common'; import { TransactionType } from '@blockstack/stacks-blockchain-api-types'; import { getTxTypeId } from '../api/controllers/db-controller'; @@ -904,7 +906,7 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte SELECT ${BLOCK_COLUMNS} FROM blocks WHERE canonical = true - ORDER BY block_height DESC + ORDER BY block_height DESC LIMIT 1 ` ); @@ -1289,6 +1291,7 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte async getTxEvents(txId: string, indexBlockHash: string) { const client = await this.pool.connect(); try { + await client.query('BEGIN'); const txIdBuffer = hexToBuffer(txId); const blockHashBuffer = hexToBuffer(indexBlockHash); const stxResults = await client.query<{ @@ -1435,6 +1438,9 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte } events.sort((a, b) => a.event_index - b.event_index); return { results: events }; + } catch (e) { + await client.query('ROLLBACK'); + throw e; } finally { client.release(); } @@ -1649,89 +1655,148 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte } async getStxBalance(stxAddress: string): Promise { - const result = await this.pool.query<{ - credit_total: string | null; - debit_total: string | null; - }>( - ` - WITH transfers AS ( - SELECT amount, sender, recipient - FROM stx_events - WHERE canonical = true AND (sender = $1 OR recipient = $1) - ), credit AS ( - SELECT sum(amount) as credit_total - FROM transfers - WHERE recipient = $1 - ), debit AS ( - SELECT sum(amount) as debit_total - FROM transfers - WHERE sender = $1 - ) - SELECT credit_total, debit_total - FROM credit CROSS JOIN debit - `, - [stxAddress] - ); - const feeQuery = await this.pool.query<{ fee_sum: string }>( - ` - SELECT sum(fee_rate) as fee_sum - FROM txs - WHERE canonical = true AND sender_address = $1 - `, - [stxAddress] - ); - const totalFees = BigInt(feeQuery.rows[0].fee_sum ?? 0); - const totalSent = BigInt(result.rows[0].debit_total ?? 0); - const totalReceived = BigInt(result.rows[0].credit_total ?? 0); - const balanceTotal = totalReceived - totalSent - totalFees; - return { - balance: balanceTotal, - totalSent, - totalReceived, - }; + const client = await this.pool.connect(); + try { + await client.query('BEGIN'); + const currentBlockQuery = await this.getCurrentBlock(); + let currentBlockHeight = 0; + if (!currentBlockQuery.found) { + currentBlockHeight = 0; + } else { + currentBlockHeight = currentBlockQuery.result.block_height; + } + const result = await client.query<{ + credit_total: string | null; + debit_total: string | null; + }>( + ` + WITH transfers AS ( + SELECT amount, sender, recipient + FROM stx_events + WHERE canonical = true AND (sender = $1 OR recipient = $1) + ), credit AS ( + SELECT sum(amount) as credit_total + FROM transfers + WHERE recipient = $1 + ), debit AS ( + SELECT sum(amount) as debit_total + FROM transfers + WHERE sender = $1 + ) + SELECT credit_total, debit_total + FROM credit CROSS JOIN debit + `, + [stxAddress] + ); + const feeQuery = await client.query<{ fee_sum: string }>( + ` + SELECT sum(fee_rate) as fee_sum + FROM txs + WHERE canonical = true AND sender_address = $1 + `, + [stxAddress] + ); + const lockQuery = await client.query<{ locked_amount: string; unlock_height: string }>( + ` + SELECT locked_amount, unlock_height + FROM stx_lock_events + WHERE canonical = true AND locked_address = $1 AND block_height >= $2 AND unlock_height < $2 + `, + [stxAddress, currentBlockHeight] + ); + if (lockQuery.rowCount !== 0 || lockQuery.rowCount > 1) { + throw new Error( + `stx_lock_events event query for ${stxAddress} should return zero or one rows but returned ${lockQuery.rowCount}` + ); + } + const totalFees = BigInt(feeQuery.rows[0].fee_sum ?? 0); + const totalSent = BigInt(result.rows[0].debit_total ?? 0); + const totalReceived = BigInt(result.rows[0].credit_total ?? 0); + const balance = totalReceived - totalSent - totalFees; + const locked = BigInt(lockQuery.rows[0]?.locked_amount ?? 0); + const unlockHeight = BigInt(lockQuery.rows[0]?.unlock_height ?? 0); + return { + balance, + locked, + unlockHeight, + totalSent, + totalReceived, + }; + } catch (e) { + await client.query('ROLLBACK'); + throw e; + } finally { + client.release(); + } } async getStxBalanceAtBlock(stxAddress: string, blockHeight: number): Promise { - const result = await this.pool.query<{ - credit_total: string | null; - debit_total: string | null; - }>( - ` - WITH transfers AS ( - SELECT amount, sender, recipient - FROM stx_events - WHERE canonical = true AND (sender = $1 OR recipient = $1) AND block_height <= $2 - ), credit AS ( - SELECT sum(amount) as credit_total - FROM transfers - WHERE recipient = $1 - ), debit AS ( - SELECT sum(amount) as debit_total - FROM transfers - WHERE sender = $1 - ) - SELECT credit_total, debit_total - FROM credit CROSS JOIN debit - `, - [stxAddress, blockHeight] - ); - const feeQuery = await this.pool.query<{ fee_sum: string }>( - ` - SELECT sum(fee_rate) as fee_sum - FROM txs - WHERE canonical = true AND sender_address = $1 - `, - [stxAddress] - ); - const totalFees = BigInt(feeQuery.rows[0].fee_sum ?? 0); - const totalSent = BigInt(result.rows[0].debit_total ?? 0); - const totalReceived = BigInt(result.rows[0].credit_total ?? 0); - const balanceTotal = totalReceived - totalSent - totalFees; - return { - balance: balanceTotal, - totalSent, - totalReceived, - }; + const client = await this.pool.connect(); + try { + await client.query('BEGIN'); + const result = await client.query<{ + credit_total: string | null; + debit_total: string | null; + }>( + ` + WITH transfers AS ( + SELECT amount, sender, recipient + FROM stx_events + WHERE canonical = true AND (sender = $1 OR recipient = $1) AND block_height <= $2 + ), credit AS ( + SELECT sum(amount) as credit_total + FROM transfers + WHERE recipient = $1 + ), debit AS ( + SELECT sum(amount) as debit_total + FROM transfers + WHERE sender = $1 + ) + SELECT credit_total, debit_total + FROM credit CROSS JOIN debit + `, + [stxAddress, blockHeight] + ); + const feeQuery = await client.query<{ fee_sum: string }>( + ` + SELECT sum(fee_rate) as fee_sum + FROM txs + WHERE canonical = true AND sender_address = $1 + `, + [stxAddress] + ); + const lockQuery = await client.query<{ locked_amount: string; unlock_height: string }>( + ` + SELECT locked_amount, unlock_height + FROM stx_lock_events + WHERE canonical = true AND locked_address = $1 AND block_height >= $2 AND unlock_height < $2 + `, + [stxAddress, blockHeight] + ); + if (lockQuery.rowCount !== 0 || lockQuery.rowCount > 1) { + throw new Error( + `stx_lock_events event query for ${stxAddress} should return zero or one rows but returned ${lockQuery.rowCount}` + ); + } + const locked = BigInt(lockQuery.rows[0]?.locked_amount ?? 0); + const unlockHeight = BigInt(lockQuery.rows[0]?.unlock_height ?? 0); + const totalFees = BigInt(feeQuery.rows[0].fee_sum ?? 0); + const totalSent = BigInt(result.rows[0].debit_total ?? 0); + const totalReceived = BigInt(result.rows[0].credit_total ?? 0); + const balance = totalReceived - totalSent - totalFees; + return { + balance, + locked, + unlockHeight, + totalSent, + totalReceived, + }; + } catch (e) { + await client.query('ROLLBACK'); + throw e; + } finally { + client.release(); + } } async getAddressAssetEvents({ @@ -1744,7 +1809,7 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte offset: number; }): Promise<{ results: DbEvent[]; total: number }> { const results = await this.pool.query<{ - asset_type: 'stx' | 'ft' | 'nft'; + asset_type: 'stx_lock' | 'stx' | 'ft' | 'nft'; event_index: number; tx_id: Buffer; tx_index: number; @@ -1755,22 +1820,32 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte recipient?: string; asset_identifier: string; amount?: string; + unlock_height?: string; value?: Buffer; }>( ` SELECT * FROM ( SELECT - 'stx' as asset_type, event_index, tx_id, tx_index, block_height, canonical, asset_event_type_id, sender, recipient, '' as asset_identifier, amount::numeric(78, 0), null::bytea as value + 'stx_lock' as asset_type, event_index, tx_id, tx_index, block_height, canonical, 0 as asset_event_type_id, + locked_address as sender, '' as recipient, '' as asset_identifier, locked_amount as amount, unlock_height, null::bytea as value + FROM stx_lock_events + WHERE canonical = true AND locked_address = $1 + UNION ALL + SELECT + 'stx' as asset_type, event_index, tx_id, tx_index, block_height, canonical, asset_event_type_id, + sender, recipient, '' as asset_identifier, amount::numeric, null::numeric as unlock_height, null::bytea as value FROM stx_events WHERE canonical = true AND (sender = $1 OR recipient = $1) UNION ALL SELECT - 'ft' as asset_type, event_index, tx_id, tx_index, block_height, canonical, asset_event_type_id, sender, recipient, asset_identifier, amount, null::bytea as value + 'ft' as asset_type, event_index, tx_id, tx_index, block_height, canonical, asset_event_type_id, + sender, recipient, asset_identifier, amount, null::numeric as unlock_height, null::bytea as value FROM ft_events WHERE canonical = true AND (sender = $1 OR recipient = $1) UNION ALL SELECT - 'nft' as asset_type, event_index, tx_id, tx_index, block_height, canonical, asset_event_type_id, sender, recipient, asset_identifier, null::numeric(78, 0) as amount, value + 'nft' as asset_type, event_index, tx_id, tx_index, block_height, canonical, asset_event_type_id, + sender, recipient, asset_identifier, null::numeric as amount, null::numeric as unlock_height, value FROM nft_events WHERE canonical = true AND (sender = $1 OR recipient = $1) ) asset_events @@ -1782,7 +1857,20 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte ); const events: DbEvent[] = results.rows.map(row => { - if (row.asset_type === 'stx') { + if (row.asset_type === 'stx_lock') { + const event: DbStxLockEvent = { + event_index: row.event_index, + tx_id: bufferToHexPrefixString(row.tx_id), + tx_index: row.tx_index, + block_height: row.block_height, + canonical: row.canonical, + locked_address: assertNotNullish(row.sender), + locked_amount: BigInt(assertNotNullish(row.amount)), + unlock_height: BigInt(assertNotNullish(row.unlock_height)), + event_type: DbEventTypeId.StxLock, + }; + return event; + } else if (row.asset_type === 'stx') { const event: DbStxEvent = { event_index: row.event_index, tx_id: bufferToHexPrefixString(row.tx_id), @@ -1836,7 +1924,7 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte }; } - async getFungibleTokenBalances(stxAddress: string): Promise> { + async getFungibleTokenBalances(stxAddress: string): Promise> { const result = await this.pool.query<{ asset_identifier: string; credit_total: string | null; @@ -1867,7 +1955,7 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte const rows = result.rows.sort((r1, r2) => r1.asset_identifier.localeCompare(r2.asset_identifier) ); - const assetBalances = new Map( + const assetBalances = new Map( rows.map(r => { const totalSent = BigInt(r.debit_total ?? 0); const totalReceived = BigInt(r.credit_total ?? 0); diff --git a/src/helpers.ts b/src/helpers.ts index c0911811eb..257e3e9e73 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -151,7 +151,7 @@ export function formatMapToObject( return obj; } -export const MICROSTACKS_IN_STACKS = BigInt(1_000_000); +export const MICROSTACKS_IN_STACKS = 1_000_000n; export function stxToMicroStx(microStx: bigint | number): bigint { const input = typeof microStx === 'bigint' ? microStx : BigInt(microStx); diff --git a/src/migrations/1588256295395_ft_events.ts b/src/migrations/1588256295395_ft_events.ts index a864545b15..1ba83673e7 100644 --- a/src/migrations/1588256295395_ft_events.ts +++ b/src/migrations/1588256295395_ft_events.ts @@ -39,7 +39,7 @@ export async function up(pgm: MigrationBuilder): Promise { notNull: true, }, amount: { - type: 'numeric(78, 0)', // 78 is the max number of digits for a 256bit integer + type: 'numeric', notNull: true, }, sender: 'string', diff --git a/src/rosetta-helpers.ts b/src/rosetta-helpers.ts index ccb931834f..1f822a6c9f 100644 --- a/src/rosetta-helpers.ts +++ b/src/rosetta-helpers.ts @@ -84,7 +84,7 @@ function makeFeeOperation(tx: BaseTx): RosettaOperation { status: getTxStatus(tx.status), account: { address: tx.sender_address }, amount: { - value: (BigInt(0) - tx.fee_rate).toString(10), + value: (0n - tx.fee_rate).toString(10), currency: { symbol: 'STX', decimals: 6 }, }, }; diff --git a/src/tests-rosetta/api.ts b/src/tests-rosetta/api.ts index e3867aa4c7..1a6b78d50e 100644 --- a/src/tests-rosetta/api.ts +++ b/src/tests-rosetta/api.ts @@ -458,7 +458,7 @@ describe('Rosetta API', () => { coinbase_payload: Buffer.from('coinbase hi'), status: 1, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -508,7 +508,7 @@ describe('Rosetta API', () => { receipt_time: 1594307695, coinbase_payload: Buffer.from('coinbase hi'), post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, diff --git a/src/tests/api-tests.ts b/src/tests/api-tests.ts index 474e465b10..45b7ef7d0c 100644 --- a/src/tests/api-tests.ts +++ b/src/tests/api-tests.ts @@ -87,7 +87,7 @@ describe('api tests', () => { receipt_time: 1594307695, coinbase_payload: Buffer.from('coinbase hi'), post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -122,7 +122,7 @@ describe('api tests', () => { receipt_time: 1594307695, coinbase_payload: Buffer.from('coinbase hi'), post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: true, sender_address: 'sender-addr', sponsor_address: 'sponsor-addr', @@ -160,7 +160,7 @@ describe('api tests', () => { coinbase_payload: Buffer.from('coinbase hi'), status: 1, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -247,7 +247,7 @@ describe('api tests', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -262,7 +262,7 @@ describe('api tests', () => { coinbase_payload: Buffer.from('coinbase hi'), status: 1, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -427,14 +427,14 @@ describe('api tests', () => { block_height: 68456, burn_block_time: 2837565, type_id: DbTxTypeId.TokenTransfer, - token_transfer_amount: BigInt(1), + token_transfer_amount: 1n, token_transfer_memo: Buffer.from('hi'), token_transfer_recipient_address: 'none', status: 1, raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: addr1, origin_hash_mode: 1, @@ -463,14 +463,14 @@ describe('api tests', () => { block_height: 68456, burn_block_time: 2837565, type_id: DbTxTypeId.TokenTransfer, - token_transfer_amount: BigInt(1), + token_transfer_amount: 1n, token_transfer_memo: Buffer.from('hi'), token_transfer_recipient_address: addr2, status: 1, raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'none', origin_hash_mode: 1, @@ -498,7 +498,7 @@ describe('api tests', () => { tx_id: '0x1111000000000000000000000000000000000000000000000000000000000000', tx_index: 1, block_height: 1, - amount: BigInt(1), + amount: 1n, recipient: addr3, sender: 'none', }; @@ -525,7 +525,7 @@ describe('api tests', () => { tx_id: '0x1111000000000000000000000000000000000000000000000000000000000000', tx_index: 1, block_height: 1, - amount: BigInt(1), + amount: 1n, recipient: 'none', sender: addr4, }; @@ -553,7 +553,7 @@ describe('api tests', () => { tx_index: 1, block_height: 1, asset_identifier: 'some-asset', - amount: BigInt(1), + amount: 1n, recipient: addr5, sender: 'none', }; @@ -581,7 +581,7 @@ describe('api tests', () => { tx_index: 1, block_height: 1, asset_identifier: 'some-asset', - amount: BigInt(1), + amount: 1n, recipient: 'none', sender: addr6, }; @@ -671,7 +671,7 @@ describe('api tests', () => { status: 1, raw_result: '0x0100000000000000000000000000000001', // u1 post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'none', origin_hash_mode: 1, @@ -707,7 +707,7 @@ describe('api tests', () => { smart_contract_source_code: '(some-src)', status: 1, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'none', origin_hash_mode: 1, @@ -794,7 +794,7 @@ describe('api tests', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: sender, origin_hash_mode: 1, @@ -828,7 +828,7 @@ describe('api tests', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: testAddr1, origin_hash_mode: 1, @@ -959,7 +959,13 @@ describe('api tests', () => { expect(fetchAddrBalance1.status).toBe(200); expect(fetchAddrBalance1.type).toBe('application/json'); const expectedResp1 = { - stx: { balance: '94913', total_sent: '1385', total_received: '100000' }, + stx: { + balance: '94913', + locked: '0', + unlock_height: '0', + total_sent: '1385', + total_received: '100000', + }, fungible_tokens: { bux: { balance: '99615', total_sent: '385', total_received: '100000' }, cash: { balance: '500000', total_sent: '0', total_received: '500000' }, @@ -981,7 +987,13 @@ describe('api tests', () => { expect(fetchAddrBalance2.status).toBe(200); expect(fetchAddrBalance2.type).toBe('application/json'); const expectedResp2 = { - stx: { balance: '101', total_sent: '15', total_received: '1350' }, + stx: { + balance: '101', + locked: '0', + unlock_height: '0', + total_sent: '15', + total_received: '1350', + }, fungible_tokens: { bux: { balance: '335', total_sent: '15', total_received: '350' }, gox: { balance: '525', total_sent: '25', total_received: '550' }, @@ -998,7 +1010,13 @@ describe('api tests', () => { ); expect(fetchAddrStxBalance1.status).toBe(200); expect(fetchAddrStxBalance1.type).toBe('application/json'); - const expectedStxResp1 = { balance: '101', total_sent: '15', total_received: '1350' }; + const expectedStxResp1 = { + balance: '101', + locked: '0', + unlock_height: '0', + total_sent: '15', + total_received: '1350', + }; expect(JSON.parse(fetchAddrStxBalance1.text)).toEqual(expectedStxResp1); const fetchAddrAssets1 = await supertest(api.server).get( @@ -1219,7 +1237,7 @@ describe('api tests', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -1337,7 +1355,7 @@ describe('api tests', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, diff --git a/src/tests/core-rpc-tests.ts b/src/tests/core-rpc-tests.ts index d995eceb49..a3ba67a246 100644 --- a/src/tests/core-rpc-tests.ts +++ b/src/tests/core-rpc-tests.ts @@ -24,6 +24,6 @@ describe('core RPC tests', () => { test('get account balance', async () => { const balance = await client.getAccountBalance('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6'); - expect(balance).toBe(BigInt(10000000000000000)); + expect(balance).toBe(10000000000000000n); }); }); diff --git a/src/tests/datastore-tests.ts b/src/tests/datastore-tests.ts index bb6e08c2fd..61c3d40a74 100644 --- a/src/tests/datastore-tests.ts +++ b/src/tests/datastore-tests.ts @@ -72,7 +72,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'addrA', origin_hash_mode: 1, @@ -80,7 +80,7 @@ describe('postgres datastore', () => { const tx2 = { ...tx, tx_id: '0x2345', - fee_rate: BigInt(100), + fee_rate: 100n, }; const createStxEvent = ( sender: string, @@ -122,24 +122,32 @@ describe('postgres datastore', () => { const addrDResult = await db.getStxBalance('addrD'); expect(addrAResult).toEqual({ - balance: BigInt(98281), - totalReceived: BigInt(100000), - totalSent: BigInt(385), + balance: 98281n, + locked: 0n, + unlockHeight: 0n, + totalReceived: 100000n, + totalSent: 385n, }); expect(addrBResult).toEqual({ - balance: BigInt(335), - totalReceived: BigInt(350), - totalSent: BigInt(15), + balance: 335n, + locked: 0n, + unlockHeight: 0n, + totalReceived: 350n, + totalSent: 15n, }); expect(addrCResult).toEqual({ - balance: BigInt(50), - totalReceived: BigInt(50), - totalSent: BigInt(0), + balance: 50n, + locked: 0n, + unlockHeight: 0n, + totalReceived: 50n, + totalSent: 0n, }); expect(addrDResult).toEqual({ - balance: BigInt(0), - totalReceived: BigInt(0), - totalSent: BigInt(0), + balance: 0n, + locked: 0n, + unlockHeight: 0n, + totalReceived: 0n, + totalSent: 0n, }); }); @@ -158,7 +166,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -211,21 +219,18 @@ describe('postgres datastore', () => { const addrDResult = await db.getFungibleTokenBalances('addrD'); expect([...addrAResult]).toEqual([ - ['bux', { balance: BigInt(99615), totalReceived: BigInt(100000), totalSent: BigInt(385) }], - ['cash', { balance: BigInt(500000), totalReceived: BigInt(500000), totalSent: BigInt(0) }], - ['gox', { balance: BigInt(199375), totalReceived: BigInt(200000), totalSent: BigInt(625) }], - [ - 'tendies', - { balance: BigInt(-1000000), totalReceived: BigInt(0), totalSent: BigInt(1000000) }, - ], + ['bux', { balance: 99615n, totalReceived: 100000n, totalSent: 385n }], + ['cash', { balance: 500000n, totalReceived: 500000n, totalSent: 0n }], + ['gox', { balance: 199375n, totalReceived: 200000n, totalSent: 625n }], + ['tendies', { balance: -1000000n, totalReceived: 0n, totalSent: 1000000n }], ]); expect([...addrBResult]).toEqual([ - ['bux', { balance: BigInt(335), totalReceived: BigInt(350), totalSent: BigInt(15) }], - ['gox', { balance: BigInt(525), totalReceived: BigInt(550), totalSent: BigInt(25) }], + ['bux', { balance: 335n, totalReceived: 350n, totalSent: 15n }], + ['gox', { balance: 525n, totalReceived: 550n, totalSent: 25n }], ]); expect([...addrCResult]).toEqual([ - ['bux', { balance: BigInt(50), totalReceived: BigInt(50), totalSent: BigInt(0) }], - ['gox', { balance: BigInt(100), totalReceived: BigInt(100), totalSent: BigInt(0) }], + ['bux', { balance: 50n, totalReceived: 50n, totalSent: 0n }], + ['gox', { balance: 100n, totalReceived: 100n, totalSent: 0n }], ]); expect([...addrDResult]).toEqual([]); }); @@ -245,7 +250,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -302,18 +307,18 @@ describe('postgres datastore', () => { const addrDResult = await db.getNonFungibleTokenCounts('addrD'); expect([...addrAResult]).toEqual([ - ['bux', { count: BigInt(262), totalReceived: BigInt(300), totalSent: BigInt(38) }], - ['cash', { count: BigInt(500), totalReceived: BigInt(500), totalSent: BigInt(0) }], - ['gox', { count: BigInt(138), totalReceived: BigInt(200), totalSent: BigInt(62) }], - ['tendies', { count: BigInt(-100), totalReceived: BigInt(0), totalSent: BigInt(100) }], + ['bux', { count: 262n, totalReceived: 300n, totalSent: 38n }], + ['cash', { count: 500n, totalReceived: 500n, totalSent: 0n }], + ['gox', { count: 138n, totalReceived: 200n, totalSent: 62n }], + ['tendies', { count: -100n, totalReceived: 0n, totalSent: 100n }], ]); expect([...addrBResult]).toEqual([ - ['bux', { count: BigInt(34), totalReceived: BigInt(35), totalSent: BigInt(1) }], - ['gox', { count: BigInt(53), totalReceived: BigInt(55), totalSent: BigInt(2) }], + ['bux', { count: 34n, totalReceived: 35n, totalSent: 1n }], + ['gox', { count: 53n, totalReceived: 55n, totalSent: 2n }], ]); expect([...addrCResult]).toEqual([ - ['bux', { count: BigInt(4), totalReceived: BigInt(4), totalSent: BigInt(0) }], - ['gox', { count: BigInt(9), totalReceived: BigInt(9), totalSent: BigInt(0) }], + ['bux', { count: 4n, totalReceived: 4n, totalSent: 0n }], + ['gox', { count: 9n, totalReceived: 9n, totalSent: 0n }], ]); expect([...addrDResult]).toEqual([]); }); @@ -351,7 +356,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -386,7 +391,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: sender, origin_hash_mode: 1, @@ -534,7 +539,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -585,7 +590,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -647,7 +652,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -1331,7 +1336,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -1356,7 +1361,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -1364,7 +1369,7 @@ describe('postgres datastore', () => { await expect(db.updateTx(client, tx)).rejects.toEqual( new Error('new row for relation "txs" violates check constraint "valid_token_transfer"') ); - tx.token_transfer_amount = BigInt(34); + tx.token_transfer_amount = 34n; tx.token_transfer_memo = Buffer.from('thx'); tx.token_transfer_recipient_address = 'recipient-addr'; await db.updateTx(client, tx); @@ -1387,7 +1392,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -1417,7 +1422,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -1448,7 +1453,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -1478,7 +1483,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -1508,7 +1513,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -1549,7 +1554,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -1570,7 +1575,7 @@ describe('postgres datastore', () => { sender: 'sender-addr', recipient: 'recipient-addr', event_type: DbEventTypeId.StxAsset, - amount: BigInt(789), + amount: 789n, }; const ftEvent1: DbFtEvent = { event_index: 2, @@ -1582,7 +1587,7 @@ describe('postgres datastore', () => { sender: 'sender-addr', recipient: 'recipient-addr', event_type: DbEventTypeId.FungibleTokenAsset, - amount: BigInt(789), + amount: 789n, asset_identifier: 'ft-asset-id', }; const nftEvent1: DbNftEvent = { @@ -1769,12 +1774,12 @@ describe('postgres datastore', () => { raw_tx: Buffer.from('test-raw-tx'), type_id: DbTxTypeId.TokenTransfer, receipt_time: 123456, - token_transfer_amount: BigInt(1), + token_transfer_amount: 1n, token_transfer_memo: Buffer.from('hi'), token_transfer_recipient_address: 'stx-recipient-addr', status: DbTxStatus.Pending, post_conditions: Buffer.from([]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -1978,7 +1983,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: false, post_conditions: Buffer.from([]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -1998,7 +2003,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: false, post_conditions: Buffer.from([]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -2117,7 +2122,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -2137,7 +2142,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, @@ -2200,7 +2205,7 @@ describe('postgres datastore', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'sender-addr', origin_hash_mode: 1, diff --git a/src/tests/websocket-tests.ts b/src/tests/websocket-tests.ts index 96175b7f1b..0adcd227b4 100644 --- a/src/tests/websocket-tests.ts +++ b/src/tests/websocket-tests.ts @@ -71,13 +71,13 @@ describe('websocket notifications', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'ST3GQB6WGCWKDNFNPSQRV8DY93JN06XPZ2ZE9EVMA', origin_hash_mode: 1, token_transfer_recipient_address: 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6', - token_transfer_amount: BigInt(100), - token_transfer_memo: new Buffer('memo'), + token_transfer_amount: 100n, + token_transfer_memo: Buffer.from('memo'), }; const mempoolTx: DbMempoolTx = { @@ -203,13 +203,13 @@ describe('websocket notifications', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'ST3GQB6WGCWKDNFNPSQRV8DY93JN06XPZ2ZE9EVMA', origin_hash_mode: 1, token_transfer_recipient_address: 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6', - token_transfer_amount: BigInt(100), - token_transfer_memo: new Buffer('memo'), + token_transfer_amount: 100n, + token_transfer_memo: Buffer.from('memo'), }; const mempoolTx: DbMempoolTx = { @@ -328,13 +328,13 @@ describe('websocket notifications', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'ST3GQB6WGCWKDNFNPSQRV8DY93JN06XPZ2ZE9EVMA', origin_hash_mode: 1, token_transfer_recipient_address: 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6', - token_transfer_amount: BigInt(100), - token_transfer_memo: new Buffer('memo'), + token_transfer_amount: 100n, + token_transfer_memo: Buffer.from('memo'), }; const stxEvent: DbStxEvent = { @@ -441,13 +441,13 @@ describe('websocket notifications', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'ST3GQB6WGCWKDNFNPSQRV8DY93JN06XPZ2ZE9EVMA', origin_hash_mode: 1, token_transfer_recipient_address: 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6', - token_transfer_amount: BigInt(100), - token_transfer_memo: new Buffer('memo'), + token_transfer_amount: 100n, + token_transfer_memo: Buffer.from('memo'), }; const stxEvent: DbStxEvent = { @@ -532,13 +532,13 @@ describe('websocket notifications', () => { raw_result: '0x0100000000000000000000000000000001', // u1 canonical: true, post_conditions: Buffer.from([0x01, 0xf5]), - fee_rate: BigInt(1234), + fee_rate: 1234n, sponsored: false, sender_address: 'ST3GQB6WGCWKDNFNPSQRV8DY93JN06XPZ2ZE9EVMA', origin_hash_mode: 1, token_transfer_recipient_address: 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6', - token_transfer_amount: BigInt(100), - token_transfer_memo: new Buffer('memo'), + token_transfer_amount: 100n, + token_transfer_memo: Buffer.from('memo'), }; const mempoolTx: DbMempoolTx = { diff --git a/tsconfig.json b/tsconfig.json index b8e9df02ff..84065be41f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es2019", + "target": "es2020", "module": "commonjs", "moduleResolution": "node", "declaration": false,