@0xobelisk/client 0.3.1 → 0.3.2

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/dist/index.js CHANGED
@@ -918,10 +918,10 @@ var Obelisk = class {
918
918
  if (metadata !== void 0) {
919
919
  this.metadata = metadata;
920
920
  Object.values(metadata).forEach((value) => {
921
- let data = value;
922
- let moduleName = data.name;
921
+ const data = value;
922
+ const moduleName = data.name;
923
923
  Object.entries(data.exposedFunctions).forEach(([funcName, value2]) => {
924
- let meta = value2;
924
+ const meta = value2;
925
925
  meta.moudleName = moduleName;
926
926
  meta.funcName = funcName;
927
927
  if (isUndefined(__privateGet(this, _query)[moduleName])) {
@@ -1130,119 +1130,85 @@ var Obelisk = class {
1130
1130
  async getWorld(worldObjectId) {
1131
1131
  return this.suiInteractor.getObject(worldObjectId);
1132
1132
  }
1133
- async listComponentNames(worldId) {
1134
- let worldObject = await this.getObject(worldId);
1135
- let newObjectContent = worldObject.objectFields;
1136
- return newObjectContent["compnames"];
1133
+ async listSchemaNames(worldId) {
1134
+ const worldObject = await this.getObject(worldId);
1135
+ const newObjectContent = worldObject.objectFields;
1136
+ return newObjectContent["schemaNames"];
1137
1137
  }
1138
- async getEntity(worldId, componentName, entityId) {
1139
- let componentMoudleName = `${componentName}_comp`;
1138
+ async getEntity(worldId, schemaName, entityId) {
1139
+ const schemaMoudleName = `${schemaName}_schema`;
1140
1140
  const tx = new import_sui9.TransactionBlock();
1141
- let params = [tx.pure(worldId)];
1141
+ const params = [tx.pure(worldId)];
1142
1142
  if (entityId !== void 0) {
1143
1143
  params.push(tx.pure(entityId));
1144
1144
  }
1145
- const getResult = await this.query[componentMoudleName].get(
1145
+ const getResult = await this.query[schemaMoudleName].get(
1146
1146
  tx,
1147
1147
  params
1148
1148
  );
1149
- let returnValue = [];
1150
- let resultList = getResult.results[0].returnValues;
1151
- for (let res of resultList) {
1152
- const bcs = new import_bcs.BCS((0, import_bcs.getSuiMoveConfig)());
1153
- let value = Uint8Array.from(res[0]);
1154
- let data = bcs.de(res[1], value);
1155
- returnValue.push(data);
1149
+ const returnValue = [];
1150
+ if (getResult.effects.status.status === "success") {
1151
+ const resultList = getResult.results[0].returnValues;
1152
+ for (const res of resultList) {
1153
+ const bcs = new import_bcs.BCS((0, import_bcs.getSuiMoveConfig)());
1154
+ const value = Uint8Array.from(res[0]);
1155
+ const data = bcs.de(res[1], value);
1156
+ returnValue.push(data);
1157
+ }
1158
+ return returnValue;
1159
+ } else {
1160
+ return void 0;
1156
1161
  }
1157
- return returnValue;
1158
1162
  }
1159
- async getEntities(worldId, componentName, cursor, limit) {
1160
- let componentMoudleName = `${componentName}_comp`;
1163
+ async containEntity(worldId, schemaName, entityId) {
1164
+ const schemaMoudleName = `${schemaName}_schema`;
1161
1165
  const tx = new import_sui9.TransactionBlock();
1162
- let params = [tx.pure(worldId)];
1163
- const tableResult = await this.query[componentMoudleName].entities(
1166
+ const params = [tx.pure(worldId)];
1167
+ if (entityId !== void 0) {
1168
+ params.push(tx.pure(entityId));
1169
+ }
1170
+ const getResult = await this.query[schemaMoudleName].contains(
1164
1171
  tx,
1165
1172
  params
1166
1173
  );
1167
- const entities = tableResult.results;
1168
- const bcs = new import_bcs.BCS((0, import_bcs.getSuiMoveConfig)());
1169
- let value = Uint8Array.from(entities[0].returnValues[0][0]);
1170
- let tableId = "0x" + bcs.de("address", value);
1171
- let dynamicFields = await this.suiInteractor.getDynamicFields(
1172
- tableId,
1173
- cursor,
1174
- limit
1175
- );
1176
- let objectIds = dynamicFields.data.map((field) => field.objectId);
1177
- let objectDatas = await this.suiInteractor.getEntitiesObjects(objectIds);
1178
- return {
1179
- data: objectDatas,
1180
- nextCursor: dynamicFields.nextCursor,
1181
- hasNextPage: dynamicFields.hasNextPage
1182
- };
1174
+ if (getResult.effects.status.status === "success") {
1175
+ const res = getResult.results[0].returnValues[0];
1176
+ const bcs = new import_bcs.BCS((0, import_bcs.getSuiMoveConfig)());
1177
+ const value = Uint8Array.from(res[0]);
1178
+ return bcs.de(res[1], value);
1179
+ } else {
1180
+ return void 0;
1181
+ }
1183
1182
  }
1184
- // async getEntity(worldId: string, componentName: string, entityId: string) {
1185
- // let checkWorldId = normalizeHexAddress(worldId);
1186
- // if (checkWorldId) {
1187
- // worldId = checkWorldId;
1188
- // } else {
1189
- // return undefined;
1190
- // }
1191
- // let checkEntityId = normalizeHexAddress(entityId);
1192
- // if (checkEntityId) {
1193
- // entityId = checkEntityId;
1194
- // } else {
1195
- // return undefined;
1196
- // }
1197
- // const parentId = await this.getComponentTable(worldId, componentName);
1198
- // const name = {
1199
- // type: 'address',
1200
- // value: entityId,
1201
- // } as DynamicFieldName;
1202
- // let dynamicFieldObject = await this.suiInteractor.getDynamicFieldObject(
1203
- // parentId,
1204
- // name
1205
- // );
1206
- // return dynamicFieldObject;
1207
- // }
1208
- // async getEntityData(
1183
+ // async getEntities(
1209
1184
  // worldId: string,
1210
- // componentName: string,
1211
- // entityId: string
1185
+ // schemaName: string,
1186
+ // cursor?: string,
1187
+ // limit?: number
1212
1188
  // ) {
1213
- // const parentId = await this.getComponentTable(worldId, componentName);
1214
- // const name = {
1215
- // type: 'address',
1216
- // value: entityId,
1217
- // } as DynamicFieldName;
1218
- // let dynamicFieldObject = await this.suiInteractor.getDynamicFieldObject(
1219
- // parentId,
1220
- // name
1221
- // );
1222
- // let componentMoudleName = `${componentName}_comp`;
1189
+ // let schemaMoudleName = `${schemaName}_schema`;
1223
1190
  // const tx = new TransactionBlock();
1224
- // let params = [] as SuiTxArgument[];
1225
- // const typeResult = (await this.query[componentMoudleName].types(
1191
+ // let params = [tx.pure(worldId)] as SuiTxArgument[];
1192
+ // const tableResult = (await this.query[schemaonentMoudleName].entities(
1226
1193
  // tx,
1227
1194
  // params
1228
1195
  // )) as DevInspectResults;
1229
- // let typeReturn = typeResult.results as SuiReturnValues;
1230
- // console.log(typeReturn[0].returnValues[0][0]);
1231
- // const typeBCS = new BCS(getSuiMoveConfig());
1232
- // let typeValue = Uint8Array.from(typeReturn[0].returnValues[0][0]);
1233
- // let typeData = typeBCS.de('vector<vector<u8>>', typeValue);
1234
- // console.log(typeData);
1235
- // const entityType = String.fromCharCode(...typeData[0]);
1236
- // let dynamicFieldContent = dynamicFieldObject.data!
1237
- // .content as DynamicFieldContentType;
1238
- // let entityValue = dynamicFieldContent.fields['value'];
1196
+ // const entities = tableResult.results as SuiReturnValues;
1239
1197
  // const bcs = new BCS(getSuiMoveConfig());
1240
- // let value = Uint8Array.from(entityValue);
1241
- // console.log(entityType);
1242
- // console.log(value);
1243
- // let data = bcs.de(entityType, value);
1244
- // console.log(data);
1245
- // return data;
1198
+ // let value = Uint8Array.from(entities[0].returnValues[0][0]);
1199
+ // let tableId = '0x' + bcs.de('address', value);
1200
+ // let dynamicFields = await this.suiInteractor.getDynamicFields(
1201
+ // tableId,
1202
+ // cursor,
1203
+ // limit
1204
+ // );
1205
+ // let objectIds = dynamicFields.data.map((field) => field.objectId);
1206
+ // let objectDatas = await this.suiInteractor.getEntitiesObjects(objectIds);
1207
+ // return {
1208
+ // data: objectDatas,
1209
+ // nextCursor: dynamicFields.nextCursor,
1210
+ // hasNextPage: dynamicFields.hasNextPage,
1211
+ // };
1246
1212
  // }
1247
1213
  async getOwnedObjects(owner, cursor, limit) {
1248
1214
  const ownedObjects = await this.suiInteractor.getOwnedObjects(
@@ -1250,9 +1216,9 @@ var Obelisk = class {
1250
1216
  cursor,
1251
1217
  limit
1252
1218
  );
1253
- let ownedObjectsRes = [];
1219
+ const ownedObjectsRes = [];
1254
1220
  for (const object of ownedObjects.data) {
1255
- let objectDetail = await this.getObject(object.data.objectId);
1221
+ const objectDetail = await this.getObject(object.data.objectId);
1256
1222
  if (objectDetail.objectType.split("::")[0] === this.contractFactory.packageId) {
1257
1223
  ownedObjectsRes.push(objectDetail);
1258
1224
  }
@@ -1260,7 +1226,7 @@ var Obelisk = class {
1260
1226
  return ownedObjectsRes;
1261
1227
  }
1262
1228
  async entity_key_from_object(objectId) {
1263
- let checkObjectId = normalizeHexAddress(objectId);
1229
+ const checkObjectId = normalizeHexAddress(objectId);
1264
1230
  if (checkObjectId !== null) {
1265
1231
  objectId = checkObjectId;
1266
1232
  return objectId;
@@ -1269,11 +1235,11 @@ var Obelisk = class {
1269
1235
  }
1270
1236
  }
1271
1237
  async entity_key_from_bytes(bytes) {
1272
- let hashBytes = (0, import_keccak256.default)(bytes);
1238
+ const hashBytes = (0, import_keccak256.default)(bytes);
1273
1239
  const hashU8Array = Array.from(hashBytes);
1274
1240
  const bcs = new import_bcs.BCS((0, import_bcs.getSuiMoveConfig)());
1275
- let value = Uint8Array.from(hashU8Array);
1276
- let data = bcs.de("address", value);
1241
+ const value = Uint8Array.from(hashU8Array);
1242
+ const data = bcs.de("address", value);
1277
1243
  return "0x" + data;
1278
1244
  }
1279
1245
  async entity_key_from_u256(x) {
@@ -1281,7 +1247,7 @@ var Obelisk = class {
1281
1247
  }
1282
1248
  async formatData(type, value) {
1283
1249
  const bcs = new import_bcs.BCS((0, import_bcs.getSuiMoveConfig)());
1284
- let u8Value = Uint8Array.from(value);
1250
+ const u8Value = Uint8Array.from(value);
1285
1251
  return bcs.de(type, u8Value);
1286
1252
  }
1287
1253
  };