Skip to content

Commit 46a64e2

Browse files
authored
AtomicAssets API documentation (#211)
1 parent 9e1a924 commit 46a64e2

File tree

7 files changed

+13672
-29
lines changed

7 files changed

+13672
-29
lines changed

docs/.vitepress/locales/en/components/sidebar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ export default [
290290
collapsed: true,
291291
items: [
292292
{text: 'Chain API', link: '/build/api-reference/rpc_api'},
293+
{text: 'AtomicAssets API', link: '/build/api-reference/atomic_api'},
293294
{text: 'CDT', link: '/build/api-reference/cdt_api'},
294295
],
295296
},

docs/.vitepress/theme/index.ts

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,45 @@ import type { Theme } from 'vitepress'
55
import './style.css'
66
import { theme, useOpenapi } from 'vitepress-openapi/client'
77
import 'vitepress-openapi/dist/style.css'
8-
import spec from '../../openapi/chain-openapi.json' with { type: 'json' }
98

10-
// Default servers fallback
11-
const defaultServers = [
12-
'https://wax.greymass.com'
13-
]
9+
// Global server fetching utility
10+
export const fetchWaxEndpoints = async () => {
11+
// Check cache first
12+
const cacheKey = 'wax-endpoints-cache'
13+
const cacheExpiry = 1000 * 60 * 60 * 24 // 24 hours in milliseconds
14+
15+
try {
16+
const cached = localStorage.getItem(cacheKey)
17+
if (cached) {
18+
const { endpoints: cachedEndpoints, timestamp } = JSON.parse(cached)
19+
const now = Date.now()
20+
21+
// Use cached endpoints if they're still valid
22+
if (now - timestamp < cacheExpiry) {
23+
console.log('Using cached endpoint list')
24+
return cachedEndpoints
25+
}
26+
}
27+
28+
// Fetch fresh data if cache is expired or doesn't exist
29+
console.log('Fetching fresh endpoint list')
30+
const response = await fetch('https://validate.eosnation.io/wax/reports/endpoints.json')
31+
const data = await response.json()
32+
const endpoints = data.report
33+
34+
// Cache the new data
35+
const cacheData = {
36+
endpoints,
37+
timestamp: Date.now()
38+
}
39+
localStorage.setItem(cacheKey, JSON.stringify(cacheData))
40+
41+
return endpoints
42+
} catch (err) {
43+
console.error('Failed to fetch endpoints, using defaults:', err)
44+
return null
45+
}
46+
}
1447

1548
/** @type {import('vitepress').Theme} */
1649
export default {
@@ -21,32 +54,8 @@ export default {
2154
})
2255
},
2356
async enhanceApp({ app, router, siteData }) {
24-
// Fetch dynamic servers
25-
let dynamicServers = defaultServers
26-
try {
27-
const response = await fetch('https://validate.eosnation.io/wax/reports/endpoints.json')
28-
const data = await response.json()
29-
dynamicServers = data.report.api_https2.map(item => item[1])
30-
} catch (err) {
31-
console.error('Failed to fetch dynamic servers, using defaults:', err)
32-
}
33-
3457
useOpenapi({
35-
spec: {
36-
...spec,
37-
servers: dynamicServers.map(item => ({
38-
url: `${item}/v1/chain`,
39-
})).sort((a, b) => {
40-
// if url contains greymass, it should be the first server
41-
if (a.url.includes('greymass')) return -1
42-
if (b.url.includes('greymass')) return 1
43-
return 0
44-
})
45-
},
4658
config: {
47-
operation: {
48-
defaultBaseUrl: 'https://wax.greymass.com/v1/chain',
49-
},
5059
spec: {
5160
groupByTags: false,
5261
},
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: WAX AtomicAssets API Reference
3+
aside: false
4+
outline: false
5+
---
6+
7+
<script setup>
8+
import { ref, onMounted, nextTick } from 'vue'
9+
import { useTheme } from 'vitepress-openapi/client'
10+
import { fetchWaxEndpoints } from '../../../.vitepress/theme/index.ts'
11+
import spec from '../../../openapi/atomic-openapi.json' with { type: 'json' }
12+
13+
// Default servers fallback
14+
const defaultServers = [
15+
'https://atomic.3dkrender.com'
16+
]
17+
18+
const dynamicSpec = ref(spec)
19+
20+
const updateSpecWithServers = async (endpoints) => {
21+
if (!endpoints) {
22+
// Use defaults if no endpoints available
23+
const defaultSpec = {
24+
...spec,
25+
servers: defaultServers.map(item => ({
26+
url: `${item}/v1/chain`,
27+
}))
28+
}
29+
dynamicSpec.value = defaultSpec
30+
return
31+
}
32+
33+
const dynamicServers = endpoints.atomic_https.map(item => item[1])
34+
const newSpec = {
35+
...spec,
36+
servers: dynamicServers.map(item => ({
37+
url: item,
38+
})),
39+
}
40+
41+
dynamicSpec.value = newSpec
42+
}
43+
44+
onMounted(async () => {
45+
const endpoints = await fetchWaxEndpoints()
46+
updateSpecWithServers(endpoints)
47+
})
48+
49+
useTheme({
50+
operation: {
51+
defaultBaseUrl: defaultServers[0],
52+
},
53+
})
54+
</script>
55+
56+
<OASpec
57+
:key="dynamicSpec.servers?.length || 0"
58+
:spec="dynamicSpec"
59+
hideBranding
60+
hideServers
61+
hidePathsSummary
62+
/>

docs/en/build/api-reference/rpc_api.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,63 @@ aside: false
44
outline: false
55
---
66

7+
<script setup>
8+
import { ref, onMounted, nextTick } from 'vue'
9+
import { useTheme } from 'vitepress-openapi/client'
10+
import { fetchWaxEndpoints } from '../../../.vitepress/theme/index.ts'
11+
import spec from '../../../openapi/chain-openapi.json' with { type: 'json' }
12+
13+
// Default servers fallback
14+
const defaultServers = [
15+
'https://wax.greymass.com'
16+
]
17+
18+
const dynamicSpec = ref(spec)
19+
20+
const updateSpecWithServers = async (endpoints) => {
21+
if (!endpoints) {
22+
// Use defaults if no endpoints available
23+
const defaultSpec = {
24+
...spec,
25+
servers: defaultServers.map(item => ({
26+
url: `${item}/v1/chain`,
27+
}))
28+
}
29+
dynamicSpec.value = defaultSpec
30+
return
31+
}
32+
33+
const dynamicServers = endpoints.api_https2.map(item => item[1])
34+
const newSpec = {
35+
...spec,
36+
servers: dynamicServers.map(item => ({
37+
url: `${item}/v1/chain`,
38+
})).sort((a, b) => {
39+
// if url contains greymass, it should be the first server
40+
if (a.url.includes('greymass')) return -1
41+
if (b.url.includes('greymass')) return 1
42+
return 0
43+
}),
44+
}
45+
46+
dynamicSpec.value = newSpec
47+
}
48+
49+
onMounted(async () => {
50+
const endpoints = await fetchWaxEndpoints()
51+
updateSpecWithServers(endpoints)
52+
})
53+
54+
useTheme({
55+
operation: {
56+
defaultBaseUrl: `${defaultServers[0]}/v1/chain`,
57+
},
58+
})
59+
</script>
60+
761
<OASpec
62+
:key="dynamicSpec.servers?.length || 0"
63+
:spec="dynamicSpec"
864
hideBranding
965
hideServers
1066
hidePathsSummary

0 commit comments

Comments
 (0)