Skip to content

Commit 9e9fd99

Browse files
committed
feat: #302 add btc info to blocks, #301 pull stacks-node from dockerhub image
1 parent e6e445b commit 9e9fd99

File tree

17 files changed

+163
-34
lines changed

17 files changed

+163
-34
lines changed

client/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ services:
99
POSTGRES_PASSWORD: postgres
1010
POSTGRES_DB: stacks_blockchain_api
1111
POSTGRES_PORT: 5432
12-
volumes:
13-
- database-data:/var/lib/postgresql/data/ # persist data even if container shuts down
1412
networks:
1513
- backend
1614
stacks-blockchain:
@@ -60,6 +58,3 @@ services:
6058

6159
networks:
6260
backend:
63-
64-
volumes:
65-
database-data:

docs/entities/blocks/block.example.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
"parent_block_hash": "0x75ab21ef25cbff2caa14c27d830ed7886a4d1522e1b6f9e5dc3b59ccf73ed49f",
66
"burn_block_time": 1594233639,
77
"burn_block_time_iso": "2020-08-27T16:41:26.000Z",
8+
"burn_block_hash": "0xb154c008df2101023a6d0d54986b3964cee58119eed14f5bed98e15678e18fe2",
9+
"burn_block_height": 654439,
10+
"miner_txid": "0xd7d56070277ccd87b42acf0c91f915dd181f9db4cf878a4e95518bc397c240cc",
811
"txs": ["0x66557c219c6b0cdb40681ecf79a69f03654d88ef1910651a7db0b078f58af5ca"]
912
}

docs/entities/blocks/block.schema.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"title": "Block",
44
"description": "A block",
55
"type": "object",
6-
"required": ["canonical", "height", "hash", "parent_block_hash", "txs", "burn_block_time", "burn_block_time_iso"],
6+
"required": ["canonical", "height", "hash", "parent_block_hash", "txs", "burn_block_time", "burn_block_time_iso", "burn_block_hash", "burn_block_height", "miner_txid"],
77
"properties": {
88
"canonical": {
99
"type": "boolean",
@@ -19,7 +19,7 @@
1919
},
2020
"parent_block_hash": {
2121
"type": "string",
22-
"description": "Hash of the prant block"
22+
"description": "Hash of the parent block"
2323
},
2424
"burn_block_time": {
2525
"type": "number",
@@ -29,6 +29,18 @@
2929
"type": "string",
3030
"description": "An ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) indicating when this block was mined."
3131
},
32+
"burn_block_hash": {
33+
"type": "string",
34+
"description": "Hash of the anchor chain block"
35+
},
36+
"burn_block_height": {
37+
"type": "integer",
38+
"description": "Height of the anchor chain block"
39+
},
40+
"miner_txid": {
41+
"type": "string",
42+
"description": "Anchor chain transaction ID"
43+
},
3244
"txs": {
3345
"type": "array",
3446
"description": "List of transactions included in the block",

docs/index.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ export interface Block {
696696
*/
697697
hash: string;
698698
/**
699-
* Hash of the prant block
699+
* Hash of the parent block
700700
*/
701701
parent_block_hash: string;
702702
/**
@@ -707,6 +707,18 @@ export interface Block {
707707
* An ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) indicating when this block was mined.
708708
*/
709709
burn_block_time_iso: string;
710+
/**
711+
* Hash of the anchor chain block
712+
*/
713+
burn_block_hash: string;
714+
/**
715+
* Height of the anchor chain block
716+
*/
717+
burn_block_height: number;
718+
/**
719+
* Anchor chain transaction ID
720+
*/
721+
miner_txid: string;
710722
/**
711723
* List of transactions included in the block
712724
*/

follower.Dockerfile

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,8 @@ RUN npm install
88
RUN npm run build
99
RUN npm prune --production
1010

11-
1211
### Fetch stacks-node binary
13-
FROM everpeace/curl-jq as stacks-node-build
14-
ENV ARTIFACTS "http://blockstack-stacks-blockchain_artifacts.storage.googleapis.com/index.json"
15-
RUN curl -s "$ARTIFACTS" --output ./artifacts-resp.json \
16-
&& cat ./artifacts-resp.json | jq -r '."stacks-node-krypton"."linux-x64".latest.url' > ./url \
17-
&& mkdir -p /app \
18-
&& echo "Fetching $(cat ./url)" \
19-
&& curl --compressed $(cat ./url) --output /stacks-node \
20-
&& chmod +x /stacks-node
21-
12+
FROM blockstack/stacks-blockchain:v23.0.0.10-krypton-stretch as stacks-node-build
2213

2314
### Begin building base image
2415
FROM ubuntu:focal
@@ -53,7 +44,7 @@ ENV PATH=$PATH:/home/stacky/.nvm/versions/node/v${NODE_VERSION}/bin
5344
RUN node -e 'console.log("Node.js runs")'
5445

5546
### Setup stacks-node
56-
COPY --from=stacks-node-build /stacks-node stacks-node/
47+
COPY --from=stacks-node-build /bin/stacks-node stacks-node/
5748
ENV PATH="$PATH:$HOME/stacks-node"
5849

5950
#### Copy stacks-node mocknet config

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"devenv:follower": "docker-compose -f docker-compose.dev.postgres.yml -f docker-compose.dev.stacks-blockchain-follower.yml up",
2525
"devenv:stop": "docker-compose -f docker-compose.dev.postgres.yml -f docker-compose.dev.stacks-blockchain.yml -f docker-compose.dev.bitcoind.yml down -v -t 0",
2626
"devenv:logs": "docker-compose -f docker-compose.dev.postgres.yml -f docker-compose.dev.stacks-blockchain.yml -f docker-compose.dev.bitcoind.yml logs -t -f",
27-
"docs:generate": "cd docs && npm run generate:types && npm run generate:docs && cd ../client && typedoc",
27+
"docs:generate": "cd docs && npm run generate:types && npm run generate:docs && cd ../client && npm run generate:docs",
2828
"docs:deploy": "npm run docs:generate && cd docs && gulp deployDocs"
2929
},
3030
"repository": {

src/api/controllers/db-controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ export async function getBlockFromDataStore(
293293
parent_block_hash: dbBlock.parent_block_hash,
294294
burn_block_time: dbBlock.burn_block_time,
295295
burn_block_time_iso: unixEpochToIso(dbBlock.burn_block_time),
296+
burn_block_hash: dbBlock.burn_block_hash,
297+
burn_block_height: dbBlock.burn_block_height,
298+
miner_txid: dbBlock.miner_txid,
296299
txs: txIds.results,
297300
};
298301
return { found: true, result: apiBlock };

src/datastore/common.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import { getTxSenderAddress } from '../event-stream/reader';
1616
export interface DbBlock {
1717
block_hash: string;
1818
burn_block_time: number;
19+
burn_block_hash: string;
20+
burn_block_height: number;
21+
miner_txid: string;
1922
index_block_hash: string;
2023
parent_index_block_hash: string;
2124
parent_block_hash: string;

src/datastore/postgres-store.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ const MEMPOOL_TX_ID_COLUMNS = `
151151
`;
152152

153153
const BLOCK_COLUMNS = `
154-
block_hash, index_block_hash, parent_index_block_hash, parent_block_hash, parent_microblock, block_height, burn_block_time, canonical
154+
block_hash, index_block_hash, parent_index_block_hash, parent_block_hash, parent_microblock, block_height,
155+
burn_block_time, burn_block_hash, burn_block_height, miner_txid, canonical
155156
`;
156157

157158
interface BlockQueryResult {
@@ -162,6 +163,9 @@ interface BlockQueryResult {
162163
parent_microblock: Buffer;
163164
block_height: number;
164165
burn_block_time: number;
166+
burn_block_hash: Buffer;
167+
burn_block_height: number;
168+
miner_txid: Buffer;
165169
canonical: boolean;
166170
}
167171

@@ -787,8 +791,9 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte
787791
const result = await client.query(
788792
`
789793
INSERT INTO blocks(
790-
block_hash, index_block_hash, parent_index_block_hash, parent_block_hash, parent_microblock, block_height, burn_block_time, canonical
791-
) values($1, $2, $3, $4, $5, $6, $7, $8)
794+
block_hash, index_block_hash, parent_index_block_hash, parent_block_hash, parent_microblock, block_height,
795+
burn_block_time, burn_block_hash, burn_block_height, miner_txid, canonical
796+
) values($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
792797
ON CONFLICT (index_block_hash)
793798
DO NOTHING
794799
`,
@@ -800,6 +805,9 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte
800805
hexToBuffer(block.parent_microblock),
801806
block.block_height,
802807
block.burn_block_time,
808+
hexToBuffer(block.burn_block_hash),
809+
block.burn_block_height,
810+
hexToBuffer(block.miner_txid),
803811
block.canonical,
804812
]
805813
);
@@ -815,6 +823,9 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte
815823
parent_microblock: bufferToHexPrefixString(row.parent_microblock),
816824
block_height: row.block_height,
817825
burn_block_time: row.burn_block_time,
826+
burn_block_hash: bufferToHexPrefixString(row.burn_block_hash),
827+
burn_block_height: row.burn_block_height,
828+
miner_txid: bufferToHexPrefixString(row.miner_txid),
818829
canonical: row.canonical,
819830
};
820831
return block;

0 commit comments

Comments
 (0)