2020117-agent 0.2.3 → 0.2.4

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.
Files changed (2) hide show
  1. package/dist/agent.js +16 -17
  2. package/package.json +1 -1
package/dist/agent.js CHANGED
@@ -696,36 +696,35 @@ async function startSwarmListener(label) {
696
696
  }
697
697
  const job = {
698
698
  socket,
699
- credit: 0,
699
+ credit: CHUNKS_PER_PAYMENT, // start with free credit; debit after delivery
700
700
  ndebit: msg.ndebit,
701
701
  totalEarned: 0,
702
702
  stopped: false,
703
703
  };
704
704
  p2pJobs.set(msg.id, job);
705
- // Send offer
705
+ // Send offer (price quote — no payment yet)
706
706
  node.send(socket, {
707
707
  type: 'offer',
708
708
  id: msg.id,
709
709
  sats_per_chunk: SATS_PER_CHUNK,
710
710
  chunks_per_payment: CHUNKS_PER_PAYMENT,
711
711
  });
712
- // Debit first payment cycle via CLINK
713
- const paid = await collectP2PPayment({
714
- job, node, jobId: msg.id,
715
- satsPerChunk: SATS_PER_CHUNK,
716
- chunksPerPayment: CHUNKS_PER_PAYMENT,
717
- lightningAddress: LIGHTNING_ADDRESS,
718
- label,
719
- });
720
- if (!paid) {
721
- console.log(`[${label}] P2P job ${msg.id}: first debit failed, aborting`);
722
- p2pJobs.delete(msg.id);
723
- releaseSlot();
724
- return;
725
- }
726
- // Start generating
712
+ // Generate first, pay after delivery
727
713
  node.send(socket, { type: 'accepted', id: msg.id });
728
714
  await runP2PGeneration(node, job, msg, label);
715
+ // Debit after result delivered
716
+ if (!job.stopped) {
717
+ const paid = await collectP2PPayment({
718
+ job, node, jobId: msg.id,
719
+ satsPerChunk: SATS_PER_CHUNK,
720
+ chunksPerPayment: CHUNKS_PER_PAYMENT,
721
+ lightningAddress: LIGHTNING_ADDRESS,
722
+ label,
723
+ });
724
+ if (!paid) {
725
+ console.log(`[${label}] P2P job ${msg.id}: post-delivery debit failed`);
726
+ }
727
+ }
729
728
  }
730
729
  if (msg.type === 'stop') {
731
730
  const job = p2pJobs.get(msg.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "2020117-agent",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "2020117 agent runtime — API polling + Hyperswarm P2P + CLINK Lightning payments",
5
5
  "type": "module",
6
6
  "bin": {