suidouble 0.0.36 → 0.0.38
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/index.js +4 -0
- package/lib/SuiMaster.js +1 -0
- package/lib/SuiMemoryObjectStorage.js +63 -0
- package/lib/SuiPackageModule.js +27 -81
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -3,6 +3,7 @@ const SuiInBrowser = require('./lib/SuiInBrowser.js');
|
|
|
3
3
|
const SuiTestScenario = require('./lib/SuiTestScenario.js');
|
|
4
4
|
const SuiObject = require('./lib/SuiObject.js');
|
|
5
5
|
const SuiLocalTestValidator = require('./lib/SuiLocalTestValidator.js');
|
|
6
|
+
const sui = require('@mysten/sui.js');
|
|
6
7
|
|
|
7
8
|
module.exports = {
|
|
8
9
|
SuiMaster,
|
|
@@ -11,4 +12,7 @@ module.exports = {
|
|
|
11
12
|
SuiTestScenario,
|
|
12
13
|
SuiLocalTestValidator,
|
|
13
14
|
MIST_PER_SUI: SuiMaster.MIST_PER_SUI,
|
|
15
|
+
|
|
16
|
+
TransactionBlock: sui.TransactionBlock,
|
|
17
|
+
Transactions: sui.Transactions,
|
|
14
18
|
};
|
package/lib/SuiMaster.js
CHANGED
|
@@ -97,6 +97,7 @@ class SuiMaster extends SuiCommonMethods {
|
|
|
97
97
|
// we are differient single instances of object storage by provider name (so we can separate like devnet-testnet entities if needed)
|
|
98
98
|
this._objectStorage = SuiMemoryObjectStorage.instanceOf(this._providerName, {
|
|
99
99
|
debug: this._debug,
|
|
100
|
+
suiMaster: this,
|
|
100
101
|
});
|
|
101
102
|
|
|
102
103
|
this._initialized = false;
|
|
@@ -4,6 +4,7 @@ class SuiMemoryObjectStorage extends SuiCommonMethods {
|
|
|
4
4
|
constructor(params = {}) {
|
|
5
5
|
super(params);
|
|
6
6
|
|
|
7
|
+
this._suiMaster = params.suiMaster;
|
|
7
8
|
this._objects = {};
|
|
8
9
|
}
|
|
9
10
|
|
|
@@ -60,6 +61,68 @@ class SuiMemoryObjectStorage extends SuiCommonMethods {
|
|
|
60
61
|
return null;
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
async fetchObjects() {
|
|
65
|
+
const objectsToFetch = this.asArray(); //Object.values(this._objects);
|
|
66
|
+
|
|
67
|
+
const objectIds = [];
|
|
68
|
+
for (const object of objectsToFetch) {
|
|
69
|
+
if (!object.isDeleted && objectIds.indexOf(object.address) === -1) {
|
|
70
|
+
objectIds.push(object.address);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.log('querying details about', objectIds.length, 'objects');
|
|
75
|
+
this.log(objectIds);
|
|
76
|
+
|
|
77
|
+
let results = [];
|
|
78
|
+
const maxCountToFetch = 50;
|
|
79
|
+
for (let i = 0; i < objectIds.length; i += maxCountToFetch) {
|
|
80
|
+
const objectIdsSlice = objectIds.slice(i, i + maxCountToFetch);
|
|
81
|
+
|
|
82
|
+
let resultsSlice = [];
|
|
83
|
+
let consoleWarnMessage = null;
|
|
84
|
+
try {
|
|
85
|
+
const originalConsoleWarn = console.warn;
|
|
86
|
+
console.warn = (e)=>{
|
|
87
|
+
consoleWarnMessage = e;
|
|
88
|
+
};
|
|
89
|
+
resultsSlice = await this._suiMaster._provider.multiGetObjects({
|
|
90
|
+
ids: objectIdsSlice,
|
|
91
|
+
options: { showType: true, showContent: true, showOwner: true, showDisplay: true, },
|
|
92
|
+
});
|
|
93
|
+
console.warn = originalConsoleWarn;
|
|
94
|
+
} catch(e) {
|
|
95
|
+
console.error(e);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (consoleWarnMessage) {
|
|
99
|
+
this.log('got', resultsSlice.length, 'objects but with warning (ok, but probably it is different client vs rpc versions)');
|
|
100
|
+
} else {
|
|
101
|
+
this.log('got', resultsSlice.length, 'objects');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (resultsSlice && resultsSlice.length) {
|
|
105
|
+
results = results.concat(resultsSlice);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
for (const object of objectsToFetch) {
|
|
110
|
+
const foundInResults = results.find(element => object.idEquals(element?.data?.objectId));
|
|
111
|
+
if (foundInResults) {
|
|
112
|
+
object.tryToFillDataFromObjectChange(foundInResults);
|
|
113
|
+
// this.log('got updates for object', object.address, object.fields);
|
|
114
|
+
} else {
|
|
115
|
+
// object is removed?
|
|
116
|
+
const foundInRemoved = results.find(element => (element?.error?.code == 'deleted' && object.idEquals(element?.error?.object_id)));
|
|
117
|
+
if (foundInRemoved) {
|
|
118
|
+
object.markAsDeleted();
|
|
119
|
+
} else {
|
|
120
|
+
this.log('not found in results', object);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
63
126
|
static _instances = {};
|
|
64
127
|
|
|
65
128
|
static instanceOf(validatorId, params = {}) {
|
package/lib/SuiPackageModule.js
CHANGED
|
@@ -115,29 +115,34 @@ class SuiPackageModule extends SuiCommonMethods {
|
|
|
115
115
|
async moveCall(methodName, params) {
|
|
116
116
|
await this._package.checkOnChainIfNeeded();
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
118
|
+
let tx = null;
|
|
119
|
+
if (params.tx) {
|
|
120
|
+
tx = params.tx;
|
|
121
|
+
} else {
|
|
122
|
+
tx = new sui.TransactionBlock();
|
|
123
|
+
|
|
124
|
+
const callArgs = [];
|
|
125
|
+
|
|
126
|
+
for (let param of params) {
|
|
127
|
+
if (param && param.type && param.amount && param.type === 'SUI') {
|
|
128
|
+
let amount = BigInt(param.amount);
|
|
129
|
+
const coin = tx.add(sui.Transactions.SplitCoins(tx.gas, [tx.pure(amount)]));
|
|
130
|
+
callArgs.push(coin);
|
|
131
|
+
} else if (param && Array.isArray(param) && param.length == 1 && param[0].type && param[0].amount && param[0].type === 'SUI') {
|
|
132
|
+
// vector<Coin<SUI>>
|
|
133
|
+
let amount = BigInt(param[0].amount);
|
|
134
|
+
const coin = tx.add(sui.Transactions.SplitCoins(tx.gas, [tx.pure(amount)]));
|
|
135
|
+
callArgs.push(tx.makeMoveVec({ objects: [coin]}));
|
|
136
|
+
} else {
|
|
137
|
+
callArgs.push(tx.pure(param));
|
|
138
|
+
}
|
|
134
139
|
}
|
|
140
|
+
|
|
141
|
+
tx.moveCall({
|
|
142
|
+
target: `${this._package.address}::${this._moduleName}::${methodName}`,
|
|
143
|
+
arguments: callArgs,
|
|
144
|
+
});
|
|
135
145
|
}
|
|
136
|
-
|
|
137
|
-
tx.moveCall({
|
|
138
|
-
target: `${this._package.address}::${this._moduleName}::${methodName}`,
|
|
139
|
-
arguments: callArgs,
|
|
140
|
-
});
|
|
141
146
|
|
|
142
147
|
const result = await this._suiMaster._signer.signAndExecuteTransactionBlock({
|
|
143
148
|
transactionBlock: tx,
|
|
@@ -246,66 +251,7 @@ class SuiPackageModule extends SuiCommonMethods {
|
|
|
246
251
|
}
|
|
247
252
|
|
|
248
253
|
async fetchObjects() {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const objectIds = [];
|
|
252
|
-
for (const object of objectsToFetch) {
|
|
253
|
-
if (!object.isDeleted && objectIds.indexOf(object.address) === -1) {
|
|
254
|
-
objectIds.push(object.address);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
this.log('querying details about', objectIds.length, 'objects');
|
|
259
|
-
this.log(objectIds);
|
|
260
|
-
|
|
261
|
-
let results = [];
|
|
262
|
-
const maxCountToFetch = 50;
|
|
263
|
-
for (let i = 0; i < objectIds.length; i += maxCountToFetch) {
|
|
264
|
-
const objectIdsSlice = objectIds.slice(i, i + maxCountToFetch);
|
|
265
|
-
|
|
266
|
-
let resultsSlice = [];
|
|
267
|
-
let consoleWarnMessage = null;
|
|
268
|
-
try {
|
|
269
|
-
const originalConsoleWarn = console.warn;
|
|
270
|
-
console.warn = (e)=>{
|
|
271
|
-
consoleWarnMessage = e;
|
|
272
|
-
};
|
|
273
|
-
resultsSlice = await this._suiMaster._provider.multiGetObjects({
|
|
274
|
-
ids: objectIdsSlice,
|
|
275
|
-
// only fetch the object type
|
|
276
|
-
options: { showType: true, showContent: true, showOwner: true, showDisplay: true, },
|
|
277
|
-
});
|
|
278
|
-
console.warn = originalConsoleWarn;
|
|
279
|
-
} catch(e) {
|
|
280
|
-
console.error(e);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (consoleWarnMessage) {
|
|
284
|
-
this.log('got', resultsSlice.length, 'objects but with warning (ok, but probably it is different client vs rpc versions)');
|
|
285
|
-
} else {
|
|
286
|
-
this.log('got', resultsSlice.length, 'objects');
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (resultsSlice && resultsSlice.length) {
|
|
290
|
-
results = results.concat(resultsSlice);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
for (const object of objectsToFetch) {
|
|
295
|
-
const foundInResults = results.find(element => object.idEquals(element?.data?.objectId));
|
|
296
|
-
if (foundInResults) {
|
|
297
|
-
object.tryToFillDataFromObjectChange(foundInResults);
|
|
298
|
-
// this.log('got updates for object', object.address, object.fields);
|
|
299
|
-
} else {
|
|
300
|
-
// object is removed?
|
|
301
|
-
const foundInRemoved = results.find(element => (element?.error?.code == 'deleted' && object.idEquals(element?.error?.object_id)));
|
|
302
|
-
if (foundInRemoved) {
|
|
303
|
-
object.markAsDeleted();
|
|
304
|
-
} else {
|
|
305
|
-
this.log('not found in results', object);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
254
|
+
return await this.objectStorage.fetchObjects();
|
|
309
255
|
}
|
|
310
256
|
|
|
311
257
|
async getNormalizedPackageAddress() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suidouble",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"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
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"author": "Jeka Kiselyov <jeka911@gmail.com> (https://github.com/jeka-kiselyov)",
|
|
22
22
|
"license": "Apache-2.0",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@mysten/sui.js": "^0.
|
|
24
|
+
"@mysten/sui.js": "^0.39.0",
|
|
25
25
|
"@wallet-standard/core": "^1.0.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|