@dcasegr/amm-client 0.39.0 → 0.42.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 +70 -31
- package/dist/client.d.ts +190 -62
- package/dist/client.js +493 -322
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +6 -3
- package/dist/index.d.ts +16 -4
- package/dist/index.js +16 -4
- package/dist/lib/overlay.d.ts +132 -50
- package/dist/lib/overlay.js +169 -160
- package/dist/lib/skein.d.ts +22 -0
- package/dist/lib/skein.js +16 -1
- package/dist/market/activeSwap.d.ts +77 -96
- package/dist/market/activeSwap.js +146 -166
- package/dist/market/plan.d.ts +2 -1
- package/dist/market/plan.js +1 -1
- package/dist/market/swapAction.d.ts +150 -145
- package/dist/market/swapAction.js +292 -213
- package/dist/market/swapFlow.d.ts +3 -6
- package/dist/market/swapFlow.js +4 -22
- package/dist/pool/pool.artifact.json +760 -528
- package/dist/pool/template.d.ts +10 -2
- package/dist/pool/template.js +16 -6
- package/dist/wallet/color.d.ts +13 -9
- package/dist/wallet/color.js +13 -10
- package/dist/wallet/swapPayouts.d.ts +45 -28
- package/dist/wallet/swapPayouts.js +129 -117
- package/package.json +2 -2
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
* refused / timeout / an error answer to submit (nothing recorded):
|
|
10
10
|
* nothing to undo: the leg's `amm-swap` outputs stay there
|
|
11
11
|
* no answer (a network failure, the host's 503 past its bound, a `pending` record, the
|
|
12
|
-
* relay's transport `failed`): "no answer yet", left alone — the relay may still carry it
|
|
13
|
-
*
|
|
12
|
+
* relay's transport `failed`): "no answer yet", left alone — the relay may still carry it
|
|
13
|
+
* (0.40.0: the swap's loop resolves it from the overlay, sends it once more, or races it;
|
|
14
|
+
* src/client.ts `executeSwap`).
|
|
14
15
|
*
|
|
15
16
|
* The swap's id is the relay's (amm-p2p relay.zig `idOf`): sha256 of the swap as submitted (the
|
|
16
17
|
* validator's slot empty), hex — known to the page, so a lost answer can be checked again.
|
|
@@ -45,8 +46,6 @@ export interface RelayContext {
|
|
|
45
46
|
authFetch: AuthFetchLike;
|
|
46
47
|
/** The token instance's AMM base. */
|
|
47
48
|
base: string;
|
|
48
|
-
/** The plain fetch "Check again" reads the record with (default: the browser's). */
|
|
49
|
-
fetch?: (url: string, init?: RequestInit) => Promise<Response>;
|
|
50
49
|
}
|
|
51
50
|
/** The relay's id of a prepared swap: sha256 of the swap's bytes as submitted, hex. */
|
|
52
51
|
export declare function swapIdOf(p: PreparedSwap): string;
|
|
@@ -54,5 +53,3 @@ export declare function swapIdOf(p: PreparedSwap): string;
|
|
|
54
53
|
export declare const NO_ANSWER_YET = "no answer yet";
|
|
55
54
|
/** `peerId`: the chosen validator's libp2p peer ID, from the pools route's row (the relay dials it). */
|
|
56
55
|
export declare function relaySwap(c: RelayContext, p: PreparedSwap, peerId: string): Promise<SwapOutcome>;
|
|
57
|
-
/** "Check again" for an unknown outcome: the record read ONCE, plain (`GET <base>/swaps?id=`, P10), and acted on. */
|
|
58
|
-
export declare function checkAgain(c: RelayContext, p: PreparedSwap, id: string): Promise<SwapOutcome>;
|
package/dist/market/swapFlow.js
CHANGED
|
@@ -9,16 +9,16 @@
|
|
|
9
9
|
* refused / timeout / an error answer to submit (nothing recorded):
|
|
10
10
|
* nothing to undo: the leg's `amm-swap` outputs stay there
|
|
11
11
|
* no answer (a network failure, the host's 503 past its bound, a `pending` record, the
|
|
12
|
-
* relay's transport `failed`): "no answer yet", left alone — the relay may still carry it
|
|
13
|
-
*
|
|
12
|
+
* relay's transport `failed`): "no answer yet", left alone — the relay may still carry it
|
|
13
|
+
* (0.40.0: the swap's loop resolves it from the overlay, sends it once more, or races it;
|
|
14
|
+
* src/client.ts `executeSwap`).
|
|
14
15
|
*
|
|
15
16
|
* The swap's id is the relay's (amm-p2p relay.zig `idOf`): sha256 of the swap as submitted (the
|
|
16
17
|
* validator's slot empty), hex — known to the page, so a lost answer can be checked again.
|
|
17
18
|
*/
|
|
18
19
|
import { Hash, Utils } from "@bsv/sdk";
|
|
19
|
-
import { RelayError,
|
|
20
|
+
import { RelayError, submitSwap } from "./relay.js";
|
|
20
21
|
import { completeSwap } from "./swapAction.js";
|
|
21
|
-
import { readSwap } from "../lib/overlay.js";
|
|
22
22
|
const errText = (e) => (e instanceof Error ? e.message : String(e));
|
|
23
23
|
/** The relay's id of a prepared swap: sha256 of the swap's bytes as submitted, hex. */
|
|
24
24
|
export function swapIdOf(p) {
|
|
@@ -66,21 +66,3 @@ async function act(c, p, r) {
|
|
|
66
66
|
return { status: "unknown", id: r.id, reason: `the relay could not reach the validator (${r.reason})` };
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
/** "Check again" for an unknown outcome: the record read ONCE, plain (`GET <base>/swaps?id=`, P10), and acted on. */
|
|
70
|
-
export async function checkAgain(c, p, id) {
|
|
71
|
-
let raw;
|
|
72
|
-
try {
|
|
73
|
-
raw = await readSwap(c.base, id, c.fetch);
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
return { status: "unknown", id, reason: `${NO_ANSWER_YET}: ${errText(err)}` };
|
|
77
|
-
}
|
|
78
|
-
if (raw === null)
|
|
79
|
-
return { status: "unknown", id, reason: `${NO_ANSWER_YET}: the relay has no record of it` };
|
|
80
|
-
try {
|
|
81
|
-
return await act(c, p, parseSwapRecord(raw));
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
return { status: "unknown", id, reason: errText(err) };
|
|
85
|
-
}
|
|
86
|
-
}
|