@shipload/sdk 1.0.0-next.13 → 1.0.0-next.14
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 +129 -1
- package/lib/shipload.js +268 -18
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +261 -19
- 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/recipes.json +4 -4
- package/src/derivation/capabilities.ts +8 -8
- package/src/format.ts +26 -4
- package/src/index-module.ts +16 -2
- package/src/nft/atomicassets.ts +108 -0
- package/src/nft/index.ts +1 -0
- package/src/resolution/display-name.ts +4 -0
|
@@ -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
|
@@ -19,6 +19,10 @@ export function displayName(resolved: DisplayNameInput): string {
|
|
|
19
19
|
return resolved.name
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
export function displayNameWithTier(resolved: DisplayNameInput): string {
|
|
23
|
+
return `${displayName(resolved)} (T${resolved.tier})`
|
|
24
|
+
}
|
|
25
|
+
|
|
22
26
|
export interface DescribeOptions {
|
|
23
27
|
translate?: (key: string) => string
|
|
24
28
|
formatNumber?: (n: number) => string
|