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