Merge pull request #4624 from mempool/nymkappa/api-key-rest

[doc] add accelerator rest api documentation
This commit is contained in:
softsimon 2024-02-11 20:02:41 +08:00 committed by GitHub
commit a40727b194
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 451 additions and 51 deletions

View File

@ -9871,7 +9871,403 @@ export const restApiDocsData = [
codeSampleBisq: emptyCodeSample,
}
}
},
{
type: "category",
category: "accelerator",
fragment: "accelerator",
title: "Accelerator",
showConditions: [""],
options: { officialOnly: true },
},
{
options: { officialOnly: true },
type: "endpoint",
category: "accelerator",
httpRequestMethod: "GET",
fragment: "accelerator-deposit-history",
title: "GET Deposit History",
description: {
default: "<p>Returns a list of deposits the user has made as prepayment for the accelerator service.</p>"
},
urlString: "/v1/services/accelerator/deposit-history",
showConditions: [""],
showJsExamples: showJsExamplesDefaultFalse,
codeExample: {
default: {
codeTemplate: {
curl: `/api/v1/services/accelerator/deposit-history`,
commonJS: ``,
esModule: ``
},
codeSampleMainnet: {
esModule: [],
commonJS: [],
curl: [],
headers: "api_key: stacksats",
response: `[
{
"type": "Bitcoin",
"invoiceId": "CCunucVyNw7jUiUz64mmHz",
"amount": 10311031,
"status": "pending",
"date": 1706372653000,
"link": "/payment/bitcoin/CCunucVyNw7jUiUz64mmHz"
},
{
"type": "Bitcoin",
"invoiceId": "SG1U27R9PdWi3gH3jB9tm9",
"amount": 21000000,
"status": "paid",
"date": 1706372582000,
"link": null
},
...
]`,
},
}
}
},
{
options: { officialOnly: true },
type: "endpoint",
category: "accelerator",
httpRequestMethod: "GET",
fragment: "accelerator-balance",
title: "GET Available Balance",
description: {
default: "<p>Returns the user's currently available balance, currently locked funds, and total fees paid so far.</p>"
},
urlString: "/v1/services/accelerator/balance",
showConditions: [""],
showJsExamples: showJsExamplesDefaultFalse,
codeExample: {
default: {
codeTemplate: {
curl: `/api/v1/services/accelerator/balance`,
commonJS: ``,
esModule: ``
},
codeSampleMainnet: {
esModule: [],
commonJS: [],
curl: [],
headers: "api_key: stacksats",
response: `{
"balance": 99900000,
"hold": 101829,
"feesPaid": 133721
}`,
},
}
}
},
{
options: { officialOnly: true },
type: "endpoint",
category: "accelerator",
httpRequestMethod: "POST",
fragment: "accelerator-estimate",
title: "POST Calculate Estimated Costs",
description: {
default: "<p>Returns estimated costs to accelerate a transaction.</p>"
},
urlString: "/v1/services/accelerator/estimate",
showConditions: [""],
showJsExamples: showJsExamplesDefaultFalse,
codeExample: {
default: {
codeTemplate: {
curl: `%{1}" "[[hostname]][[baseNetworkUrl]]/api/v1/services/accelerator/estimate`, //custom interpolation technique handled in replaceCurlPlaceholder()
commonJS: ``,
esModule: ``
},
codeSampleMainnet: {
esModule: [],
commonJS: [],
curl: ["txInput=ee13ebb99632377c15c94980357f674d285ac413452050031ea6dcd3e9b2dc29"],
headers: "api_key: stacksats",
response: `{
"txSummary": {
"txid": "ee13ebb99632377c15c94980357f674d285ac413452050031ea6dcd3e9b2dc29",
"effectiveVsize": 154,
"effectiveFee": 154,
"ancestorCount": 1
},
"cost": 3850,
"targetFeeRate": 26,
"nextBlockFee": 4004,
"userBalance": 99900000,
"mempoolBaseFee": 40000,
"vsizeFee": 50000,
"hasAccess": true
}`,
},
}
}
},
{
options: { officialOnly: true },
type: "endpoint",
category: "accelerator",
httpRequestMethod: "POST",
fragment: "accelerator-accelerate",
title: "POST Accelerate A Transaction",
description: {
default: "<p>Sends a request to accelerate a transaction.</p>"
},
urlString: "/v1/services/accelerator/accelerate",
showConditions: [""],
showJsExamples: showJsExamplesDefaultFalse,
codeExample: {
default: {
codeTemplate: {
curl: `%{1}" "[[hostname]][[baseNetworkUrl]]/api/v1/services/accelerator/accelerate`, //custom interpolation technique handled in replaceCurlPlaceholder()
commonJS: ``,
esModule: ``
},
codeSampleMainnet: {
esModule: [],
commonJS: [],
curl: ["txInput=ee13ebb99632377c15c94980357f674d285ac413452050031ea6dcd3e9b2dc29&userBid=21000000"],
headers: "api_key: stacksats",
response: `HTTP/1.1 200 OK`,
},
}
}
},
{
options: { officialOnly: true },
type: "endpoint",
category: "accelerator",
httpRequestMethod: "GET",
fragment: "accelerator-history",
title: "GET Private Acceleration History",
description: {
default: "<p>Returns the user's past acceleration requests.</p><p>Pass one of the following for <code>:status</code>: <code>all</code>, <code>requested</code>, <code>accelerating</code>, <code>mined</code>, <code>completed</code>, <code>failed</code>. Pass <code>true</code> in <code>:details</code> to get a detailed <code>history</code> of the acceleration request.</p>"
},
urlString: "/v1/services/accelerator/history?status=:status&details=:details",
showConditions: [""],
showJsExamples: showJsExamplesDefaultFalse,
codeExample: {
default: {
codeTemplate: {
curl: `/api/v1/services/accelerator/history?status=all&details=true`,
commonJS: ``,
esModule: ``
},
codeSampleMainnet: {
esModule: [],
commonJS: [],
curl: [],
headers: "api_key: stacksats",
response: `[
{
"id": 89,
"user_id": 1,
"txid": "ae2639469ec000ed1d14e2550cbb01794e1cd288a00cdc7cce18398ba3cc2ffe",
"status": "failed",
"estimated_fee": 247,
"fee_paid": 0,
"added": 1706378712,
"last_updated": 1706378712,
"confirmations": 4,
"base_fee": 0,
"vsize_fee": 0,
"max_bid": 7000,
"effective_vsize": 135,
"effective_fee": 3128,
"history": [
{
"event": "user-requested-acceleration",
"timestamp": 1706378712
},
{
"event": "accepted_test-api-key",
"timestamp": 1706378712
},
{
"event": "failed-at-block-827672",
"timestamp": 1706380261
}
]
},
{
"id": 88,
"user_id": 1,
"txid": "c5840e89173331760e959a190b24e2a289121277ed7f8a095fe289b37cee9fde",
"status": "completed",
"estimated_fee": 223,
"fee_paid": 140019,
"added": 1706378704,
"last_updated": 1706380231,
"confirmations": 6,
"base_fee": 40000,
"vsize_fee": 100000,
"max_bid": 14000,
"effective_vsize": 135,
"effective_fee": 3152,
"history": [
{
"event": "user-requested-acceleration",
"timestamp": 1706378704
},
{
"event": "accepted_test-api-key",
"timestamp": 1706378704
},
{
"event": "complete-at-block-827670",
"timestamp": 1706380231
}
]
},
{
"id": 87,
"user_id": 1,
"txid": "178b5b9b310f0d667d7ea563a2cdcc17bc8cd15261b58b1653860a724ca83458",
"status": "completed",
"estimated_fee": 115,
"fee_paid": 90062,
"added": 1706378684,
"last_updated": 1706380231,
"confirmations": 6,
"base_fee": 40000,
"vsize_fee": 50000,
"max_bid": 14000,
"effective_vsize": 135,
"effective_fee": 3260,
"history": [
{
"event": "user-requested-acceleration",
"timestamp": 1706378684
},
{
"event": "accepted_test-api-key",
"timestamp": 1706378684
},
{
"event": "complete-at-block-827670",
"timestamp": 1706380231
}
]
}
]`,
},
}
}
},
{
options: { officialOnly: true },
type: "endpoint",
category: "accelerator",
httpRequestMethod: "GET",
fragment: "accelerator-pending",
title: "GET Pending Accelerations",
description: {
default: "<p>Returns all transactions currently being accelerated.</p>"
},
urlString: "/v1/services/accelerator/accelerations",
showConditions: [""],
showJsExamples: showJsExamplesDefaultFalse,
codeExample: {
default: {
codeTemplate: {
curl: `/api/v1/services/accelerator/accelerations`,
commonJS: ``,
esModule: ``
},
codeSampleMainnet: {
esModule: [],
commonJS: [],
curl: [],
headers: '',
response: `[
{
"txid": "8a183c8ae929a2afb857e7f2acd440aaefdf2797f8f7eab1c5f95ff8602abc81",
"added": 1707558316,
"feeDelta": 3500,
"effectiveVsize": 111,
"effectiveFee": 1671,
"pools": [
111
]
},
{
"txid": "6097f295e21bdd8d725bd8d9ad4dd72b05bd795dc648bfef52150a9b2b7f7a45",
"added": 1707560464,
"feeDelta": 60000,
"effectiveVsize": 812,
"effectiveFee": 7790,
"pools": [
111
]
}
]`,
},
}
}
},
{
options: { officialOnly: true },
type: "endpoint",
category: "accelerator",
httpRequestMethod: "GET",
fragment: "accelerator-public-history",
title: "GET Public Acceleration History",
description: {
default: `<p>Returns all past accelerated transactions.
Filters can be applied:<ul>
<li><code>status</code>: <code>all</code>, <code>requested</code>, <code>accelerating</code>, <code>mined</code>, <code>completed</code>, <code>failed</code></li>
<li><code>timeframe</code>: <code>24h</code>, <code>3d</code>, <code>1w</code>, <code>1m</code>, <code>3m</code>, <code>6m</code>, <code>1y</code>, <code>2y</code>, <code>3y</code>, <code>all</code></li>
<li><code>poolUniqueId</code>: any id from <a target="_blank" href="https://github.com/mempool/mining-pools/blob/master/pools-v2.json">https://github.com/mempool/mining-pools/blob/master/pools-v2.json</a>
<li><code>blockHash</code>: a block hash</a>
<li><code>blockHeight</code>: a block height</a>
<li><code>page</code>: the requested page number if using pagination</a>
<li><code>pageLength</code>: the page lenght if using pagination</a>
</ul></p>`
},
urlString: "/v1/services/accelerator/accelerations/history",
showConditions: [""],
showJsExamples: showJsExamplesDefaultFalse,
codeExample: {
default: {
codeTemplate: {
curl: `/api/v1/services/accelerator/accelerations/history?blockHash=00000000000000000000482f0746d62141694b9210a813b97eb8445780a32003`,
commonJS: ``,
esModule: ``
},
codeSampleMainnet: {
esModule: [],
commonJS: [],
curl: [],
headers: '',
response: `[
{
"txid": "d7e1796d8eb4a09d4e6c174e36cfd852f1e6e6c9f7df4496339933cd32cbdd1d",
"status": "completed",
"feePaid": 53239,
"added": 1707421053,
"lastUpdated": 1707422952,
"baseFee": 50000,
"vsizeFee": 0,
"effectiveFee": 146,
"effectiveVsize": 141,
"feeDelta": 14000,
"blockHash": "00000000000000000000482f0746d62141694b9210a813b97eb8445780a32003",
"blockHeight": 829559,
"pools": [
{
"pool_unique_id": 111,
"username": "foundryusa"
}
]
}
]`,
},
}
}
},
];
export const faqData = [

View File

@ -1,4 +1,4 @@
<div *ngFor="let item of tabData">
<p *ngIf="( item.type === 'category' ) && ( item.showConditions.indexOf(network.val) > -1 )">{{ item.title }}</p>
<p *ngIf="( item.type === 'category' ) && ( item.showConditions.indexOf(network.val) > -1 ) && ( !item.hasOwnProperty('options') || ( item.hasOwnProperty('options') && item.options.hasOwnProperty('officialOnly') && item.options.officialOnly && officialMempoolInstance ))">{{ item.title }}</p>
<a *ngIf="( item.type !== 'category' ) && ( item.showConditions.indexOf(network.val) > -1 ) && ( !item.hasOwnProperty('options') || ( item.hasOwnProperty('options') && item.options.hasOwnProperty('officialOnly') && item.options.officialOnly && officialMempoolInstance ) || ( item.hasOwnProperty('options') && item.options.hasOwnProperty('auditOnly') && item.options.auditOnly && auditEnabled ) )" [routerLink]="['./']" fragment="{{ item.fragment }}" (click)="navLinkClick($event)">{{ item.title }}</a>
</div>

View File

@ -43,6 +43,7 @@
<p class="doc-welcome-note api-note" *ngIf="officialMempoolInstance">Note that we enforce rate limits. If you exceed these limits, you will get an HTTP 429 error. If you repeatedly exceed the limits, you may be banned from accessing the service altogether. Consider an <a href="https://mempool.space/enterprise">enterprise sponsorship</a> if you need higher API limits.</p>
<div class="doc-item-container" *ngFor="let item of restDocs">
<div *ngIf="!item.hasOwnProperty('options') || ( item.hasOwnProperty('options') && item.options.hasOwnProperty('officialOnly') && item.options.officialOnly && officialMempoolInstance )">
<h3 *ngIf="( item.type === 'category' ) && ( item.showConditions.indexOf(network.val) > -1 )">{{ item.title }}</h3>
<div *ngIf="( item.type !== 'category' ) && ( item.showConditions.indexOf(network.val) > -1 )" class="endpoint-container" id="{{ item.fragment }}">
<a id="{{ item.fragment + '-tab-header' }}" class="section-header" (click)="anchorLinkClick( $event )" [routerLink]="['./']" fragment="{{ item.fragment }}">{{ item.title }} <span>{{ item.category }}</span></a>
@ -94,6 +95,7 @@
</div>
</div>
</div>
</div>
</div>
</div>

View File

@ -311,27 +311,29 @@ yarn add @mempool/liquid.js`;
text = text.replace('%{' + indexNumber + '}', textReplace);
}
const headersString = code.headers ? ` -H "${code.headers}"` : ``;
if (this.env.BASE_MODULE === 'mempool') {
if (this.network === 'main' || this.network === '') {
if (this.method === 'POST') {
return `curl -X POST -sSLd "${text}"`;
return `curl${headersString} -X POST -sSLd "${text}"`;
}
return `curl -sSL "${this.hostname}${text}"`;
return `curl${headersString} -sSL "${this.hostname}${text}"`;
}
if (this.method === 'POST') {
return `curl -X POST -sSLd "${text}"`;
return `curl${headersString} -X POST -sSLd "${text}"`;
}
return `curl -sSL "${this.hostname}/${this.network}${text}"`;
return `curl${headersString} -sSL "${this.hostname}/${this.network}${text}"`;
} else if (this.env.BASE_MODULE === 'liquid') {
if (this.method === 'POST') {
if (this.network !== 'liquid') {
text = text.replace('/api', `/${this.network}/api`);
}
return `curl -X POST -sSLd "${text}"`;
return `curl${headersString} -X POST -sSLd "${text}"`;
}
return ( this.network === 'liquid' ? `curl -sSL "${this.hostname}${text}"` : `curl -sSL "${this.hostname}/${this.network}${text}"` );
return ( this.network === 'liquid' ? `curl${headersString} -sSL "${this.hostname}${text}"` : `curl${headersString} -sSL "${this.hostname}/${this.network}${text}"` );
} else {
return `curl -sSL "${this.hostname}${text}"`;
return `curl${headersString} -sSL "${this.hostname}${text}"`;
}
}