@midnight-ntwrk/wallet-sdk-dust-wallet 5.0.0-beta.0 → 5.0.0-beta.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.
|
@@ -26,11 +26,34 @@ export declare const DustSectionSchema: Schema.Struct<{
|
|
|
26
26
|
}>>;
|
|
27
27
|
}>;
|
|
28
28
|
type DustSection = Schema.Schema.Type<typeof DustSectionSchema>;
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Dust entry schema. Extends the common entry shape with an optional `dust` section. Tightening — required `dust` plus
|
|
31
|
+
* required `protocolVersion`/`status`/`fees` — happens at the writer-input type, not on the stored shape.
|
|
32
|
+
*/
|
|
33
|
+
export declare const DustTransactionHistoryEntrySchema: Schema.Struct<Readonly<{
|
|
30
34
|
hash: typeof Schema.String;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
identifiers: Schema.Array$<typeof Schema.String>;
|
|
36
|
+
protocolVersion: Schema.optional<typeof Schema.Number>;
|
|
37
|
+
status: Schema.optional<Schema.Literal<["SUCCESS", "FAILURE", "PARTIAL_SUCCESS"]>>;
|
|
38
|
+
timestamp: Schema.optional<typeof Schema.Date>;
|
|
39
|
+
fees: Schema.optional<Schema.NullOr<typeof Schema.BigInt>>;
|
|
40
|
+
lifecycle: Schema.Union<[Schema.Struct<{
|
|
41
|
+
status: Schema.Literal<["pending"]>;
|
|
42
|
+
submittedAt: typeof Schema.Date;
|
|
43
|
+
}>, Schema.Struct<{
|
|
44
|
+
status: Schema.Literal<["finalized"]>;
|
|
45
|
+
finalizedBlock: Schema.Struct<{
|
|
46
|
+
hash: typeof Schema.String;
|
|
47
|
+
height: typeof Schema.Number;
|
|
48
|
+
timestamp: typeof Schema.Date;
|
|
49
|
+
}>;
|
|
50
|
+
}>, Schema.Struct<{
|
|
51
|
+
status: Schema.Literal<["rejected"]>;
|
|
52
|
+
rejectedAt: typeof Schema.Date;
|
|
53
|
+
reason: Schema.optional<typeof Schema.String>;
|
|
54
|
+
}>]>;
|
|
55
|
+
}> & {
|
|
56
|
+
dust: Schema.optional<Schema.Struct<{
|
|
34
57
|
receivedUtxos: Schema.Array$<Schema.Struct<{
|
|
35
58
|
initialValue: typeof Schema.BigInt;
|
|
36
59
|
nonce: typeof Schema.BigInt;
|
|
@@ -45,19 +68,26 @@ export declare const DustTransactionHistoryEntrySchema: Schema.Struct<{
|
|
|
45
68
|
backingNight: typeof Schema.String;
|
|
46
69
|
mtIndex: typeof Schema.BigInt;
|
|
47
70
|
}>>;
|
|
48
|
-
}
|
|
71
|
+
}>>;
|
|
49
72
|
}>;
|
|
50
73
|
export type DustTransactionHistoryEntry = Schema.Schema.Type<typeof DustTransactionHistoryEntrySchema>;
|
|
74
|
+
export type DustHistoryStorage = TransactionHistoryStorage.TransactionHistoryReader<TransactionHistoryStorage.TransactionHistoryEntryWithHash> & TransactionHistoryStorage.TransactionHistoryWriter<DustTransactionHistoryEntry>;
|
|
51
75
|
export type DefaultTransactionHistoryConfiguration = {
|
|
52
|
-
txHistoryStorage:
|
|
76
|
+
txHistoryStorage: DustHistoryStorage;
|
|
53
77
|
indexerClientConnection: {
|
|
54
78
|
indexerHttpUrl: string;
|
|
55
79
|
};
|
|
56
80
|
};
|
|
57
81
|
export type TransactionDetails = {
|
|
58
82
|
hash: string;
|
|
59
|
-
|
|
83
|
+
block: {
|
|
84
|
+
hash: string;
|
|
85
|
+
height: number;
|
|
86
|
+
timestamp: number;
|
|
87
|
+
};
|
|
60
88
|
status: 'SUCCESS' | 'FAILURE' | 'PARTIAL_SUCCESS';
|
|
89
|
+
identifiers: readonly string[];
|
|
90
|
+
fees: bigint | null;
|
|
61
91
|
};
|
|
62
92
|
export type TransactionHistoryService = {
|
|
63
93
|
put(changes: ledger.DustStateChanges, metadata: TransactionDetails, protocolVersion: number): Effect.Effect<void, TransactionHistoryError>;
|
|
@@ -26,13 +26,15 @@ export const DustSectionSchema = Schema.Struct({
|
|
|
26
26
|
receivedUtxos: Schema.Array(DustUtxoInfoSchema),
|
|
27
27
|
spentUtxos: Schema.Array(DustUtxoInfoSchema),
|
|
28
28
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Dust entry schema. Extends the common entry shape with an optional `dust` section. Tightening — required `dust` plus
|
|
31
|
+
* required `protocolVersion`/`status`/`fees` — happens at the writer-input type, not on the stored shape.
|
|
32
|
+
*/
|
|
33
|
+
export const DustTransactionHistoryEntrySchema = TransactionHistoryStorage.extendEntrySchema({
|
|
34
|
+
dust: Schema.optional(DustSectionSchema),
|
|
34
35
|
});
|
|
35
36
|
const utxoEquals = Schema.equivalence(DustUtxoInfoSchema);
|
|
37
|
+
const isFinalized = (entry) => entry !== undefined && entry.lifecycle.status === 'finalized';
|
|
36
38
|
export const mergeDustSections = (existing, incoming) => ({
|
|
37
39
|
receivedUtxos: EArray.unionWith(existing.receivedUtxos, incoming.receivedUtxos, utxoEquals),
|
|
38
40
|
spentUtxos: EArray.unionWith(existing.spentUtxos, incoming.spentUtxos, utxoEquals),
|
|
@@ -44,37 +46,49 @@ const convertQualifiedDustOutput = (utxo) => ({
|
|
|
44
46
|
backingNight: utxo.backingNight,
|
|
45
47
|
mtIndex: utxo.mtIndex,
|
|
46
48
|
});
|
|
47
|
-
const
|
|
49
|
+
const convertUpdateToFinalizedInput = (changes, metadata, protocolVersion) => ({
|
|
48
50
|
hash: changes.source,
|
|
49
51
|
protocolVersion,
|
|
50
52
|
status: metadata.status,
|
|
53
|
+
identifiers: metadata.identifiers,
|
|
54
|
+
fees: metadata.fees,
|
|
55
|
+
finalizedBlock: {
|
|
56
|
+
hash: metadata.block.hash,
|
|
57
|
+
height: metadata.block.height,
|
|
58
|
+
timestamp: new Date(metadata.block.timestamp),
|
|
59
|
+
},
|
|
51
60
|
dust: {
|
|
52
61
|
receivedUtxos: changes.receivedUtxos.map(convertQualifiedDustOutput),
|
|
53
62
|
spentUtxos: changes.spentUtxos.map(convertQualifiedDustOutput),
|
|
54
63
|
},
|
|
55
64
|
});
|
|
56
|
-
const
|
|
57
|
-
try: () => txHistoryStorage.
|
|
58
|
-
catch: (e) => new TransactionHistoryError({ message: `Failed to
|
|
65
|
+
const gotFinalizedDust = (txHistoryStorage, input) => Effect.tryPromise({
|
|
66
|
+
try: () => txHistoryStorage.gotFinalized(input),
|
|
67
|
+
catch: (e) => new TransactionHistoryError({ message: `Failed to record finalized history entry for ${input.hash}`, cause: e }),
|
|
59
68
|
});
|
|
60
69
|
export const makeDefaultTransactionHistoryService = (config, _getContext) => {
|
|
61
70
|
const txHistoryStorage = config.txHistoryStorage;
|
|
62
71
|
const queryClientLayer = HttpQueryClient.layer({ url: config.indexerClientConnection.indexerHttpUrl });
|
|
63
72
|
return {
|
|
64
|
-
put: (changes, metadata, protocolVersion) =>
|
|
65
|
-
const entry = convertUpdateToStorageEntry(changes, metadata, protocolVersion);
|
|
66
|
-
return upsertDustEntry(txHistoryStorage, entry);
|
|
67
|
-
},
|
|
73
|
+
put: (changes, metadata, protocolVersion) => gotFinalizedDust(txHistoryStorage, convertUpdateToFinalizedInput(changes, metadata, protocolVersion)),
|
|
68
74
|
getTransactionDetails: (hash) => Effect.gen(function* () {
|
|
69
75
|
const statusQuery = yield* TransactionHistoryDetail;
|
|
70
76
|
const result = yield* statusQuery({ transactionHash: hash });
|
|
71
77
|
const tx = result.transactions[0];
|
|
72
78
|
const rawStatus = tx.__typename === 'RegularTransaction' ? tx.transactionResult.status : undefined;
|
|
73
79
|
const status = rawStatus === 'FAILURE' || rawStatus === 'PARTIAL_SUCCESS' ? rawStatus : 'SUCCESS';
|
|
80
|
+
const identifiers = tx.__typename === 'RegularTransaction' ? tx.identifiers : [];
|
|
81
|
+
const fees = tx.__typename === 'RegularTransaction' ? BigInt(tx.fees.paidFees) : null;
|
|
74
82
|
return {
|
|
75
83
|
hash: tx.hash,
|
|
76
|
-
|
|
84
|
+
block: {
|
|
85
|
+
hash: tx.block.hash,
|
|
86
|
+
height: tx.block.height,
|
|
87
|
+
timestamp: tx.block.timestamp,
|
|
88
|
+
},
|
|
77
89
|
status,
|
|
90
|
+
identifiers,
|
|
91
|
+
fees,
|
|
78
92
|
};
|
|
79
93
|
}).pipe(Effect.provide(queryClientLayer), Effect.scoped, Effect.retry(Schedule.exponential(Duration.seconds(1)).pipe(Schedule.compose(Schedule.recurs(3)))), Effect.mapError((cause) => new TransactionHistoryError({
|
|
80
94
|
message: `Failed to fetch transaction metadata for ${hash}`,
|
|
@@ -86,20 +100,23 @@ export const makeSimulatorTransactionHistoryService = (config, _getContext) => {
|
|
|
86
100
|
const txHistoryStorage = config.txHistoryStorage;
|
|
87
101
|
return {
|
|
88
102
|
put: (changes, metadata, protocolVersion) => {
|
|
89
|
-
const
|
|
90
|
-
return
|
|
91
|
-
...entry,
|
|
92
|
-
timestamp: new Date(metadata.timestamp),
|
|
93
|
-
});
|
|
103
|
+
const input = convertUpdateToFinalizedInput(changes, metadata, protocolVersion);
|
|
104
|
+
return gotFinalizedDust(txHistoryStorage, { ...input, timestamp: input.finalizedBlock.timestamp });
|
|
94
105
|
},
|
|
95
106
|
getTransactionDetails: (hash) => Effect.tryPromise({
|
|
96
107
|
try: () => txHistoryStorage.get(hash),
|
|
97
108
|
catch: (e) => new TransactionHistoryError({ message: `Failed to get transaction details for ${hash}`, cause: e }),
|
|
98
|
-
}).pipe(Effect.flatMap((entry) => entry
|
|
109
|
+
}).pipe(Effect.flatMap((entry) => isFinalized(entry)
|
|
99
110
|
? Effect.succeed({
|
|
100
111
|
hash: entry.hash,
|
|
101
|
-
|
|
102
|
-
|
|
112
|
+
block: {
|
|
113
|
+
hash: entry.lifecycle.finalizedBlock.hash,
|
|
114
|
+
height: entry.lifecycle.finalizedBlock.height,
|
|
115
|
+
timestamp: entry.lifecycle.finalizedBlock.timestamp.getTime(),
|
|
116
|
+
},
|
|
117
|
+
status: entry.status ?? 'SUCCESS',
|
|
118
|
+
identifiers: entry.identifiers,
|
|
119
|
+
fees: entry.fees ?? null,
|
|
103
120
|
})
|
|
104
121
|
: Effect.fail(new TransactionHistoryError({ message: `No transaction found in storage for hash: ${hash}` })))),
|
|
105
122
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midnight-ntwrk/wallet-sdk-dust-wallet",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@midnightntwrk/ledger-v9": "1.0.0-rc.
|
|
34
|
-
"@midnight-ntwrk/wallet-sdk-abstractions": "
|
|
35
|
-
"@midnight-ntwrk/wallet-sdk-address-format": "
|
|
36
|
-
"@midnight-ntwrk/wallet-sdk-capabilities": "
|
|
37
|
-
"@midnight-ntwrk/wallet-sdk-indexer-client": "
|
|
38
|
-
"@midnight-ntwrk/wallet-sdk-runtime": "
|
|
39
|
-
"@midnight-ntwrk/wallet-sdk-utilities": "
|
|
33
|
+
"@midnightntwrk/ledger-v9": "1.0.0-rc.3",
|
|
34
|
+
"@midnight-ntwrk/wallet-sdk-abstractions": "3.0.0-beta.0",
|
|
35
|
+
"@midnight-ntwrk/wallet-sdk-address-format": "4.0.0-beta.2",
|
|
36
|
+
"@midnight-ntwrk/wallet-sdk-capabilities": "4.0.0-beta.2",
|
|
37
|
+
"@midnight-ntwrk/wallet-sdk-indexer-client": "1.3.0-beta.1",
|
|
38
|
+
"@midnight-ntwrk/wallet-sdk-runtime": "1.0.6-beta.0",
|
|
39
|
+
"@midnight-ntwrk/wallet-sdk-utilities": "1.2.0",
|
|
40
40
|
"effect": "^3.19.19",
|
|
41
41
|
"rxjs": "^7.8.2"
|
|
42
42
|
},
|
|
@@ -54,6 +54,6 @@
|
|
|
54
54
|
"publint": "publint --strict"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@midnight-ntwrk/wallet-sdk-hd": "^3.1.0-beta.
|
|
57
|
+
"@midnight-ntwrk/wallet-sdk-hd": "^3.1.0-beta.1"
|
|
58
58
|
}
|
|
59
59
|
}
|