@0xobelisk/sui-client 1.1.1 → 1.1.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.
- package/dist/dubhe.d.ts +6 -1
- package/dist/index.js +40 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -14
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.ts +3 -1
- package/package.json +1 -1
- package/src/dubhe.ts +63 -31
- package/src/types/index.ts +4 -0
package/dist/types/index.d.ts
CHANGED
|
@@ -73,11 +73,13 @@ export interface ContractQuery extends MessageMeta {
|
|
|
73
73
|
}): Promise<DevInspectResults | TransactionResult>;
|
|
74
74
|
}
|
|
75
75
|
export interface ContractTx extends MessageMeta {
|
|
76
|
-
({ tx, params, typeArguments, isRaw, }: {
|
|
76
|
+
({ tx, params, typeArguments, isRaw, onSuccess, onError, }: {
|
|
77
77
|
tx: Transaction;
|
|
78
78
|
params?: (TransactionArgument | SerializedBcs<any>)[];
|
|
79
79
|
typeArguments?: string[];
|
|
80
80
|
isRaw?: boolean;
|
|
81
|
+
onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
|
|
82
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
81
83
|
}): Promise<SuiTransactionBlockResponse | TransactionResult>;
|
|
82
84
|
}
|
|
83
85
|
export type MapMessageTx = Record<string, ContractTx>;
|
package/package.json
CHANGED
package/src/dubhe.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import keccak256 from 'keccak256';
|
|
2
|
-
import { getFullnodeUrl } from '@mysten/sui/client';
|
|
3
2
|
import { Transaction, TransactionResult } from '@mysten/sui/transactions';
|
|
4
3
|
import { BcsType, fromHex, SerializedBcs, toHex } from '@mysten/bcs';
|
|
5
4
|
import type { TransactionArgument } from '@mysten/sui/transactions';
|
|
@@ -14,18 +13,9 @@ import type {
|
|
|
14
13
|
import { SuiAccountManager } from './libs/suiAccountManager';
|
|
15
14
|
import { SuiTx } from './libs/suiTxBuilder';
|
|
16
15
|
import { SuiInteractor } from './libs/suiInteractor';
|
|
17
|
-
import {
|
|
18
|
-
MapObjectStruct,
|
|
19
|
-
MoveStructType,
|
|
20
|
-
DubheObjectContent,
|
|
21
|
-
SuiDubheReturnType,
|
|
22
|
-
MoveEnumType,
|
|
23
|
-
} from './types';
|
|
16
|
+
import { MapObjectStruct, MoveStructType, MoveEnumType } from './types';
|
|
24
17
|
import { SuiContractFactory } from './libs/suiContractFactory';
|
|
25
|
-
import {
|
|
26
|
-
SuiMoveMoudleFuncType,
|
|
27
|
-
SuiMoveMoudleValueType,
|
|
28
|
-
} from './libs/suiContractFactory/types';
|
|
18
|
+
import { SuiMoveMoudleFuncType } from './libs/suiContractFactory/types';
|
|
29
19
|
import { getDefaultURL, NetworkConfig } from './libs/suiInteractor';
|
|
30
20
|
import {
|
|
31
21
|
ContractQuery,
|
|
@@ -36,7 +26,6 @@ import {
|
|
|
36
26
|
MapMoudleFuncTx,
|
|
37
27
|
DubheParams,
|
|
38
28
|
SuiTxArg,
|
|
39
|
-
// SuiTxArgument,
|
|
40
29
|
SuiObjectArg,
|
|
41
30
|
SuiVecTxArg,
|
|
42
31
|
} from './types';
|
|
@@ -106,7 +95,9 @@ function createTx(
|
|
|
106
95
|
tx: Transaction,
|
|
107
96
|
params?: (TransactionArgument | SerializedBcs<any>)[],
|
|
108
97
|
typeArguments?: string[],
|
|
109
|
-
isRaw?: boolean
|
|
98
|
+
isRaw?: boolean,
|
|
99
|
+
onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>,
|
|
100
|
+
onError?: (error: Error) => void | Promise<void>
|
|
110
101
|
) => Promise<SuiTransactionBlockResponse | TransactionResult>
|
|
111
102
|
): ContractTx {
|
|
112
103
|
return withMeta(
|
|
@@ -116,13 +107,17 @@ function createTx(
|
|
|
116
107
|
params,
|
|
117
108
|
typeArguments,
|
|
118
109
|
isRaw,
|
|
110
|
+
onSuccess,
|
|
111
|
+
onError,
|
|
119
112
|
}: {
|
|
120
113
|
tx: Transaction;
|
|
121
114
|
params?: (TransactionArgument | SerializedBcs<any>)[];
|
|
122
115
|
typeArguments?: string[];
|
|
123
116
|
isRaw?: boolean;
|
|
117
|
+
onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
|
|
118
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
124
119
|
}): Promise<SuiTransactionBlockResponse | TransactionResult> => {
|
|
125
|
-
return await fn(tx, params, typeArguments, isRaw);
|
|
120
|
+
return await fn(tx, params, typeArguments, isRaw, onSuccess, onError);
|
|
126
121
|
}
|
|
127
122
|
);
|
|
128
123
|
}
|
|
@@ -357,8 +352,16 @@ export class Dubhe {
|
|
|
357
352
|
if (isUndefined(this.#tx[moduleName][funcName])) {
|
|
358
353
|
this.#tx[moduleName][funcName] = createTx(
|
|
359
354
|
meta,
|
|
360
|
-
(tx, p, typeArguments, isRaw) =>
|
|
361
|
-
this.#exec(
|
|
355
|
+
(tx, p, typeArguments, isRaw, onSuccess, onError) =>
|
|
356
|
+
this.#exec(
|
|
357
|
+
meta,
|
|
358
|
+
tx,
|
|
359
|
+
p,
|
|
360
|
+
typeArguments,
|
|
361
|
+
isRaw,
|
|
362
|
+
onSuccess,
|
|
363
|
+
onError
|
|
364
|
+
)
|
|
362
365
|
);
|
|
363
366
|
}
|
|
364
367
|
}
|
|
@@ -393,7 +396,9 @@ export class Dubhe {
|
|
|
393
396
|
tx: Transaction,
|
|
394
397
|
params?: (TransactionArgument | SerializedBcs<any>)[],
|
|
395
398
|
typeArguments?: string[],
|
|
396
|
-
isRaw?: boolean
|
|
399
|
+
isRaw?: boolean,
|
|
400
|
+
onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>,
|
|
401
|
+
onError?: (error: Error) => void | Promise<void>
|
|
397
402
|
) => {
|
|
398
403
|
if (isRaw === true) {
|
|
399
404
|
return tx.moveCall({
|
|
@@ -408,7 +413,7 @@ export class Dubhe {
|
|
|
408
413
|
arguments: params,
|
|
409
414
|
typeArguments,
|
|
410
415
|
});
|
|
411
|
-
return await this.signAndSendTxn(tx);
|
|
416
|
+
return await this.signAndSendTxn({ tx, onSuccess, onError });
|
|
412
417
|
};
|
|
413
418
|
|
|
414
419
|
#read = async (
|
|
@@ -1421,12 +1426,39 @@ export class Dubhe {
|
|
|
1421
1426
|
return await keyPair.signTransaction(txBytes);
|
|
1422
1427
|
}
|
|
1423
1428
|
|
|
1424
|
-
async signAndSendTxn(
|
|
1425
|
-
tx
|
|
1426
|
-
derivePathParams
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1429
|
+
async signAndSendTxn({
|
|
1430
|
+
tx,
|
|
1431
|
+
derivePathParams,
|
|
1432
|
+
onSuccess,
|
|
1433
|
+
onError,
|
|
1434
|
+
}: {
|
|
1435
|
+
tx: Uint8Array | Transaction | SuiTx;
|
|
1436
|
+
derivePathParams?: DerivePathParams;
|
|
1437
|
+
onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
|
|
1438
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
1439
|
+
}): Promise<SuiTransactionBlockResponse> {
|
|
1440
|
+
try {
|
|
1441
|
+
const { bytes, signature } = await this.signTxn(tx, derivePathParams);
|
|
1442
|
+
const result = await this.sendTx(bytes, signature);
|
|
1443
|
+
|
|
1444
|
+
if (result.effects?.status.status === 'success') {
|
|
1445
|
+
if (onSuccess) {
|
|
1446
|
+
await onSuccess(result);
|
|
1447
|
+
}
|
|
1448
|
+
} else {
|
|
1449
|
+
if (onError) {
|
|
1450
|
+
await onError(
|
|
1451
|
+
new Error(`Transaction failed: ${result.effects?.status.error}`)
|
|
1452
|
+
);
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
return result;
|
|
1456
|
+
} catch (error) {
|
|
1457
|
+
if (onError) {
|
|
1458
|
+
await onError(error as Error);
|
|
1459
|
+
}
|
|
1460
|
+
throw error;
|
|
1461
|
+
}
|
|
1430
1462
|
}
|
|
1431
1463
|
|
|
1432
1464
|
async sendTx(
|
|
@@ -1453,7 +1485,7 @@ export class Dubhe {
|
|
|
1453
1485
|
) {
|
|
1454
1486
|
const tx = new SuiTx();
|
|
1455
1487
|
tx.transferSui(recipient, amount);
|
|
1456
|
-
return this.signAndSendTxn(tx, derivePathParams);
|
|
1488
|
+
return this.signAndSendTxn({ tx, derivePathParams });
|
|
1457
1489
|
}
|
|
1458
1490
|
|
|
1459
1491
|
/**
|
|
@@ -1469,7 +1501,7 @@ export class Dubhe {
|
|
|
1469
1501
|
) {
|
|
1470
1502
|
const tx = new SuiTx();
|
|
1471
1503
|
tx.transferSuiToMany(recipients, amounts);
|
|
1472
|
-
return this.signAndSendTxn(tx, derivePathParams);
|
|
1504
|
+
return this.signAndSendTxn({ tx, derivePathParams });
|
|
1473
1505
|
}
|
|
1474
1506
|
|
|
1475
1507
|
/**
|
|
@@ -1499,7 +1531,7 @@ export class Dubhe {
|
|
|
1499
1531
|
recipients,
|
|
1500
1532
|
amounts
|
|
1501
1533
|
);
|
|
1502
|
-
return this.signAndSendTxn(tx, derivePathParams);
|
|
1534
|
+
return this.signAndSendTxn({ tx, derivePathParams });
|
|
1503
1535
|
}
|
|
1504
1536
|
|
|
1505
1537
|
async transferCoin(
|
|
@@ -1523,7 +1555,7 @@ export class Dubhe {
|
|
|
1523
1555
|
) {
|
|
1524
1556
|
const tx = new SuiTx();
|
|
1525
1557
|
tx.transferObjects(objects, recipient);
|
|
1526
|
-
return this.signAndSendTxn(tx, derivePathParams);
|
|
1558
|
+
return this.signAndSendTxn({ tx, derivePathParams });
|
|
1527
1559
|
}
|
|
1528
1560
|
|
|
1529
1561
|
async moveCall(callParams: {
|
|
@@ -1540,7 +1572,7 @@ export class Dubhe {
|
|
|
1540
1572
|
} = callParams;
|
|
1541
1573
|
const tx = new SuiTx();
|
|
1542
1574
|
tx.moveCall(target, args, typeArguments);
|
|
1543
|
-
return this.signAndSendTxn(tx, derivePathParams);
|
|
1575
|
+
return this.signAndSendTxn({ tx, derivePathParams });
|
|
1544
1576
|
}
|
|
1545
1577
|
|
|
1546
1578
|
/**
|
|
@@ -1578,7 +1610,7 @@ export class Dubhe {
|
|
|
1578
1610
|
) {
|
|
1579
1611
|
const tx = new SuiTx();
|
|
1580
1612
|
tx.stakeSui(amount, validatorAddr);
|
|
1581
|
-
return this.signAndSendTxn(tx, derivePathParams);
|
|
1613
|
+
return this.signAndSendTxn({ tx, derivePathParams });
|
|
1582
1614
|
}
|
|
1583
1615
|
|
|
1584
1616
|
/**
|
package/src/types/index.ts
CHANGED
|
@@ -111,11 +111,15 @@ export interface ContractTx extends MessageMeta {
|
|
|
111
111
|
params,
|
|
112
112
|
typeArguments,
|
|
113
113
|
isRaw,
|
|
114
|
+
onSuccess,
|
|
115
|
+
onError,
|
|
114
116
|
}: {
|
|
115
117
|
tx: Transaction;
|
|
116
118
|
params?: (TransactionArgument | SerializedBcs<any>)[];
|
|
117
119
|
typeArguments?: string[];
|
|
118
120
|
isRaw?: boolean;
|
|
121
|
+
onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
|
|
122
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
119
123
|
}): Promise<SuiTransactionBlockResponse | TransactionResult>;
|
|
120
124
|
}
|
|
121
125
|
|