Skip to content

Commit

Permalink
adding a command to derive olympia addresses (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
balda-rdx authored Oct 5, 2023
1 parent d5a9484 commit 0add212
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
21 changes: 19 additions & 2 deletions node-runner-cli/commands/retcommand.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from argparse import ArgumentParser, RawTextHelpFormatter
from commands.subcommand import get_decorator, argument
from ret.accounts import derive_address
from ret.accounts import derive_address, derive_babylon_address_from_olympia_account_address

ret_cli = ArgumentParser(
description='Subcommand to help use the Radix Engine Toolkit aka RET',
Expand Down Expand Up @@ -29,4 +29,21 @@ def derive(args):
Derive a babylon address from a private key.
"""
address = derive_address(args.keystore, args.password, int(args.network))
print(address.address_string())
print(address.address_string())


@retcommand([
argument("-oa", "--olympia-address", required=True,
help="Olympia address",
action="store"),
argument("-n", "--network", required=True,
help="Network id. Int format",
action="store")
])
def derive_from_olympia(args):
"""
Derive a babylon address from a private key.
"""
print(
derive_babylon_address_from_olympia_account_address(
args.olympia_address, int(args.network)))
12 changes: 10 additions & 2 deletions node-runner-cli/ret/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from radix_engine_toolkit import (
PrivateKey,
Address,
derive_virtual_account_address_from_public_key
derive_virtual_account_address_from_public_key, derive_virtual_account_address_from_olympia_account_address,
OlympiaAddress
)


Expand All @@ -25,4 +26,11 @@ def derive_address(keystore: str, password: str, network_id: int) -> Address:
private_key = PrivateKey.new_secp256k1(private_signing_key.to_string())

return derive_virtual_account_address_from_public_key(
public_key=private_key.public_key(), network_id=network_id)
public_key=private_key.public_key(), network_id=network_id)


def derive_babylon_address_from_olympia_account_address(address: str, network: int):
address = OlympiaAddress(address)
babylon_address = derive_virtual_account_address_from_olympia_account_address(
address, network_id=network)
return babylon_address.as_str()

0 comments on commit 0add212

Please sign in to comment.