From fe4879dd7c254dfba8cf9a3c4c48b4bda4d8de73 Mon Sep 17 00:00:00 2001 From: Peter Date: Wed, 29 Nov 2023 16:51:05 +0100 Subject: [PATCH 1/3] Adds management command for inserting safe master copy --- .../commands/insert_safe_master_copy.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 safe_transaction_service/history/management/commands/insert_safe_master_copy.py diff --git a/safe_transaction_service/history/management/commands/insert_safe_master_copy.py b/safe_transaction_service/history/management/commands/insert_safe_master_copy.py new file mode 100644 index 000000000..656d03282 --- /dev/null +++ b/safe_transaction_service/history/management/commands/insert_safe_master_copy.py @@ -0,0 +1,48 @@ +import binascii + +from django.core.management.base import BaseCommand +from ...models import SafeL2MasterCopy + +class Command(BaseCommand): + help = "Insert SafeL2MasterCopy objects" + + def add_arguments(self, parser): + parser.add_argument("--address", help="SafeMasterCopy address", required=True) + parser.add_argument("--initial-block-number", help="Initial block number", required=False, default=0) + parser.add_argument("--tx-block-number", help="Transaction block number", required=False, default=None) + parser.add_argument("--version", help="Safe Version", required=False, default="1.3.0") + parser.add_argument("--l2", help="Address on L2", required=False, default=True) + parser.add_argument("--deployer", help="Deployer", required=False, default="Gnosis") + + def handle(self, *args, **options): + mastercopy_address = options["address"] + initial_block_number = options["initial-block-number"] + tx_block_number = options["tx-block-number"] + version = options["version"] + l2 = options["l2"] + deployer = options["deployer"] + + # Convert the mastercopy address to binary + address = self.ethereum_address_to_binary(mastercopy_address) + + # Create SafeL2MasterCopy object + SafeL2MasterCopy.objects.create( + address=address, + initial_block_number=initial_block_number, + tx_block_number=tx_block_number, + version=version, + l2=l2, + deployer=deployer, + ) + + self.stdout.write(self.style.SUCCESS(f"Created SafeL2MasterCopy for {mastercopy_address}")) + + def ethereum_address_to_binary(self, address): + # Remove the '0x' prefix from the address if it exists + if address.startswith('0x'): + address = address[2:] + + # Convert the hexadecimal string to binary representation + binary_representation = binascii.unhexlify(address) + + return binary_representation \ No newline at end of file From 3660a9898b1e3ba06eb14c7c4fb2a44f910501bf Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 30 Nov 2023 09:20:00 +0100 Subject: [PATCH 2/3] Fixes incorrect model reference and objects creation --- .../commands/insert_safe_master_copy.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/safe_transaction_service/history/management/commands/insert_safe_master_copy.py b/safe_transaction_service/history/management/commands/insert_safe_master_copy.py index 656d03282..ad0ca80bf 100644 --- a/safe_transaction_service/history/management/commands/insert_safe_master_copy.py +++ b/safe_transaction_service/history/management/commands/insert_safe_master_copy.py @@ -1,32 +1,32 @@ import binascii from django.core.management.base import BaseCommand -from ...models import SafeL2MasterCopy +from ...models import SafeMasterCopy class Command(BaseCommand): - help = "Insert SafeL2MasterCopy objects" + help = "Insert SafeMasterCopy objects" def add_arguments(self, parser): parser.add_argument("--address", help="SafeMasterCopy address", required=True) parser.add_argument("--initial-block-number", help="Initial block number", required=False, default=0) parser.add_argument("--tx-block-number", help="Transaction block number", required=False, default=None) - parser.add_argument("--version", help="Safe Version", required=False, default="1.3.0") + parser.add_argument("--safe-version", help="Safe Version", required=False, default="1.3.0") parser.add_argument("--l2", help="Address on L2", required=False, default=True) parser.add_argument("--deployer", help="Deployer", required=False, default="Gnosis") def handle(self, *args, **options): mastercopy_address = options["address"] - initial_block_number = options["initial-block-number"] - tx_block_number = options["tx-block-number"] - version = options["version"] + initial_block_number = options["initial_block_number"] + tx_block_number = options["tx_block_number"] + version = options["safe_version"] l2 = options["l2"] deployer = options["deployer"] # Convert the mastercopy address to binary address = self.ethereum_address_to_binary(mastercopy_address) - # Create SafeL2MasterCopy object - SafeL2MasterCopy.objects.create( + # Create SafeMasterCopy object + SafeMasterCopy.objects.create( address=address, initial_block_number=initial_block_number, tx_block_number=tx_block_number, @@ -35,7 +35,7 @@ def handle(self, *args, **options): deployer=deployer, ) - self.stdout.write(self.style.SUCCESS(f"Created SafeL2MasterCopy for {mastercopy_address}")) + self.stdout.write(self.style.SUCCESS(f"Created SafeMasterCopy for {mastercopy_address}")) def ethereum_address_to_binary(self, address): # Remove the '0x' prefix from the address if it exists From 9b94d9a04bf1b201588f281c9e9867d0d93ba9c2 Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 5 Mar 2024 22:52:59 +0100 Subject: [PATCH 3/3] Removes redundant ethereum address to binaryr --- .../commands/insert_safe_master_copy.py | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/safe_transaction_service/history/management/commands/insert_safe_master_copy.py b/safe_transaction_service/history/management/commands/insert_safe_master_copy.py index ad0ca80bf..767ea38fa 100644 --- a/safe_transaction_service/history/management/commands/insert_safe_master_copy.py +++ b/safe_transaction_service/history/management/commands/insert_safe_master_copy.py @@ -11,8 +11,8 @@ def add_arguments(self, parser): parser.add_argument("--initial-block-number", help="Initial block number", required=False, default=0) parser.add_argument("--tx-block-number", help="Transaction block number", required=False, default=None) parser.add_argument("--safe-version", help="Safe Version", required=False, default="1.3.0") - parser.add_argument("--l2", help="Address on L2", required=False, default=True) - parser.add_argument("--deployer", help="Deployer", required=False, default="Gnosis") + parser.add_argument("--l2", help="Address on L2", required=False, default=False) + parser.add_argument("--deployer", help="Deployer", required=False, default="Safe") def handle(self, *args, **options): mastercopy_address = options["address"] @@ -21,13 +21,9 @@ def handle(self, *args, **options): version = options["safe_version"] l2 = options["l2"] deployer = options["deployer"] - - # Convert the mastercopy address to binary - address = self.ethereum_address_to_binary(mastercopy_address) - # Create SafeMasterCopy object SafeMasterCopy.objects.create( - address=address, + address=mastercopy_address, initial_block_number=initial_block_number, tx_block_number=tx_block_number, version=version, @@ -35,14 +31,4 @@ def handle(self, *args, **options): deployer=deployer, ) - self.stdout.write(self.style.SUCCESS(f"Created SafeMasterCopy for {mastercopy_address}")) - - def ethereum_address_to_binary(self, address): - # Remove the '0x' prefix from the address if it exists - if address.startswith('0x'): - address = address[2:] - - # Convert the hexadecimal string to binary representation - binary_representation = binascii.unhexlify(address) - - return binary_representation \ No newline at end of file + self.stdout.write(self.style.SUCCESS(f"Created SafeMasterCopy for {mastercopy_address}")) \ No newline at end of file