Skip to content

Commit 3535c11

Browse files
authored
feat: add /extended/v2/smart-contracts/status endpoint (#1833)
* feat: new endpoint * docs: openapi * feat: response type * fix: add route * fix: new schema * test: add * fix: rename result * docs: example result
1 parent dce6104 commit 3535c11

16 files changed

+406
-3
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.swap-helper-bridged-v1-1": {
3+
"found": true,
4+
"result": {
5+
"contract_id": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.swap-helper-bridged-v1-1",
6+
"status": "success",
7+
"tx_id": "0x8542d28e427256ea3c29dcd8793222891999ceff4ef1bb062e2f21cb6def6884",
8+
"block_height": 111021
9+
}
10+
},
11+
"SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60.name-registrar": {
12+
"found": true,
13+
"result": {
14+
"contract_id": "SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60.name-registrar",
15+
"status": "success",
16+
"tx_id": "0x6e1114cce8c6f2e9c8130f9acd75d67bb667ae584f882acdd2db6dd74e6cbe5e",
17+
"block_height": 113010
18+
}
19+
},
20+
"SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.stacking-dao-core-v1": {
21+
"found": true,
22+
"result": {
23+
"contract_id": "SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.stacking-dao-core-v1",
24+
"status": "pending",
25+
"tx_id": "0x10bdcf10ffee72994f493ac36760f4e95a76c8471370182fd4705c2153dc173d"
26+
}
27+
},
28+
"SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.stacking-dao-core": {
29+
"found": false
30+
}
31+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"description": "GET request that returns the deployment status of multiple smart contracts",
3+
"title": "SmartContractsStatusResponse",
4+
"type": "object",
5+
"additionalProperties": {
6+
"anyOf": [
7+
{
8+
"$ref": "./smart-contract-found.schema.json"
9+
},
10+
{
11+
"$ref": "./smart-contract-not-found.schema.json"
12+
}
13+
]
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type": "object",
3+
"title": "SmartContractFound",
4+
"additionalProperties": false,
5+
"required": ["found", "result"],
6+
"properties": {
7+
"found": {
8+
"type": "boolean",
9+
"enum": [true]
10+
},
11+
"result": {
12+
"$ref": "../../entities/smart-contracts/smart-contract-status.schema.json"
13+
}
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "object",
3+
"title": "SmartContractNotFound",
4+
"additionalProperties": false,
5+
"properties": {
6+
"found": {
7+
"type": "boolean",
8+
"enum": [false]
9+
}
10+
},
11+
"required": ["found"]
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"contract_id": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.swap-helper-bridged-v1-1",
3+
"status": "success",
4+
"tx_id": "0x8542d28e427256ea3c29dcd8793222891999ceff4ef1bb062e2f21cb6def6884",
5+
"block_height": 111021
6+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"title": "SmartContractStatus",
3+
"description": "Deployment status of a smart contract",
4+
"type": "object",
5+
"additionalProperties": false,
6+
"required": [
7+
"status",
8+
"tx_id",
9+
"contract_id"
10+
],
11+
"properties": {
12+
"status": {
13+
"type": "string",
14+
"description": "Smart contract deployment transaction status"
15+
},
16+
"tx_id": {
17+
"type": "string",
18+
"description": "Deployment transaction ID"
19+
},
20+
"contract_id": {
21+
"type": "string",
22+
"description": "Smart contract ID"
23+
},
24+
"block_height": {
25+
"type": "integer",
26+
"description": "Height of the transaction confirmation block"
27+
}
28+
}
29+
}

docs/generated.d.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ export type SchemaMergeRootStub =
9393
| SearchSuccessResult
9494
| TxSearchResult
9595
| SearchResult
96+
| SmartContractsStatusResponse
97+
| SmartContractFound
98+
| SmartContractNotFound
9699
| PoolDelegationsResponse
97100
| {
98101
[k: string]: unknown | undefined;
@@ -177,6 +180,7 @@ export type SchemaMergeRootStub =
177180
| RosettaSyncStatus
178181
| TransactionIdentifier
179182
| RosettaTransaction
183+
| SmartContractStatus
180184
| PoolDelegation
181185
| NonFungibleTokenHistoryEventWithTxId
182186
| NonFungibleTokenHistoryEventWithTxMetadata
@@ -3059,6 +3063,40 @@ export interface TxSearchResult {
30593063
metadata?: Transaction;
30603064
};
30613065
}
3066+
/**
3067+
* GET request that returns the deployment status of multiple smart contracts
3068+
*/
3069+
export interface SmartContractsStatusResponse {
3070+
[k: string]: (SmartContractFound | SmartContractNotFound) | undefined;
3071+
}
3072+
export interface SmartContractFound {
3073+
found: true;
3074+
result: SmartContractStatus;
3075+
}
3076+
/**
3077+
* Deployment status of a smart contract
3078+
*/
3079+
export interface SmartContractStatus {
3080+
/**
3081+
* Smart contract deployment transaction status
3082+
*/
3083+
status: string;
3084+
/**
3085+
* Deployment transaction ID
3086+
*/
3087+
tx_id: string;
3088+
/**
3089+
* Smart contract ID
3090+
*/
3091+
contract_id: string;
3092+
/**
3093+
* Height of the transaction confirmation block
3094+
*/
3095+
block_height?: number;
3096+
}
3097+
export interface SmartContractNotFound {
3098+
found: false;
3099+
}
30623100
/**
30633101
* GET request that returns stacking pool member details for a given pool (delegator) principal
30643102
*/

docs/openapi.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,36 @@ paths:
834834
example:
835835
$ref: ./api/transaction/get-transactions.example.json
836836

837+
/extended/v2/smart-contracts/status:
838+
get:
839+
summary: Get smart contracts status
840+
description: |
841+
Retrieves the deployment status of multiple smart contracts.
842+
tags:
843+
- Smart Contracts
844+
operationId: get_smart_contracts_status
845+
parameters:
846+
- name: contract_id
847+
in: query
848+
description: contract ids to fetch status for
849+
required: true
850+
style: form
851+
explode: true
852+
schema:
853+
type: array
854+
example: "SPQZF23W7SEYBFG5JQ496NMY0G7379SRYEDREMSV.Candy"
855+
items:
856+
type: string
857+
responses:
858+
200:
859+
description: List of smart contract status
860+
content:
861+
application/json:
862+
schema:
863+
$ref: ./api/smart-contracts/get-smart-contracts-status.schema.json
864+
example:
865+
$ref: ./api/smart-contracts/get-smart-contracts-status.example.json
866+
837867
/extended/v1/block:
838868
get:
839869
summary: Get recent blocks

src/api/controllers/db-controller.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ export function getTxTypeId(typeString: Transaction['tx_type']): DbTxTypeId[] {
149149
}
150150
}
151151

152-
function getTxStatusString(txStatus: DbTxStatus): TransactionStatus | MempoolTransactionStatus {
152+
export function getTxStatusString(
153+
txStatus: DbTxStatus
154+
): TransactionStatus | MempoolTransactionStatus {
153155
switch (txStatus) {
154156
case DbTxStatus.Pending:
155157
return 'pending';

src/api/init.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { createV2BlocksRouter } from './routes/v2/blocks';
5353
import { getReqQuery } from './query-helpers';
5454
import { createV2BurnBlocksRouter } from './routes/v2/burn-blocks';
5555
import { createMempoolRouter } from './routes/v2/mempool';
56+
import { createV2SmartContractsRouter } from './routes/v2/smart-contracts';
5657

5758
export interface ApiServer {
5859
expressApp: express.Express;
@@ -234,6 +235,7 @@ export async function startApiServer(opts: {
234235
const v2 = express.Router();
235236
v2.use('/blocks', createV2BlocksRouter(datastore));
236237
v2.use('/burn-blocks', createV2BurnBlocksRouter(datastore));
238+
v2.use('/smart-contracts', createV2SmartContractsRouter(datastore));
237239
v2.use('/mempool', createMempoolRouter(datastore));
238240
return v2;
239241
})()

0 commit comments

Comments
 (0)