@midnightntwrk/wallet-sdk-capabilities 4.0.0-rc.0 → 4.0.0-rc.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/README.md +10 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/liveness/index.d.ts +2 -0
- package/dist/liveness/index.js +14 -0
- package/dist/liveness/livenessReads.d.ts +73 -0
- package/dist/liveness/livenessReads.js +229 -0
- package/dist/liveness/livenessService.d.ts +137 -0
- package/dist/liveness/livenessService.js +200 -0
- package/dist/proving/index.d.ts +1 -0
- package/dist/proving/index.js +1 -0
- package/dist/proving/provingService.d.ts +15 -48
- package/dist/proving/provingService.js +1 -89
- package/dist/proving/v8ProvingService.d.ts +33 -6
- package/dist/proving/v8ProvingService.js +35 -5
- package/dist/proving/v9ProvingService.d.ts +108 -0
- package/dist/proving/v9ProvingService.js +146 -0
- package/dist/proving/versionedProving.d.ts +22 -4
- package/dist/proving/versionedProving.js +27 -1
- package/dist/simulation/index.d.ts +4 -6
- package/dist/simulation/index.js +4 -7
- package/dist/simulation/v8/Simulator.d.ts +0 -2
- package/dist/simulation/v8/Simulator.js +0 -2
- package/dist/simulation/v8/SimulatorState.d.ts +0 -9
- package/dist/simulation/v8/SimulatorState.js +0 -8
- package/dist/simulation/v8/index.d.ts +1 -1
- package/dist/simulation/v8/index.js +1 -1
- package/dist/simulation/v9/Simulator.d.ts +0 -2
- package/dist/simulation/v9/Simulator.js +0 -2
- package/dist/simulation/v9/SimulatorState.d.ts +0 -9
- package/dist/simulation/v9/SimulatorState.js +0 -8
- package/dist/simulation/v9/index.d.ts +1 -1
- package/dist/simulation/v9/index.js +1 -1
- package/dist/submission/submissionService.d.ts +57 -9
- package/dist/submission/submissionService.js +61 -15
- package/dist/transactionLifecycle/SnapshotFormat.d.ts +51 -0
- package/dist/transactionLifecycle/SnapshotFormat.js +120 -0
- package/dist/transactionLifecycle/index.d.ts +4 -0
- package/dist/{pendingTransactions → transactionLifecycle}/index.js +4 -2
- package/dist/transactionLifecycle/lifecycle.d.ts +402 -0
- package/dist/transactionLifecycle/lifecycle.js +407 -0
- package/dist/transactionLifecycle/lifecycleService.d.ts +448 -0
- package/dist/transactionLifecycle/lifecycleService.js +350 -0
- package/dist/transactionLifecycle/transactionTraits.d.ts +106 -0
- package/dist/transactionLifecycle/transactionTraits.js +53 -0
- package/dist/validation/blockData.d.ts +23 -4
- package/dist/validation/blockData.js +34 -10
- package/dist/validation/index.d.ts +1 -0
- package/dist/validation/index.js +1 -0
- package/dist/validation/promiseBoundary.d.ts +10 -0
- package/dist/validation/promiseBoundary.js +30 -0
- package/dist/validation/v8ValidationService.d.ts +5 -4
- package/dist/validation/v8ValidationService.js +10 -3
- package/dist/validation/v9ValidationService.d.ts +30 -0
- package/dist/validation/v9ValidationService.js +61 -0
- package/dist/validation/validationService.d.ts +53 -31
- package/dist/validation/validationService.js +29 -49
- package/dist/validation/versionedValidation.d.ts +5 -3
- package/dist/validation/versionedValidation.js +5 -3
- package/package.json +13 -13
- package/dist/pendingTransactions/index.d.ts +0 -2
- package/dist/pendingTransactions/pendingTransactions.d.ts +0 -165
- package/dist/pendingTransactions/pendingTransactions.js +0 -202
- package/dist/pendingTransactions/pendingTransactionsService.d.ts +0 -68
- package/dist/pendingTransactions/pendingTransactionsService.js +0 -158
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Either, type ParseResult } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* Every format version the transaction lifecycle store has been written in, oldest first.
|
|
4
|
+
*
|
|
5
|
+
* Declared here, with no ledger import, so the reader and the upgrade step share one source of truth.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SNAPSHOT_FORMAT_VERSIONS: readonly ["v1", "v2"];
|
|
8
|
+
/** The format version of a store holding pending items and reservations side by side. */
|
|
9
|
+
export declare const V1_SNAPSHOT_FORMAT_VERSION = "v1";
|
|
10
|
+
/**
|
|
11
|
+
* The format version of a store holding one lifecycle record per transaction. {@link upgradeSnapshotV1ToV2} is the one
|
|
12
|
+
* step into it, and this is the version it stamps. Frozen: a later bump adds a version and a step of its own and leaves
|
|
13
|
+
* this one as it is.
|
|
14
|
+
*/
|
|
15
|
+
export declare const V2_SNAPSHOT_FORMAT_VERSION = "v2";
|
|
16
|
+
/**
|
|
17
|
+
* The current format version of the store. This is the constant a bump moves; the upgrade steps never read it, because
|
|
18
|
+
* each stamps the version it upgrades to.
|
|
19
|
+
*/
|
|
20
|
+
export declare const SNAPSHOT_FORMAT_VERSION = "v2";
|
|
21
|
+
/**
|
|
22
|
+
* Refuses a store stamped `v1` that does not have the `v1` shape, with the reason it does not.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Run before {@link upgradeSnapshotV1ToV2}, which hands back anything that is not a `v1` store unchanged. Without this
|
|
26
|
+
* check a damaged `v1` store would reach the `v2` reader and be refused for its version, which this build does read,
|
|
27
|
+
* rather than for what is actually wrong in it. Anything not stamped `v1` passes through for the reader after it to
|
|
28
|
+
* judge.
|
|
29
|
+
* @example
|
|
30
|
+
* const checked = checkV1Store(JSON.parse(stored));
|
|
31
|
+
*
|
|
32
|
+
* @param json The store as decoded from its JSON string.
|
|
33
|
+
* @returns The input unchanged, or why a store stamped `v1` is not one.
|
|
34
|
+
*/
|
|
35
|
+
export declare const checkV1Store: (json: unknown) => Either.Either<unknown, ParseResult.ParseError>;
|
|
36
|
+
/**
|
|
37
|
+
* Upgrades a decoded transaction lifecycle store from format version `v1` to `v2`.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* A pure function on the decoded JSON, run before any schema, so the schema only ever has to describe one shape. Each
|
|
41
|
+
* pending item and each reservation becomes one lifecycle record, pending items first; every other top-level member,
|
|
42
|
+
* known or not, passes through untouched. It fills in only what `v1` recorded and leaves out what it never did, so
|
|
43
|
+
* the reader derives that from the transaction or goes without. Anything that is not a `v1` store is handed back as
|
|
44
|
+
* it came, for the schema after it to refuse with a precise reason; and applying the step twice is applying it once.
|
|
45
|
+
* @example
|
|
46
|
+
* const current = upgradeSnapshotV1ToV2(JSON.parse(stored));
|
|
47
|
+
*
|
|
48
|
+
* @param json The store as decoded from its JSON string.
|
|
49
|
+
* @returns The same store in format `v2`, or the input unchanged when the step does not apply.
|
|
50
|
+
*/
|
|
51
|
+
export declare const upgradeSnapshotV1ToV2: (json: unknown) => unknown;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of MIDNIGHT-WALLET-SDK.
|
|
3
|
+
* Copyright (C) Midnight Foundation
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* You may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
import { Either, Schema } from 'effect';
|
|
16
|
+
/**
|
|
17
|
+
* Every format version the transaction lifecycle store has been written in, oldest first.
|
|
18
|
+
*
|
|
19
|
+
* Declared here, with no ledger import, so the reader and the upgrade step share one source of truth.
|
|
20
|
+
*/
|
|
21
|
+
export const SNAPSHOT_FORMAT_VERSIONS = ['v1', 'v2'];
|
|
22
|
+
/** The format version of a store holding pending items and reservations side by side. */
|
|
23
|
+
export const V1_SNAPSHOT_FORMAT_VERSION = 'v1';
|
|
24
|
+
/**
|
|
25
|
+
* The format version of a store holding one lifecycle record per transaction. {@link upgradeSnapshotV1ToV2} is the one
|
|
26
|
+
* step into it, and this is the version it stamps. Frozen: a later bump adds a version and a step of its own and leaves
|
|
27
|
+
* this one as it is.
|
|
28
|
+
*/
|
|
29
|
+
export const V2_SNAPSHOT_FORMAT_VERSION = 'v2';
|
|
30
|
+
/**
|
|
31
|
+
* The current format version of the store. This is the constant a bump moves; the upgrade steps never read it, because
|
|
32
|
+
* each stamps the version it upgrades to.
|
|
33
|
+
*/
|
|
34
|
+
export const SNAPSHOT_FORMAT_VERSION = V2_SNAPSHOT_FORMAT_VERSION;
|
|
35
|
+
const V1PendingItem = Schema.Struct({
|
|
36
|
+
tx: Schema.String,
|
|
37
|
+
creationTime: Schema.String,
|
|
38
|
+
protocolVersion: Schema.optional(Schema.String),
|
|
39
|
+
});
|
|
40
|
+
const V1Reservation = Schema.Struct({
|
|
41
|
+
identifiers: Schema.Array(Schema.String),
|
|
42
|
+
intentHashes: Schema.Array(Schema.String),
|
|
43
|
+
inputs: Schema.Struct({
|
|
44
|
+
unshielded: Schema.Array(Schema.String),
|
|
45
|
+
shielded: Schema.optional(Schema.Array(Schema.String)),
|
|
46
|
+
}),
|
|
47
|
+
ttl: Schema.String,
|
|
48
|
+
createdAt: Schema.String,
|
|
49
|
+
expired: Schema.Boolean,
|
|
50
|
+
});
|
|
51
|
+
/** What the step looks for: a `v1` store, whose reservations arrived after it was in the field and may be absent. */
|
|
52
|
+
const V1Store = Schema.Struct({
|
|
53
|
+
version: Schema.Literal(V1_SNAPSHOT_FORMAT_VERSION),
|
|
54
|
+
transactions: Schema.Array(V1PendingItem),
|
|
55
|
+
reservations: Schema.optional(Schema.Array(V1Reservation)),
|
|
56
|
+
});
|
|
57
|
+
const isV1Store = Schema.is(V1Store);
|
|
58
|
+
const isStampedV1 = (json) => typeof json === 'object' && json !== null && 'version' in json && json.version === V1_SNAPSHOT_FORMAT_VERSION;
|
|
59
|
+
/**
|
|
60
|
+
* Refuses a store stamped `v1` that does not have the `v1` shape, with the reason it does not.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* Run before {@link upgradeSnapshotV1ToV2}, which hands back anything that is not a `v1` store unchanged. Without this
|
|
64
|
+
* check a damaged `v1` store would reach the `v2` reader and be refused for its version, which this build does read,
|
|
65
|
+
* rather than for what is actually wrong in it. Anything not stamped `v1` passes through for the reader after it to
|
|
66
|
+
* judge.
|
|
67
|
+
* @example
|
|
68
|
+
* const checked = checkV1Store(JSON.parse(stored));
|
|
69
|
+
*
|
|
70
|
+
* @param json The store as decoded from its JSON string.
|
|
71
|
+
* @returns The input unchanged, or why a store stamped `v1` is not one.
|
|
72
|
+
*/
|
|
73
|
+
export const checkV1Store = (json) => isStampedV1(json) ? Either.map(Schema.decodeUnknownEither(V1Store)(json), () => json) : Either.right(json);
|
|
74
|
+
/**
|
|
75
|
+
* A pending item was finalized at least, and `v1` showed it as submitted. When it was submitted was never kept: its
|
|
76
|
+
* creation time is when it was finalized. Its identifiers, intent hashes, inputs and TTL live in the transaction, for
|
|
77
|
+
* the reader to take from it.
|
|
78
|
+
*/
|
|
79
|
+
const fromPendingItem = (item) => ({
|
|
80
|
+
tx: item.tx,
|
|
81
|
+
createdAt: item.creationTime,
|
|
82
|
+
...(item.protocolVersion === undefined ? {} : { protocolVersion: item.protocolVersion }),
|
|
83
|
+
state: { _tag: 'Submitted' },
|
|
84
|
+
});
|
|
85
|
+
/** A reservation never held its transaction or the version it was built for, so its record holds neither. */
|
|
86
|
+
const fromReservation = (reservation) => ({
|
|
87
|
+
identifiers: reservation.identifiers,
|
|
88
|
+
intentHashes: reservation.intentHashes,
|
|
89
|
+
inputs: reservation.inputs.shielded === undefined
|
|
90
|
+
? { unshielded: reservation.inputs.unshielded }
|
|
91
|
+
: { unshielded: reservation.inputs.unshielded, shielded: reservation.inputs.shielded },
|
|
92
|
+
ttl: reservation.ttl,
|
|
93
|
+
createdAt: reservation.createdAt,
|
|
94
|
+
state: { _tag: reservation.expired ? 'Expired' : 'Balanced' },
|
|
95
|
+
});
|
|
96
|
+
/**
|
|
97
|
+
* Upgrades a decoded transaction lifecycle store from format version `v1` to `v2`.
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* A pure function on the decoded JSON, run before any schema, so the schema only ever has to describe one shape. Each
|
|
101
|
+
* pending item and each reservation becomes one lifecycle record, pending items first; every other top-level member,
|
|
102
|
+
* known or not, passes through untouched. It fills in only what `v1` recorded and leaves out what it never did, so
|
|
103
|
+
* the reader derives that from the transaction or goes without. Anything that is not a `v1` store is handed back as
|
|
104
|
+
* it came, for the schema after it to refuse with a precise reason; and applying the step twice is applying it once.
|
|
105
|
+
* @example
|
|
106
|
+
* const current = upgradeSnapshotV1ToV2(JSON.parse(stored));
|
|
107
|
+
*
|
|
108
|
+
* @param json The store as decoded from its JSON string.
|
|
109
|
+
* @returns The same store in format `v2`, or the input unchanged when the step does not apply.
|
|
110
|
+
*/
|
|
111
|
+
export const upgradeSnapshotV1ToV2 = (json) => {
|
|
112
|
+
if (!isV1Store(json))
|
|
113
|
+
return json;
|
|
114
|
+
const { transactions, reservations = [], ...rest } = json;
|
|
115
|
+
return {
|
|
116
|
+
...rest,
|
|
117
|
+
version: V2_SNAPSHOT_FORMAT_VERSION,
|
|
118
|
+
records: [...transactions.map(fromPendingItem), ...reservations.map(fromReservation)],
|
|
119
|
+
};
|
|
120
|
+
};
|
|
@@ -12,5 +12,7 @@
|
|
|
12
12
|
* See the License for the specific language governing permissions and
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
|
-
export * from './
|
|
16
|
-
export * as
|
|
15
|
+
export * as TransactionTraits from './transactionTraits.js';
|
|
16
|
+
export * as Lifecycle from './lifecycle.js';
|
|
17
|
+
export * from './lifecycleService.js';
|
|
18
|
+
export * as LifecycleFormat from './SnapshotFormat.js';
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One record per transaction, from the moment it is balanced to the moment nothing can change its outcome.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* The states, what moves a record between them and what each stores are decided in ADR 0011. Every transition here is
|
|
6
|
+
* total: an event that does not apply to a record leaves it as it was, so a final state never moves, save that a
|
|
7
|
+
* reported inclusion overrules an end the wallet only inferred. No transition frees a coin; each wallet's own sweep
|
|
8
|
+
* does.
|
|
9
|
+
*/
|
|
10
|
+
import { ProtocolVersion, SnapshotFormat } from '@midnightntwrk/wallet-sdk-abstractions';
|
|
11
|
+
import { Data, DateTime, Either, Option, ParseResult } from 'effect';
|
|
12
|
+
import { type FailedTransactionResult, type Inputs, type VersionedTransactionTrait } from './transactionTraits.js';
|
|
13
|
+
export type { Inputs } from './transactionTraits.js';
|
|
14
|
+
/** Why a submitted transaction will never be included: the chain refused it, or its TTL passed while it waited. */
|
|
15
|
+
export type RejectedVerdict = FailedTransactionResult | Readonly<{
|
|
16
|
+
status: 'TTL_PASSED';
|
|
17
|
+
}>;
|
|
18
|
+
/** Where a transaction is in its lifecycle. */
|
|
19
|
+
export type LifecycleState = Data.TaggedEnum<{
|
|
20
|
+
Balanced: Record<never, never>;
|
|
21
|
+
Finalized: Record<never, never>;
|
|
22
|
+
Submitted: Record<never, never>;
|
|
23
|
+
Confirmed: Record<never, never>;
|
|
24
|
+
Rejected: {
|
|
25
|
+
readonly verdict: RejectedVerdict;
|
|
26
|
+
};
|
|
27
|
+
Orphaned: {
|
|
28
|
+
readonly authoredFor: ProtocolVersion.ProtocolVersion;
|
|
29
|
+
readonly chainNow: ProtocolVersion.ProtocolVersion;
|
|
30
|
+
};
|
|
31
|
+
Expired: Record<never, never>;
|
|
32
|
+
Reverted: Record<never, never>;
|
|
33
|
+
}>;
|
|
34
|
+
export declare const LifecycleState: {
|
|
35
|
+
readonly Submitted: Data.Case.Constructor<{
|
|
36
|
+
readonly _tag: "Submitted";
|
|
37
|
+
}, "_tag">;
|
|
38
|
+
readonly Expired: Data.Case.Constructor<{
|
|
39
|
+
readonly _tag: "Expired";
|
|
40
|
+
}, "_tag">;
|
|
41
|
+
readonly Balanced: Data.Case.Constructor<{
|
|
42
|
+
readonly _tag: "Balanced";
|
|
43
|
+
}, "_tag">;
|
|
44
|
+
readonly Finalized: Data.Case.Constructor<{
|
|
45
|
+
readonly _tag: "Finalized";
|
|
46
|
+
}, "_tag">;
|
|
47
|
+
readonly Confirmed: Data.Case.Constructor<{
|
|
48
|
+
readonly _tag: "Confirmed";
|
|
49
|
+
}, "_tag">;
|
|
50
|
+
readonly Rejected: Data.Case.Constructor<{
|
|
51
|
+
readonly _tag: "Rejected";
|
|
52
|
+
readonly verdict: RejectedVerdict;
|
|
53
|
+
}, "_tag">;
|
|
54
|
+
readonly Orphaned: Data.Case.Constructor<{
|
|
55
|
+
readonly _tag: "Orphaned";
|
|
56
|
+
readonly authoredFor: ProtocolVersion.ProtocolVersion;
|
|
57
|
+
readonly chainNow: ProtocolVersion.ProtocolVersion;
|
|
58
|
+
}, "_tag">;
|
|
59
|
+
readonly Reverted: Data.Case.Constructor<{
|
|
60
|
+
readonly _tag: "Reverted";
|
|
61
|
+
}, "_tag">;
|
|
62
|
+
readonly $is: <Tag extends "Submitted" | "Expired" | "Balanced" | "Finalized" | "Confirmed" | "Rejected" | "Orphaned" | "Reverted">(tag: Tag) => (u: unknown) => u is Extract<{
|
|
63
|
+
readonly _tag: "Submitted";
|
|
64
|
+
}, {
|
|
65
|
+
readonly _tag: Tag;
|
|
66
|
+
}> | Extract<{
|
|
67
|
+
readonly _tag: "Expired";
|
|
68
|
+
}, {
|
|
69
|
+
readonly _tag: Tag;
|
|
70
|
+
}> | Extract<{
|
|
71
|
+
readonly _tag: "Balanced";
|
|
72
|
+
}, {
|
|
73
|
+
readonly _tag: Tag;
|
|
74
|
+
}> | Extract<{
|
|
75
|
+
readonly _tag: "Finalized";
|
|
76
|
+
}, {
|
|
77
|
+
readonly _tag: Tag;
|
|
78
|
+
}> | Extract<{
|
|
79
|
+
readonly _tag: "Confirmed";
|
|
80
|
+
}, {
|
|
81
|
+
readonly _tag: Tag;
|
|
82
|
+
}> | Extract<{
|
|
83
|
+
readonly _tag: "Rejected";
|
|
84
|
+
readonly verdict: RejectedVerdict;
|
|
85
|
+
}, {
|
|
86
|
+
readonly _tag: Tag;
|
|
87
|
+
}> | Extract<{
|
|
88
|
+
readonly _tag: "Orphaned";
|
|
89
|
+
readonly authoredFor: ProtocolVersion.ProtocolVersion;
|
|
90
|
+
readonly chainNow: ProtocolVersion.ProtocolVersion;
|
|
91
|
+
}, {
|
|
92
|
+
readonly _tag: Tag;
|
|
93
|
+
}> | Extract<{
|
|
94
|
+
readonly _tag: "Reverted";
|
|
95
|
+
}, {
|
|
96
|
+
readonly _tag: Tag;
|
|
97
|
+
}>;
|
|
98
|
+
readonly $match: {
|
|
99
|
+
<const Cases extends {
|
|
100
|
+
readonly Submitted: (args: {
|
|
101
|
+
readonly _tag: "Submitted";
|
|
102
|
+
}) => any;
|
|
103
|
+
readonly Expired: (args: {
|
|
104
|
+
readonly _tag: "Expired";
|
|
105
|
+
}) => any;
|
|
106
|
+
readonly Balanced: (args: {
|
|
107
|
+
readonly _tag: "Balanced";
|
|
108
|
+
}) => any;
|
|
109
|
+
readonly Finalized: (args: {
|
|
110
|
+
readonly _tag: "Finalized";
|
|
111
|
+
}) => any;
|
|
112
|
+
readonly Confirmed: (args: {
|
|
113
|
+
readonly _tag: "Confirmed";
|
|
114
|
+
}) => any;
|
|
115
|
+
readonly Rejected: (args: {
|
|
116
|
+
readonly _tag: "Rejected";
|
|
117
|
+
readonly verdict: RejectedVerdict;
|
|
118
|
+
}) => any;
|
|
119
|
+
readonly Orphaned: (args: {
|
|
120
|
+
readonly _tag: "Orphaned";
|
|
121
|
+
readonly authoredFor: ProtocolVersion.ProtocolVersion;
|
|
122
|
+
readonly chainNow: ProtocolVersion.ProtocolVersion;
|
|
123
|
+
}) => any;
|
|
124
|
+
readonly Reverted: (args: {
|
|
125
|
+
readonly _tag: "Reverted";
|
|
126
|
+
}) => any;
|
|
127
|
+
}>(cases: Cases & { [K in Exclude<keyof Cases, "Submitted" | "Expired" | "Balanced" | "Finalized" | "Confirmed" | "Rejected" | "Orphaned" | "Reverted">]: never; }): (value: {
|
|
128
|
+
readonly _tag: "Submitted";
|
|
129
|
+
} | {
|
|
130
|
+
readonly _tag: "Expired";
|
|
131
|
+
} | {
|
|
132
|
+
readonly _tag: "Balanced";
|
|
133
|
+
} | {
|
|
134
|
+
readonly _tag: "Finalized";
|
|
135
|
+
} | {
|
|
136
|
+
readonly _tag: "Confirmed";
|
|
137
|
+
} | {
|
|
138
|
+
readonly _tag: "Rejected";
|
|
139
|
+
readonly verdict: RejectedVerdict;
|
|
140
|
+
} | {
|
|
141
|
+
readonly _tag: "Orphaned";
|
|
142
|
+
readonly authoredFor: ProtocolVersion.ProtocolVersion;
|
|
143
|
+
readonly chainNow: ProtocolVersion.ProtocolVersion;
|
|
144
|
+
} | {
|
|
145
|
+
readonly _tag: "Reverted";
|
|
146
|
+
}) => import("effect/Unify").Unify<ReturnType<Cases["Submitted" | "Expired" | "Balanced" | "Finalized" | "Confirmed" | "Rejected" | "Orphaned" | "Reverted"]>>;
|
|
147
|
+
<const Cases extends {
|
|
148
|
+
readonly Submitted: (args: {
|
|
149
|
+
readonly _tag: "Submitted";
|
|
150
|
+
}) => any;
|
|
151
|
+
readonly Expired: (args: {
|
|
152
|
+
readonly _tag: "Expired";
|
|
153
|
+
}) => any;
|
|
154
|
+
readonly Balanced: (args: {
|
|
155
|
+
readonly _tag: "Balanced";
|
|
156
|
+
}) => any;
|
|
157
|
+
readonly Finalized: (args: {
|
|
158
|
+
readonly _tag: "Finalized";
|
|
159
|
+
}) => any;
|
|
160
|
+
readonly Confirmed: (args: {
|
|
161
|
+
readonly _tag: "Confirmed";
|
|
162
|
+
}) => any;
|
|
163
|
+
readonly Rejected: (args: {
|
|
164
|
+
readonly _tag: "Rejected";
|
|
165
|
+
readonly verdict: RejectedVerdict;
|
|
166
|
+
}) => any;
|
|
167
|
+
readonly Orphaned: (args: {
|
|
168
|
+
readonly _tag: "Orphaned";
|
|
169
|
+
readonly authoredFor: ProtocolVersion.ProtocolVersion;
|
|
170
|
+
readonly chainNow: ProtocolVersion.ProtocolVersion;
|
|
171
|
+
}) => any;
|
|
172
|
+
readonly Reverted: (args: {
|
|
173
|
+
readonly _tag: "Reverted";
|
|
174
|
+
}) => any;
|
|
175
|
+
}>(value: {
|
|
176
|
+
readonly _tag: "Submitted";
|
|
177
|
+
} | {
|
|
178
|
+
readonly _tag: "Expired";
|
|
179
|
+
} | {
|
|
180
|
+
readonly _tag: "Balanced";
|
|
181
|
+
} | {
|
|
182
|
+
readonly _tag: "Finalized";
|
|
183
|
+
} | {
|
|
184
|
+
readonly _tag: "Confirmed";
|
|
185
|
+
} | {
|
|
186
|
+
readonly _tag: "Rejected";
|
|
187
|
+
readonly verdict: RejectedVerdict;
|
|
188
|
+
} | {
|
|
189
|
+
readonly _tag: "Orphaned";
|
|
190
|
+
readonly authoredFor: ProtocolVersion.ProtocolVersion;
|
|
191
|
+
readonly chainNow: ProtocolVersion.ProtocolVersion;
|
|
192
|
+
} | {
|
|
193
|
+
readonly _tag: "Reverted";
|
|
194
|
+
}, cases: Cases & { [K in Exclude<keyof Cases, "Submitted" | "Expired" | "Balanced" | "Finalized" | "Confirmed" | "Rejected" | "Orphaned" | "Reverted">]: never; }): import("effect/Unify").Unify<ReturnType<Cases["Submitted" | "Expired" | "Balanced" | "Finalized" | "Confirmed" | "Rejected" | "Orphaned" | "Reverted"]>>;
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
/** The record of one transaction. */
|
|
198
|
+
export type LifecycleRecord<TTransaction> = Readonly<{
|
|
199
|
+
/** What ties the record to the transaction at every state: proving and binding leave identifiers unchanged. */
|
|
200
|
+
identifiers: readonly string[];
|
|
201
|
+
/** The values the ledger stamps on the coins the transaction creates. */
|
|
202
|
+
intentHashes: readonly string[];
|
|
203
|
+
inputs: Inputs;
|
|
204
|
+
/** From this instant the ledger rejects the transaction. */
|
|
205
|
+
ttl: Date;
|
|
206
|
+
/**
|
|
207
|
+
* The version the transaction's bytes were built for; `none` for a record that never held its transaction, or one
|
|
208
|
+
* stored before transactions were stamped, which is read with the oldest trait and never orphaned.
|
|
209
|
+
*/
|
|
210
|
+
protocolVersion: Option.Option<ProtocolVersion.ProtocolVersion>;
|
|
211
|
+
/** The transaction in the form for its state; `none` only for a record that never held its transaction. */
|
|
212
|
+
tx: Option.Option<TTransaction>;
|
|
213
|
+
/** When the record began, whichever state it began in. */
|
|
214
|
+
createdAt: DateTime.Utc;
|
|
215
|
+
/** When the transaction was submitted, kept through its verdict; `none` while it never was. */
|
|
216
|
+
submittedAt: Option.Option<DateTime.Utc>;
|
|
217
|
+
state: LifecycleState;
|
|
218
|
+
}>;
|
|
219
|
+
/** Every transaction's record. */
|
|
220
|
+
export type TransactionLifecycle<TTransaction> = Readonly<{
|
|
221
|
+
records: ReadonlyArray<LifecycleRecord<TTransaction>>;
|
|
222
|
+
/**
|
|
223
|
+
* The top-level members of the stored payload this build does not declare, exactly as they were read, written back so
|
|
224
|
+
* a later release that wrote them still finds them. Absent when the payload carried none.
|
|
225
|
+
*/
|
|
226
|
+
unknownFields?: SnapshotFormat.UnknownFields;
|
|
227
|
+
}>;
|
|
228
|
+
/** What the facade knows about a transaction when it moves it into a state. */
|
|
229
|
+
export type TransactionFacts<TTransaction> = Readonly<{
|
|
230
|
+
tx: TTransaction;
|
|
231
|
+
identifiers: readonly string[];
|
|
232
|
+
intentHashes: readonly string[];
|
|
233
|
+
inputs: Inputs;
|
|
234
|
+
ttl: Date;
|
|
235
|
+
protocolVersion: ProtocolVersion.ProtocolVersion;
|
|
236
|
+
}>;
|
|
237
|
+
/** No transaction recorded. */
|
|
238
|
+
export declare const empty: <TTransaction>() => TransactionLifecycle<TTransaction>;
|
|
239
|
+
/**
|
|
240
|
+
* Whether a record can still leave its state: balanced, finalized or submitted.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* const open = state.records.filter(isLive);
|
|
244
|
+
*
|
|
245
|
+
* @param record The record.
|
|
246
|
+
* @returns `true` while some event can still move it.
|
|
247
|
+
*/
|
|
248
|
+
export declare const isLive: <TTransaction>(record: LifecycleRecord<TTransaction>) => boolean;
|
|
249
|
+
/**
|
|
250
|
+
* Records a transaction as balanced, replacing a balanced record of the same spend: balancing it again begins it anew.
|
|
251
|
+
* So does balancing a spend whose record ended without its coins being spent on chain; a confirmed spend stays as it
|
|
252
|
+
* is, and so does one already finalized or submitted.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* const held = balanced(state, { tx: erased, identifiers, intentHashes, inputs, ttl, protocolVersion }, now);
|
|
256
|
+
*
|
|
257
|
+
* @param state The records.
|
|
258
|
+
* @param facts The balanced transaction, with its proofs erased.
|
|
259
|
+
* @param now When it was balanced.
|
|
260
|
+
* @returns The records with the transaction balanced, or unchanged when the spend has already moved past balancing.
|
|
261
|
+
*/
|
|
262
|
+
export declare const balanced: <TTransaction>(state: TransactionLifecycle<TTransaction>, facts: TransactionFacts<TTransaction>, now: DateTime.Utc) => TransactionLifecycle<TTransaction>;
|
|
263
|
+
/**
|
|
264
|
+
* Records a transaction as finalized, from balanced or from nothing. Every record the finalized transaction covers is
|
|
265
|
+
* folded into one, because merging the parts of a recipe makes one transaction.
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* const proven = finalized(
|
|
269
|
+
* state,
|
|
270
|
+
* { tx: finalizedTx, identifiers, intentHashes, inputs, ttl, protocolVersion },
|
|
271
|
+
* now,
|
|
272
|
+
* );
|
|
273
|
+
*
|
|
274
|
+
* @param state The records.
|
|
275
|
+
* @param facts The finalized transaction.
|
|
276
|
+
* @param now When it was finalized.
|
|
277
|
+
* @returns The records with the transaction finalized, or unchanged when the spend has already been submitted.
|
|
278
|
+
*/
|
|
279
|
+
export declare const finalized: <TTransaction>(state: TransactionLifecycle<TTransaction>, facts: TransactionFacts<TTransaction>, now: DateTime.Utc) => TransactionLifecycle<TTransaction>;
|
|
280
|
+
/**
|
|
281
|
+
* Records a transaction as submitted, from balanced, finalized, reverted or nothing: a transaction proven outside the
|
|
282
|
+
* facade arrives still balanced, and an adopted one arrives unrecorded. A reverted one is sent again after a submission
|
|
283
|
+
* that threw: once it is sent it is in flight, whatever the wallet concluded before.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* const sent = submitted(state, { tx: finalizedTx, identifiers, intentHashes, inputs, ttl, protocolVersion }, now);
|
|
287
|
+
*
|
|
288
|
+
* @param state The records.
|
|
289
|
+
* @param facts The submitted transaction.
|
|
290
|
+
* @param now When it was submitted.
|
|
291
|
+
* @returns The records with the transaction submitted, or unchanged when it already was.
|
|
292
|
+
*/
|
|
293
|
+
export declare const submitted: <TTransaction>(state: TransactionLifecycle<TTransaction>, facts: TransactionFacts<TTransaction>, now: DateTime.Utc) => TransactionLifecycle<TTransaction>;
|
|
294
|
+
/**
|
|
295
|
+
* Records that a transaction was included, whichever live state its record is in: inclusion is a fact, and nothing
|
|
296
|
+
* overrules it afterwards.
|
|
297
|
+
*
|
|
298
|
+
* It also overrules an end the wallet only inferred (expired, rejected at its TTL, orphaned, reverted): a block's time
|
|
299
|
+
* is within the transaction's TTL, so an inclusion reported after such an end happened before it.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* const included = confirmed(state, [...tx.identifiers()]);
|
|
303
|
+
*
|
|
304
|
+
* @param state The records.
|
|
305
|
+
* @param identifiers The included transaction's identifiers.
|
|
306
|
+
* @returns The records with the transaction confirmed; a record whose end the chain reported is left as it was.
|
|
307
|
+
*/
|
|
308
|
+
export declare const confirmed: <TTransaction>(state: TransactionLifecycle<TTransaction>, identifiers: readonly string[]) => TransactionLifecycle<TTransaction>;
|
|
309
|
+
/**
|
|
310
|
+
* Records that the chain refused a finalized or submitted transaction. A finalized one counts too, because another
|
|
311
|
+
* party may have submitted it, as in a swap, and the chain's answer about it is a fact. A balanced one is left as it
|
|
312
|
+
* was: it is not yet proven, so no chain can have been asked to include it.
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* const refused = rejected(state, [...tx.identifiers()], { status: 'FAILURE', segments });
|
|
316
|
+
*
|
|
317
|
+
* @param state The records.
|
|
318
|
+
* @param identifiers The refused transaction's identifiers.
|
|
319
|
+
* @param verdict What the chain reported.
|
|
320
|
+
* @returns The records with the transaction rejected.
|
|
321
|
+
*/
|
|
322
|
+
export declare const rejected: <TTransaction>(state: TransactionLifecycle<TTransaction>, identifiers: readonly string[], verdict: FailedTransactionResult) => TransactionLifecycle<TTransaction>;
|
|
323
|
+
/**
|
|
324
|
+
* Gives up on every live transaction built for an epoch the chain has left. A record whose version was never known is
|
|
325
|
+
* left as it was: that is no evidence it was left behind.
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* const stranded = orphanBeyond(state, traits, chainNow);
|
|
329
|
+
*
|
|
330
|
+
* @param state The records.
|
|
331
|
+
* @param epochs The protocol version epochs, as the registry of traits keys them.
|
|
332
|
+
* @param chainNow The version the chain has reached.
|
|
333
|
+
* @returns The records with every stranded transaction orphaned.
|
|
334
|
+
*/
|
|
335
|
+
export declare const orphanBeyond: <TTransaction, TEpoch>(state: TransactionLifecycle<TTransaction>, epochs: ProtocolVersion.Registry<TEpoch>, chainNow: ProtocolVersion.ProtocolVersion) => TransactionLifecycle<TTransaction>;
|
|
336
|
+
/**
|
|
337
|
+
* Records that a transaction was reverted, so no chain will be asked to include it.
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* const abandoned = reverted(state, [...tx.identifiers()]);
|
|
341
|
+
*
|
|
342
|
+
* @param state The records.
|
|
343
|
+
* @param identifiers The reverted transaction's identifiers.
|
|
344
|
+
* @returns The records with the transaction reverted; a final record is left as it was.
|
|
345
|
+
*/
|
|
346
|
+
export declare const reverted: <TTransaction>(state: TransactionLifecycle<TTransaction>, identifiers: readonly string[]) => TransactionLifecycle<TTransaction>;
|
|
347
|
+
/**
|
|
348
|
+
* Ends every live record whose TTL `now` has passed: one never submitted expires, and a submitted one is rejected.
|
|
349
|
+
*
|
|
350
|
+
* @param state The records.
|
|
351
|
+
* @param now The instant to expire against.
|
|
352
|
+
* @returns The records with every passed TTL acted on, or the same state when none has passed.
|
|
353
|
+
*/
|
|
354
|
+
export declare const expire: <TTransaction>(state: TransactionLifecycle<TTransaction>, now: DateTime.Utc) => TransactionLifecycle<TTransaction>;
|
|
355
|
+
/**
|
|
356
|
+
* Drops every final record whose TTL `now` has passed.
|
|
357
|
+
*
|
|
358
|
+
* @param state The records.
|
|
359
|
+
* @param now The instant to drop against.
|
|
360
|
+
* @returns The records without them, or the same state when none is due.
|
|
361
|
+
*/
|
|
362
|
+
export declare const dropFinished: <TTransaction>(state: TransactionLifecycle<TTransaction>, now: DateTime.Utc) => TransactionLifecycle<TTransaction>;
|
|
363
|
+
/**
|
|
364
|
+
* The unshielded coin ids some live transaction still accounts for.
|
|
365
|
+
*
|
|
366
|
+
* A final record accounts for none: a confirmed transaction's coins are spent on chain, and every other final state's
|
|
367
|
+
* coins are free. Read from the inputs each record keeps, so a record that never held its transaction still counts.
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* const spokenFor = coveredUnshieldedIds(lifecycle);
|
|
371
|
+
*
|
|
372
|
+
* @param state The records.
|
|
373
|
+
* @returns Every such coin id, without repeats.
|
|
374
|
+
*/
|
|
375
|
+
export declare const coveredUnshieldedIds: <TTransaction>(state: TransactionLifecycle<TTransaction>) => readonly string[];
|
|
376
|
+
/**
|
|
377
|
+
* Writes the records in the current stored format, with every top-level member a payload it was read from carried but
|
|
378
|
+
* this build does not declare.
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* const stored = serialize(lifecycle, traits);
|
|
382
|
+
*
|
|
383
|
+
* @param state The records.
|
|
384
|
+
* @param traits The traits each record's transaction is written with, chosen by the version it was built for.
|
|
385
|
+
* @returns The records as a JSON string.
|
|
386
|
+
*/
|
|
387
|
+
export declare const serialize: <TTransaction>(state: TransactionLifecycle<TTransaction>, traits: VersionedTransactionTrait<TTransaction>) => string;
|
|
388
|
+
/**
|
|
389
|
+
* Reads records stored in any format version this build knows, upgrading an older one on the way.
|
|
390
|
+
*
|
|
391
|
+
* @remarks
|
|
392
|
+
* A record that holds its transaction but lacks a fact reads it off the transaction, with the trait registered for the
|
|
393
|
+
* version the record was stamped with, or the oldest trait when it carries no stamp. A version this build does not
|
|
394
|
+
* know is refused, never read as the current one.
|
|
395
|
+
* @example
|
|
396
|
+
* const lifecycle = deserialize(stored, traits);
|
|
397
|
+
*
|
|
398
|
+
* @param serialized The stored JSON string.
|
|
399
|
+
* @param traits The traits each record's transaction is read with, chosen by the version it was stamped with.
|
|
400
|
+
* @returns The records, or why the payload could not be read.
|
|
401
|
+
*/
|
|
402
|
+
export declare const deserialize: <TTransaction>(serialized: string, traits: VersionedTransactionTrait<TTransaction>) => Either.Either<TransactionLifecycle<TTransaction>, ParseResult.ParseError>;
|