Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply changes for Thor planet #333

Merged
merged 11 commits into from
Nov 14, 2024
Prev Previous commit
Set thor internal genesis hash
  • Loading branch information
U-lis committed Nov 13, 2024
commit e1528187b741ad903ec1f24e1c48009e7c16aca6
11 changes: 7 additions & 4 deletions common/utils/transaction.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import datetime
from typing import Any, Dict, List, Optional, Tuple, Union
from typing import Any, Dict

import bencodex

from common.utils.receipt import PlanetID


def create_unsigned_tx(planet_id: PlanetID, public_key: str, address: str, nonce: int, plain_value: Dict[str, Any], timestamp: datetime.datetime) -> bytes:
def create_unsigned_tx(planet_id: PlanetID, public_key: str, address: str, nonce: int, plain_value: Dict[str, Any],
timestamp: datetime.datetime) -> bytes:
if address.startswith("0x"):
address = address[2:]
return bencodex.dumps({
Expand All @@ -33,11 +34,13 @@ def create_unsigned_tx(planet_id: PlanetID, public_key: str, address: str, nonce
b"u": [],
})


def append_signature_to_unsigned_tx(unsigned_tx: bytes, signature: bytes) -> bytes:
decoded = bencodex.loads(unsigned_tx)
decoded[b"S"] = signature
return bencodex.dumps(decoded)


def get_genesis_block_hash(planet_id: PlanetID) -> bytes:
switcher = {
PlanetID.ODIN: bytes.fromhex("4582250d0da33b06779a8475d283d5dd210c683b9b999d74d03fac4f58fa6bce"),
Expand All @@ -46,10 +49,10 @@ def get_genesis_block_hash(planet_id: PlanetID) -> bytes:
PlanetID.HEIMDALL_INTERNAL: bytes.fromhex("729fa26958648a35b53e8e3905d11ec53b1b4929bf5f499884aed7df616f5913"),
# FIXME: Set to right genesis hash
PlanetID.THOR: bytes.fromhex("abc123"),
PlanetID.THOR_INTERNAL: bytes.fromhex("abc123"),
PlanetID.THOR_INTERNAL: bytes.fromhex("d55426c88650a1cb2cebc883e79721a4fad2ad5a62103fba5e899736b94bbacf"),
}

if planet_id not in switcher:
raise ValueError("Invalid planet id")

return switcher[planet_id]
Loading