@vordium/sdk 0.2.2 → 0.3.0
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 +18 -0
- package/dist/cjs/client.js +251 -50
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/network.js +36 -14
- package/dist/cjs/outcome.js +649 -0
- package/dist/cjs/outcomeWords.js +172 -0
- package/dist/cjs/pins.js +5 -0
- package/dist/cjs/releaseRecord.js +48 -11
- package/dist/cjs/types.js +2 -1
- package/dist/esm/client.d.ts +83 -6
- package/dist/esm/client.js +250 -49
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/network.d.ts +6 -0
- package/dist/esm/network.js +36 -14
- package/dist/esm/outcome.d.ts +201 -0
- package/dist/esm/outcome.js +623 -0
- package/dist/esm/outcomeWords.d.ts +168 -0
- package/dist/esm/outcomeWords.js +169 -0
- package/dist/esm/pins.d.ts +5 -0
- package/dist/esm/pins.js +5 -0
- package/dist/esm/releaseRecord.d.ts +6 -0
- package/dist/esm/releaseRecord.js +47 -10
- package/dist/esm/types.d.ts +1 -0
- package/dist/esm/types.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { OUTCOME_WORDS } from './outcomeWords.js';
|
|
2
|
+
import { type SignedOrder } from './client.js';
|
|
3
|
+
export type OutcomeAction = keyof typeof OUTCOME_WORDS.actions;
|
|
4
|
+
export type OutcomeState = 'pending_checking' | 'applied' | 'applied_other' | 'refused' | 'not_applied' | 'still_unknown';
|
|
5
|
+
/** How long after the send an outcome is checked before it is called `still_unknown`. */
|
|
6
|
+
export declare const LIMIT_MS: number;
|
|
7
|
+
/** How long a call waits for the outcome before it returns `pending_checking` (0 returns at once). */
|
|
8
|
+
export declare const SETTLE_MS = 30000;
|
|
9
|
+
/** The time limit of each read while checking. */
|
|
10
|
+
export declare const READ_TIMEOUT_MS = 6000;
|
|
11
|
+
/** How many of the account's latest records are read (the records have no filter by client nonce). */
|
|
12
|
+
export declare const RECORDS_LIMIT = 200;
|
|
13
|
+
/** A deadline counts as passed only this long after it, on the network's clock (seconds). */
|
|
14
|
+
export declare const DEADLINE_GRACE_S = 10;
|
|
15
|
+
/** Milliseconds to the next read: 1 s for the first 10 s, 2 s to 30 s, then 5 s. */
|
|
16
|
+
export declare const intervalMs: (elapsedMs: number) => number;
|
|
17
|
+
type Fill = Record<string, string | number | boolean | null | undefined>;
|
|
18
|
+
/** {text, next} of `action` in `state`, the placeholders filled. */
|
|
19
|
+
export declare function say(action: OutcomeAction, state: OutcomeState, fill?: Fill): {
|
|
20
|
+
text: string;
|
|
21
|
+
next: string;
|
|
22
|
+
};
|
|
23
|
+
/** A chain meaning as the end of a sentence ("Not placed: {meaning}."): no closing stop, a lower-case first word. */
|
|
24
|
+
export declare function clause(meaning: unknown): string;
|
|
25
|
+
/** sha256 hex of the exact bytes sent: the same on every copy of one signed write. */
|
|
26
|
+
export declare function bodyDigest(body: string): string;
|
|
27
|
+
export interface OutcomeRead {
|
|
28
|
+
source: 'node';
|
|
29
|
+
route: string | null;
|
|
30
|
+
height: number | null;
|
|
31
|
+
atMs: number;
|
|
32
|
+
}
|
|
33
|
+
export interface Resend {
|
|
34
|
+
allowed: boolean;
|
|
35
|
+
sameBytes: boolean;
|
|
36
|
+
label: string | null;
|
|
37
|
+
why: string;
|
|
38
|
+
}
|
|
39
|
+
/** Where one write stands. `applied` is true for applied / applied_other, false for refused / not_applied, null while it
|
|
40
|
+
* is not known. `read` is the read that decided; `resend` whether the same signed bytes may go again. */
|
|
41
|
+
export interface Outcome {
|
|
42
|
+
action: OutcomeAction;
|
|
43
|
+
state: OutcomeState;
|
|
44
|
+
text: string;
|
|
45
|
+
next: string;
|
|
46
|
+
applied: boolean | null;
|
|
47
|
+
final: boolean;
|
|
48
|
+
refusal: {
|
|
49
|
+
code: string;
|
|
50
|
+
meaning: string | null;
|
|
51
|
+
action: string | null;
|
|
52
|
+
} | null;
|
|
53
|
+
read: OutcomeRead | null;
|
|
54
|
+
resend: Resend;
|
|
55
|
+
nonce: number | null;
|
|
56
|
+
orderId: string | null;
|
|
57
|
+
agent: string | null;
|
|
58
|
+
digest: string | null;
|
|
59
|
+
attempts: number;
|
|
60
|
+
counts: Record<string, number | boolean>;
|
|
61
|
+
}
|
|
62
|
+
export declare function resendRule(action: OutcomeAction, state: OutcomeState): Resend;
|
|
63
|
+
/** One check's finding: `state` a final state or null (not shown yet). */
|
|
64
|
+
export interface View {
|
|
65
|
+
state: OutcomeState | null;
|
|
66
|
+
fill: Fill;
|
|
67
|
+
read: OutcomeRead | null;
|
|
68
|
+
refusal?: Outcome['refusal'];
|
|
69
|
+
still?: Fill;
|
|
70
|
+
/** The word-file key used instead of `still_unknown` once the limit passed (`still_unknown_gone`: the order left the
|
|
71
|
+
* book with no record yet; `still_unknown_unread`: the read that decides did not answer). */
|
|
72
|
+
stillKey?: string;
|
|
73
|
+
found?: Record<string, unknown> | null;
|
|
74
|
+
}
|
|
75
|
+
/** One GET of the node: {status, body}; status null when it failed. */
|
|
76
|
+
export type NodeRead = (path: string) => Promise<{
|
|
77
|
+
status: number | null;
|
|
78
|
+
body: unknown;
|
|
79
|
+
}>;
|
|
80
|
+
/** GET reads of one node; every route read is kept in `routes`. */
|
|
81
|
+
export declare class NodeReads {
|
|
82
|
+
private readonly read;
|
|
83
|
+
readonly routes: string[];
|
|
84
|
+
private codesRead;
|
|
85
|
+
constructor(read: NodeRead);
|
|
86
|
+
get(path: string): Promise<{
|
|
87
|
+
status: number | null;
|
|
88
|
+
body: unknown;
|
|
89
|
+
}>;
|
|
90
|
+
ok(path: string): Promise<unknown>;
|
|
91
|
+
records(owner: string): Promise<{
|
|
92
|
+
recs: Array<Record<string, unknown>> | null;
|
|
93
|
+
cov: Record<string, unknown>;
|
|
94
|
+
}>;
|
|
95
|
+
head(): Promise<number | null>;
|
|
96
|
+
codes(): Promise<Record<string, unknown>>;
|
|
97
|
+
meaning(code: string, agent: boolean): Promise<{
|
|
98
|
+
meaning: string | null;
|
|
99
|
+
action: string | null;
|
|
100
|
+
}>;
|
|
101
|
+
}
|
|
102
|
+
/** Refusal codes that name the nonce: a later copy of OUR write (or another signer's) meets them while an earlier copy
|
|
103
|
+
* applied, so they never prove that our write did not apply. */
|
|
104
|
+
export declare const NONCE_CODES: Set<string>;
|
|
105
|
+
/** Whether the signer of a write is an agent of the account, read once from the node (`/agents/{owner}/{signer}`) and
|
|
106
|
+
* kept only once the read answered: {known, agent address or null}. */
|
|
107
|
+
export declare function signerOf(r: NodeReads, owner: string, signer: string | null, journalId?: string | null): () => Promise<{
|
|
108
|
+
known: boolean;
|
|
109
|
+
agent: string | null;
|
|
110
|
+
}>;
|
|
111
|
+
/** An order by its client nonce: listed with what was signed, its closing or placing record, a refusal record with its
|
|
112
|
+
* nonce, or — for an order with a signed deadline, once it passed and a full read of the records shows nothing —
|
|
113
|
+
* not_applied. */
|
|
114
|
+
export declare function judgeOrder(r: NodeReads, owner: string, clientNonce: number, signed: SignedOrder | null, o?: {
|
|
115
|
+
rewound?: number | null;
|
|
116
|
+
validUntilS?: number | null;
|
|
117
|
+
sentAtMs?: number | null;
|
|
118
|
+
chainMs?: (() => Promise<number | null>) | null;
|
|
119
|
+
agent?: string | null;
|
|
120
|
+
}): Promise<View>;
|
|
121
|
+
/** A cancel: the order no longer listed AND its record says cancelled (applied) or filled (applied_other). */
|
|
122
|
+
export declare function judgeCancel(r: NodeReads, owner: string, orderId: bigint): Promise<View>;
|
|
123
|
+
/** The account's order ids in an `/orders` read (the network's liquidation order left out); null when unreadable. */
|
|
124
|
+
export declare function orderIds(rows: unknown, pairId?: number): string[] | null;
|
|
125
|
+
/** A cancel-all: none of the orders listed before the send is still listed, every one of them has its closing record,
|
|
126
|
+
* and at least one closed as cancelled (applied; applied_other when some filled first). With nothing listed before, or
|
|
127
|
+
* no cancel among the records, nothing shows that the cancel-all applied: it stays not known. */
|
|
128
|
+
export declare function judgeCancelAll(r: NodeReads, owner: string, before: string[] | null, pairId?: number): Promise<View>;
|
|
129
|
+
/** A batch: every place shown (or refused) by its client nonce, and every cancelled order (by id, or by client nonce)
|
|
130
|
+
* no longer listed and closed in the records. Applied only when every action is decided. */
|
|
131
|
+
export declare function judgeBatch(r: NodeReads, owner: string, places: Array<[number, SignedOrder]>, cancels: string[], rewound?: number | null, cancelNonces?: number[], agent?: string | null): Promise<View>;
|
|
132
|
+
/** An agent revoke: the agent's committed record reads `revoked`. */
|
|
133
|
+
export declare function judgeRevoke(r: NodeReads, owner: string, agent: string): Promise<View>;
|
|
134
|
+
/** The session nonce a read names (`nonce`, `last_nonce` or `session_nonce`, the largest), else null. */
|
|
135
|
+
export declare function storedSessionNonce(...reads: unknown[]): number | null;
|
|
136
|
+
/** The stop (StopAllSigners): no trading key (the session read answers "no active session") and no live agent
|
|
137
|
+
* (`/signers` names `app_session` as null and `live_agents` 0); then the open orders decide applied (none) or
|
|
138
|
+
* applied_other (orders the wallet placed itself stay). Past its deadline with a key or an agent still live, and the
|
|
139
|
+
* stored session nonce still below the stop's `nonce`: not_applied. */
|
|
140
|
+
export declare function judgeStop(r: NodeReads, owner: string, validUntilS?: number | null, chainMs?: (() => Promise<number | null>) | null, nonce?: number | null): Promise<View>;
|
|
141
|
+
/** The clock the checks run on (tests replace it with a virtual one). */
|
|
142
|
+
export declare const outcomeClock: {
|
|
143
|
+
now: () => number;
|
|
144
|
+
sleep: (ms: number) => Promise<void>;
|
|
145
|
+
};
|
|
146
|
+
export interface PendingMeta {
|
|
147
|
+
nonce?: number | null;
|
|
148
|
+
orderId?: string | null;
|
|
149
|
+
agent?: string | null;
|
|
150
|
+
digest?: string | null;
|
|
151
|
+
attempts?: number;
|
|
152
|
+
}
|
|
153
|
+
/** A sent write whose outcome is being read: `check()` reads once, `wait()` reads until a final or a time limit,
|
|
154
|
+
* `resendSame()` sends the same signed bytes again (only where the network applies the write once). */
|
|
155
|
+
export declare class PendingWrite {
|
|
156
|
+
readonly action: OutcomeAction;
|
|
157
|
+
private readonly judge;
|
|
158
|
+
private readonly opts;
|
|
159
|
+
readonly startedMs: number;
|
|
160
|
+
attempts: number;
|
|
161
|
+
last: Outcome;
|
|
162
|
+
found: Record<string, unknown> | null;
|
|
163
|
+
private busy;
|
|
164
|
+
constructor(action: OutcomeAction, judge: () => Promise<View>, opts?: {
|
|
165
|
+
meta?: PendingMeta;
|
|
166
|
+
resend?: () => Promise<unknown>;
|
|
167
|
+
journalId?: string | null;
|
|
168
|
+
startedMs?: number;
|
|
169
|
+
limitMs?: number;
|
|
170
|
+
});
|
|
171
|
+
get limitMs(): number;
|
|
172
|
+
get elapsedMs(): number;
|
|
173
|
+
private outcome;
|
|
174
|
+
/** Read once. A final ends it (and takes it off the journal); else `pending_checking` within the limit,
|
|
175
|
+
* `still_unknown` after it. */
|
|
176
|
+
check(): Promise<Outcome>;
|
|
177
|
+
/** Read until a final, or `limitMs` from now (default: to the end of the limit after the send; at least one read). */
|
|
178
|
+
wait(limitMs?: number): Promise<Outcome>;
|
|
179
|
+
/** Send the same signed bytes once more (a cancel, a revoke, the stop), then read once. Throws for any other write
|
|
180
|
+
* or once the outcome is final. */
|
|
181
|
+
resendSame(): Promise<Outcome>;
|
|
182
|
+
}
|
|
183
|
+
/** Wait inside the call: up to `settleMs` (0 = no read: `pending_checking` at once). */
|
|
184
|
+
export declare function settle(pw: PendingWrite, settleMs: number): Promise<Outcome>;
|
|
185
|
+
export declare const JOURNAL_NAME = "outcome-pending-js.json";
|
|
186
|
+
type Entry = Record<string, unknown> & {
|
|
187
|
+
digest: string;
|
|
188
|
+
sentAtMs: number;
|
|
189
|
+
};
|
|
190
|
+
/** Note a write BEFORE it is sent; returns its id (the digest of its bytes). */
|
|
191
|
+
export declare function journalAdd(entry: Entry): Promise<string>;
|
|
192
|
+
export declare function journalSet(id: string | null | undefined, fields: Record<string, unknown>): Promise<void>;
|
|
193
|
+
export declare function journalDone(id: string | null | undefined): Promise<void>;
|
|
194
|
+
/** The writes noted in this computer's journal whose outcome is not known yet (younger than a day). Check one with
|
|
195
|
+
* {@link pendingCheck} and a client of its network. */
|
|
196
|
+
export declare function pending(maxAgeMs?: number): Promise<Entry[]>;
|
|
197
|
+
/** Read one journal entry once at a node (`read`, the node it was sent to: entry.rest); a final takes it off. */
|
|
198
|
+
export declare function pendingCheck(e: Entry, read: NodeRead, chainMs?: (() => Promise<number | null>) | null): Promise<Outcome>;
|
|
199
|
+
/** A JSON value with bigint fields as strings (for the journal). */
|
|
200
|
+
export declare const plain: (v: unknown) => unknown;
|
|
201
|
+
export {};
|