@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
|
@@ -385,6 +385,7 @@ export class PseudoBackend implements IBackend {
|
|
|
385
385
|
rawData: tx.data,
|
|
386
386
|
txType: tx.txType,
|
|
387
387
|
txSubType: tx.txSubType,
|
|
388
|
+
processed: tx.processed,
|
|
388
389
|
status: tx.status,
|
|
389
390
|
statusRemark: tx.statusRemark,
|
|
390
391
|
creator: tx.creator,
|
|
@@ -429,9 +430,10 @@ export class PseudoBackend implements IBackend {
|
|
|
429
430
|
const intention: TransactionIntention = {
|
|
430
431
|
msafeAddress: input.msafeAddress,
|
|
431
432
|
sequenceNumber,
|
|
433
|
+
processed: false,
|
|
432
434
|
...IntentionHelper.getTxType(input.intention),
|
|
433
435
|
data: IntentionHelper.ser(input.intention),
|
|
434
|
-
status: '
|
|
436
|
+
status: 'NEW',
|
|
435
437
|
creator: input.userAddress,
|
|
436
438
|
};
|
|
437
439
|
await this.model.transactionIntention.save(intention);
|
|
@@ -490,9 +492,10 @@ export class PseudoBackend implements IBackend {
|
|
|
490
492
|
const intention: TransactionIntention = {
|
|
491
493
|
msafeAddress: input.msafeAddress,
|
|
492
494
|
sequenceNumber,
|
|
495
|
+
processed: false,
|
|
493
496
|
...IntentionHelper.getTxType(input.intention),
|
|
494
497
|
data: IntentionHelper.ser(input.intention),
|
|
495
|
-
status: '
|
|
498
|
+
status: 'SUCCESS',
|
|
496
499
|
creator: input.userAddress,
|
|
497
500
|
};
|
|
498
501
|
await this.model.transactionIntention.save(intention);
|
|
@@ -696,10 +699,6 @@ export class PseudoBackend implements IBackend {
|
|
|
696
699
|
const historyTx = await this.model.historyTransaction.findOneBy({ digest });
|
|
697
700
|
if (historyTx) {
|
|
698
701
|
// Already processed, directly return
|
|
699
|
-
const allHistories = await this.model.historyTransaction.findBy({
|
|
700
|
-
msafeAddress: (historyTx as HistoryTransaction).msafeAddress,
|
|
701
|
-
});
|
|
702
|
-
console.log(allHistories);
|
|
703
702
|
return;
|
|
704
703
|
}
|
|
705
704
|
const pendingTx = await this.model.pendingTransaction.findOneBy({ digest });
|
|
@@ -709,7 +708,7 @@ export class PseudoBackend implements IBackend {
|
|
|
709
708
|
// Mark the intention as processed.
|
|
710
709
|
await this.model.transactionIntention.update(
|
|
711
710
|
{ msafeAddress: pendingTx.msafeAddress, sequenceNumber: pendingTx.sequenceNumber },
|
|
712
|
-
{
|
|
711
|
+
{ processed: true },
|
|
713
712
|
);
|
|
714
713
|
// Delete the current pending transaction.
|
|
715
714
|
// There can be multiple transactions. mark one as executed, other as rejected
|
|
@@ -784,6 +783,15 @@ export class PseudoBackend implements IBackend {
|
|
|
784
783
|
creator: nextTx.creator,
|
|
785
784
|
};
|
|
786
785
|
await this.model.pendingTransaction.save(newPending);
|
|
786
|
+
await this.model.transactionIntention.update(
|
|
787
|
+
{
|
|
788
|
+
msafeAddress: input.msafeAddress,
|
|
789
|
+
sequenceNumber: nextSequenceNumber,
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
status: 'SUCCESS',
|
|
793
|
+
},
|
|
794
|
+
);
|
|
787
795
|
} catch (e: unknown) {
|
|
788
796
|
// Build failed. Mark the intention as failed.
|
|
789
797
|
await this.model.transactionIntention.update(
|
|
@@ -792,7 +800,7 @@ export class PseudoBackend implements IBackend {
|
|
|
792
800
|
sequenceNumber: nextSequenceNumber,
|
|
793
801
|
},
|
|
794
802
|
{
|
|
795
|
-
status: '
|
|
803
|
+
status: 'FAILED',
|
|
796
804
|
statusRemark: (e as any).toString(),
|
|
797
805
|
},
|
|
798
806
|
);
|
|
@@ -825,7 +833,7 @@ export class PseudoBackend implements IBackend {
|
|
|
825
833
|
if (failedIntention === null) {
|
|
826
834
|
throw new Error('Next intention not found');
|
|
827
835
|
}
|
|
828
|
-
if (failedIntention.status !== '
|
|
836
|
+
if (failedIntention.status !== 'FAILED') {
|
|
829
837
|
throw new Error('Next intention not failed');
|
|
830
838
|
}
|
|
831
839
|
|
|
@@ -839,6 +847,11 @@ export class PseudoBackend implements IBackend {
|
|
|
839
847
|
status: 'build-failed',
|
|
840
848
|
};
|
|
841
849
|
await this.model.historyTransaction.save(history);
|
|
850
|
+
|
|
851
|
+
await this.model.transactionIntention.update(
|
|
852
|
+
{ msafeAddress: input.msafeAddress, sequenceNumber: nextSequenceNumber },
|
|
853
|
+
{ processed: true },
|
|
854
|
+
);
|
|
842
855
|
}
|
|
843
856
|
|
|
844
857
|
private async getUser(address: string): Promise<User | null> {
|
package/src/globals/const.ts
CHANGED
|
@@ -25,6 +25,12 @@ export interface MSafeConfigOptions {
|
|
|
25
25
|
// Use pseudo backend for now.
|
|
26
26
|
export type DBConfig = ModelConfig;
|
|
27
27
|
|
|
28
|
+
export const UNIT_DATABASE_CONFIG: DBConfig = {
|
|
29
|
+
type: 'sqlite',
|
|
30
|
+
database: ':memory:',
|
|
31
|
+
logging: false,
|
|
32
|
+
};
|
|
33
|
+
|
|
28
34
|
export const LOCAL_DATABASE_CONFIG: DBConfig = {
|
|
29
35
|
type: 'mysql',
|
|
30
36
|
host: '127.0.0.1',
|
|
@@ -55,7 +61,7 @@ export const ENV_CONFIGS = new Map<MSafeEnv, MSafeConfig>([
|
|
|
55
61
|
suiClient: {
|
|
56
62
|
url: TESTNET_RPC_URL,
|
|
57
63
|
},
|
|
58
|
-
backend:
|
|
64
|
+
backend: UNIT_DATABASE_CONFIG,
|
|
59
65
|
},
|
|
60
66
|
],
|
|
61
67
|
[
|