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