@msafe/sui3-sdk 0.0.2 → 0.0.3
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/README.md +21 -0
- package/dist/index.cjs +29 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +28 -10
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/src/backend/PseudoBackend.ts +22 -9
- package/src/globals/const.ts +7 -1
- package/src/types/msafe.ts +1 -0
package/README.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
1
|
# msafe-sui3-sdk
|
|
2
2
|
|
|
3
3
|
SDK for MSafe SUI V3
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Test
|
|
7
|
+
|
|
8
|
+
### Local test
|
|
9
|
+
|
|
10
|
+
Make sure you have MySQL database installed and setup.
|
|
11
|
+
|
|
12
|
+
```shell
|
|
13
|
+
yarn test
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The data will be written into the local database for further debug purpose.
|
|
17
|
+
|
|
18
|
+
### Unit test (CI)
|
|
19
|
+
|
|
20
|
+
```shell
|
|
21
|
+
yarn unit
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Running this command will connect Sqlite DB only in memory.
|
package/dist/index.cjs
CHANGED
|
@@ -50,6 +50,7 @@ __export(src_exports, {
|
|
|
50
50
|
SUI_COIN: () => SUI_COIN,
|
|
51
51
|
SignatureVerifier: () => SignatureVerifier,
|
|
52
52
|
TESTNET_RPC_URL: () => TESTNET_RPC_URL,
|
|
53
|
+
UNIT_DATABASE_CONFIG: () => UNIT_DATABASE_CONFIG,
|
|
53
54
|
Uint8ArrayToHex: () => Uint8ArrayToHex,
|
|
54
55
|
getAllCoins: () => getAllCoins,
|
|
55
56
|
getMSafeConfig: () => getMSafeConfig,
|
|
@@ -1196,6 +1197,7 @@ var PseudoBackend = class _PseudoBackend {
|
|
|
1196
1197
|
rawData: tx.data,
|
|
1197
1198
|
txType: tx.txType,
|
|
1198
1199
|
txSubType: tx.txSubType,
|
|
1200
|
+
processed: tx.processed,
|
|
1199
1201
|
status: tx.status,
|
|
1200
1202
|
statusRemark: tx.statusRemark,
|
|
1201
1203
|
creator: tx.creator,
|
|
@@ -1229,9 +1231,10 @@ var PseudoBackend = class _PseudoBackend {
|
|
|
1229
1231
|
const intention = {
|
|
1230
1232
|
msafeAddress: input.msafeAddress,
|
|
1231
1233
|
sequenceNumber,
|
|
1234
|
+
processed: false,
|
|
1232
1235
|
...IntentionHelper.getTxType(input.intention),
|
|
1233
1236
|
data: IntentionHelper.ser(input.intention),
|
|
1234
|
-
status: "
|
|
1237
|
+
status: "NEW",
|
|
1235
1238
|
creator: input.userAddress
|
|
1236
1239
|
};
|
|
1237
1240
|
await this.model.transactionIntention.save(intention);
|
|
@@ -1278,9 +1281,10 @@ var PseudoBackend = class _PseudoBackend {
|
|
|
1278
1281
|
const intention = {
|
|
1279
1282
|
msafeAddress: input.msafeAddress,
|
|
1280
1283
|
sequenceNumber,
|
|
1284
|
+
processed: false,
|
|
1281
1285
|
...IntentionHelper.getTxType(input.intention),
|
|
1282
1286
|
data: IntentionHelper.ser(input.intention),
|
|
1283
|
-
status: "
|
|
1287
|
+
status: "SUCCESS",
|
|
1284
1288
|
creator: input.userAddress
|
|
1285
1289
|
};
|
|
1286
1290
|
await this.model.transactionIntention.save(intention);
|
|
@@ -1451,10 +1455,6 @@ var PseudoBackend = class _PseudoBackend {
|
|
|
1451
1455
|
async processExecutedTransaction(digest) {
|
|
1452
1456
|
const historyTx = await this.model.historyTransaction.findOneBy({ digest });
|
|
1453
1457
|
if (historyTx) {
|
|
1454
|
-
const allHistories = await this.model.historyTransaction.findBy({
|
|
1455
|
-
msafeAddress: historyTx.msafeAddress
|
|
1456
|
-
});
|
|
1457
|
-
console.log(allHistories);
|
|
1458
1458
|
return;
|
|
1459
1459
|
}
|
|
1460
1460
|
const pendingTx = await this.model.pendingTransaction.findOneBy({ digest });
|
|
@@ -1463,7 +1463,7 @@ var PseudoBackend = class _PseudoBackend {
|
|
|
1463
1463
|
}
|
|
1464
1464
|
await this.model.transactionIntention.update(
|
|
1465
1465
|
{ msafeAddress: pendingTx.msafeAddress, sequenceNumber: pendingTx.sequenceNumber },
|
|
1466
|
-
{
|
|
1466
|
+
{ processed: true }
|
|
1467
1467
|
);
|
|
1468
1468
|
const pendings = await this.model.pendingTransaction.findBy({
|
|
1469
1469
|
msafeAddress: pendingTx.msafeAddress,
|
|
@@ -1531,6 +1531,15 @@ var PseudoBackend = class _PseudoBackend {
|
|
|
1531
1531
|
creator: nextTx.creator
|
|
1532
1532
|
};
|
|
1533
1533
|
await this.model.pendingTransaction.save(newPending);
|
|
1534
|
+
await this.model.transactionIntention.update(
|
|
1535
|
+
{
|
|
1536
|
+
msafeAddress: input.msafeAddress,
|
|
1537
|
+
sequenceNumber: nextSequenceNumber
|
|
1538
|
+
},
|
|
1539
|
+
{
|
|
1540
|
+
status: "SUCCESS"
|
|
1541
|
+
}
|
|
1542
|
+
);
|
|
1534
1543
|
} catch (e) {
|
|
1535
1544
|
await this.model.transactionIntention.update(
|
|
1536
1545
|
{
|
|
@@ -1538,7 +1547,7 @@ var PseudoBackend = class _PseudoBackend {
|
|
|
1538
1547
|
sequenceNumber: nextSequenceNumber
|
|
1539
1548
|
},
|
|
1540
1549
|
{
|
|
1541
|
-
status: "
|
|
1550
|
+
status: "FAILED",
|
|
1542
1551
|
statusRemark: e.toString()
|
|
1543
1552
|
}
|
|
1544
1553
|
);
|
|
@@ -1568,7 +1577,7 @@ var PseudoBackend = class _PseudoBackend {
|
|
|
1568
1577
|
if (failedIntention === null) {
|
|
1569
1578
|
throw new Error("Next intention not found");
|
|
1570
1579
|
}
|
|
1571
|
-
if (failedIntention.status !== "
|
|
1580
|
+
if (failedIntention.status !== "FAILED") {
|
|
1572
1581
|
throw new Error("Next intention not failed");
|
|
1573
1582
|
}
|
|
1574
1583
|
const history = {
|
|
@@ -1582,6 +1591,10 @@ var PseudoBackend = class _PseudoBackend {
|
|
|
1582
1591
|
status: "build-failed"
|
|
1583
1592
|
};
|
|
1584
1593
|
await this.model.historyTransaction.save(history);
|
|
1594
|
+
await this.model.transactionIntention.update(
|
|
1595
|
+
{ msafeAddress: input.msafeAddress, sequenceNumber: nextSequenceNumber },
|
|
1596
|
+
{ processed: true }
|
|
1597
|
+
);
|
|
1585
1598
|
}
|
|
1586
1599
|
async getUser(address) {
|
|
1587
1600
|
return this.model.user.findOneBy({ address });
|
|
@@ -1600,6 +1613,11 @@ var MSafeEnv = /* @__PURE__ */ ((MSafeEnv3) => {
|
|
|
1600
1613
|
MSafeEnv3["prod"] = "prod";
|
|
1601
1614
|
return MSafeEnv3;
|
|
1602
1615
|
})(MSafeEnv || {});
|
|
1616
|
+
var UNIT_DATABASE_CONFIG = {
|
|
1617
|
+
type: "sqlite",
|
|
1618
|
+
database: ":memory:",
|
|
1619
|
+
logging: false
|
|
1620
|
+
};
|
|
1603
1621
|
var LOCAL_DATABASE_CONFIG = {
|
|
1604
1622
|
type: "mysql",
|
|
1605
1623
|
host: "127.0.0.1",
|
|
@@ -1627,7 +1645,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1627
1645
|
suiClient: {
|
|
1628
1646
|
url: TESTNET_RPC_URL
|
|
1629
1647
|
},
|
|
1630
|
-
backend:
|
|
1648
|
+
backend: UNIT_DATABASE_CONFIG
|
|
1631
1649
|
}
|
|
1632
1650
|
],
|
|
1633
1651
|
[
|
|
@@ -1800,6 +1818,7 @@ var MSafeClient = class _MSafeClient {
|
|
|
1800
1818
|
SUI_COIN,
|
|
1801
1819
|
SignatureVerifier,
|
|
1802
1820
|
TESTNET_RPC_URL,
|
|
1821
|
+
UNIT_DATABASE_CONFIG,
|
|
1803
1822
|
Uint8ArrayToHex,
|
|
1804
1823
|
getAllCoins,
|
|
1805
1824
|
getMSafeConfig,
|