@molteee/arena-tools 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.
- package/dist/commands/play.js +10 -11
- package/dist/commands/play.js.map +1 -1
- package/package.json +1 -1
package/dist/commands/play.js
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
import { encodeFunctionData, parseEther, getAddress as checksumAddress } from "viem";
|
|
9
9
|
import { CONTRACTS, GAME_CONTRACTS, GAME_TYPES } from "../config.js";
|
|
10
10
|
import { escrowAbi } from "../contracts.js";
|
|
11
|
-
import { getPublicClient, getAddress } from "../client.js";
|
|
12
11
|
import { sendTx } from "../utils/tx.js";
|
|
13
12
|
import { event, fail } from "../utils/output.js";
|
|
14
13
|
import { respondCommand } from "./respond.js";
|
|
@@ -19,7 +18,6 @@ export async function playCommand(opponent, wager, gameType, opts) {
|
|
|
19
18
|
}
|
|
20
19
|
const gameContract = GAME_CONTRACTS[gt];
|
|
21
20
|
const wagerWei = parseEther(wager);
|
|
22
|
-
const myAddress = getAddress();
|
|
23
21
|
// Step 1: Create the challenge
|
|
24
22
|
event({ event: "challenging", opponent, wager, gameType: gt });
|
|
25
23
|
const data = encodeFunctionData({
|
|
@@ -27,19 +25,20 @@ export async function playCommand(opponent, wager, gameType, opts) {
|
|
|
27
25
|
functionName: "createMatch",
|
|
28
26
|
args: [checksumAddress(opponent), gameContract],
|
|
29
27
|
});
|
|
30
|
-
const { hash } = await sendTx({
|
|
28
|
+
const { hash, logs } = await sendTx({
|
|
31
29
|
to: CONTRACTS.Escrow,
|
|
32
30
|
data,
|
|
33
31
|
value: wagerWei,
|
|
34
32
|
});
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
// Parse matchId from MatchCreated event in tx logs (topics[1]).
|
|
34
|
+
// Race-safe — reads directly from our own tx receipt, not from global state.
|
|
35
|
+
let matchId = -1;
|
|
36
|
+
for (const log of logs) {
|
|
37
|
+
if (log.address.toLowerCase() === CONTRACTS.Escrow.toLowerCase() && log.topics.length > 1) {
|
|
38
|
+
matchId = Number(BigInt(log.topics[1]));
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
43
42
|
event({ event: "challenge_created", matchId, opponent, wager, gameType: gt, txHash: hash });
|
|
44
43
|
// Step 2: Delegate to respond — it handles waiting for acceptance, game creation, and play
|
|
45
44
|
await respondCommand(String(matchId), opts);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"play.js","sourceRoot":"","sources":["../../src/commands/play.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,mFAAmF;AACnF,EAAE;AACF,0FAA0F;AAC1F,EAAE;AACF,oFAAoF;AACpF,uDAAuD;AACvD,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,UAAU,IAAI,eAAe,EAAE,MAAM,MAAM,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"play.js","sourceRoot":"","sources":["../../src/commands/play.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,mFAAmF;AACnF,EAAE;AACF,0FAA0F;AAC1F,EAAE;AACF,oFAAoF;AACpF,uDAAuD;AACvD,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,UAAU,IAAI,eAAe,EAAE,MAAM,MAAM,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MA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