Skip to content

Commit 90a3194

Browse files
committed
fixed
1 parent 2e8efb5 commit 90a3194

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

minichain/block.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ def to_header_dict(self):
7373
"timestamp": self.timestamp,
7474
"difficulty": self.difficulty,
7575
"nonce": self.nonce,
76-
"miner": self.miner,
7776
}
7877

7978
# -------------------------
@@ -90,11 +89,11 @@ def to_body_dict(self):
9089
# FULL BLOCK
9190
# -------------------------
9291
def to_dict(self):
93-
return {
94-
**self.to_header_dict(),
95-
**self.to_body_dict(),
96-
"hash": self.hash,
97-
}
92+
data = self.to_header_dict()
93+
data["transactions"] = [tx.to_dict() for tx in self.transactions]
94+
data["hash"] = self.hash
95+
data["miner"] = self.miner
96+
return data
9897

9998
# -------------------------
10099
# HASH CALCULATION

minichain/p2p.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ async def _listen_to_peer(
303303

304304
async def _broadcast_raw(self, payload: dict):
305305
"""Send a JSON message to every connected peer."""
306-
line = (json.dumps(payload) + "\n").encode()
307306
line = (canonical_json_dumps(payload) + "\n").encode()
308307
disconnected = []
309308
for reader, writer in self._peers:
@@ -333,12 +332,16 @@ async def broadcast_transaction(self, tx):
333332
self._mark_seen("tx", payload["data"])
334333
await self._broadcast_raw(payload)
335334

336-
async def broadcast_block(self, block):
335+
async def broadcast_block(self, block, miner=None):
337336
logger.info("Network: Broadcasting Block #%d", block.index)
337+
338+
# Ensure the block object has the miner set if provided
339+
if miner:
340+
block.miner = miner
341+
338342
payload = {
339343
"type": "block",
340-
"data": json.loads(block.canonical_payload.decode('utf-8')),
341-
"miner": block.miner
344+
"data": json.loads(block.canonical_payload.decode('utf-8'))
342345
}
343346
self._mark_seen("block", payload["data"])
344347
await self._broadcast_raw(payload)

0 commit comments

Comments
 (0)