Skip to content

Commit 726c691

Browse files
authored
Merge pull request #1052 from hirosystems/develop
Merge develop in master -- release v2.1.0
2 parents cd51c1b + f9e88cb commit 726c691

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+987
-410
lines changed

.env

Lines changed: 10 additions & 0 deletions
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+
9+
# Can be any string, use to specify a use case specific to a deployment
10+
PG_APPLICATION_NAME=stacks-blockchain-api
11+
812
# The connection URI below can be used in place of the PG variables above,
913
# but if enabled it must be defined without others or omitted.
1014
# PG_CONNECTION_URI=
@@ -96,6 +100,12 @@ MAINNET_SEND_MANY_CONTRACT_ID=SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.send-man
96100
# STACKS_API_ENABLE_FT_METADATA=1
97101
# STACKS_API_ENABLE_NFT_METADATA=1
98102

103+
# Controls the token metadata error handling mode. The possible values are:
104+
# * `warning`: If required metadata is not found, the API will issue a warning and not display data for that token.
105+
# * `error`: If required metadata is not found, the API will throw an error.
106+
# If not specified or any other value is provided, the mode will be set to `warning`.
107+
# STACKS_API_TOKEN_METADATA_ERROR_MODE=
108+
99109
# Configure a script to handle image URLs during token metadata processing.
100110
# This example script uses the `imgix.net` service to create CDN URLs.
101111
# Must be an executable script that accepts the URL as the first program argument

.github/workflows/ci.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ jobs:
5757
working-directory: ./docs
5858
steps:
5959
- uses: actions/checkout@v2
60+
with:
61+
fetch-depth: 0
6062

6163
- name: Use Node.js
6264
uses: actions/setup-node@v2
@@ -290,12 +292,12 @@ jobs:
290292
run: echo "STACKS_CORE_EVENT_HOST=http://0.0.0.0">> $GITHUB_ENV
291293

292294
- name: Setup cli enviroment variable
293-
run: |
295+
run: |
294296
echo STACKS_BLOCKCHAIN_API_HOST=0.0.0.0>> .env
295297
echo STACKS_CORE_PROXY_HOST=0.0.0.0 >> .env
296298
echo STACKS_CORE_RPC_HOST=0.0.0.0 >> .env
297299
echo STACKS_CORE_EVENT_HOST=0.0.0.0 >> .env
298-
echo BTC_RPC_HOST=http://0.0.0.0 >> .env
300+
echo BTC_RPC_HOST=http://0.0.0.0 >> .env
299301
300302
- name: Setup integration environment
301303
run: |
@@ -347,14 +349,14 @@ jobs:
347349

348350
- name: Setup env vars
349351
run: echo "STACKS_CORE_EVENT_HOST=http://0.0.0.0">> $GITHUB_ENV
350-
352+
351353
- name: Setup cli enviroment variable
352-
run: |
354+
run: |
353355
echo STACKS_BLOCKCHAIN_API_HOST=0.0.0.0>> .env
354356
echo STACKS_CORE_PROXY_HOST=0.0.0.0 >> .env
355357
echo STACKS_CORE_RPC_HOST=0.0.0.0 >> .env
356358
echo STACKS_CORE_EVENT_HOST=0.0.0.0 >> .env
357-
echo BTC_RPC_HOST=http://0.0.0.0 >> .env
359+
echo BTC_RPC_HOST=http://0.0.0.0 >> .env
358360
359361
- name: Setup integration environment
360362
run: |

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"lint:openapi": "lint-openapi ./openapi.yaml",
1414
"generate:types": "ts-node ./scripts/generate-types.ts",
1515
"generate:schemas": "gulp && npm run generate:types",
16-
"generate:git-info": "npm run git-info --prefix .. && export API_VERSION=$(shx tail -n 1 ../.git-info) && speccy resolve --output .tmp/openapi.resolved.yaml openapi.yaml && shx sed -i 'STACKS_API_VERSION' ${API_VERSION:-1.0.0} .tmp/openapi.resolved.yaml > /dev/null",
16+
"generate:git-info": "npm run generate:git-info --prefix .. && export API_VERSION=$(shx tail -n 1 ../.git-info) && speccy resolve --output .tmp/openapi.resolved.yaml openapi.yaml && shx sed -i 'STACKS_API_VERSION' ${API_VERSION:-1.0.0} .tmp/openapi.resolved.yaml > /dev/null",
1717
"generate:docs": "redoc-cli bundle --output .tmp/index.html .tmp/openapi.resolved.yaml",
1818
"generate:postman": "openapi2postmanv2 --spec .tmp/openapi.resolved.yaml --output .tmp/collection.json --options folderStrategy=Tags,requestParametersResolution=Example,exampleParametersResolution=Example,schemaFaker=false 2>/dev/null",
1919
"validate:schemas": "rimraf .tmp && gulp flattenSchemas --silent && ts-node ./scripts/validate-schemas.ts",

git-info-generator.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { execSync } from 'child_process';
2+
import { writeFileSync } from 'fs';
3+
4+
try {
5+
execSync('git --version');
6+
} catch (error) {
7+
console.error(error.message);
8+
throw new Error(`git is missing, please install git and retry`);
9+
}
10+
const gitInfo = [
11+
'git rev-parse --abbrev-ref HEAD',
12+
'git log -1 --pretty=format:%h',
13+
'git describe --tags --abbrev=0',
14+
].map((r, index) => {
15+
try {
16+
return execSync(r, { encoding: 'utf8' }).trim();
17+
} catch (error) {
18+
console.error(error.message);
19+
if (index === 2) throw new Error(`no tag found fetch tags by running "git fetch --all --tags"`);
20+
throw error;
21+
}
22+
});
23+
writeFileSync('.git-info', gitInfo.join('\n'));

package-lock.json

Lines changed: 37 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"test:integration:bns": "npm run devenv:deploy -- -d && cross-env NODE_ENV=development jest --config ./jest.config.bns.js --coverage --no-cache --runInBand; npm run devenv:stop",
2121
"test:integration:microblocks": "npm run devenv:deploy:pg -- -d && cross-env NODE_ENV=development jest --config ./jest.config.microblocks.js --coverage --no-cache --runInBand; npm run devenv:stop:pg",
2222
"test:integration:tokens": "npm run devenv:deploy -- -d && cross-env NODE_ENV=development jest --config ./jest.config.tokens.js --coverage --no-cache --runInBand; npm run devenv:stop",
23-
"git-info": "echo \"$(git rev-parse --abbrev-ref HEAD)\n$(git log -1 --pretty=format:%h)\n$(git describe --tags --abbrev=0)\" > ./.git-info",
24-
"build": "npm run git-info && rimraf ./lib && tsc -p tsconfig.build.json",
23+
"generate:git-info": "node ./git-info-generator.mjs",
24+
"build": "npm run generate:git-info && rimraf ./lib && tsc -p tsconfig.build.json",
2525
"build:tests": "tsc -p tsconfig.json",
2626
"build:docs": "npm i --prefix docs && npm run build --prefix docs && npm i --prefix client && npm run generate:docs --prefix client",
2727
"start": "node ./lib/index.js",
@@ -127,7 +127,7 @@
127127
"lru-cache": "^6.0.0",
128128
"micro-base58": "^0.5.0",
129129
"node-fetch": "^2.6.0",
130-
"node-pg-migrate": "^5.9.0",
130+
"node-pg-migrate": "^6.2.1",
131131
"p-queue": "^6.3.0",
132132
"path-to-regexp": "^6.2.0",
133133
"pg": "^8.2.1",

src/api/controllers/db-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ export function parseContractCallMetadata(tx: BaseTx): ContractCallTransactionMe
695695
let functionAbi: ClarityAbiFunction | undefined;
696696
const abi = tx.abi;
697697
if (abi) {
698-
const contractAbi: ClarityAbi = typeof abi === 'string' ? JSON.parse(abi) : abi;
698+
const contractAbi: ClarityAbi = JSON.parse(abi);
699699
functionAbi = contractAbi.functions.find(fn => fn.name === functionName);
700700
if (!functionAbi) {
701701
throw new Error(`Could not find function name "${functionName}" in ABI for ${contractId}`);

src/api/routes/contract.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function createContractRouter(db: DataStore): express.Router {
3232
}
3333
const contractResults = smartContracts.result.map(contract => ({
3434
...contract,
35-
abi: JSON.stringify(contract.abi),
35+
abi: contract.abi,
3636
}));
3737
res.json({ limit, offset, results: contractResults });
3838
})
@@ -49,7 +49,7 @@ export function createContractRouter(db: DataStore): express.Router {
4949
}
5050
const contractResult = {
5151
...contractQuery.result,
52-
abi: JSON.stringify(contractQuery.result.abi),
52+
abi: contractQuery.result.abi,
5353
};
5454
res.json(contractResult);
5555
})

src/api/routes/debug.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ export function createDebugRouter(db: DataStore): express.Router {
755755
res.status(404).json({ error: `cannot find contract by ID ${contract_id}` });
756756
return;
757757
}
758-
const contractAbi: ClarityAbi = dbContractQuery.result.abi as any;
758+
const contractAbi: ClarityAbi = JSON.parse(dbContractQuery.result.abi as string);
759759
let formHtml = contractCallHtml;
760760
let funcHtml = '';
761761

@@ -805,7 +805,7 @@ export function createDebugRouter(db: DataStore): express.Router {
805805
res.status(404).json({ error: `could not find contract by ID ${contractId}` });
806806
return;
807807
}
808-
const contractAbi: ClarityAbi = dbContractQuery.result.abi as any;
808+
const contractAbi: ClarityAbi = JSON.parse(dbContractQuery.result.abi as string);
809809

810810
const body = req.body as Record<string, string>;
811811
const originKey = body['origin_key'];

src/api/routes/rosetta/account.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function createRosettaAccountRouter(db: DataStore, chainId: ChainID): exp
2727
asyncHandler(async (req, res) => {
2828
const valid: ValidSchema = await rosettaValidateRequest(req.originalUrl, req.body, chainId);
2929
if (!valid.valid) {
30-
res.status(500).json(makeRosettaError(valid));
30+
res.status(400).json(makeRosettaError(valid));
3131
return;
3232
}
3333

@@ -38,7 +38,7 @@ export function createRosettaAccountRouter(db: DataStore, chainId: ChainID): exp
3838
let blockHash: string = '0x';
3939

4040
if (accountIdentifier === undefined) {
41-
res.status(500).json(RosettaErrors[RosettaErrorsTypes.emptyAccountIdentifier]);
41+
res.status(400).json(RosettaErrors[RosettaErrorsTypes.emptyAccountIdentifier]);
4242
return;
4343
}
4444

@@ -55,7 +55,7 @@ export function createRosettaAccountRouter(db: DataStore, chainId: ChainID): exp
5555
}
5656
blockQuery = await db.getBlock({ hash: blockHash });
5757
} else {
58-
res.status(500).json(RosettaErrors[RosettaErrorsTypes.invalidBlockIdentifier]);
58+
res.status(400).json(RosettaErrors[RosettaErrorsTypes.invalidBlockIdentifier]);
5959
return;
6060
}
6161

@@ -67,7 +67,7 @@ export function createRosettaAccountRouter(db: DataStore, chainId: ChainID): exp
6767
const block = blockQuery.result;
6868

6969
if (blockIdentifier?.hash !== undefined && block.block_hash !== blockIdentifier.hash) {
70-
res.status(500).json(RosettaErrors[RosettaErrorsTypes.invalidBlockHash]);
70+
res.status(400).json(RosettaErrors[RosettaErrorsTypes.invalidBlockHash]);
7171
return;
7272
}
7373

@@ -114,7 +114,7 @@ export function createRosettaAccountRouter(db: DataStore, chainId: ChainID): exp
114114
}
115115
break;
116116
default:
117-
res.status(500).json(RosettaErrors[RosettaErrorsTypes.invalidSubAccount]);
117+
res.status(400).json(RosettaErrors[RosettaErrorsTypes.invalidSubAccount]);
118118
return;
119119
}
120120
}

0 commit comments

Comments
 (0)