Skip to content

Commit

Permalink
feat: add mempool openapi docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie authored and zone117x committed Aug 26, 2020
1 parent 731fb20 commit b981c49
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 11 deletions.
87 changes: 87 additions & 0 deletions docs/api/transaction/get-mempool-transactions.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"limit": 96,
"offset": 0,
"total": 5,
"results": [
{
"tx_id": "0xb31df5a363dad31723324cb5e0eefa04d491519fd30827a521cbc830114aa50c",
"tx_status": "pending",
"tx_type": "token_transfer",
"receipt_time": 1598288370,
"receipt_time_iso": "2020-08-24T16:59:30.000Z",
"fee_rate": "180",
"sender_address": "STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6",
"sponsored": false,
"post_condition_mode": "deny",
"token_transfer": {
"recipient_address": "ST1GY25DM8RZV4X15X07THRZ2C5NMWPGQWKFGV87F",
"amount": "500000",
"memo": "0x46617563657400000000000000000000000000000000000000000000000000000000"
}
},
{
"tx_id": "0x5bed8e3f801cb4e2c74d2815a092f7c1c6a35f2fce4a80c80ca70848d34cb395",
"tx_status": "pending",
"tx_type": "token_transfer",
"receipt_time": 1598282326,
"receipt_time_iso": "2020-08-24T15:18:46.000Z",
"fee_rate": "180",
"sender_address": "ST1PS1KF93VBY5A1JV7TM66KN046KP3E3761DBSAG",
"sponsored": false,
"post_condition_mode": "deny",
"token_transfer": {
"recipient_address": "ST2H33S8SEY27QKEKQKR6S5PECYPKY45CQYGGQR8X",
"amount": "1000",
"memo": "0x00000000000000000000000000000000000000000000000000000000000000000000"
}
},
{
"tx_id": "0x9916036fde08a207e581cdcabc18ff55469861cb81194ab0e3e7c9a02cd5a17c",
"tx_status": "pending",
"tx_type": "smart_contract",
"receipt_time": 1598258958,
"receipt_time_iso": "2020-08-24T08:49:18.000Z",
"fee_rate": "2000",
"sender_address": "ST2R1XSFXYHCSFE426HP45TTD8ZWV9XHX2SRP3XA8",
"sponsored": false,
"post_condition_mode": "deny",
"post_conditions": [],
"smart_contract": {
"contract_id": "ST2R1XSFXYHCSFE426HP45TTD8ZWV9XHX2SRP3XA8.test-loans-1",
"source_code": "(define-data-var stx-loaned int 0)\n(define-data-var lockup-period int 0)\n(define-data-var stx-return int 0)\n(define-public (get-stx-return (stx uint) (months uint))\n (ok\n (begin\n (var-set stx-loaned (to-int(stx))\n (var-set lockup-period (to-int(months))\n (calculate-stx-return)\n (print (var-get stx-return))\n (transfer-to-server)\n )\n )\n)\n(define-private (calculate-stx-return)\n (ok\n (begin\n (var-set stx-return (- (+ (* (/ (* (var-get stx-loaned) 5) 100) (var-get lockup-period)) (var-get stx-loaned)) 5))\n )\n )\n)\n(define-private (transfer-to-server)\n (begin\n (unwrap-panic (stx-transfer? (to-uint (var-get stx-loaned)) tx-sender 'ST2R1XSFXYHCSFE426HP45TTD8ZWV9XHX2SRP3XA8))\n (ok (to-uint (var-get stx-loaned)))\n )\n)"
}
},
{
"tx_id": "0x871fb186c8d6ac6ede2822c71074d9884b593c0d7f2d0d6e8516e615484d7501",
"tx_status": "pending",
"tx_type": "smart_contract",
"receipt_time": 1598230365,
"receipt_time_iso": "2020-08-24T00:52:45.000Z",
"fee_rate": "2000",
"sender_address": "ST1FJGMWPGM1P7N0K3N9QEPZK5H1VDC5YWTVMEAZ1",
"sponsored": false,
"post_condition_mode": "deny",
"post_conditions": [],
"smart_contract": {
"contract_id": "ST1FJGMWPGM1P7N0K3N9QEPZK5H1VDC5YWTVMEAZ1.contract-hook-1598230358601",
"source_code": ";; ## CUSTOM FUNCTION TO EXTRACT A SUBSTRING\n\n(define-read-only (subs (source (buff 10)) \n (start int) \n (end int))\n (begin\n (unwrap-panic (if (and (<= 0 start) (<= start 10)) (ok 1) (err \"Out of bounds: start\")))\n (unwrap-panic (if (and (<= 0 end) (<= end 10)) (ok 1) (err \"Out of bounds: end\")))\n (let ((temp1 (fold subs1 source \n {start: start, end: end, cursor: 1, data: \"\"})))\n (let ((data (get data temp1))) \n data))))\n \n;; Call the function to extract the substring between the bounds:\n\n;; (subs \"123456789\" 2 5)\n\n(define-read-only (subs1 \n (ch (buff 1))\n (acc {data: (buff 10), \n start: int,\n end: int,\n cursor: int})) \n (let ((data (get data acc))\n (start (get start acc))\n (cursor (get cursor acc))\n (end (get end acc))) \n (let ((temp2 \n {cursor: (+ 1 cursor),\n data: (default-to \"\"\n (as-max-len?\n (concat data \n (if (let ((temp3 start)\n (temp4 cursor)\n (temp5 end))\n (and (<= temp3 temp4)\n (<= temp4 temp5)))\n ch \n \"\"))\n u10))}))\n {start: (get start acc),\n end: (get end acc),\n cursor: (get cursor temp2),\n data: (get data temp2)})))\n"
}
},
{
"tx_id": "0x66df10d99d3a26018f521d60e9f744b083386c73e47ad39c394d570abee55f1f",
"tx_status": "pending",
"tx_type": "smart_contract",
"receipt_time": 1598230066,
"receipt_time_iso": "2020-08-24T00:47:46.000Z",
"fee_rate": "2000",
"sender_address": "ST1FJGMWPGM1P7N0K3N9QEPZK5H1VDC5YWTVMEAZ1",
"sponsored": false,
"post_condition_mode": "deny",
"post_conditions": [],
"smart_contract": {
"contract_id": "ST1FJGMWPGM1P7N0K3N9QEPZK5H1VDC5YWTVMEAZ1.contract-hook-1598230054238",
"source_code": "(define-read-only (subs1 \n (ch (buff 1))\n (acc {data: (buff 10), \n start: int,\n end: int,\n cursor: int}))\n (begin\n (unwrap-panic (if (and (<= 1 (get start acc)) (<= (get start acc) 10)) (ok 1) (err \"Out of bounds: start\")))\n (unwrap-panic (if (and (<= 1 (get end acc)) (<= (get end acc) 10)) (ok 1) (err \"Out of bounds: end\")))\n (unwrap-panic (if (and (<= 1 (get cursor acc)) (<= (get cursor acc) 10)) (ok 1) (err \"Out of bounds: cursor\")))\n (let ((data (get data acc))\n (start (get start acc))\n (cursor (get cursor acc))\n (end (get end acc))) \n (let ((temp1 \n {cursor: (+ 1 cursor),\n data: (default-to \"\"\n (as-max-len?\n (concat data \n (if (let ((temp2 start)\n (temp3 cursor)\n (temp4 end))\n (and (<= temp2 temp3)\n (<= temp3 temp4)))\n ch \n \"\"))\n u10))}))\n {start: (get start acc),\n end: (get end acc),\n cursor: (get cursor temp1),\n data: (get data temp1)}))))\n"
}
}
]
}
39 changes: 28 additions & 11 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ paths:
example:
$ref: ./api/faucet/run-faucet.example.json
500:
description: Failed to run faucet
description: Failed to run faucet
/extended/v1/faucets/btc:
parameters:
- name: address
Expand All @@ -84,17 +84,17 @@ paths:
example:
$ref: ./api/faucet/run-faucet.example.json
500:
description: Failed to run faucet
description: Failed to run faucet

/extended/v1/tx:
get:
summary: Get recent transactions
tags:
- Transactions
operationId: get_transaction_list
description: |
description: |
Get all recently mined transactions
If using TypeScript, import typings for this response from our types package:
`import type { TransactionResults } from '@blockstack/stacks-blockchain-api-types';`
Expand All @@ -108,6 +108,23 @@ paths:
example:
$ref: ./api/transaction/get-transactions.example.json

/extended/v1/tx/mempool:
get:
summary: Get mempool transactions
tags:
- Transactions
operationId: get_mempool_transaction_list
description: Get all recently-broadcast mempool transactions
responses:
200:
description: List of mempool transactions
content:
application/json:
schema:
$ref: ./api/transaction/get-mempool-transactions.schema.json
example:
$ref: ./api/transaction/get-mempool-transactions.example.json

/extended/v1/tx/stream:
get:
summary: Stream transaction events
Expand Down Expand Up @@ -204,12 +221,12 @@ paths:
$ref: ./api/blocks/get-blocks.example.json
/extended/v1/block/{block_hash}:
parameters:
- name: block_hash
in: path
description: Hash of the block
required: true
schema:
type: string
- name: block_hash
in: path
description: Hash of the block
required: true
schema:
type: string
get:
summary: Get block
description: Get a specific block by hash
Expand Down Expand Up @@ -281,7 +298,7 @@ paths:
$ref: ./entities/transaction-events/transaction-event.schema.json
example:
$ref: ./entities/transaction-events/transaction-event-smart-contract-log.example.json

/v2/contracts/interface/{stacks_address}/{contract_name}:
get:
summary: Get contract interface
Expand Down

0 comments on commit b981c49

Please sign in to comment.