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