Skip to content

Commit c60d9ca

Browse files
committed
Merge branch 'develop' into feat/event-replay-tests
2 parents a178bed + eb9fd0e commit c60d9ca

25 files changed

+975
-229
lines changed

.env

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ PG_PASSWORD=postgres
55
PG_DATABASE=stacks_blockchain_api
66
PG_SCHEMA=public
77
PG_SSL=false
8+
# Idle connection timeout in seconds, defaults to 30
9+
# PG_IDLE_TIMEOUT=30
10+
# Max connection lifetime in seconds, defaults to 60
11+
# PG_MAX_LIFETIME=60
812

913
# Can be any string, use to specify a use case specific to a deployment
1014
PG_APPLICATION_NAME=stacks-blockchain-api
@@ -27,12 +31,13 @@ PG_APPLICATION_NAME=stacks-blockchain-api
2731
# PG_PRIMARY_DATABASE=
2832
# PG_PRIMARY_SCHEMA=
2933
# PG_PRIMARY_SSL=
34+
# PG_PRIMARY_IDLE_TIMEOUT=
35+
# PG_PRIMARY_MAX_LIFETIME=
3036
# The connection URI below can be used in place of the PG variables above,
3137
# but if enabled it must be defined without others or omitted.
3238
# PG_PRIMARY_CONNECTION_URI=
3339

3440
# Limit to how many concurrent connections can be created, defaults to 10
35-
# See https://node-postgres.com/api/pool
3641
# PG_CONNECTION_POOL_MAX=10
3742

3843
# If specified, controls the Stacks Blockchain API mode. The possible values are:

.gitpod.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM blockstack/stacks-blockchain:2.05.0.3.0-stretch as corenode
1+
FROM blockstack/stacks-blockchain:2.05.0.4.0 as corenode
22

33
FROM gitpod/workspace-postgres
44

CHANGELOG.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,98 @@
1+
## [6.1.0](https://github.com/hirosystems/stacks-blockchain-api/compare/v6.0.4...v6.1.0) (2022-10-13)
2+
3+
4+
### Features
5+
6+
* configurable pg connection lifetime and idle timeouts ([#1355](https://github.com/hirosystems/stacks-blockchain-api/issues/1355)) ([46ccf06](https://github.com/hirosystems/stacks-blockchain-api/commit/46ccf0640de0c42e5fd71795521992fdfdc8d293))
7+
8+
9+
### Bug Fixes
10+
11+
* refresh materialized views in their own pg connection ([#1356](https://github.com/hirosystems/stacks-blockchain-api/issues/1356)) ([9433d3c](https://github.com/hirosystems/stacks-blockchain-api/commit/9433d3c9c2d46eeff143a6c04438a94505549f3f))
12+
13+
## [6.0.4](https://github.com/hirosystems/stacks-blockchain-api/compare/v6.0.3...v6.0.4) (2022-10-12)
14+
15+
16+
### Bug Fixes
17+
18+
* handle pg exceptions on web socket transmitter ([#1353](https://github.com/hirosystems/stacks-blockchain-api/issues/1353)) ([2e6448d](https://github.com/hirosystems/stacks-blockchain-api/commit/2e6448d7afc7bb35d5bcd3da88105f0552a13764))
19+
20+
## [6.0.3](https://github.com/hirosystems/stacks-blockchain-api/compare/v6.0.2...v6.0.3) (2022-10-12)
21+
22+
23+
### Bug Fixes
24+
25+
* skip migrations on read-only start ([#1351](https://github.com/hirosystems/stacks-blockchain-api/issues/1351)) ([1d32261](https://github.com/hirosystems/stacks-blockchain-api/commit/1d322614e70e125b924c7d0a8b9f536ca81eb48f))
26+
27+
## [6.0.2](https://github.com/hirosystems/stacks-blockchain-api/compare/v6.0.1...v6.0.2) (2022-10-12)
28+
29+
30+
### Bug Fixes
31+
32+
* catch pg exceptions on queries outside of express ([#1348](https://github.com/hirosystems/stacks-blockchain-api/issues/1348)) ([1f07b85](https://github.com/hirosystems/stacks-blockchain-api/commit/1f07b8587ccf0206e085d272e6cb5ee62f816fd9))
33+
34+
## [6.0.1](https://github.com/hirosystems/stacks-blockchain-api/compare/v6.0.0...v6.0.1) (2022-10-06)
35+
36+
37+
### Bug Fixes
38+
39+
* guard against empty lists before querying postgres ([#1345](https://github.com/hirosystems/stacks-blockchain-api/issues/1345)) ([6c88a16](https://github.com/hirosystems/stacks-blockchain-api/commit/6c88a166c8742c869222f7f754838af386e2cd16))
40+
41+
## [6.0.0](https://github.com/hirosystems/stacks-blockchain-api/compare/v5.0.1...v6.0.0) (2022-10-06)
42+
43+
44+
### ⚠ BREAKING CHANGES
45+
46+
* remove deprecated `/nft_events` endpoint (#1329)
47+
* mark breaking change
48+
49+
### Features
50+
51+
* add `transaction_count` for `microblocks_accepted` in block ([#1162](https://github.com/hirosystems/stacks-blockchain-api/issues/1162)) ([78d7d9c](https://github.com/hirosystems/stacks-blockchain-api/commit/78d7d9c9f72db8ce6c59e0ea59a2579aceec014e))
52+
* add API version in response header ([#1216](https://github.com/hirosystems/stacks-blockchain-api/issues/1216)) ([1e998db](https://github.com/hirosystems/stacks-blockchain-api/commit/1e998db7d1c87c064376cb950d05b073d9d3f076))
53+
* add owner index to subdomains table ([#1331](https://github.com/hirosystems/stacks-blockchain-api/issues/1331)) ([a6c5e12](https://github.com/hirosystems/stacks-blockchain-api/commit/a6c5e12faa256633a7c9ae4c7cf8524013d187d6))
54+
* add token_type metadata for rosetta ft operations ([#1332](https://github.com/hirosystems/stacks-blockchain-api/issues/1332)) ([09af27b](https://github.com/hirosystems/stacks-blockchain-api/commit/09af27b24be8e30a840707707b79d65cd45f2351))
55+
* mark breaking change ([669fd0d](https://github.com/hirosystems/stacks-blockchain-api/commit/669fd0d8c00b8ca9224c9b5411a070b32c3b0529))
56+
* mempool stats endpoint and prometheus metrics ([#1241](https://github.com/hirosystems/stacks-blockchain-api/issues/1241)) ([9482238](https://github.com/hirosystems/stacks-blockchain-api/commit/9482238599549fd651c8c87b545c175d8a219521))
57+
* refactor pg classes, switch to postgres.js ([#1148](https://github.com/hirosystems/stacks-blockchain-api/issues/1148)) ([3ff4177](https://github.com/hirosystems/stacks-blockchain-api/commit/3ff41779f844c611fbd95429aeefbdb085a59026)), closes [#1168](https://github.com/hirosystems/stacks-blockchain-api/issues/1168)
58+
* send nft updates through websocket channels ([#1218](https://github.com/hirosystems/stacks-blockchain-api/issues/1218)) ([920a7b8](https://github.com/hirosystems/stacks-blockchain-api/commit/920a7b892a39f0f1e76363211573d935ae2c75da))
59+
60+
61+
### Bug Fixes
62+
63+
* consolidate db migrations ([#1314](https://github.com/hirosystems/stacks-blockchain-api/issues/1314)) ([d6bdf9f](https://github.com/hirosystems/stacks-blockchain-api/commit/d6bdf9faff905d5e208e61b04c34321e954a2fb1))
64+
* event_observer_requests json writes ([#1334](https://github.com/hirosystems/stacks-blockchain-api/issues/1334)) ([465aa0b](https://github.com/hirosystems/stacks-blockchain-api/commit/465aa0b42ca3dda57d06f6c0756b03d591e7f027))
65+
* included query params in redirecting to prefix 0x in tx endpoint ([#1205](https://github.com/hirosystems/stacks-blockchain-api/issues/1205)) ([664cce7](https://github.com/hirosystems/stacks-blockchain-api/commit/664cce744d1aecc0b3226ae07ac81e5d0cd13871))
66+
* incorrect websocket/socket.io transaction updates ([#1197](https://github.com/hirosystems/stacks-blockchain-api/issues/1197)) ([8ee1da8](https://github.com/hirosystems/stacks-blockchain-api/commit/8ee1da840bfa3fcecac79e09e375b720cd0ccc04))
67+
* mobx breakage by locking package dependencies ([#1206](https://github.com/hirosystems/stacks-blockchain-api/issues/1206)) ([5f8bc9f](https://github.com/hirosystems/stacks-blockchain-api/commit/5f8bc9fd4f45877eedbfbce29c7feb5905ba8836))
68+
* optimize `getMicroblocks` query ([#1179](https://github.com/hirosystems/stacks-blockchain-api/issues/1179)) ([7691109](https://github.com/hirosystems/stacks-blockchain-api/commit/769110926eb7b7c9a4d2754af8ce6f1213e2c56f))
69+
* optimize block endpoint ([#1190](https://github.com/hirosystems/stacks-blockchain-api/issues/1190)) ([943e2d1](https://github.com/hirosystems/stacks-blockchain-api/commit/943e2d1c555473f7f0fb61959ed89185e89ed062))
70+
* refresh materialized views concurrently in new pg format ([#1324](https://github.com/hirosystems/stacks-blockchain-api/issues/1324)) ([20b284f](https://github.com/hirosystems/stacks-blockchain-api/commit/20b284fa381041fb842bf61d8a184be6ea84810f))
71+
* remove duplicate txs in microblock responses ([#1167](https://github.com/hirosystems/stacks-blockchain-api/issues/1167)) ([15c0c11](https://github.com/hirosystems/stacks-blockchain-api/commit/15c0c1124a2c91756389274c8a6ebfa8aa44228b))
72+
* remove live tsv append ([#1315](https://github.com/hirosystems/stacks-blockchain-api/issues/1315)) ([e2a1247](https://github.com/hirosystems/stacks-blockchain-api/commit/e2a124710f955d9d32ff5a928af7da08823689d4))
73+
* retry pg connection on new library code ([#1326](https://github.com/hirosystems/stacks-blockchain-api/issues/1326)) ([35db939](https://github.com/hirosystems/stacks-blockchain-api/commit/35db939199a2d826e7ee4dbe31af48cc42364ea2))
74+
* support multiple BNS name events in the same transaction ([#1337](https://github.com/hirosystems/stacks-blockchain-api/issues/1337)) ([1edb256](https://github.com/hirosystems/stacks-blockchain-api/commit/1edb25697df689dbf1da5d412f5d40e4aac024f3))
75+
* tests ([1c1fd16](https://github.com/hirosystems/stacks-blockchain-api/commit/1c1fd1619c8ea97c2636082203fb678f06493786))
76+
* upgrade stacks node versions to 2.05.0.3.0 ([#1328](https://github.com/hirosystems/stacks-blockchain-api/issues/1328)) ([e30636e](https://github.com/hirosystems/stacks-blockchain-api/commit/e30636e30f716a7335792914a142fa54f423dc9a))
77+
* upsert nft and ft metadata ([#1193](https://github.com/hirosystems/stacks-blockchain-api/issues/1193)) ([c4eec5d](https://github.com/hirosystems/stacks-blockchain-api/commit/c4eec5d060666b660c48d326e74b4f989b9ee21d))
78+
79+
80+
### Reverts
81+
82+
* Revert "chore!: remove deprecated `/nft_events` endpoint (#1329)" (#1343) ([c537ee4](https://github.com/hirosystems/stacks-blockchain-api/commit/c537ee4c6f333c0a43c9e9e1ca1e073f03c58fc5)), closes [#1329](https://github.com/hirosystems/stacks-blockchain-api/issues/1329) [#1343](https://github.com/hirosystems/stacks-blockchain-api/issues/1343)
83+
84+
85+
### Miscellaneous Chores
86+
87+
* remove deprecated `/nft_events` endpoint ([#1329](https://github.com/hirosystems/stacks-blockchain-api/issues/1329)) ([65bb4e5](https://github.com/hirosystems/stacks-blockchain-api/commit/65bb4e55fabf21a70183d2b16c8bc1f6f742d04e))
88+
89+
## [6.0.0-beta.10](https://github.com/hirosystems/stacks-blockchain-api/compare/v6.0.0-beta.9...v6.0.0-beta.10) (2022-10-06)
90+
91+
92+
### Reverts
93+
94+
* Revert "chore!: remove deprecated `/nft_events` endpoint (#1329)" (#1343) ([c537ee4](https://github.com/hirosystems/stacks-blockchain-api/commit/c537ee4c6f333c0a43c9e9e1ca1e073f03c58fc5)), closes [#1329](https://github.com/hirosystems/stacks-blockchain-api/issues/1329) [#1343](https://github.com/hirosystems/stacks-blockchain-api/issues/1343)
95+
196
## [6.0.0-beta.9](https://github.com/hirosystems/stacks-blockchain-api/compare/v6.0.0-beta.8...v6.0.0-beta.9) (2022-09-30)
297

398

docker/stx-rosetta.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG STACKS_API_VERSION=v0.71.2
2-
ARG STACKS_NODE_VERSION=2.05.0.3.0
2+
ARG STACKS_NODE_VERSION=2.05.0.4.0
33
ARG STACKS_API_REPO=blockstack/stacks-blockchain-api
44
ARG STACKS_NODE_REPO=blockstack/stacks-blockchain
55
ARG PG_VERSION=12
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"limit": 20,
3+
"offset": 0,
4+
"total": 1,
5+
"nft_events": [
6+
{
7+
"sender": "none",
8+
"recipient": "ST1HB64MAJ1MBV4CQ80GF01DZS4T1DSMX20ADCRA4",
9+
"asset_identifier": "some-asset",
10+
"value": { "hex": "0x00", "repr": "0" }
11+
}
12+
]
13+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"type": "object",
3+
"title": "AddressNftListResponse",
4+
"additionalProperties": false,
5+
"required": [
6+
"limit",
7+
"offset",
8+
"total",
9+
"nft_events"
10+
],
11+
"properties": {
12+
"limit": {
13+
"type": "integer"
14+
},
15+
"offset": {
16+
"type": "integer"
17+
},
18+
"total": {
19+
"type": "integer"
20+
},
21+
"nft_events": {
22+
"type": "array",
23+
"items": {
24+
"$ref": "../../entities/nft-events/nft-event.schema.json"
25+
}
26+
}
27+
}
28+
}

docs/openapi.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,63 @@ paths:
16431643
example:
16441644
$ref: ./api/address/get-address-stx-inbound.example.json
16451645

1646+
/extended/v1/address/{principal}/nft_events:
1647+
get:
1648+
summary: Get nft events
1649+
deprecated: true
1650+
description: |
1651+
**NOTE:** This endpoint is deprecated in favor of [Non-Fungible Token holdings](#operation/get_nft_holdings).
1652+
1653+
Retrieves a list of all nfts owned by an address, contains the clarity value of the identifier of the nft.
1654+
tags:
1655+
- Accounts
1656+
operationId: get_account_nft
1657+
parameters:
1658+
- name: principal
1659+
in: path
1660+
description: Stacks address or a Contract identifier
1661+
required: true
1662+
schema:
1663+
type: string
1664+
example: "SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0"
1665+
- name: limit
1666+
in: query
1667+
description: number of items to return
1668+
required: false
1669+
schema:
1670+
type: integer
1671+
- name: offset
1672+
in: query
1673+
description: number of items to skip
1674+
required: false
1675+
schema:
1676+
type: integer
1677+
example: 42000
1678+
- name: unanchored
1679+
in: query
1680+
description: Include transaction data from unanchored (i.e. unconfirmed) microblocks
1681+
required: false
1682+
schema:
1683+
type: boolean
1684+
example: true
1685+
default: false
1686+
- name: until_block
1687+
in: query
1688+
description: returned data representing the state up until that point in time, rather than the current block. Note - Use either of the query parameters but not both at a time.
1689+
required: false
1690+
schema:
1691+
type: string
1692+
example: 60000
1693+
responses:
1694+
200:
1695+
description: Success
1696+
content:
1697+
application/json:
1698+
schema:
1699+
$ref: ./api/address/get-address-nft-events.schema.json
1700+
example:
1701+
$ref: ./api/address/get-address-nft-events.example.json
1702+
16461703
/v2/accounts/{principal}:
16471704
get:
16481705
summary: Get account info

src/api/init.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import * as expressWinston from 'express-winston';
55
import * as winston from 'winston';
66
import { v4 as uuid } from 'uuid';
77
import * as cors from 'cors';
8-
import * as WebSocket from 'ws';
9-
import * as SocketIO from 'socket.io';
108

119
import { createTxRouter } from './routes/tx';
1210
import { createDebugRouter } from './routes/debug';
@@ -47,6 +45,7 @@ import * as fs from 'fs';
4745
import { PgStore } from '../datastore/pg-store';
4846
import { PgWriteStore } from '../datastore/pg-write-store';
4947
import { WebSocketTransmitter } from './routes/ws/web-socket-transmitter';
48+
import { isPgConnectionError } from '../datastore/helpers';
5049

5150
export interface ApiServer {
5251
expressApp: express.Express;
@@ -300,6 +299,8 @@ export async function startApiServer(opts: {
300299
if (error && !res.headersSent) {
301300
if (error instanceof InvalidRequestError) {
302301
res.status(error.status).json({ error: error.message }).end();
302+
} else if (isPgConnectionError(error)) {
303+
res.status(503).json({ error: `The database service is unavailable` }).end();
303304
} else {
304305
res.status(500);
305306
const errorTag = uuid();

src/api/routes/address.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,59 @@ export function createAddressRouter(db: PgStore, chainId: ChainID): express.Rout
476476
})
477477
);
478478

479+
/**
480+
* @deprecated Use `/extended/v1/tokens/nft/holdings` instead.
481+
*/
482+
router.get(
483+
'/:stx_address/nft_events',
484+
cacheHandler,
485+
asyncHandler(async (req, res, next) => {
486+
// get recent asset event associated with address
487+
const stxAddress = req.params['stx_address'];
488+
validatePrincipal(stxAddress);
489+
490+
const untilBlock = parseUntilBlockQuery(req, res, next);
491+
const blockHeight = await getBlockHeight(untilBlock, req, res, next, db);
492+
const limit = parseAssetsQueryLimit(req.query.limit ?? 20);
493+
const offset = parsePagingQueryInput(req.query.offset ?? 0);
494+
const includeUnanchored = isUnanchoredRequest(req, res, next);
495+
496+
const response = await db.getAddressNFTEvent({
497+
stxAddress,
498+
limit,
499+
offset,
500+
blockHeight,
501+
includeUnanchored,
502+
});
503+
const nft_events = response.results.map(row => {
504+
const parsedClarityValue = decodeClarityValueToRepr(row.value);
505+
const r: NftEvent = {
506+
sender: row.sender,
507+
recipient: row.recipient,
508+
asset_identifier: row.asset_identifier,
509+
value: {
510+
hex: row.value,
511+
repr: parsedClarityValue,
512+
},
513+
tx_id: row.tx_id,
514+
block_height: row.block_height,
515+
event_index: row.event_index,
516+
asset_event_type: getAssetEventTypeString(row.asset_event_type_id),
517+
tx_index: row.tx_index,
518+
};
519+
return r;
520+
});
521+
const nftListResponse: AddressNftListResponse = {
522+
nft_events: nft_events,
523+
total: response.total,
524+
limit: limit,
525+
offset: offset,
526+
};
527+
setETagCacheHeaders(res);
528+
res.json(nftListResponse);
529+
})
530+
);
531+
479532
router.get(
480533
'/:address/mempool',
481534
mempoolCacheHandler,

0 commit comments

Comments
 (0)