Skip to content

Commit 3c67602

Browse files
More work on hydra networking
1 parent 5ac74dc commit 3c67602

File tree

7 files changed

+48
-197
lines changed

7 files changed

+48
-197
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
8+
"start": "vite",
89
"build": "tsc -b && vite build",
910
"lint": "eslint .",
1011
"lint:fix": "eslint --fix .",

public/websockets-doom.wasm

-15.3 KB
Binary file not shown.

public/websockets-doom.wasm.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/DoomCanvas/DoomCanvas.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ const DoomCanvas: React.FC = () => {
1010
const { gameData } = useAppContext();
1111
const keys = useKeys();
1212

13-
console.log("keys", keys);
14-
1513
useEffect(() => {
1614
// Prevent effect from running twice
1715

src/hooks/useKeys.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ const useKeys = () => {
6464
initKeys();
6565
}, [keys.sessionKeyBech32, sessionKeyBech32, generateKeys]);
6666

67-
console.log("keys", keys);
68-
6967
return keys;
7068
};
7169

src/utils/hydra-multiplayer.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export class HydraMultiplayer {
1717
constructor(keys: Keys, url: string) {
1818
this.keys = keys;
1919
this.hydra = new Hydra(url, 100);
20-
this.hydra.onTxSeen = this.onTxSeen;
20+
this.hydra.onTxSeen = this.onTxSeen.bind(this);
21+
22+
this.SendPacket = this.SendPacket.bind(this);
23+
this.setIP = this.setIP.bind(this);
2124
}
2225

2326
public setIP(ip: number) {
@@ -28,11 +31,17 @@ export class HydraMultiplayer {
2831
if (!!this.latestUTxO) {
2932
return;
3033
}
34+
await this.hydra.populateUTxO();
3135
let utxos = await this.hydra.getUtxos(this.keys.address!);
32-
this.latestUTxO = utxos[0];
36+
// TODO: robust
37+
if (this.myIP === 1) {
38+
this.latestUTxO = utxos.find(u => u.outputIndex === 1)!;
39+
} else {
40+
this.latestUTxO = utxos.find(u => u.outputIndex === 0)!;
41+
}
3342
}
3443

35-
public async sendPacket(to: number, from: number, data: Uint8Array): Promise<void> {
44+
public async SendPacket(to: number, from: number, data: Uint8Array): Promise<void> {
3645
this.packetQueue.push({ to, from, data });
3746
await this.sendPacketQueue();
3847
}
@@ -108,7 +117,6 @@ const buildTx = (
108117
datumLengthHex = "0" + datumLengthHex;
109118
}
110119
const lengthLengthTag = 57 + datumLengthHex.length / 2;
111-
console.log(datumLengthHex);
112120
const txBodyByHand =
113121
`a3` + // Prefix
114122
`0081825820${inputUtxo.txHash}0${inputUtxo.outputIndex}` + // One input

0 commit comments

Comments
 (0)