Comparing version 0.0.41 to 0.0.42
@@ -160,15 +160,9 @@ const sui = require('@mysten/sui.js'); | ||
do { | ||
await paginatedResponse.nextPage(); | ||
if (paginatedResponse.data && paginatedResponse.data.length) { | ||
for (const object of paginatedResponse.data) { | ||
if (object?.data?.content?.fields?.package) { | ||
if (packagesOnChainIds.indexOf(object?.data?.content?.fields?.package) === -1) { | ||
packagesOnChainIds.push(object?.data?.content?.fields?.package); | ||
} | ||
} | ||
} | ||
await paginatedResponse.forEach((suiObject)=>{ | ||
const packageId = suiObject.fields.package; | ||
if (packageId && packagesOnChainIds.indexOf(packageId) === -1) { | ||
packagesOnChainIds.push(packageId); | ||
} | ||
} while(paginatedResponse.hasNextPage); | ||
}); // go through all available UpgradeCap | ||
// paginatedResponse.forEach also accepts async callbacks | ||
@@ -175,0 +169,0 @@ // queriing packages out of the loop, as not sure if pagination cursor works ok with mixed calls, @todo: check |
@@ -226,2 +226,37 @@ const sui = require('@mysten/sui.js'); | ||
} | ||
async getOwnedObjects(params = {}) { | ||
/// | ||
/// the pagination is not accurate, because previous page may have | ||
/// been updated when the next page is fetched. Please use suix_queryObjects if this is a concern. | ||
/// | ||
const normalizedPackageAddress = await this.getNormalizedPackageAddress(); | ||
const queryParams = { | ||
owner: this._suiMaster.address, | ||
filter: { MoveModule: { package: normalizedPackageAddress, module: this._moduleName } }, | ||
limit: 50, // max limit is 50 | ||
options: { | ||
showType: true, | ||
showContent: true, | ||
showOwner: true, | ||
showDisplay: true, | ||
}, | ||
}; | ||
if (params.typeName) { | ||
queryParams.filter = { StructType: `${normalizedPackageAddress}::${this._moduleName}::${params.typeName}`}; | ||
} | ||
const paginatedResponse = new SuiPaginatedResponse({ | ||
debug: this._debug, | ||
suiMaster: this._suiMaster, | ||
params: queryParams, | ||
method: 'getOwnedObjects', | ||
order: params.order, | ||
}); | ||
await paginatedResponse.fetch(); | ||
return paginatedResponse; | ||
} | ||
@@ -228,0 +263,0 @@ async fetchEvents(params = {}) { |
@@ -88,4 +88,7 @@ const sui = require('@mysten/sui.js'); | ||
} else if (this._method === 'queryTransactionBlocks') { | ||
// convert data to SuiEvent instances | ||
// convert data to SuiTransaction instances | ||
this._data = response.data.map((raw)=>(new SuiTransaction({data: raw, suiMaster: this._suiMaster, debug: this._debug}))); | ||
} else if (this._method === 'getOwnedObjects') { | ||
// convert data to SuiObject instances | ||
this._data = response.data.map((raw)=>(new (this._suiMaster.SuiObject)({suiMaster: this._suiMaster, debug: this._debug, objectChange: raw}))); | ||
} else { | ||
@@ -92,0 +95,0 @@ this._data = response.data; |
{ | ||
"name": "suidouble", | ||
"version": "0.0.41", | ||
"version": "0.0.42", | ||
"description": "Set of provider, package and object classes for javascript representation of Sui Move smart contracts. Use same code for publishing, upgrading, integration testing, interaction with smart contracts and integration in browser web3 dapps", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -279,2 +279,15 @@ # suidouble | ||
``` | ||
Another option (if you don't know the object id) is to query current wallet owned module's objects from blockchain: | ||
```javascript | ||
const module = await contract.getModule('suidouble_chat'); | ||
const paginatedResponse = await module.getOwnedObjects(); // all module objects owned by you | ||
const paginatedResponse2 = await module.getOwnedObjects({ typeName: 'ChatResponse' }); // specific type objects owned by you | ||
await paginatedResponse.forEach(async(suiObject)=>{ | ||
console.log(suiObject.id, suiObject.typeName, suiObject.fields); | ||
}, maxLimit); // optional maxLimit, if (!maxLimit) - it will fetch and call callback for all available objects | ||
``` | ||
@todo: move pushing/fetching to SuiMemoryObjectStorage directly, as there's nothing package or module related? | ||
@@ -281,0 +294,0 @@ @todo: invalidation? No need to re-fetch all objects each time |
@@ -283,2 +283,36 @@ 'use strict' | ||
test('find owned module objects with query', async t => { | ||
const module = await contract.getModule('suidouble_chat'); | ||
const paginatedResponse = await module.getOwnedObjects(); | ||
let foundCount = 0; | ||
let foundChatOwnerCap = false; | ||
// loop through all module objects owned by current wall | ||
await paginatedResponse.forEach((suiObject)=>{ | ||
if (suiObject.typeName == 'ChatOwnerCap') { | ||
foundChatOwnerCap = true; | ||
} | ||
foundCount++; // total count | ||
}); | ||
t.ok(foundCount >= 60); // it's 60 in move code, but let's keep chat flexible | ||
t.ok(foundChatOwnerCap); // it's 60 in move code, but let's keep chat flexible | ||
/// also lets try querying specific typeName | ||
const paginatedResponse2 = await module.getOwnedObjects({ typeName: 'ChatOwnerCap' }); | ||
let foundCount2 = 0; | ||
let foundChatOwnerCap2 = false; | ||
await paginatedResponse2.forEach(async(suiObject)=>{ // paginatedResponse forEach also accepts async callbacks | ||
if (suiObject.typeName == 'ChatOwnerCap') { | ||
foundChatOwnerCap2 = true; | ||
} | ||
foundCount2++; | ||
}); | ||
t.ok(foundChatOwnerCap2); | ||
t.ok(foundCount2 == 1); // ChatOwnerCap only | ||
}); | ||
test('testing move call with coins', async t => { | ||
@@ -285,0 +319,0 @@ const balanceWas = await suiMaster.getBalance(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
211918
3280
439