@mysten/walrus 0.0.13 → 0.0.14
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/CHANGELOG.md +9 -0
- package/dist/cjs/client.d.ts +10 -2
- package/dist/cjs/client.js +156 -130
- package/dist/cjs/client.js.map +3 -3
- package/dist/cjs/types.d.ts +13 -5
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/object-loader.d.ts +4 -3
- package/dist/cjs/utils/object-loader.js +10 -36
- package/dist/cjs/utils/object-loader.js.map +2 -2
- package/dist/esm/client.d.ts +10 -2
- package/dist/esm/client.js +157 -131
- package/dist/esm/client.js.map +2 -2
- package/dist/esm/types.d.ts +13 -5
- package/dist/esm/utils/object-loader.d.ts +4 -3
- package/dist/esm/utils/object-loader.js +10 -36
- package/dist/esm/utils/object-loader.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/cjs/utils/memo.d.ts +0 -5
- package/dist/cjs/utils/memo.js +0 -59
- package/dist/cjs/utils/memo.js.map +0 -7
- package/dist/esm/utils/memo.d.ts +0 -5
- package/dist/esm/utils/memo.js +0 -39
- package/dist/esm/utils/memo.js.map +0 -7
package/dist/esm/client.d.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
import { SuiClient } from '@mysten/sui/client';
|
|
1
2
|
import type { Signer } from '@mysten/sui/cryptography';
|
|
3
|
+
import type { ClientWithExtensions } from '@mysten/sui/experimental';
|
|
2
4
|
import { Transaction } from '@mysten/sui/transactions';
|
|
3
5
|
import { Blob } from './contracts/blob.js';
|
|
4
6
|
import type { BlobStatus } from './storage-node/types.js';
|
|
5
|
-
import type { CertifyBlobOptions, DeleteBlobOptions, ExtendBlobOptions, GetBlobMetadataOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, ReadBlobOptions, RegisterBlobOptions, SliversForNode, StorageWithSizeOptions, WalrusClientConfig, WriteBlobAttributesOptions, WriteBlobOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteMetadataOptions, WriteSliverOptions, WriteSliversToNodeOptions } from './types.js';
|
|
7
|
+
import type { CertifyBlobOptions, DeleteBlobOptions, ExtendBlobOptions, GetBlobMetadataOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, ReadBlobOptions, RegisterBlobOptions, SliversForNode, StorageWithSizeOptions, WalrusClientConfig, WalrusClientExtensionOptions, WriteBlobAttributesOptions, WriteBlobOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteMetadataOptions, WriteSliverOptions, WriteSliversToNodeOptions } from './types.js';
|
|
6
8
|
export declare class WalrusClient {
|
|
7
9
|
#private;
|
|
8
10
|
constructor(config: WalrusClientConfig);
|
|
11
|
+
static experimental_asClientExtension({ packageConfig, network, ...options }?: WalrusClientExtensionOptions): {
|
|
12
|
+
name: "walrus";
|
|
13
|
+
register: (client: ClientWithExtensions<{
|
|
14
|
+
jsonRpc: SuiClient;
|
|
15
|
+
}>) => WalrusClient;
|
|
16
|
+
};
|
|
9
17
|
/** The Move type for a Blob object */
|
|
10
|
-
getBlobType
|
|
18
|
+
getBlobType(): string | Promise<string>;
|
|
11
19
|
/** The cached system object for the walrus package */
|
|
12
20
|
systemObject(): Promise<{
|
|
13
21
|
id: {
|
package/dist/esm/client.js
CHANGED
|
@@ -6,7 +6,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
6
6
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
7
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
8
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
-
var _storageNodeClient, _wasmUrl, _packageConfig, _suiClient, _objectLoader, _blobMetadataConcurrencyLimit, _readCommittee,
|
|
9
|
+
var _storageNodeClient, _wasmUrl, _packageConfig, _suiClient, _objectLoader, _blobMetadataConcurrencyLimit, _readCommittee, _cache, _WalrusClient_instances, walType_fn, getPackageId_fn, getSystemContract_fn, getSubsidiesContract_fn, getBlobContract_fn, getMetadataContract_fn, wasmBindings_fn, internalReadBlob_fn, getCertificationEpoch_fn, getReadCommittee_fn, forceGetReadCommittee_fn, withWal_fn, writeBlobAttributesForRef_fn, executeTransaction_fn, getCommittee_fn, getActiveCommittee_fn, stakingPool_fn, getNodeByShardIndex_fn, retryOnPossibleEpochChange_fn;
|
|
10
10
|
import { bcs } from "@mysten/bcs";
|
|
11
11
|
import { SuiClient } from "@mysten/sui/client";
|
|
12
12
|
import { coinWithBalance, Transaction } from "@mysten/sui/transactions";
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
TESTNET_WALRUS_PACKAGE_CONFIG
|
|
18
18
|
} from "./constants.js";
|
|
19
19
|
import { Blob, init as initBlobContract } from "./contracts/blob.js";
|
|
20
|
-
import { init as initMetadataContract } from "./contracts/metadata.js";
|
|
20
|
+
import { init as initMetadataContract, Metadata } from "./contracts/metadata.js";
|
|
21
21
|
import { StakingInnerV1 } from "./contracts/staking_inner.js";
|
|
22
22
|
import { StakingPool } from "./contracts/staking_pool.js";
|
|
23
23
|
import { Staking } from "./contracts/staking.js";
|
|
@@ -54,11 +54,10 @@ import {
|
|
|
54
54
|
toShardIndex,
|
|
55
55
|
toTypeString
|
|
56
56
|
} from "./utils/index.js";
|
|
57
|
-
import { MemoCache } from "./utils/memo.js";
|
|
58
57
|
import { SuiObjectDataLoader } from "./utils/object-loader.js";
|
|
59
58
|
import { shuffle, weightedShuffle } from "./utils/randomness.js";
|
|
60
59
|
import { getWasmBindings } from "./wasm.js";
|
|
61
|
-
class
|
|
60
|
+
const _WalrusClient = class _WalrusClient {
|
|
62
61
|
constructor(config) {
|
|
63
62
|
__privateAdd(this, _WalrusClient_instances);
|
|
64
63
|
__privateAdd(this, _storageNodeClient);
|
|
@@ -68,62 +67,9 @@ class WalrusClient {
|
|
|
68
67
|
__privateAdd(this, _objectLoader);
|
|
69
68
|
__privateAdd(this, _blobMetadataConcurrencyLimit, 10);
|
|
70
69
|
__privateAdd(this, _readCommittee);
|
|
71
|
-
__privateAdd(this,
|
|
72
|
-
/** The Move type for a WAL coin */
|
|
73
|
-
__privateAdd(this, _walType, __privateGet(this, _memo).create("walType", async () => {
|
|
74
|
-
const stakedWal = await __privateGet(this, _suiClient).getNormalizedMoveStruct({
|
|
75
|
-
package: await __privateGet(this, _getPackageId).call(this),
|
|
76
|
-
module: "staked_wal",
|
|
77
|
-
struct: "StakedWal"
|
|
78
|
-
});
|
|
79
|
-
const balanceType = stakedWal.fields.find((field) => field.name === "principal")?.type;
|
|
80
|
-
if (!balanceType) {
|
|
81
|
-
throw new WalrusClientError("WAL type not found");
|
|
82
|
-
}
|
|
83
|
-
const parsed = parseStructTag(toTypeString(balanceType));
|
|
84
|
-
const coinType = parsed.typeParams[0];
|
|
85
|
-
if (!coinType) {
|
|
86
|
-
throw new WalrusClientError("WAL type not found");
|
|
87
|
-
}
|
|
88
|
-
return normalizeStructTag(coinType);
|
|
89
|
-
}));
|
|
90
|
-
__privateAdd(this, _getPackageId, __privateGet(this, _memo).create("getPackageId", async () => {
|
|
91
|
-
const system = await __privateGet(this, _objectLoader).load(__privateGet(this, _packageConfig).systemObjectId);
|
|
92
|
-
return parseStructTag(system.type).address;
|
|
93
|
-
}));
|
|
94
|
-
/** The Move type for a Blob object */
|
|
95
|
-
this.getBlobType = __privateGet(this, _memo).create("getBlobType", async () => {
|
|
96
|
-
return `${await __privateGet(this, _getPackageId).call(this)}::blob::Blob`;
|
|
97
|
-
});
|
|
98
|
-
__privateAdd(this, _getSystemContract, __privateGet(this, _memo).create("getSystemContract", async () => {
|
|
99
|
-
const { package_id } = await this.systemObject();
|
|
100
|
-
return initSystemContract(package_id);
|
|
101
|
-
}));
|
|
102
|
-
__privateAdd(this, _getSubsidiesContract, __privateGet(this, _memo).create("getSubsidiesContract", async () => {
|
|
103
|
-
if (!__privateGet(this, _packageConfig).subsidiesObjectId) {
|
|
104
|
-
throw new WalrusClientError("Subsidies object ID not defined in package config");
|
|
105
|
-
}
|
|
106
|
-
const subsidiesObject = await __privateGet(this, _objectLoader).load(__privateGet(this, _packageConfig).subsidiesObjectId);
|
|
107
|
-
const packageId = parseStructTag(subsidiesObject.type).address;
|
|
108
|
-
return initSubsidiesContract(packageId);
|
|
109
|
-
}));
|
|
110
|
-
__privateAdd(this, _getBlobContract, __privateGet(this, _memo).create("getBlobContract", async () => {
|
|
111
|
-
const { package_id } = await this.systemObject();
|
|
112
|
-
return initBlobContract(package_id);
|
|
113
|
-
}));
|
|
114
|
-
__privateAdd(this, _getMetadataContract, __privateGet(this, _memo).create("getMetadataContract", async () => {
|
|
115
|
-
const { package_id } = await this.systemObject();
|
|
116
|
-
return initMetadataContract(package_id);
|
|
117
|
-
}));
|
|
118
|
-
__privateAdd(this, _wasmBindings, __privateGet(this, _memo).create("wasmBindings", async () => {
|
|
119
|
-
return getWasmBindings(__privateGet(this, _wasmUrl));
|
|
120
|
-
}));
|
|
70
|
+
__privateAdd(this, _cache);
|
|
121
71
|
/** Read a blob from the storage nodes */
|
|
122
72
|
this.readBlob = __privateMethod(this, _WalrusClient_instances, retryOnPossibleEpochChange_fn).call(this, __privateMethod(this, _WalrusClient_instances, internalReadBlob_fn));
|
|
123
|
-
__privateAdd(this, _getActiveCommittee, __privateGet(this, _memo).create("getActiveCommittee", async () => {
|
|
124
|
-
const stakingState = await this.stakingState();
|
|
125
|
-
return __privateMethod(this, _WalrusClient_instances, getCommittee_fn).call(this, stakingState.committee);
|
|
126
|
-
}));
|
|
127
73
|
if (config.network && !config.packageConfig) {
|
|
128
74
|
const network = config.network;
|
|
129
75
|
switch (network) {
|
|
@@ -145,6 +91,39 @@ class WalrusClient {
|
|
|
145
91
|
}));
|
|
146
92
|
__privateSet(this, _storageNodeClient, new StorageNodeClient(config.storageNodeClientOptions));
|
|
147
93
|
__privateSet(this, _objectLoader, new SuiObjectDataLoader(__privateGet(this, _suiClient)));
|
|
94
|
+
__privateSet(this, _cache, __privateGet(this, _suiClient).cache.scope("@mysten/walrus"));
|
|
95
|
+
}
|
|
96
|
+
static experimental_asClientExtension({
|
|
97
|
+
packageConfig,
|
|
98
|
+
network,
|
|
99
|
+
...options
|
|
100
|
+
} = {}) {
|
|
101
|
+
return {
|
|
102
|
+
name: "walrus",
|
|
103
|
+
register: (client) => {
|
|
104
|
+
const walrusNetwork = network || client.network;
|
|
105
|
+
if (walrusNetwork !== "mainnet" && walrusNetwork !== "testnet") {
|
|
106
|
+
throw new WalrusClientError("Walrus client only supports mainnet and testnet");
|
|
107
|
+
}
|
|
108
|
+
return new _WalrusClient(
|
|
109
|
+
packageConfig ? {
|
|
110
|
+
packageConfig,
|
|
111
|
+
suiClient: client,
|
|
112
|
+
...options
|
|
113
|
+
} : {
|
|
114
|
+
network: walrusNetwork,
|
|
115
|
+
suiClient: client,
|
|
116
|
+
...options
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/** The Move type for a Blob object */
|
|
123
|
+
getBlobType() {
|
|
124
|
+
return __privateGet(this, _cache).read(["getBlobType"], async () => {
|
|
125
|
+
return `${await __privateMethod(this, _WalrusClient_instances, getPackageId_fn).call(this)}::blob::Blob`;
|
|
126
|
+
});
|
|
148
127
|
}
|
|
149
128
|
/** The cached system object for the walrus package */
|
|
150
129
|
systemObject() {
|
|
@@ -320,7 +299,7 @@ class WalrusClient {
|
|
|
320
299
|
* Gets the blob status from multiple storage nodes and returns the latest status that can be verified.
|
|
321
300
|
*/
|
|
322
301
|
async getVerifiedBlobStatus({ blobId, signal }) {
|
|
323
|
-
const committee = await
|
|
302
|
+
const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
|
|
324
303
|
const stakingState = await this.stakingState();
|
|
325
304
|
const numShards = stakingState.n_shards;
|
|
326
305
|
const controller = new AbortController();
|
|
@@ -420,8 +399,8 @@ class WalrusClient {
|
|
|
420
399
|
const systemState = await this.systemState();
|
|
421
400
|
const encodedSize = encodedBlobLength(size, systemState.committee.n_shards);
|
|
422
401
|
const { storageCost } = await this.storageCost(size, epochs);
|
|
423
|
-
const systemContract = await
|
|
424
|
-
const subsidiesContract = __privateGet(this, _packageConfig).subsidiesObjectId ? await
|
|
402
|
+
const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
|
|
403
|
+
const subsidiesContract = __privateGet(this, _packageConfig).subsidiesObjectId ? await __privateMethod(this, _WalrusClient_instances, getSubsidiesContract_fn).call(this) : null;
|
|
425
404
|
return __privateMethod(this, _WalrusClient_instances, withWal_fn).call(this, storageCost, owner, walCoin ?? null, subsidiesContract !== null, (coin, tx) => {
|
|
426
405
|
return tx.add(
|
|
427
406
|
subsidiesContract ? subsidiesContract.reserve_space({
|
|
@@ -473,21 +452,19 @@ class WalrusClient {
|
|
|
473
452
|
});
|
|
474
453
|
const blobType = await this.getBlobType();
|
|
475
454
|
const { digest, effects } = await __privateMethod(this, _WalrusClient_instances, executeTransaction_fn).call(this, transaction, signer, "create storage");
|
|
476
|
-
const createdObjectIds = effects?.
|
|
477
|
-
const createdObjects = await __privateGet(this, _suiClient).
|
|
478
|
-
|
|
479
|
-
options: {
|
|
480
|
-
showType: true,
|
|
481
|
-
showBcs: true
|
|
482
|
-
}
|
|
455
|
+
const createdObjectIds = effects?.changedObjects.filter((object) => object.idOperation === "Created").map((object) => object.id);
|
|
456
|
+
const createdObjects = await __privateGet(this, _suiClient).core.getObjects({
|
|
457
|
+
objectIds: createdObjectIds
|
|
483
458
|
});
|
|
484
|
-
const suiBlobObject = createdObjects.find(
|
|
485
|
-
|
|
459
|
+
const suiBlobObject = createdObjects.objects.find(
|
|
460
|
+
(object) => !(object instanceof Error) && object.type === blobType
|
|
461
|
+
);
|
|
462
|
+
if (suiBlobObject instanceof Error || !suiBlobObject) {
|
|
486
463
|
throw new WalrusClientError("Storage object not found in transaction effects");
|
|
487
464
|
}
|
|
488
465
|
return {
|
|
489
466
|
digest,
|
|
490
|
-
storage: Storage().
|
|
467
|
+
storage: Storage().parse(suiBlobObject.content)
|
|
491
468
|
};
|
|
492
469
|
}
|
|
493
470
|
/**
|
|
@@ -510,7 +487,7 @@ class WalrusClient {
|
|
|
510
487
|
}) {
|
|
511
488
|
const storage = await this.createStorage({ size, epochs, walCoin, owner });
|
|
512
489
|
const { writeCost } = await this.storageCost(size, epochs);
|
|
513
|
-
const systemContract = await
|
|
490
|
+
const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
|
|
514
491
|
const writeAttributes = attributes ? await __privateMethod(this, _WalrusClient_instances, writeBlobAttributesForRef_fn).call(this, {
|
|
515
492
|
attributes,
|
|
516
493
|
existingAttributes: null
|
|
@@ -570,21 +547,19 @@ class WalrusClient {
|
|
|
570
547
|
});
|
|
571
548
|
const blobType = await this.getBlobType();
|
|
572
549
|
const { digest, effects } = await __privateMethod(this, _WalrusClient_instances, executeTransaction_fn).call(this, transaction, signer, "register blob");
|
|
573
|
-
const createdObjectIds = effects?.
|
|
574
|
-
const createdObjects = await __privateGet(this, _suiClient).
|
|
575
|
-
|
|
576
|
-
options: {
|
|
577
|
-
showType: true,
|
|
578
|
-
showBcs: true
|
|
579
|
-
}
|
|
550
|
+
const createdObjectIds = effects?.changedObjects.filter((object) => object.idOperation === "Created").map((object) => object.id);
|
|
551
|
+
const createdObjects = await __privateGet(this, _suiClient).core.getObjects({
|
|
552
|
+
objectIds: createdObjectIds
|
|
580
553
|
});
|
|
581
|
-
const suiBlobObject = createdObjects.find(
|
|
582
|
-
|
|
554
|
+
const suiBlobObject = createdObjects.objects.find(
|
|
555
|
+
(object) => !(object instanceof Error) && object.type === blobType
|
|
556
|
+
);
|
|
557
|
+
if (suiBlobObject instanceof Error || !suiBlobObject) {
|
|
583
558
|
throw new WalrusClientError("Blob object not found in transaction effects");
|
|
584
559
|
}
|
|
585
560
|
return {
|
|
586
561
|
digest,
|
|
587
|
-
blob: Blob().
|
|
562
|
+
blob: Blob().parse(suiBlobObject.content)
|
|
588
563
|
};
|
|
589
564
|
}
|
|
590
565
|
/**
|
|
@@ -597,7 +572,7 @@ class WalrusClient {
|
|
|
597
572
|
*/
|
|
598
573
|
async certifyBlob({ blobId, blobObjectId, confirmations, deletable }) {
|
|
599
574
|
const systemState = await this.systemState();
|
|
600
|
-
const committee = await
|
|
575
|
+
const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
|
|
601
576
|
if (confirmations.length !== systemState.committee.members.length) {
|
|
602
577
|
throw new WalrusClientError(
|
|
603
578
|
"Invalid number of confirmations. Confirmations array must contain an entry for each node"
|
|
@@ -617,7 +592,7 @@ class WalrusClient {
|
|
|
617
592
|
}
|
|
618
593
|
}
|
|
619
594
|
}).toBase64();
|
|
620
|
-
const bindings = await
|
|
595
|
+
const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
|
|
621
596
|
const verifySignature = bindings.getVerifySignature();
|
|
622
597
|
const filteredConfirmations = confirmations.map((confirmation, index) => {
|
|
623
598
|
const isValid = confirmation?.serializedMessage === confirmationMessage && verifySignature(
|
|
@@ -638,7 +613,7 @@ class WalrusClient {
|
|
|
638
613
|
filteredConfirmations,
|
|
639
614
|
filteredConfirmations.map(({ index }) => index)
|
|
640
615
|
);
|
|
641
|
-
const systemContract = await
|
|
616
|
+
const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
|
|
642
617
|
return (tx) => {
|
|
643
618
|
tx.add(
|
|
644
619
|
systemContract.certify_blob({
|
|
@@ -700,7 +675,7 @@ class WalrusClient {
|
|
|
700
675
|
* ```
|
|
701
676
|
*/
|
|
702
677
|
async deleteBlob({ blobObjectId }) {
|
|
703
|
-
const systemContract = await
|
|
678
|
+
const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
|
|
704
679
|
return (tx) => {
|
|
705
680
|
const storage = tx.add(
|
|
706
681
|
systemContract.delete_blob({
|
|
@@ -763,8 +738,8 @@ class WalrusClient {
|
|
|
763
738
|
};
|
|
764
739
|
}
|
|
765
740
|
const { storageCost } = await this.storageCost(Number(blob.storage.storage_size), numEpochs);
|
|
766
|
-
const systemContract = await
|
|
767
|
-
const subsidiesContract = __privateGet(this, _packageConfig).subsidiesObjectId ? await
|
|
741
|
+
const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
|
|
742
|
+
const subsidiesContract = __privateGet(this, _packageConfig).subsidiesObjectId ? await __privateMethod(this, _WalrusClient_instances, getSubsidiesContract_fn).call(this) : null;
|
|
768
743
|
return __privateMethod(this, _WalrusClient_instances, withWal_fn).call(this, storageCost, owner, walCoin ?? null, subsidiesContract !== null, (coin, tx) => {
|
|
769
744
|
tx.add(
|
|
770
745
|
subsidiesContract ? subsidiesContract.extend_blob({
|
|
@@ -814,23 +789,15 @@ class WalrusClient {
|
|
|
814
789
|
async readBlobAttributes({
|
|
815
790
|
blobObjectId
|
|
816
791
|
}) {
|
|
817
|
-
const response = await __privateGet(this, _suiClient).
|
|
792
|
+
const response = await __privateGet(this, _suiClient).core.getDynamicField({
|
|
818
793
|
parentId: blobObjectId,
|
|
819
794
|
name: {
|
|
820
795
|
type: "vector<u8>",
|
|
821
|
-
|
|
796
|
+
bcs: bcs.string().serialize("metadata").toBytes()
|
|
822
797
|
}
|
|
823
798
|
});
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
}
|
|
827
|
-
if (response.error || !response.data) {
|
|
828
|
-
throw new WalrusClientError(
|
|
829
|
-
`Failed to fetch metadata for object ${blobObjectId}: ${response.error}`
|
|
830
|
-
);
|
|
831
|
-
}
|
|
832
|
-
const metadata = response.data.content.fields.value.fields.metadata.fields.contents;
|
|
833
|
-
return Object.fromEntries(metadata.map(({ fields: { key, value } }) => [key, value]));
|
|
799
|
+
const metadata = Metadata().parse(response.dynamicField.value.bcs);
|
|
800
|
+
return Object.fromEntries(metadata.metadata.contents.map(({ key, value }) => [key, value]));
|
|
834
801
|
}
|
|
835
802
|
/**
|
|
836
803
|
* Write attributes to a blob
|
|
@@ -900,7 +867,7 @@ class WalrusClient {
|
|
|
900
867
|
*/
|
|
901
868
|
async writeSliver({ blobId, sliverPairIndex, sliverType, sliver, signal }) {
|
|
902
869
|
const systemState = await this.systemState();
|
|
903
|
-
const committee = await
|
|
870
|
+
const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
|
|
904
871
|
const shardIndex = toShardIndex(sliverPairIndex, blobId, systemState.committee.n_shards);
|
|
905
872
|
const node = await __privateMethod(this, _WalrusClient_instances, getNodeByShardIndex_fn).call(this, committee, shardIndex);
|
|
906
873
|
return await __privateGet(this, _storageNodeClient).storeSliver(
|
|
@@ -917,7 +884,7 @@ class WalrusClient {
|
|
|
917
884
|
* ```
|
|
918
885
|
*/
|
|
919
886
|
async writeMetadataToNode({ nodeIndex, blobId, metadata, signal }) {
|
|
920
|
-
const committee = await
|
|
887
|
+
const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
|
|
921
888
|
const node = committee.nodes[nodeIndex];
|
|
922
889
|
return await __privateGet(this, _storageNodeClient).storeBlobMetadata(
|
|
923
890
|
{ blobId, metadata },
|
|
@@ -939,7 +906,7 @@ class WalrusClient {
|
|
|
939
906
|
objectId,
|
|
940
907
|
signal
|
|
941
908
|
}) {
|
|
942
|
-
const committee = await
|
|
909
|
+
const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
|
|
943
910
|
const node = committee.nodes[nodeIndex];
|
|
944
911
|
const result = deletable ? await __privateGet(this, _storageNodeClient).getDeletableBlobConfirmation(
|
|
945
912
|
{ blobId, objectId },
|
|
@@ -960,9 +927,9 @@ class WalrusClient {
|
|
|
960
927
|
*/
|
|
961
928
|
async encodeBlob(blob) {
|
|
962
929
|
const systemState = await this.systemState();
|
|
963
|
-
const committee = await
|
|
930
|
+
const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
|
|
964
931
|
const numShards = systemState.committee.n_shards;
|
|
965
|
-
const bindings = await
|
|
932
|
+
const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
|
|
966
933
|
const { blobId, metadata, sliverPairs, rootHash } = bindings.encodeBlob(numShards, blob);
|
|
967
934
|
const sliversByNodeMap = /* @__PURE__ */ new Map();
|
|
968
935
|
while (sliverPairs.length > 0) {
|
|
@@ -1042,7 +1009,7 @@ class WalrusClient {
|
|
|
1042
1009
|
...options
|
|
1043
1010
|
}) {
|
|
1044
1011
|
const systemState = await this.systemState();
|
|
1045
|
-
const committee = await
|
|
1012
|
+
const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
|
|
1046
1013
|
const controller = new AbortController();
|
|
1047
1014
|
let failures = 0;
|
|
1048
1015
|
const confirmations = await Promise.all(
|
|
@@ -1156,10 +1123,9 @@ class WalrusClient {
|
|
|
1156
1123
|
*/
|
|
1157
1124
|
reset() {
|
|
1158
1125
|
__privateGet(this, _objectLoader).clearAll();
|
|
1159
|
-
|
|
1160
|
-
__privateGet(this, _memo).reset();
|
|
1126
|
+
__privateGet(this, _cache).clear();
|
|
1161
1127
|
}
|
|
1162
|
-
}
|
|
1128
|
+
};
|
|
1163
1129
|
_storageNodeClient = new WeakMap();
|
|
1164
1130
|
_wasmUrl = new WeakMap();
|
|
1165
1131
|
_packageConfig = new WeakMap();
|
|
@@ -1167,21 +1133,73 @@ _suiClient = new WeakMap();
|
|
|
1167
1133
|
_objectLoader = new WeakMap();
|
|
1168
1134
|
_blobMetadataConcurrencyLimit = new WeakMap();
|
|
1169
1135
|
_readCommittee = new WeakMap();
|
|
1170
|
-
|
|
1171
|
-
_walType = new WeakMap();
|
|
1172
|
-
_getPackageId = new WeakMap();
|
|
1173
|
-
_getSystemContract = new WeakMap();
|
|
1174
|
-
_getSubsidiesContract = new WeakMap();
|
|
1175
|
-
_getBlobContract = new WeakMap();
|
|
1176
|
-
_getMetadataContract = new WeakMap();
|
|
1177
|
-
_wasmBindings = new WeakMap();
|
|
1136
|
+
_cache = new WeakMap();
|
|
1178
1137
|
_WalrusClient_instances = new WeakSet();
|
|
1138
|
+
/** The Move type for a WAL coin */
|
|
1139
|
+
walType_fn = function() {
|
|
1140
|
+
return __privateGet(this, _cache).read(["walType"], async () => {
|
|
1141
|
+
const stakedWal = await __privateGet(this, _suiClient).jsonRpc.getNormalizedMoveStruct({
|
|
1142
|
+
package: await __privateMethod(this, _WalrusClient_instances, getPackageId_fn).call(this),
|
|
1143
|
+
module: "staked_wal",
|
|
1144
|
+
struct: "StakedWal"
|
|
1145
|
+
});
|
|
1146
|
+
const balanceType = stakedWal.fields.find((field) => field.name === "principal")?.type;
|
|
1147
|
+
if (!balanceType) {
|
|
1148
|
+
throw new WalrusClientError("WAL type not found");
|
|
1149
|
+
}
|
|
1150
|
+
const parsed = parseStructTag(toTypeString(balanceType));
|
|
1151
|
+
const coinType = parsed.typeParams[0];
|
|
1152
|
+
if (!coinType) {
|
|
1153
|
+
throw new WalrusClientError("WAL type not found");
|
|
1154
|
+
}
|
|
1155
|
+
return normalizeStructTag(coinType);
|
|
1156
|
+
});
|
|
1157
|
+
};
|
|
1158
|
+
getPackageId_fn = function() {
|
|
1159
|
+
return __privateGet(this, _cache).read(["getPackageId"], async () => {
|
|
1160
|
+
const system = await __privateGet(this, _objectLoader).load(__privateGet(this, _packageConfig).systemObjectId);
|
|
1161
|
+
return parseStructTag(system.type).address;
|
|
1162
|
+
});
|
|
1163
|
+
};
|
|
1164
|
+
getSystemContract_fn = function() {
|
|
1165
|
+
return __privateGet(this, _cache).read(["getSystemContract"], async () => {
|
|
1166
|
+
const { package_id } = await this.systemObject();
|
|
1167
|
+
return initSystemContract(package_id);
|
|
1168
|
+
});
|
|
1169
|
+
};
|
|
1170
|
+
getSubsidiesContract_fn = function() {
|
|
1171
|
+
return __privateGet(this, _cache).read(["getSubsidiesContract"], async () => {
|
|
1172
|
+
if (!__privateGet(this, _packageConfig).subsidiesObjectId) {
|
|
1173
|
+
throw new WalrusClientError("Subsidies object ID not defined in package config");
|
|
1174
|
+
}
|
|
1175
|
+
const subsidiesObject = await __privateGet(this, _objectLoader).load(__privateGet(this, _packageConfig).subsidiesObjectId);
|
|
1176
|
+
const packageId = parseStructTag(subsidiesObject.type).address;
|
|
1177
|
+
return initSubsidiesContract(packageId);
|
|
1178
|
+
});
|
|
1179
|
+
};
|
|
1180
|
+
getBlobContract_fn = function() {
|
|
1181
|
+
return __privateGet(this, _cache).read(["getBlobContract"], async () => {
|
|
1182
|
+
const { package_id } = await this.systemObject();
|
|
1183
|
+
return initBlobContract(package_id);
|
|
1184
|
+
});
|
|
1185
|
+
};
|
|
1186
|
+
getMetadataContract_fn = function() {
|
|
1187
|
+
return __privateGet(this, _cache).read(["getMetadataContract"], async () => {
|
|
1188
|
+
const { package_id } = await this.systemObject();
|
|
1189
|
+
return initMetadataContract(package_id);
|
|
1190
|
+
});
|
|
1191
|
+
};
|
|
1192
|
+
wasmBindings_fn = function() {
|
|
1193
|
+
return __privateGet(this, _cache).read(["wasmBindings"], async () => {
|
|
1194
|
+
return getWasmBindings(__privateGet(this, _wasmUrl));
|
|
1195
|
+
});
|
|
1196
|
+
};
|
|
1179
1197
|
internalReadBlob_fn = async function({ blobId, signal }) {
|
|
1180
1198
|
const systemState = await this.systemState();
|
|
1181
1199
|
const numShards = systemState.committee.n_shards;
|
|
1182
1200
|
const blobMetadata = await this.getBlobMetadata({ blobId, signal });
|
|
1183
1201
|
const slivers = await this.getSlivers({ blobId, signal });
|
|
1184
|
-
const bindings = await
|
|
1202
|
+
const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
|
|
1185
1203
|
const blobBytes = bindings.decodePrimarySlivers(
|
|
1186
1204
|
blobId,
|
|
1187
1205
|
numShards,
|
|
@@ -1230,10 +1248,10 @@ forceGetReadCommittee_fn = async function({ blobId, signal }) {
|
|
|
1230
1248
|
if (isTransitioning && certificationEpoch < stakingState.epoch) {
|
|
1231
1249
|
return await __privateMethod(this, _WalrusClient_instances, getCommittee_fn).call(this, stakingState.previous_committee);
|
|
1232
1250
|
}
|
|
1233
|
-
return await
|
|
1251
|
+
return await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
|
|
1234
1252
|
};
|
|
1235
1253
|
withWal_fn = async function(amount, owner, source, withSubsidies, fn) {
|
|
1236
|
-
const walType = await
|
|
1254
|
+
const walType = await __privateMethod(this, _WalrusClient_instances, walType_fn).call(this);
|
|
1237
1255
|
return (tx) => {
|
|
1238
1256
|
const coin = source ? tx.splitCoins(source, [amount])[0] : tx.add(
|
|
1239
1257
|
coinWithBalance({
|
|
@@ -1262,8 +1280,8 @@ writeBlobAttributesForRef_fn = async function({
|
|
|
1262
1280
|
attributes,
|
|
1263
1281
|
existingAttributes
|
|
1264
1282
|
}) {
|
|
1265
|
-
const blobContract = await
|
|
1266
|
-
const metadataContract = await
|
|
1283
|
+
const blobContract = await __privateMethod(this, _WalrusClient_instances, getBlobContract_fn).call(this);
|
|
1284
|
+
const metadataContract = await __privateMethod(this, _WalrusClient_instances, getMetadataContract_fn).call(this);
|
|
1267
1285
|
return (tx, blob) => {
|
|
1268
1286
|
if (!existingAttributes) {
|
|
1269
1287
|
tx.add(
|
|
@@ -1298,17 +1316,19 @@ writeBlobAttributesForRef_fn = async function({
|
|
|
1298
1316
|
};
|
|
1299
1317
|
};
|
|
1300
1318
|
executeTransaction_fn = async function(transaction, signer, action) {
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1319
|
+
transaction.setSenderIfNotSet(signer.toSuiAddress());
|
|
1320
|
+
const bytes = await transaction.build({ client: __privateGet(this, _suiClient).jsonRpc });
|
|
1321
|
+
const { signature } = await signer.signTransaction(bytes);
|
|
1322
|
+
const {
|
|
1323
|
+
transaction: { digest, effects }
|
|
1324
|
+
} = await __privateGet(this, _suiClient).core.executeTransaction({
|
|
1325
|
+
transaction: bytes,
|
|
1326
|
+
signatures: [signature]
|
|
1307
1327
|
});
|
|
1308
|
-
if (effects?.status.
|
|
1328
|
+
if (effects?.status.error) {
|
|
1309
1329
|
throw new WalrusClientError(`Failed to ${action}: ${effects?.status.error}`);
|
|
1310
1330
|
}
|
|
1311
|
-
await __privateGet(this, _suiClient).waitForTransaction({
|
|
1331
|
+
await __privateGet(this, _suiClient).core.waitForTransaction({
|
|
1312
1332
|
digest
|
|
1313
1333
|
});
|
|
1314
1334
|
return { digest, effects };
|
|
@@ -1336,7 +1356,12 @@ getCommittee_fn = async function(committee) {
|
|
|
1336
1356
|
nodes
|
|
1337
1357
|
};
|
|
1338
1358
|
};
|
|
1339
|
-
|
|
1359
|
+
getActiveCommittee_fn = function() {
|
|
1360
|
+
return __privateGet(this, _cache).read(["getActiveCommittee"], async () => {
|
|
1361
|
+
const stakingState = await this.stakingState();
|
|
1362
|
+
return __privateMethod(this, _WalrusClient_instances, getCommittee_fn).call(this, stakingState.committee);
|
|
1363
|
+
});
|
|
1364
|
+
};
|
|
1340
1365
|
stakingPool_fn = async function(committee) {
|
|
1341
1366
|
const nodeIds = committee.pos0.contents.map((node) => node.key);
|
|
1342
1367
|
return __privateGet(this, _objectLoader).loadManyOrThrow(nodeIds, StakingPool());
|
|
@@ -1361,6 +1386,7 @@ retryOnPossibleEpochChange_fn = function(fn) {
|
|
|
1361
1386
|
}
|
|
1362
1387
|
};
|
|
1363
1388
|
};
|
|
1389
|
+
let WalrusClient = _WalrusClient;
|
|
1364
1390
|
export {
|
|
1365
1391
|
WalrusClient
|
|
1366
1392
|
};
|