@0xobelisk/sui-client 0.5.3 → 0.5.4
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.d.ts +3 -1
- package/dist/index.js +343 -238
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +331 -245
- package/dist/index.mjs.map +1 -1
- package/dist/libs/multiSig/client.d.ts +15 -0
- package/dist/libs/multiSig/index.d.ts +1 -0
- package/dist/libs/multiSig/publickey.d.ts +2 -0
- package/dist/libs/suiAccountManager/index.d.ts +1 -1
- package/dist/libs/suiAccountManager/keypair.d.ts +1 -1
- package/dist/libs/suiContractFactory/index.d.ts +1 -1
- package/dist/libs/suiContractFactory/types.d.ts +1 -1
- package/dist/libs/suiInteractor/index.d.ts +0 -1
- package/dist/libs/suiInteractor/suiInteractor.d.ts +17 -177
- package/dist/libs/suiModel/suiOwnedObject.d.ts +4 -4
- package/dist/libs/suiModel/suiSharedObject.d.ts +4 -5
- package/dist/libs/suiTxBuilder/index.d.ts +178 -374
- package/dist/libs/suiTxBuilder/util.d.ts +41 -59
- package/dist/metadata/index.d.ts +2 -33
- package/dist/obelisk.d.ts +20 -2454
- package/dist/types/index.d.ts +28 -6
- package/package.json +22 -19
- package/src/index.ts +3 -1
- package/src/libs/multiSig/client.ts +44 -0
- package/src/libs/multiSig/index.ts +1 -0
- package/src/libs/multiSig/publickey.ts +11 -0
- package/src/libs/suiAccountManager/index.ts +1 -1
- package/src/libs/suiAccountManager/keypair.ts +1 -1
- package/src/libs/suiAccountManager/util.ts +1 -1
- package/src/libs/suiContractFactory/index.ts +1 -1
- package/src/libs/suiContractFactory/types.ts +2 -2
- package/src/libs/suiInteractor/index.ts +1 -1
- package/src/libs/suiInteractor/suiInteractor.ts +106 -111
- package/src/libs/suiModel/suiOwnedObject.ts +5 -10
- package/src/libs/suiModel/suiSharedObject.ts +4 -7
- package/src/libs/suiTxBuilder/index.ts +146 -100
- package/src/libs/suiTxBuilder/util.ts +145 -31
- package/src/metadata/index.ts +5 -3
- package/src/obelisk.ts +52 -37
- package/src/types/index.ts +53 -24
- package/dist/libs/suiInteractor/defaultConfig.d.ts +0 -10
- package/src/libs/suiInteractor/defaultConfig.ts +0 -32
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ObjectContentFields } from '@mysten/sui.js/src/types';
|
|
2
|
+
import type { TransactionBlock, TransactionObjectArgument, TransactionArgument, TransactionResult } from '@mysten/sui.js/transactions';
|
|
3
|
+
import type { SuiObjectRef, SuiMoveNormalizedModules, DevInspectResults, SuiTransactionBlockResponse, DisplayFieldsResponse, MoveStruct } from '@mysten/sui.js/client';
|
|
4
|
+
import type { SharedObjectRef, ObjectArg } from '@mysten/sui.js/bcs';
|
|
5
|
+
import type { SerializedBcs } from '@mysten/bcs';
|
|
4
6
|
import { SuiMoveMoudleFuncType } from '../libs/suiContractFactory/types';
|
|
5
7
|
export type ObeliskObjectData = {
|
|
6
8
|
objectId: string;
|
|
@@ -9,6 +11,12 @@ export type ObeliskObjectData = {
|
|
|
9
11
|
objectDisplay: DisplayFieldsResponse;
|
|
10
12
|
objectFields: ObjectContentFields;
|
|
11
13
|
};
|
|
14
|
+
export type ObeliskObjectContent = {
|
|
15
|
+
dataType: 'moveObject';
|
|
16
|
+
fields: MoveStruct;
|
|
17
|
+
hasPublicTransfer: boolean;
|
|
18
|
+
type: string;
|
|
19
|
+
};
|
|
12
20
|
export type ObeliskParams = {
|
|
13
21
|
mnemonics?: string;
|
|
14
22
|
secretKey?: string;
|
|
@@ -102,6 +110,18 @@ export type ObjectData = {
|
|
|
102
110
|
objectDisplay: DisplayFieldsResponse;
|
|
103
111
|
objectFields: ObjectContentFields;
|
|
104
112
|
};
|
|
113
|
+
type TransactionBlockType = InstanceType<typeof TransactionBlock>;
|
|
114
|
+
export type PureCallArg = {
|
|
115
|
+
Pure: number[];
|
|
116
|
+
};
|
|
117
|
+
export type ObjectCallArg = {
|
|
118
|
+
Object: ObjectArg;
|
|
119
|
+
};
|
|
120
|
+
export type TransactionType = Parameters<TransactionBlockType['add']>;
|
|
121
|
+
export type TransactionPureArgument = Extract<TransactionArgument, {
|
|
122
|
+
kind: 'Input';
|
|
123
|
+
type: 'pure';
|
|
124
|
+
}>;
|
|
105
125
|
export type ObjectFieldType = {
|
|
106
126
|
id: {
|
|
107
127
|
id: string;
|
|
@@ -114,8 +134,9 @@ export type EntityData = {
|
|
|
114
134
|
index: string;
|
|
115
135
|
key: string;
|
|
116
136
|
};
|
|
117
|
-
export type
|
|
118
|
-
export type
|
|
137
|
+
export type SuiAddressArg = TransactionArgument | SerializedBcs<any> | string | PureCallArg;
|
|
138
|
+
export type SuiTxArg = SuiAddressArg | number | bigint | boolean;
|
|
139
|
+
export type SuiObjectArg = TransactionObjectArgument | string | SharedObjectRef | SuiObjectRef | ObjectCallArg;
|
|
119
140
|
export type SuiVecTxArg = {
|
|
120
141
|
value: SuiTxArg[];
|
|
121
142
|
vecType: SuiInputTypes;
|
|
@@ -123,7 +144,7 @@ export type SuiVecTxArg = {
|
|
|
123
144
|
/**
|
|
124
145
|
* These are the basics types that can be used in the SUI
|
|
125
146
|
*/
|
|
126
|
-
export type SuiBasicTypes = 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256';
|
|
147
|
+
export type SuiBasicTypes = 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'signer';
|
|
127
148
|
export type SuiInputTypes = 'object' | SuiBasicTypes;
|
|
128
149
|
export type SuiReturnValues = {
|
|
129
150
|
returnValues: [number[], string][];
|
|
@@ -140,3 +161,4 @@ export type ObjectContent = {
|
|
|
140
161
|
hasPublicTransfer: boolean;
|
|
141
162
|
dataType: string;
|
|
142
163
|
};
|
|
164
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xobelisk/sui-client",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Tookit for interacting with move eps framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sui",
|
|
@@ -37,39 +37,42 @@
|
|
|
37
37
|
"src"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@mysten/bcs": "^0.
|
|
41
|
-
"@mysten/sui.js": "^0.
|
|
40
|
+
"@mysten/bcs": "^0.8.1",
|
|
41
|
+
"@mysten/sui.js": "^0.44.0",
|
|
42
|
+
"@noble/curves": "^1.2.0",
|
|
43
|
+
"@noble/hashes": "^1.3.2",
|
|
42
44
|
"@scure/bip39": "^1.2.1",
|
|
43
|
-
"assert": "^2.
|
|
45
|
+
"assert": "^2.1.0",
|
|
46
|
+
"superstruct": "^1.0.3",
|
|
47
|
+
"ts-retry-promise": "^0.7.1",
|
|
48
|
+
"tweetnacl": "^1.0.3",
|
|
44
49
|
"colorts": "^0.1.63",
|
|
45
50
|
"husky": "^8.0.3",
|
|
46
51
|
"keccak256": "^1.0.6",
|
|
47
52
|
"process": "^0.11.10",
|
|
48
|
-
"
|
|
49
|
-
"tmp": "^0.2.1",
|
|
50
|
-
"ts-retry-promise": "^0.7.0"
|
|
53
|
+
"tmp": "^0.2.1"
|
|
51
54
|
},
|
|
52
55
|
"peerDependencies": {
|
|
53
|
-
"@mysten/sui.js": "^0.
|
|
56
|
+
"@mysten/sui.js": "^0.44.0"
|
|
54
57
|
},
|
|
55
58
|
"devDependencies": {
|
|
56
|
-
"@commitlint/cli": "^
|
|
57
|
-
"@commitlint/config-conventional": "^
|
|
58
|
-
"@commitlint/prompt-cli": "^
|
|
59
|
-
"@types/node": "^20.
|
|
60
|
-
"@types/tmp": "^0.2.
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
62
|
-
"@typescript-eslint/parser": "^
|
|
59
|
+
"@commitlint/cli": "^18.0.0",
|
|
60
|
+
"@commitlint/config-conventional": "^18.0.0",
|
|
61
|
+
"@commitlint/prompt-cli": "^18.0.0",
|
|
62
|
+
"@types/node": "^20.8.7",
|
|
63
|
+
"@types/tmp": "^0.2.5",
|
|
64
|
+
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
|
65
|
+
"@typescript-eslint/parser": "^6.8.0",
|
|
63
66
|
"dotenv": "^16.3.1",
|
|
64
|
-
"eslint": "^8.
|
|
67
|
+
"eslint": "^8.52.0",
|
|
65
68
|
"eslint-config-prettier": "^8.8.0",
|
|
66
|
-
"eslint-plugin-prettier": "^
|
|
67
|
-
"lint-staged": "^
|
|
69
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
70
|
+
"lint-staged": "^15.0.2",
|
|
68
71
|
"prettier": "^2.8.8",
|
|
69
72
|
"ts-node": "^10.9.1",
|
|
70
73
|
"tsconfig-paths": "^4.2.0",
|
|
71
74
|
"tsup": "^7.1.0",
|
|
72
|
-
"typedoc": "^0.
|
|
75
|
+
"typedoc": "^0.25.2",
|
|
73
76
|
"typescript": "^5.0.4"
|
|
74
77
|
},
|
|
75
78
|
"lint-staged": {
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export * from '@mysten/sui.js';
|
|
1
|
+
export * from '@mysten/sui.js/utils';
|
|
2
|
+
export * from '@mysten/sui.js/transactions';
|
|
2
3
|
export { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
|
|
3
4
|
export { BCS, getSuiMoveConfig } from '@mysten/bcs';
|
|
4
5
|
export { Obelisk } from './obelisk';
|
|
5
6
|
export { SuiAccountManager } from './libs/suiAccountManager';
|
|
6
7
|
export { SuiTxBlock } from './libs/suiTxBuilder';
|
|
8
|
+
export { MultiSigClient } from './libs/multiSig';
|
|
7
9
|
export { SuiContractFactory } from './libs/suiContractFactory';
|
|
8
10
|
export { loadMetadata } from './metadata';
|
|
9
11
|
export type * from './types';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { MultiSigPublicKey } from '@mysten/sui.js/multisig';
|
|
2
|
+
import type { PublicKey } from '@mysten/sui.js/src/cryptography';
|
|
3
|
+
import { ed25519PublicKeyFromBase64 } from './publickey';
|
|
4
|
+
|
|
5
|
+
export type PublicKeyWeightPair = {
|
|
6
|
+
publicKey: PublicKey;
|
|
7
|
+
weight: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export class MultiSigClient {
|
|
11
|
+
public readonly pksWeightPairs: PublicKeyWeightPair[];
|
|
12
|
+
public readonly threshold: number;
|
|
13
|
+
public readonly multiSigPublicKey: MultiSigPublicKey;
|
|
14
|
+
constructor(pks: PublicKeyWeightPair[], threshold: number) {
|
|
15
|
+
this.pksWeightPairs = pks;
|
|
16
|
+
this.threshold = threshold;
|
|
17
|
+
this.multiSigPublicKey = MultiSigPublicKey.fromPublicKeys({
|
|
18
|
+
threshold: this.threshold,
|
|
19
|
+
publicKeys: this.pksWeightPairs,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static fromRawEd25519PublicKeys(
|
|
24
|
+
rawPublicKeys: string[],
|
|
25
|
+
weights: number[],
|
|
26
|
+
threshold: number
|
|
27
|
+
): MultiSigClient {
|
|
28
|
+
const pks = rawPublicKeys.map((rawPublicKey, i) => {
|
|
29
|
+
return {
|
|
30
|
+
publicKey: ed25519PublicKeyFromBase64(rawPublicKey),
|
|
31
|
+
weight: weights[i],
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
return new MultiSigClient(pks, threshold);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
multiSigAddress(): string {
|
|
38
|
+
return this.multiSigPublicKey.toSuiAddress();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
combinePartialSigs(sigs: string[]): string {
|
|
42
|
+
return this.multiSigPublicKey.combinePartialSignatures(sigs);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MultiSigClient } from './client';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PublicKey } from '@mysten/sui.js/cryptography';
|
|
2
|
+
import { Ed25519PublicKey } from '@mysten/sui.js/keypairs/ed25519';
|
|
3
|
+
import { fromB64 } from '@mysten/sui.js/utils';
|
|
4
|
+
|
|
5
|
+
export function ed25519PublicKeyFromBase64(rawPubkey: string): PublicKey {
|
|
6
|
+
let bytes = fromB64(rawPubkey);
|
|
7
|
+
// rawPubkeys should either be 32 bytes or 33 bytes (with the first byte being flag)
|
|
8
|
+
if (bytes.length !== 32 && bytes.length !== 33) throw 'invalid pubkey length';
|
|
9
|
+
bytes = bytes.length === 33 ? bytes.slice(1) : bytes;
|
|
10
|
+
return new Ed25519PublicKey(bytes);
|
|
11
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ed25519Keypair } from '@mysten/sui.js';
|
|
1
|
+
import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
|
|
2
2
|
import { getKeyPair } from './keypair';
|
|
3
3
|
import { hexOrBase64ToUint8Array, normalizePrivateKey } from './util';
|
|
4
4
|
import { generateMnemonic } from './crypto';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { SuiInteractor } from './suiInteractor';
|
|
2
|
-
export { getDefaultConnection } from './defaultConfig';
|
|
2
|
+
// export { getDefaultConnection } from './defaultConfig';
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { SuiClient } from '@mysten/sui.js/client';
|
|
2
|
+
import type {
|
|
3
3
|
SuiTransactionBlockResponseOptions,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
getObjectType,
|
|
10
|
-
getObjectVersion,
|
|
11
|
-
getSharedObjectInitialVersion,
|
|
12
|
-
DynamicFieldName,
|
|
13
|
-
SuiAddress,
|
|
14
|
-
} from '@mysten/sui.js';
|
|
4
|
+
SuiTransactionBlockResponse,
|
|
5
|
+
SuiObjectDataOptions,
|
|
6
|
+
SuiObjectData,
|
|
7
|
+
} from '@mysten/sui.js/client';
|
|
8
|
+
import type * as RpcTypes from '@mysten/sui.js/dist/cjs/client/types/generated';
|
|
15
9
|
import { requestSuiFromFaucetV0, getFaucetHost } from '@mysten/sui.js/faucet';
|
|
16
10
|
import { FaucetNetworkType, NetworkType, ObjectData } from '../../types';
|
|
17
11
|
import { SuiOwnedObject, SuiSharedObject } from '../suiModel';
|
|
@@ -23,24 +17,29 @@ import { delay } from './util';
|
|
|
23
17
|
* and update the gas coin after the transaction.
|
|
24
18
|
*/
|
|
25
19
|
export class SuiInteractor {
|
|
26
|
-
public readonly
|
|
27
|
-
public
|
|
20
|
+
public readonly clients: SuiClient[];
|
|
21
|
+
public currentClient: SuiClient;
|
|
22
|
+
public readonly fullNodes: string[];
|
|
23
|
+
public currentFullNode: string;
|
|
24
|
+
|
|
28
25
|
public network?: NetworkType;
|
|
29
26
|
|
|
30
27
|
constructor(fullNodeUrls: string[], network?: NetworkType) {
|
|
31
28
|
if (fullNodeUrls.length === 0)
|
|
32
29
|
throw new Error('fullNodeUrls must not be empty');
|
|
33
|
-
this.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.
|
|
30
|
+
this.fullNodes = fullNodeUrls;
|
|
31
|
+
this.clients = fullNodeUrls.map((url) => new SuiClient({ url }));
|
|
32
|
+
this.currentFullNode = fullNodeUrls[0];
|
|
33
|
+
this.currentClient = this.clients[0];
|
|
37
34
|
this.network = network;
|
|
38
35
|
}
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
this.
|
|
43
|
-
this.
|
|
37
|
+
switchToNextClient() {
|
|
38
|
+
const currentClientIdx = this.clients.indexOf(this.currentClient);
|
|
39
|
+
this.currentClient =
|
|
40
|
+
this.clients[(currentClientIdx + 1) % this.clients.length];
|
|
41
|
+
this.currentFullNode =
|
|
42
|
+
this.fullNodes[(currentClientIdx + 1) % this.clients.length];
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
async sendTx(
|
|
@@ -60,17 +59,16 @@ export class SuiInteractor {
|
|
|
60
59
|
// ...this.providers.slice(0, currentProviderIdx),
|
|
61
60
|
// ]
|
|
62
61
|
|
|
63
|
-
for (const
|
|
62
|
+
for (const clientIdx in this.clients) {
|
|
64
63
|
try {
|
|
65
|
-
|
|
64
|
+
return await this.clients[clientIdx].executeTransactionBlock({
|
|
66
65
|
transactionBlock,
|
|
67
66
|
signature,
|
|
68
67
|
options: txResOptions,
|
|
69
68
|
});
|
|
70
|
-
return res;
|
|
71
69
|
} catch (err) {
|
|
72
70
|
console.warn(
|
|
73
|
-
`Failed to send transaction with fullnode ${
|
|
71
|
+
`Failed to send transaction with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
74
72
|
);
|
|
75
73
|
await delay(2000);
|
|
76
74
|
}
|
|
@@ -78,46 +76,33 @@ export class SuiInteractor {
|
|
|
78
76
|
throw new Error('Failed to send transaction with all fullnodes');
|
|
79
77
|
}
|
|
80
78
|
|
|
81
|
-
async getObjects(
|
|
82
|
-
|
|
79
|
+
async getObjects(
|
|
80
|
+
ids: string[],
|
|
81
|
+
options?: SuiObjectDataOptions
|
|
82
|
+
): Promise<SuiObjectData[]> {
|
|
83
|
+
const opts: SuiObjectDataOptions = options ?? {
|
|
83
84
|
showContent: true,
|
|
84
85
|
showDisplay: true,
|
|
85
86
|
showType: true,
|
|
86
87
|
showOwner: true,
|
|
87
88
|
};
|
|
88
89
|
|
|
89
|
-
|
|
90
|
-
// const providers = [
|
|
91
|
-
// ...this.providers.slice(currentProviderIdx, this.providers.length),
|
|
92
|
-
// ...this.providers.slice(0, currentProviderIdx),
|
|
93
|
-
// ]
|
|
94
|
-
|
|
95
|
-
for (const provider of this.providers) {
|
|
90
|
+
for (const clientIdx in this.clients) {
|
|
96
91
|
try {
|
|
97
|
-
const objects = await
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const objectType = getObjectType(object);
|
|
101
|
-
const objectVersion = getObjectVersion(object);
|
|
102
|
-
const objectDigest = object.data ? object.data.digest : undefined;
|
|
103
|
-
const initialSharedVersion = getSharedObjectInitialVersion(object);
|
|
104
|
-
const objectFields = getObjectFields(object);
|
|
105
|
-
const objectDisplay = getObjectDisplay(object);
|
|
106
|
-
return {
|
|
107
|
-
objectId,
|
|
108
|
-
objectType,
|
|
109
|
-
objectVersion,
|
|
110
|
-
objectDigest,
|
|
111
|
-
objectFields,
|
|
112
|
-
objectDisplay,
|
|
113
|
-
initialSharedVersion,
|
|
114
|
-
};
|
|
92
|
+
const objects = await this.clients[clientIdx].multiGetObjects({
|
|
93
|
+
ids,
|
|
94
|
+
options: opts,
|
|
115
95
|
});
|
|
116
|
-
|
|
96
|
+
const parsedObjects = objects
|
|
97
|
+
.map((object) => {
|
|
98
|
+
return object.data;
|
|
99
|
+
})
|
|
100
|
+
.filter((object) => object !== null && object !== undefined);
|
|
101
|
+
return parsedObjects as SuiObjectData[];
|
|
117
102
|
} catch (err) {
|
|
118
103
|
await delay(2000);
|
|
119
104
|
console.warn(
|
|
120
|
-
`Failed to get objects with fullnode ${
|
|
105
|
+
`Failed to get objects with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
121
106
|
);
|
|
122
107
|
}
|
|
123
108
|
}
|
|
@@ -129,48 +114,20 @@ export class SuiInteractor {
|
|
|
129
114
|
return objects[0];
|
|
130
115
|
}
|
|
131
116
|
|
|
132
|
-
// async getEntitiesObjects(ids: string[]) {
|
|
133
|
-
// const options = {
|
|
134
|
-
// showContent: true,
|
|
135
|
-
// showType: true,
|
|
136
|
-
// };
|
|
137
|
-
|
|
138
|
-
// for (const provider of this.providers) {
|
|
139
|
-
// try {
|
|
140
|
-
// const objects = await provider.multiGetObjects({ ids, options });
|
|
141
|
-
// const parsedObjects = objects.map((object) => {
|
|
142
|
-
// const objectId = getObjectId(object);
|
|
143
|
-
// const objectFields = getObjectFields(object) as ObjectFieldType;
|
|
144
|
-
// const index = objectFields.name;
|
|
145
|
-
// const key = objectFields.value;
|
|
146
|
-
// return {
|
|
147
|
-
// objectId,
|
|
148
|
-
// index,
|
|
149
|
-
// key,
|
|
150
|
-
// };
|
|
151
|
-
// });
|
|
152
|
-
// return parsedObjects as EntityData[];
|
|
153
|
-
// } catch (err) {
|
|
154
|
-
// await delay(2000);
|
|
155
|
-
// console.warn(
|
|
156
|
-
// `Failed to get EntitiesObjects with fullnode ${provider.connection.fullnode}: ${err}`
|
|
157
|
-
// );
|
|
158
|
-
// }
|
|
159
|
-
// }
|
|
160
|
-
// throw new Error('Failed to get EntitiesObjects with all fullnodes');
|
|
161
|
-
// }
|
|
162
|
-
|
|
163
117
|
async getDynamicFieldObject(
|
|
164
118
|
parentId: string,
|
|
165
|
-
name:
|
|
119
|
+
name: RpcTypes.DynamicFieldName
|
|
166
120
|
) {
|
|
167
|
-
for (const
|
|
121
|
+
for (const clientIdx in this.clients) {
|
|
168
122
|
try {
|
|
169
|
-
return
|
|
123
|
+
return await this.clients[clientIdx].getDynamicFieldObject({
|
|
124
|
+
parentId,
|
|
125
|
+
name,
|
|
126
|
+
});
|
|
170
127
|
} catch (err) {
|
|
171
128
|
await delay(2000);
|
|
172
129
|
console.warn(
|
|
173
|
-
`Failed to get DynamicFieldObject with fullnode ${
|
|
130
|
+
`Failed to get DynamicFieldObject with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
174
131
|
);
|
|
175
132
|
}
|
|
176
133
|
}
|
|
@@ -178,27 +135,59 @@ export class SuiInteractor {
|
|
|
178
135
|
}
|
|
179
136
|
|
|
180
137
|
async getDynamicFields(parentId: string, cursor?: string, limit?: number) {
|
|
181
|
-
for (const
|
|
138
|
+
for (const clientIdx in this.clients) {
|
|
182
139
|
try {
|
|
183
|
-
return
|
|
140
|
+
return await this.clients[clientIdx].getDynamicFields({
|
|
141
|
+
parentId,
|
|
142
|
+
cursor,
|
|
143
|
+
limit,
|
|
144
|
+
});
|
|
184
145
|
} catch (err) {
|
|
185
146
|
await delay(2000);
|
|
186
147
|
console.warn(
|
|
187
|
-
`Failed to get DynamicFields with fullnode ${
|
|
148
|
+
`Failed to get DynamicFields with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
188
149
|
);
|
|
189
150
|
}
|
|
190
151
|
}
|
|
191
152
|
throw new Error('Failed to get DynamicFields with all fullnodes');
|
|
192
153
|
}
|
|
193
154
|
|
|
194
|
-
async
|
|
195
|
-
for (const
|
|
155
|
+
async getTxDetails(digest: string) {
|
|
156
|
+
for (const clientIdx in this.clients) {
|
|
196
157
|
try {
|
|
197
|
-
|
|
158
|
+
const txResOptions: SuiTransactionBlockResponseOptions = {
|
|
159
|
+
showEvents: true,
|
|
160
|
+
showEffects: true,
|
|
161
|
+
showObjectChanges: true,
|
|
162
|
+
showBalanceChanges: true,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
return await this.clients[clientIdx].getTransactionBlock({
|
|
166
|
+
digest,
|
|
167
|
+
options: txResOptions,
|
|
168
|
+
});
|
|
198
169
|
} catch (err) {
|
|
199
170
|
await delay(2000);
|
|
200
171
|
console.warn(
|
|
201
|
-
`Failed to get
|
|
172
|
+
`Failed to get TransactionBlocks with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
throw new Error('Failed to get TransactionBlocks with all fullnodes');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async getOwnedObjects(owner: string, cursor?: string, limit?: number) {
|
|
180
|
+
for (const clientIdx in this.clients) {
|
|
181
|
+
try {
|
|
182
|
+
return await this.clients[clientIdx].getOwnedObjects({
|
|
183
|
+
owner,
|
|
184
|
+
cursor,
|
|
185
|
+
limit,
|
|
186
|
+
});
|
|
187
|
+
} catch (err) {
|
|
188
|
+
await delay(2000);
|
|
189
|
+
console.warn(
|
|
190
|
+
`Failed to get OwnedObjects with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
202
191
|
);
|
|
203
192
|
}
|
|
204
193
|
}
|
|
@@ -206,15 +195,15 @@ export class SuiInteractor {
|
|
|
206
195
|
}
|
|
207
196
|
|
|
208
197
|
async getNormalizedMoveModulesByPackage(packageId: string) {
|
|
209
|
-
for (const
|
|
198
|
+
for (const clientIdx in this.clients) {
|
|
210
199
|
try {
|
|
211
|
-
return
|
|
200
|
+
return await this.clients[clientIdx].getNormalizedMoveModulesByPackage({
|
|
212
201
|
package: packageId,
|
|
213
202
|
});
|
|
214
203
|
} catch (err) {
|
|
215
204
|
await delay(2000);
|
|
216
205
|
console.warn(
|
|
217
|
-
`Failed to get NormalizedMoveModules with fullnode ${
|
|
206
|
+
`Failed to get NormalizedMoveModules with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
218
207
|
);
|
|
219
208
|
}
|
|
220
209
|
}
|
|
@@ -230,13 +219,22 @@ export class SuiInteractor {
|
|
|
230
219
|
const objects = await this.getObjects(objectIds);
|
|
231
220
|
for (const object of objects) {
|
|
232
221
|
const suiObject = suiObjects.find(
|
|
233
|
-
(obj) => obj.objectId === object
|
|
222
|
+
(obj) => obj.objectId === object?.objectId
|
|
234
223
|
);
|
|
235
224
|
if (suiObject instanceof SuiSharedObject) {
|
|
236
|
-
|
|
225
|
+
if (
|
|
226
|
+
object.owner &&
|
|
227
|
+
typeof object.owner === 'object' &&
|
|
228
|
+
'Shared' in object.owner
|
|
229
|
+
) {
|
|
230
|
+
suiObject.initialSharedVersion =
|
|
231
|
+
object.owner.Shared.initial_shared_version;
|
|
232
|
+
} else {
|
|
233
|
+
suiObject.initialSharedVersion = undefined;
|
|
234
|
+
}
|
|
237
235
|
} else if (suiObject instanceof SuiOwnedObject) {
|
|
238
|
-
suiObject.version = object
|
|
239
|
-
suiObject.digest = object
|
|
236
|
+
suiObject.version = object?.version;
|
|
237
|
+
suiObject.digest = object?.digest;
|
|
240
238
|
}
|
|
241
239
|
}
|
|
242
240
|
}
|
|
@@ -259,9 +257,9 @@ export class SuiInteractor {
|
|
|
259
257
|
}[] = [];
|
|
260
258
|
let totalAmount = 0;
|
|
261
259
|
let hasNext = true,
|
|
262
|
-
nextCursor: string | null = null;
|
|
260
|
+
nextCursor: string | null | undefined = null;
|
|
263
261
|
while (hasNext && totalAmount < amount) {
|
|
264
|
-
const coins = await this.
|
|
262
|
+
const coins = await this.currentClient.getCoins({
|
|
265
263
|
owner: addr,
|
|
266
264
|
coinType: coinType,
|
|
267
265
|
cursor: nextCursor,
|
|
@@ -290,13 +288,10 @@ export class SuiInteractor {
|
|
|
290
288
|
return selectedCoins;
|
|
291
289
|
}
|
|
292
290
|
|
|
293
|
-
async requestFaucet(address:
|
|
291
|
+
async requestFaucet(address: string, network: FaucetNetworkType) {
|
|
294
292
|
await requestSuiFromFaucetV0({
|
|
295
293
|
host: getFaucetHost(network),
|
|
296
294
|
recipient: address,
|
|
297
295
|
});
|
|
298
|
-
// let params = {
|
|
299
|
-
// owner: address
|
|
300
|
-
// } as GetBalanceParams;
|
|
301
296
|
}
|
|
302
297
|
}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
getObjectChanges,
|
|
4
|
-
SuiTransactionBlockResponse,
|
|
5
|
-
ObjectCallArg,
|
|
6
|
-
ObjectId,
|
|
7
|
-
} from '@mysten/sui.js';
|
|
1
|
+
import type { SuiTransactionBlockResponse } from '@mysten/sui.js/client';
|
|
2
|
+
import type { CallArg } from '@mysten/sui.js/bcs';
|
|
8
3
|
|
|
9
4
|
export class SuiOwnedObject {
|
|
10
5
|
public readonly objectId: string;
|
|
11
|
-
public version?:
|
|
6
|
+
public version?: string;
|
|
12
7
|
public digest?: string;
|
|
13
8
|
|
|
14
9
|
constructor(param: { objectId: string; version?: string; digest?: string }) {
|
|
@@ -26,7 +21,7 @@ export class SuiOwnedObject {
|
|
|
26
21
|
return !!this.version && !!this.digest;
|
|
27
22
|
}
|
|
28
23
|
|
|
29
|
-
asCallArg():
|
|
24
|
+
asCallArg(): CallArg | string {
|
|
30
25
|
if (!this.version || !this.digest) {
|
|
31
26
|
return this.objectId;
|
|
32
27
|
}
|
|
@@ -46,7 +41,7 @@ export class SuiOwnedObject {
|
|
|
46
41
|
* @param txResponse
|
|
47
42
|
*/
|
|
48
43
|
updateFromTxResponse(txResponse: SuiTransactionBlockResponse) {
|
|
49
|
-
const changes =
|
|
44
|
+
const changes = txResponse.objectChanges;
|
|
50
45
|
if (!changes) {
|
|
51
46
|
throw new Error('Bad transaction response!');
|
|
52
47
|
}
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ObjectCallArg, ObjectId } from '@mysten/sui.js';
|
|
1
|
+
import type { CallArg } from '@mysten/sui.js/bcs';
|
|
3
2
|
|
|
4
3
|
export class SuiSharedObject {
|
|
5
4
|
public readonly objectId: string;
|
|
6
|
-
public initialSharedVersion?:
|
|
5
|
+
public initialSharedVersion?: string;
|
|
7
6
|
|
|
8
7
|
constructor(param: {
|
|
9
8
|
objectId: string;
|
|
10
|
-
initialSharedVersion?:
|
|
9
|
+
initialSharedVersion?: string;
|
|
11
10
|
mutable?: boolean;
|
|
12
11
|
}) {
|
|
13
12
|
this.objectId = param.objectId;
|
|
14
13
|
this.initialSharedVersion = param.initialSharedVersion;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
asCallArg(
|
|
18
|
-
mutable: boolean = false
|
|
19
|
-
): Infer<typeof ObjectCallArg> | Infer<typeof ObjectId> {
|
|
16
|
+
asCallArg(mutable: boolean = false): CallArg | string {
|
|
20
17
|
if (!this.initialSharedVersion) {
|
|
21
18
|
return this.objectId;
|
|
22
19
|
}
|