@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.
@@ -0,0 +1,9 @@
1
+ export * from '@mysten/sui.js';
2
+ export { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
3
+ export * from '@mysten/bcs';
4
+ export { Obelisk } from './obelisk';
5
+ export { SuiAccountManager } from './libs/suiAccountManager';
6
+ export { SuiTxBlock } from './libs/suiTxBuilder';
7
+ export { SuiContractFactory } from './libs/suiContractFactory';
8
+ export { getMetadata } from './metadata';
9
+ export type * from './types';
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,125 +1130,85 @@ var Obelisk = class {
1130
1130
  async getWorld(worldObjectId) {
1131
1131
  return this.suiInteractor.getObject(worldObjectId);
1132
1132
  }
1133
- async getComponents(worldId, cursor, limit) {
1134
- const parentId = (await this.suiInteractor.getObject(worldId)).objectFields.comps.fields.id.id;
1135
- return await this.suiInteractor.getDynamicFields(parentId, cursor, limit);
1136
- }
1137
- async getComponentByName(worldId, componentName) {
1138
- const componentNameId = `${componentName}`;
1139
- const componentId = (0, import_keccak256.default)(componentNameId);
1140
- return await this.getComponent(worldId, componentId);
1141
- }
1142
- async getComponent(worldId, componentId) {
1143
- const componentIdValue = Array.from(componentId);
1144
- const parentId = (await this.suiInteractor.getObject(worldId)).objectFields.comps.fields.id.id;
1145
- const name = {
1146
- type: "address",
1147
- value: componentIdValue
1148
- };
1149
- return await this.suiInteractor.getDynamicFieldObject(parentId, name);
1133
+ async listSchemaNames(worldId) {
1134
+ const worldObject = await this.getObject(worldId);
1135
+ const newObjectContent = worldObject.objectFields;
1136
+ return newObjectContent["schemaNames"];
1150
1137
  }
1151
- async getComponentTable(worldId, componentName) {
1152
- let componentMoudleName = `${componentName}_comp`;
1138
+ async getEntity(worldId, schemaName, entityId) {
1139
+ const schemaMoudleName = `${schemaName}_schema`;
1153
1140
  const tx = new import_sui9.TransactionBlock();
1154
- let params = [tx.pure(worldId)];
1155
- const tableResult = await this.query[componentMoudleName].data(
1141
+ const params = [tx.pure(worldId)];
1142
+ if (entityId !== void 0) {
1143
+ params.push(tx.pure(entityId));
1144
+ }
1145
+ const getResult = await this.query[schemaMoudleName].get(
1156
1146
  tx,
1157
1147
  params
1158
1148
  );
1159
- const tableId = tableResult.results;
1160
- const bcs = new import_bcs.BCS((0, import_bcs.getSuiMoveConfig)());
1161
- let value = Uint8Array.from(tableId[0].returnValues[0][0]);
1162
- let data = bcs.de("address", value);
1163
- return "0x" + 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;
1161
+ }
1164
1162
  }
1165
- async getEntities(worldId, componentName, cursor, limit) {
1166
- let componentMoudleName = `${componentName}_comp`;
1163
+ async containEntity(worldId, schemaName, entityId) {
1164
+ const schemaMoudleName = `${schemaName}_schema`;
1167
1165
  const tx = new import_sui9.TransactionBlock();
1168
- let params = [tx.pure(worldId)];
1169
- 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(
1170
1171
  tx,
1171
1172
  params
1172
1173
  );
1173
- const entities = tableResult.results;
1174
- const bcs = new import_bcs.BCS((0, import_bcs.getSuiMoveConfig)());
1175
- let value = Uint8Array.from(entities[0].returnValues[0][0]);
1176
- let tableId = "0x" + bcs.de("address", value);
1177
- let dynamicFields = await this.suiInteractor.getDynamicFields(
1178
- tableId,
1179
- cursor,
1180
- limit
1181
- );
1182
- let objectIds = dynamicFields.data.map((field) => field.objectId);
1183
- let objectDatas = await this.suiInteractor.getEntitiesObjects(objectIds);
1184
- return {
1185
- data: objectDatas,
1186
- nextCursor: dynamicFields.nextCursor,
1187
- hasNextPage: dynamicFields.hasNextPage
1188
- };
1189
- }
1190
- async getEntity(worldId, componentName, entityId) {
1191
- let checkWorldId = normalizeHexAddress(worldId);
1192
- if (checkWorldId) {
1193
- worldId = checkWorldId;
1194
- } else {
1195
- return void 0;
1196
- }
1197
- let checkEntityId = normalizeHexAddress(entityId);
1198
- if (checkEntityId) {
1199
- entityId = checkEntityId;
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);
1200
1179
  } else {
1201
1180
  return void 0;
1202
1181
  }
1203
- const parentId = await this.getComponentTable(worldId, componentName);
1204
- const name = {
1205
- type: "address",
1206
- value: entityId
1207
- };
1208
- let dynamicFieldObject = await this.suiInteractor.getDynamicFieldObject(
1209
- parentId,
1210
- name
1211
- );
1212
- return dynamicFieldObject;
1213
1182
  }
1214
- // async getEntityData(
1183
+ // async getEntities(
1215
1184
  // worldId: string,
1216
- // componentName: string,
1217
- // entityId: string
1185
+ // schemaName: string,
1186
+ // cursor?: string,
1187
+ // limit?: number
1218
1188
  // ) {
1219
- // const parentId = await this.getComponentTable(worldId, componentName);
1220
- // const name = {
1221
- // type: 'address',
1222
- // value: entityId,
1223
- // } as DynamicFieldName;
1224
- // let dynamicFieldObject = await this.suiInteractor.getDynamicFieldObject(
1225
- // parentId,
1226
- // name
1227
- // );
1228
- // let componentMoudleName = `${componentName}_comp`;
1189
+ // let schemaMoudleName = `${schemaName}_schema`;
1229
1190
  // const tx = new TransactionBlock();
1230
- // let params = [] as SuiTxArgument[];
1231
- // const typeResult = (await this.query[componentMoudleName].types(
1191
+ // let params = [tx.pure(worldId)] as SuiTxArgument[];
1192
+ // const tableResult = (await this.query[schemaonentMoudleName].entities(
1232
1193
  // tx,
1233
1194
  // params
1234
1195
  // )) as DevInspectResults;
1235
- // let typeReturn = typeResult.results as SuiReturnValues;
1236
- // console.log(typeReturn[0].returnValues[0][0]);
1237
- // const typeBCS = new BCS(getSuiMoveConfig());
1238
- // let typeValue = Uint8Array.from(typeReturn[0].returnValues[0][0]);
1239
- // let typeData = typeBCS.de('vector<vector<u8>>', typeValue);
1240
- // console.log(typeData);
1241
- // const entityType = String.fromCharCode(...typeData[0]);
1242
- // let dynamicFieldContent = dynamicFieldObject.data!
1243
- // .content as DynamicFieldContentType;
1244
- // let entityValue = dynamicFieldContent.fields['value'];
1196
+ // const entities = tableResult.results as SuiReturnValues;
1245
1197
  // const bcs = new BCS(getSuiMoveConfig());
1246
- // let value = Uint8Array.from(entityValue);
1247
- // console.log(entityType);
1248
- // console.log(value);
1249
- // let data = bcs.de(entityType, value);
1250
- // console.log(data);
1251
- // 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
+ // };
1252
1212
  // }
1253
1213
  async getOwnedObjects(owner, cursor, limit) {
1254
1214
  const ownedObjects = await this.suiInteractor.getOwnedObjects(
@@ -1256,9 +1216,9 @@ var Obelisk = class {
1256
1216
  cursor,
1257
1217
  limit
1258
1218
  );
1259
- let ownedObjectsRes = [];
1219
+ const ownedObjectsRes = [];
1260
1220
  for (const object of ownedObjects.data) {
1261
- let objectDetail = await this.getObject(object.data.objectId);
1221
+ const objectDetail = await this.getObject(object.data.objectId);
1262
1222
  if (objectDetail.objectType.split("::")[0] === this.contractFactory.packageId) {
1263
1223
  ownedObjectsRes.push(objectDetail);
1264
1224
  }
@@ -1266,7 +1226,7 @@ var Obelisk = class {
1266
1226
  return ownedObjectsRes;
1267
1227
  }
1268
1228
  async entity_key_from_object(objectId) {
1269
- let checkObjectId = normalizeHexAddress(objectId);
1229
+ const checkObjectId = normalizeHexAddress(objectId);
1270
1230
  if (checkObjectId !== null) {
1271
1231
  objectId = checkObjectId;
1272
1232
  return objectId;
@@ -1275,11 +1235,11 @@ var Obelisk = class {
1275
1235
  }
1276
1236
  }
1277
1237
  async entity_key_from_bytes(bytes) {
1278
- let hashBytes = (0, import_keccak256.default)(bytes);
1238
+ const hashBytes = (0, import_keccak256.default)(bytes);
1279
1239
  const hashU8Array = Array.from(hashBytes);
1280
1240
  const bcs = new import_bcs.BCS((0, import_bcs.getSuiMoveConfig)());
1281
- let value = Uint8Array.from(hashU8Array);
1282
- let data = bcs.de("address", value);
1241
+ const value = Uint8Array.from(hashU8Array);
1242
+ const data = bcs.de("address", value);
1283
1243
  return "0x" + data;
1284
1244
  }
1285
1245
  async entity_key_from_u256(x) {
@@ -1287,7 +1247,7 @@ var Obelisk = class {
1287
1247
  }
1288
1248
  async formatData(type, value) {
1289
1249
  const bcs = new import_bcs.BCS((0, import_bcs.getSuiMoveConfig)());
1290
- let u8Value = Uint8Array.from(value);
1250
+ const u8Value = Uint8Array.from(value);
1291
1251
  return bcs.de(type, u8Value);
1292
1252
  }
1293
1253
  };