@tempoxyz/patron 0.0.29 → 0.0.31
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/dist/bin.js +11 -3
- package/dist/chunks/{-OLVAZG3H.js → -K6MPD575.js} +256 -64
- package/dist/chunks/{chunk-HQ2ZLUTT.js → chunk-6G6SAUGB.js} +1 -1
- package/dist/chunks/{chunk-SAEZ54SS.js → chunk-AN64RW3X.js} +8 -8
- package/dist/chunks/{chunk-ZOQJ4CZE.js → chunk-GBZCXMDZ.js} +7 -165
- package/dist/chunks/chunk-IIB6TI3U.js +196 -0
- package/dist/chunks/{chunk-EISHX7Q3.js → chunk-JTPFWITF.js} +208 -48
- package/dist/chunks/{chunk-OQXACACU.js → chunk-NDBTADXZ.js} +9 -2
- package/dist/chunks/{hook-HYV4BSCN.js → hook-6DQ3RLVH.js} +7 -8
- package/dist/chunks/{hook-process-6WSLYXC7.js → hook-process-W3ZK5FT3.js} +60 -14
- package/dist/chunks/{wallet-LOLL66ID.js → wallet-WR6EBMN6.js} +3 -4
- package/package.json +1 -1
- package/dist/chunks/chunk-3CYJJJR3.js +0 -56
|
@@ -2,16 +2,22 @@ import { createRequire as __patronCreateRequire } from 'node:module'
|
|
|
2
2
|
const require = __patronCreateRequire(import.meta.url)
|
|
3
3
|
|
|
4
4
|
// src/settings.ts
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
5
6
|
import { homedir } from "node:os";
|
|
6
7
|
import { join } from "node:path";
|
|
7
8
|
var DEFAULT_GATEWAY_URL = "https://patron-gateway.tempo-dev.workers.dev";
|
|
8
9
|
var DEFAULT_RELAY_URL = "https://patron-relay.tempo-dev.workers.dev";
|
|
9
|
-
function
|
|
10
|
+
function inferHome(script) {
|
|
11
|
+
const match = script ? /^(.+)[/\\]cli[/\\][^/\\]+[/\\]dist[/\\]bin\.js$/.exec(script) : null;
|
|
12
|
+
const home = match?.[1];
|
|
13
|
+
return home && existsSync(join(home, "cli", "current")) ? home : void 0;
|
|
14
|
+
}
|
|
15
|
+
function resolveSettings(env = process.env, script = process.argv[1]) {
|
|
10
16
|
const key = env.PATRON_PRIVATE_KEY?.trim();
|
|
11
17
|
const privateKey = key && /^0x[0-9a-fA-F]{64}$/.test(key) ? key : void 0;
|
|
12
18
|
return {
|
|
13
19
|
gatewayUrl: env.PATRON_GATEWAY_URL || DEFAULT_GATEWAY_URL,
|
|
14
|
-
home: env.PATRON_HOME || join(homedir(), ".patron"),
|
|
20
|
+
home: env.PATRON_HOME || inferHome(script) || join(homedir(), ".patron"),
|
|
15
21
|
network: env.PATRON_NETWORK === "testnet" ? "testnet" : "mainnet",
|
|
16
22
|
overridden: {
|
|
17
23
|
gatewayUrl: Boolean(env.PATRON_GATEWAY_URL),
|
|
@@ -32,6 +38,7 @@ function settingsFor(settings, saved) {
|
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
export {
|
|
41
|
+
inferHome,
|
|
35
42
|
resolveSettings,
|
|
36
43
|
settingsFor
|
|
37
44
|
};
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
parseHookInput,
|
|
9
9
|
payableDomain,
|
|
10
10
|
turnEnd
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-6G6SAUGB.js";
|
|
12
12
|
import {
|
|
13
13
|
FileTokenStore,
|
|
14
14
|
codexHome,
|
|
@@ -16,20 +16,19 @@ import {
|
|
|
16
16
|
redeem,
|
|
17
17
|
refillSize,
|
|
18
18
|
storedIssuer
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-AN64RW3X.js";
|
|
20
20
|
import {
|
|
21
21
|
settingsFor
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-NDBTADXZ.js";
|
|
23
|
+
import "./chunk-GBZCXMDZ.js";
|
|
23
24
|
import {
|
|
25
|
+
clampTokensPerPage,
|
|
24
26
|
readConfig,
|
|
25
27
|
readUsage,
|
|
26
28
|
updateUsage,
|
|
29
|
+
withLock,
|
|
27
30
|
writePrivateFile
|
|
28
|
-
} from "./chunk-
|
|
29
|
-
import {
|
|
30
|
-
clampTokensPerPage,
|
|
31
|
-
withLock
|
|
32
|
-
} from "./chunk-EISHX7Q3.js";
|
|
31
|
+
} from "./chunk-JTPFWITF.js";
|
|
33
32
|
import "./chunk-GTMLTZRN.js";
|
|
34
33
|
|
|
35
34
|
// src/hook.ts
|
|
@@ -7,20 +7,23 @@ import {
|
|
|
7
7
|
isCursorPayload,
|
|
8
8
|
parseHookInput,
|
|
9
9
|
turnEnd
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-6G6SAUGB.js";
|
|
11
11
|
import {
|
|
12
|
+
claimRedemptions,
|
|
13
|
+
redemptionWait,
|
|
12
14
|
startDrain,
|
|
13
15
|
startRefill
|
|
14
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-IIB6TI3U.js";
|
|
15
17
|
import {
|
|
16
18
|
resolveSettings
|
|
17
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-NDBTADXZ.js";
|
|
18
20
|
import {
|
|
19
21
|
tryLock
|
|
20
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-JTPFWITF.js";
|
|
21
23
|
import "./chunk-GTMLTZRN.js";
|
|
22
24
|
|
|
23
25
|
// src/hook-process.ts
|
|
26
|
+
import { utimes as utimes2 } from "node:fs/promises";
|
|
24
27
|
import { homedir } from "node:os";
|
|
25
28
|
import { join as join2 } from "node:path";
|
|
26
29
|
|
|
@@ -41,7 +44,9 @@ function queuePaths(home) {
|
|
|
41
44
|
return {
|
|
42
45
|
dir: join(home, "pay-queue"),
|
|
43
46
|
lock: join(home, "pay.lock"),
|
|
44
|
-
start: join(home, "pay.start")
|
|
47
|
+
start: join(home, "pay.start"),
|
|
48
|
+
/** Held by a drainer waiting out a hold on redemptions (spacing.ts); touched each check. */
|
|
49
|
+
wait: join(home, "pay-wait.lock")
|
|
45
50
|
};
|
|
46
51
|
}
|
|
47
52
|
var MAX_QUEUED = 500;
|
|
@@ -82,10 +87,15 @@ async function take(path) {
|
|
|
82
87
|
}
|
|
83
88
|
}
|
|
84
89
|
async function drainerRunning(home, now = Date.now()) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
()
|
|
88
|
-
|
|
90
|
+
const paths = queuePaths(home);
|
|
91
|
+
for (const path of [paths.lock, paths.wait]) {
|
|
92
|
+
const live = await stat(path).then(
|
|
93
|
+
(stats) => now - stats.mtimeMs <= DRAIN_STALE_MS,
|
|
94
|
+
() => false
|
|
95
|
+
);
|
|
96
|
+
if (live) return true;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
89
99
|
}
|
|
90
100
|
async function claimStart(home) {
|
|
91
101
|
return tryLock(queuePaths(home).start, START_STALE_MS).catch(() => void 0);
|
|
@@ -124,11 +134,16 @@ async function drainHeld(dir, lock, options, deadline) {
|
|
|
124
134
|
return name;
|
|
125
135
|
}
|
|
126
136
|
};
|
|
137
|
+
let held = false;
|
|
127
138
|
const worker = async () => {
|
|
128
139
|
for (; ; ) {
|
|
129
|
-
if (Date.now() >= deadline) return;
|
|
140
|
+
if (Date.now() >= deadline || held) return;
|
|
130
141
|
const name = await next();
|
|
131
142
|
if (!name) return;
|
|
143
|
+
if (options.ready && !await options.ready().catch(() => false)) {
|
|
144
|
+
held = true;
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
132
147
|
const event = await take(join(dir, name));
|
|
133
148
|
if (!event) continue;
|
|
134
149
|
await options.pay(event).catch(() => void 0);
|
|
@@ -172,9 +187,10 @@ async function runHookProcess(argument = process.argv[3]) {
|
|
|
172
187
|
if (!claim) return;
|
|
173
188
|
if (await startDrain()) return;
|
|
174
189
|
await claim();
|
|
190
|
+
if (!await claimRedemptions(settings.home, Date.now(), HOOK_TIMEOUT_MS)) return;
|
|
175
191
|
const own = await take(path);
|
|
176
192
|
if (!own) return;
|
|
177
|
-
}
|
|
193
|
+
} else if (!await claimRedemptions(settings.home, Date.now(), HOOK_TIMEOUT_MS)) return;
|
|
178
194
|
await payEvent(
|
|
179
195
|
event,
|
|
180
196
|
settings,
|
|
@@ -182,8 +198,13 @@ async function runHookProcess(argument = process.argv[3]) {
|
|
|
182
198
|
started + HOOK_TIMEOUT_MS - Date.now()
|
|
183
199
|
);
|
|
184
200
|
}
|
|
201
|
+
var HOLD_WAIT_MAX_MS = 30 * 6e4;
|
|
202
|
+
var HOLD_RECHECK_MS = 3e4;
|
|
185
203
|
async function runPayProcess() {
|
|
186
|
-
|
|
204
|
+
const hardStop = setTimeout(
|
|
205
|
+
() => process.exit(0),
|
|
206
|
+
DRAIN_MAX_MS + PAY_TIMEOUT_MS + 5e3
|
|
207
|
+
).unref();
|
|
187
208
|
const settings = resolveSettings();
|
|
188
209
|
const raw = await readStdin(HOOK_TIMEOUT_MS);
|
|
189
210
|
if (raw.trim()) await enqueue(settings.home, { raw });
|
|
@@ -195,14 +216,39 @@ async function runPayProcess() {
|
|
|
195
216
|
};
|
|
196
217
|
await drainQueue(settings.home, {
|
|
197
218
|
deadline: Date.now() + DRAIN_MAX_MS,
|
|
198
|
-
pay: (event) => payEvent(event, settings, refill, PAY_TIMEOUT_MS)
|
|
219
|
+
pay: (event) => payEvent(event, settings, refill, PAY_TIMEOUT_MS),
|
|
220
|
+
ready: () => claimRedemptions(settings.home, Date.now(), PAY_TIMEOUT_MS)
|
|
199
221
|
});
|
|
222
|
+
if (await queuedCount(settings.home) === 0) return;
|
|
223
|
+
if (await redemptionWait(settings.home) > 0) {
|
|
224
|
+
clearTimeout(hardStop);
|
|
225
|
+
setTimeout(() => process.exit(0), HOLD_WAIT_MAX_MS + 5e3).unref();
|
|
226
|
+
if (!await waitForHold(settings.home)) return;
|
|
227
|
+
}
|
|
200
228
|
if (!await drainerRunning(settings.home) && await queuedCount(settings.home) > 0)
|
|
201
229
|
await startDrain();
|
|
202
230
|
}
|
|
231
|
+
async function waitForHold(home) {
|
|
232
|
+
const path = queuePaths(home).wait;
|
|
233
|
+
const release = await tryLock(path, DRAIN_STALE_MS).catch(() => void 0);
|
|
234
|
+
if (!release) return false;
|
|
235
|
+
try {
|
|
236
|
+
const deadline = Date.now() + HOLD_WAIT_MAX_MS;
|
|
237
|
+
for (; ; ) {
|
|
238
|
+
const wait = await redemptionWait(home);
|
|
239
|
+
if (wait <= 0) return true;
|
|
240
|
+
if (Date.now() + wait > deadline) return false;
|
|
241
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(wait, HOLD_RECHECK_MS)));
|
|
242
|
+
const now = /* @__PURE__ */ new Date();
|
|
243
|
+
await utimes2(path, now, now).catch(() => void 0);
|
|
244
|
+
}
|
|
245
|
+
} finally {
|
|
246
|
+
await release();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
203
249
|
async function payEvent(event, settings, refill, timeoutMs) {
|
|
204
250
|
if (timeoutMs <= 0) return;
|
|
205
|
-
const { runHook } = await import("./hook-
|
|
251
|
+
const { runHook } = await import("./hook-6DQ3RLVH.js");
|
|
206
252
|
await runHook(
|
|
207
253
|
{
|
|
208
254
|
readInput: async () => event.raw,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { createRequire as __patronCreateRequire } from 'node:module'
|
|
2
2
|
const require = __patronCreateRequire(import.meta.url)
|
|
3
|
+
import "./chunk-GBZCXMDZ.js";
|
|
3
4
|
import {
|
|
5
|
+
accessKeyLimitUnits,
|
|
4
6
|
statePaths
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import {
|
|
7
|
-
accessKeyLimitUnits
|
|
8
|
-
} from "./chunk-EISHX7Q3.js";
|
|
7
|
+
} from "./chunk-JTPFWITF.js";
|
|
9
8
|
import "./chunk-GTMLTZRN.js";
|
|
10
9
|
|
|
11
10
|
// src/wallet.ts
|
package/package.json
CHANGED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { createRequire as __patronCreateRequire } from 'node:module'
|
|
2
|
-
const require = __patronCreateRequire(import.meta.url)
|
|
3
|
-
|
|
4
|
-
// src/refill-process.ts
|
|
5
|
-
import { spawn } from "node:child_process";
|
|
6
|
-
import { createRequire } from "node:module";
|
|
7
|
-
function startRefill(options = {}, script = process.argv[1]) {
|
|
8
|
-
try {
|
|
9
|
-
if (!script) return;
|
|
10
|
-
const [command, refillArgs] = refillCommand(script);
|
|
11
|
-
const args = options.delayed ? [...refillArgs, "--delay"] : refillArgs;
|
|
12
|
-
const child = spawn(command, args, {
|
|
13
|
-
detached: true,
|
|
14
|
-
env: process.env,
|
|
15
|
-
stdio: "ignore"
|
|
16
|
-
});
|
|
17
|
-
child.on("error", () => void 0);
|
|
18
|
-
child.unref();
|
|
19
|
-
} catch {
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function refillCommand(script) {
|
|
23
|
-
try {
|
|
24
|
-
createRequire(script).resolve("mppx");
|
|
25
|
-
return [process.execPath, [...process.execArgv, script, "refill"]];
|
|
26
|
-
} catch {
|
|
27
|
-
return [
|
|
28
|
-
process.platform === "win32" ? "npx.cmd" : "npx",
|
|
29
|
-
["-y", "@tempoxyz/patron", "refill"]
|
|
30
|
-
];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function startDrain(script = process.argv[1]) {
|
|
34
|
-
return new Promise((resolve) => {
|
|
35
|
-
try {
|
|
36
|
-
if (!script) return resolve(false);
|
|
37
|
-
const child = spawn(process.execPath, [...process.execArgv, script, "pay"], {
|
|
38
|
-
detached: true,
|
|
39
|
-
env: process.env,
|
|
40
|
-
stdio: "ignore"
|
|
41
|
-
});
|
|
42
|
-
child.on("error", () => resolve(false));
|
|
43
|
-
child.on("spawn", () => {
|
|
44
|
-
child.unref();
|
|
45
|
-
resolve(true);
|
|
46
|
-
});
|
|
47
|
-
} catch {
|
|
48
|
-
resolve(false);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export {
|
|
54
|
-
startRefill,
|
|
55
|
-
startDrain
|
|
56
|
-
};
|