@shipload/sdk 1.0.0-next.24 → 1.0.0-next.26

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.
@@ -11,6 +11,7 @@ import {
11
11
  import {deserializeAtomicData, type SchemaField} from './atomicdata'
12
12
  import {deserializeAsset, type NFTCargoItem, type NFTModuleSlot} from './deserializers'
13
13
  import type {ImmutableEntry} from './buildImmutableData'
14
+ import atomicAssetsAbi from './atomicassets.abi.json'
14
15
 
15
16
  const PLACEHOLDER_AUTH = PermissionLevel.from({
16
17
  actor: '............1',
@@ -20,6 +21,8 @@ const PLACEHOLDER_AUTH = PermissionLevel.from({
20
21
  export const ATOMICASSETS_ACCOUNT = 'atomicassets'
21
22
  export const SHIPLOAD_COLLECTION = 'shipload'
22
23
 
24
+ export const ATOMICASSETS_ABI = ABI.from(atomicAssetsAbi as ABIDef)
25
+
23
26
  const ATOMIC_ATTRIBUTE_VARIANT_NAME =
24
27
  'variant_int8_int16_int32_int64_uint8_uint16_uint32_uint64_float32_float64_string_INT8_VEC_INT16_VEC_INT32_VEC_INT64_VEC_UINT8_VEC_UINT16_VEC_UINT32_VEC_UINT64_VEC_FLOAT_VEC_DOUBLE_VEC_STRING_VEC'
25
28
 
@@ -147,6 +150,7 @@ export interface AtomicSchemaRow {
147
150
  export interface FetchAssetsOptions {
148
151
  collection?: NameType
149
152
  pageSize?: number
153
+ account?: NameType
150
154
  }
151
155
 
152
156
  export async function fetchAtomicAssetsForOwner(
@@ -156,11 +160,12 @@ export async function fetchAtomicAssetsForOwner(
156
160
  ): Promise<AtomicAssetRow[]> {
157
161
  const collection = opts.collection ? String(Name.from(opts.collection)) : undefined
158
162
  const pageSize = opts.pageSize ?? 1000
163
+ const account = Name.from(opts.account ?? ATOMICASSETS_ACCOUNT)
159
164
  const out: AtomicAssetRow[] = []
160
165
  let lower: UInt64 | undefined
161
166
  while (true) {
162
167
  const res = await client.v1.chain.get_table_rows({
163
- code: Name.from(ATOMICASSETS_ACCOUNT),
168
+ code: account,
164
169
  scope: String(Name.from(owner)),
165
170
  table: Name.from('assets'),
166
171
  limit: pageSize,
@@ -178,13 +183,14 @@ export async function fetchAtomicAssetsForOwner(
178
183
 
179
184
  export async function fetchAtomicSchemas(
180
185
  client: APIClient,
181
- collection: NameType
186
+ collection: NameType,
187
+ account: NameType = ATOMICASSETS_ACCOUNT
182
188
  ): Promise<AtomicSchemaRow[]> {
183
189
  const out: AtomicSchemaRow[] = []
184
190
  let lower: Name | undefined
185
191
  while (true) {
186
192
  const res = await client.v1.chain.get_table_rows({
187
- code: Name.from(ATOMICASSETS_ACCOUNT),
193
+ code: Name.from(account),
188
194
  scope: String(Name.from(collection)),
189
195
  table: Name.from('schemas'),
190
196
  limit: 100,
@@ -60,7 +60,10 @@ export function scheduleRemaining(entity: ScheduleData, now: Date): number {
60
60
  }
61
61
 
62
62
  export function scheduleComplete(entity: ScheduleData, now: Date): boolean {
63
- return hasSchedule(entity) && scheduleRemaining(entity, now) === 0
63
+ if (!hasSchedule(entity)) return false
64
+ if ((entity.schedule?.tasks ?? []).some((t) => t.type.toNumber() === TaskType.RESERVED))
65
+ return false
66
+ return scheduleRemaining(entity, now) === 0
64
67
  }
65
68
 
66
69
  export function currentTaskIndex(entity: ScheduleData, now: Date): number {
@@ -124,6 +127,8 @@ export function getTaskRemaining(entity: ScheduleData, index: number, now: Date)
124
127
  export function isTaskComplete(entity: ScheduleData, index: number, now: Date): boolean {
125
128
  if (!entity.schedule || index < 0 || index >= entity.schedule.tasks.length) return false
126
129
 
130
+ if (entity.schedule.tasks[index].type.toNumber() === TaskType.RESERVED) return false
131
+
127
132
  const taskDuration = entity.schedule.tasks[index].duration.toNumber()
128
133
  const taskElapsed = getTaskElapsed(entity, index, now)
129
134
  return taskElapsed >= taskDuration
package/src/shipload.ts CHANGED
@@ -18,6 +18,7 @@ interface ShiploadOptions {
18
18
  serverContractName?: string
19
19
  client?: APIClient
20
20
  subscriptionsUrl?: string
21
+ atomicAssetsAccount?: string
21
22
  }
22
23
 
23
24
  interface ShiploadConstructorOptions extends ShiploadOptions {
@@ -40,7 +41,12 @@ export class Shipload {
40
41
  ? serverContract
41
42
  : new ServerContract.Contract({client: apiClient})
42
43
 
43
- this._context = new GameContext(apiClient, server, platform)
44
+ this._context = new GameContext(
45
+ apiClient,
46
+ server,
47
+ platform,
48
+ constructorOptions?.atomicAssetsAccount ?? 'atomicassets'
49
+ )
44
50
 
45
51
  if (constructorOptions?.subscriptionsUrl) {
46
52
  this._context.setSubscriptionsUrl(constructorOptions.subscriptionsUrl)
@@ -80,6 +86,10 @@ export class Shipload {
80
86
  return this._context.client
81
87
  }
82
88
 
89
+ get atomicAssetsAccount(): string {
90
+ return this._context.atomicAssetsAccount
91
+ }
92
+
83
93
  get server(): Contract {
84
94
  return this._context.server
85
95
  }
package/src/types.ts CHANGED
@@ -55,6 +55,7 @@ export enum TaskType {
55
55
  DEMOLISH = 13,
56
56
  CLAIMPLOT = 14,
57
57
  BUILDPLOT = 15,
58
+ RESERVED = 16,
58
59
  }
59
60
 
60
61
  export enum LocationType {
@@ -1,8 +0,0 @@
1
- import {UInt32, type UInt64} from '@wharfkit/antelope'
2
- import type {LoaderCapability} from '../types/capabilities'
3
-
4
- export function calcLoadDuration(entity: LoaderCapability, cargoMass: UInt64): UInt32 {
5
- const totalThrust = entity.loaders.thrust.toNumber() * entity.loaders.quantity.toNumber()
6
- if (totalThrust === 0) return UInt32.from(0)
7
- return UInt32.from(Math.ceil(Number(cargoMass) / totalThrust))
8
- }