@shipload/sdk 1.0.0-next.13 → 1.0.0-next.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/shipload.d.ts +139 -5
- package/lib/shipload.js +297 -28
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +287 -28
- package/lib/shipload.m.js.map +1 -1
- package/lib/testing.d.ts +49 -0
- package/lib/testing.js +148 -1
- package/lib/testing.js.map +1 -1
- package/lib/testing.m.js +148 -1
- package/lib/testing.m.js.map +1 -1
- package/package.json +1 -1
- package/src/contracts/server.ts +106 -1
- package/src/data/kind-registry.ts +4 -0
- package/src/data/recipes.json +4 -4
- package/src/derivation/capabilities.ts +8 -8
- package/src/format.ts +26 -4
- package/src/index-module.ts +16 -1
- package/src/nft/atomicassets.ts +108 -0
- package/src/nft/index.ts +1 -0
- package/src/resolution/display-name.ts +32 -10
- package/src/types.ts +5 -2
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {type APIClient, Name, type NameType, UInt64} from '@wharfkit/antelope'
|
|
2
|
+
import {deserializeAtomicData, type SchemaField} from './atomicdata'
|
|
3
|
+
import {deserializeAsset, type NFTCargoItem, type NFTModuleSlot} from './deserializers'
|
|
4
|
+
|
|
5
|
+
export const ATOMICASSETS_ACCOUNT = 'atomicassets'
|
|
6
|
+
export const SHIPLOAD_COLLECTION = 'shipload'
|
|
7
|
+
|
|
8
|
+
export interface AtomicAssetRow {
|
|
9
|
+
asset_id: string
|
|
10
|
+
collection_name: string
|
|
11
|
+
schema_name: string
|
|
12
|
+
template_id: number
|
|
13
|
+
ram_payer?: string
|
|
14
|
+
backed_tokens?: string[]
|
|
15
|
+
immutable_serialized_data: string | number[]
|
|
16
|
+
mutable_serialized_data?: string | number[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AtomicSchemaRow {
|
|
20
|
+
schema_name: string
|
|
21
|
+
format: SchemaField[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface FetchAssetsOptions {
|
|
25
|
+
collection?: NameType
|
|
26
|
+
pageSize?: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function fetchAtomicAssetsForOwner(
|
|
30
|
+
client: APIClient,
|
|
31
|
+
owner: NameType,
|
|
32
|
+
opts: FetchAssetsOptions = {}
|
|
33
|
+
): Promise<AtomicAssetRow[]> {
|
|
34
|
+
const collection = opts.collection ? String(Name.from(opts.collection)) : undefined
|
|
35
|
+
const pageSize = opts.pageSize ?? 1000
|
|
36
|
+
const out: AtomicAssetRow[] = []
|
|
37
|
+
let lower: UInt64 | undefined
|
|
38
|
+
while (true) {
|
|
39
|
+
const res = await client.v1.chain.get_table_rows({
|
|
40
|
+
code: Name.from(ATOMICASSETS_ACCOUNT),
|
|
41
|
+
scope: String(Name.from(owner)),
|
|
42
|
+
table: Name.from('assets'),
|
|
43
|
+
limit: pageSize,
|
|
44
|
+
lower_bound: lower,
|
|
45
|
+
json: true,
|
|
46
|
+
})
|
|
47
|
+
for (const row of res.rows as AtomicAssetRow[]) {
|
|
48
|
+
if (!collection || row.collection_name === collection) out.push(row)
|
|
49
|
+
}
|
|
50
|
+
if (!res.more) break
|
|
51
|
+
lower = UInt64.from(String(res.next_key))
|
|
52
|
+
}
|
|
53
|
+
return out
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function fetchAtomicSchemas(
|
|
57
|
+
client: APIClient,
|
|
58
|
+
collection: NameType
|
|
59
|
+
): Promise<AtomicSchemaRow[]> {
|
|
60
|
+
const out: AtomicSchemaRow[] = []
|
|
61
|
+
let lower: Name | undefined
|
|
62
|
+
while (true) {
|
|
63
|
+
const res = await client.v1.chain.get_table_rows({
|
|
64
|
+
code: Name.from(ATOMICASSETS_ACCOUNT),
|
|
65
|
+
scope: String(Name.from(collection)),
|
|
66
|
+
table: Name.from('schemas'),
|
|
67
|
+
limit: 100,
|
|
68
|
+
lower_bound: lower,
|
|
69
|
+
json: true,
|
|
70
|
+
})
|
|
71
|
+
for (const row of res.rows as AtomicSchemaRow[]) out.push(row)
|
|
72
|
+
if (!res.more) break
|
|
73
|
+
lower = Name.from(String(res.next_key))
|
|
74
|
+
}
|
|
75
|
+
return out
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface DecodedAtomicAsset {
|
|
79
|
+
asset_id: bigint
|
|
80
|
+
schema_name: string
|
|
81
|
+
template_id: number
|
|
82
|
+
item_id: number
|
|
83
|
+
quantity: number
|
|
84
|
+
stats: string
|
|
85
|
+
origin_x: bigint
|
|
86
|
+
origin_y: bigint
|
|
87
|
+
modules?: NFTModuleSlot[]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function decodeAtomicAsset(
|
|
91
|
+
asset: AtomicAssetRow,
|
|
92
|
+
schemaFormat: SchemaField[],
|
|
93
|
+
itemId: number
|
|
94
|
+
): DecodedAtomicAsset {
|
|
95
|
+
const data = deserializeAtomicData(asset.immutable_serialized_data, schemaFormat)
|
|
96
|
+
const cargo: NFTCargoItem = deserializeAsset(data, itemId)
|
|
97
|
+
return {
|
|
98
|
+
asset_id: BigInt(String(asset.asset_id)),
|
|
99
|
+
schema_name: String(asset.schema_name),
|
|
100
|
+
template_id: Number(asset.template_id),
|
|
101
|
+
item_id: cargo.item_id,
|
|
102
|
+
quantity: cargo.quantity,
|
|
103
|
+
stats: cargo.stats,
|
|
104
|
+
origin_x: BigInt(String(data.origin_x ?? 0)),
|
|
105
|
+
origin_y: BigInt(String(data.origin_y ?? 0)),
|
|
106
|
+
modules: cargo.modules,
|
|
107
|
+
}
|
|
108
|
+
}
|
package/src/nft/index.ts
CHANGED
|
@@ -1,22 +1,44 @@
|
|
|
1
1
|
import type {ResolvedItem} from './resolve-item'
|
|
2
2
|
import type {ResourceCategory} from '../types'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
CATEGORY_LABELS,
|
|
5
|
+
RESOURCE_TIER_ADJECTIVES,
|
|
6
|
+
COMPONENT_TIER_PREFIXES,
|
|
7
|
+
MODULE_TIER_PREFIXES,
|
|
8
|
+
} from '../types'
|
|
4
9
|
import {formatMass as defaultFormatMass} from '../format'
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
itemType: 'resource' | 'component' | 'module' | 'entity' | string
|
|
11
|
+
interface DisplayNameInputCommon {
|
|
8
12
|
tier: number
|
|
9
13
|
category?: ResourceCategory
|
|
10
14
|
name: string
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
export type DisplayNameInput =
|
|
18
|
+
| (DisplayNameInputCommon & {itemType: 'resource' | 'component' | 'module' | 'entity' | string})
|
|
19
|
+
| (DisplayNameInputCommon & {type: string})
|
|
20
|
+
|
|
21
|
+
function itemTypeOf(item: DisplayNameInput): string {
|
|
22
|
+
return 'itemType' in item ? item.itemType : item.type
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function tierPrefix(item: DisplayNameInput): string | null {
|
|
26
|
+
const t = itemTypeOf(item)
|
|
27
|
+
if (t === 'resource') return RESOURCE_TIER_ADJECTIVES[item.tier] ?? null
|
|
28
|
+
if (t === 'component') return COMPONENT_TIER_PREFIXES[item.tier] ?? null
|
|
29
|
+
if (t === 'module') return MODULE_TIER_PREFIXES[item.tier] ?? null
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function baseName(item: DisplayNameInput): string {
|
|
34
|
+
if (itemTypeOf(item) !== 'resource') return item.name
|
|
35
|
+
return item.category ? CATEGORY_LABELS[item.category] : 'Resource'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function displayName(item: DisplayNameInput): string {
|
|
39
|
+
const prefix = tierPrefix(item)
|
|
40
|
+
const head = prefix ? `${prefix} ${baseName(item)}` : baseName(item)
|
|
41
|
+
return `${head} (T${item.tier})`
|
|
20
42
|
}
|
|
21
43
|
|
|
22
44
|
export interface DescribeOptions {
|
package/src/types.ts
CHANGED
|
@@ -120,7 +120,7 @@ export type ModuleType =
|
|
|
120
120
|
| 'storage'
|
|
121
121
|
| 'hauler'
|
|
122
122
|
|
|
123
|
-
export const
|
|
123
|
+
export const RESOURCE_TIER_ADJECTIVES: Record<number, string> = {
|
|
124
124
|
1: 'Crude',
|
|
125
125
|
2: 'Dense',
|
|
126
126
|
3: 'Pure',
|
|
@@ -133,6 +133,9 @@ export const TIER_ADJECTIVES: Record<number, string> = {
|
|
|
133
133
|
10: 'Ascendant',
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
export const COMPONENT_TIER_PREFIXES: Record<number, string> = {}
|
|
137
|
+
export const MODULE_TIER_PREFIXES: Record<number, string> = {}
|
|
138
|
+
|
|
136
139
|
export const CATEGORY_LABELS: Record<ResourceCategory, string> = {
|
|
137
140
|
ore: 'Ore',
|
|
138
141
|
crystal: 'Crystal',
|
|
@@ -158,5 +161,5 @@ export function formatTier(tier: number): string {
|
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
export function tierAdjective(tier: number): string {
|
|
161
|
-
return
|
|
164
|
+
return RESOURCE_TIER_ADJECTIVES[tier] ?? `T${tier}`
|
|
162
165
|
}
|