Skip to content

Commit

Permalink
rewritting to fix missing stuff
Browse files Browse the repository at this point in the history
should I default value theme to None?
Signed-off-by: LukeBair <[email protected]>
  • Loading branch information
LukeBair committed Mar 5, 2025
1 parent ccabc08 commit 1543e42
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 45 deletions.
3 changes: 2 additions & 1 deletion src/hiero_sdk_python/account/account_create_transaction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Union

from hiero_sdk_python.hapi.services.duration_pb2 import Duration
from hiero_sdk_python.transaction.transaction import Transaction
from hiero_sdk_python.hapi.services import crypto_create_pb2, duration_pb2
from hiero_sdk_python.response_code import ResponseCode
Expand Down Expand Up @@ -137,7 +138,7 @@ def build_transaction_body(self):
key=self.key.to_proto(),
initialBalance=initial_balance_tinybars,
receiverSigRequired=self.receiver_signature_required,
autoRenewPeriod=duration_pb2.Duration(seconds=self.auto_renew_period),
autoRenewPeriod=Duration(seconds=self.auto_renew_period),
memo=self.account_memo
)

Expand Down
37 changes: 27 additions & 10 deletions tck/account_create.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import utils

from jsonrpcserver import method, Success

from hiero_sdk_python import PrivateKey, PublicKey
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
from key_identifier import KeyIdentifier

def identify_key(key: str) -> (PrivateKey | PublicKey, bool) :
try:
return PrivateKey.from_string(key), False
except ValueError:
try:
return PublicKey.from_string(key), True
except Exception as e:
raise e

@method
def createAccount(key: str = None, initialBalance: str = None, receiverSignatureRequired: bool = None, autoRenewPeriod: str = None,

Check warning on line 17 in tck/account_create.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tck/account_create.py#L17

Method createAccount has 11 parameters (limit is 8)
Expand All @@ -24,24 +33,32 @@ def createAccount(key: str = None, initialBalance: str = None, receiverSignature
:return accountId: string, The ID of the created account.
:return status: string, The status of the submitted AccountCreateTransaction (from a TransactionReceipt).
"""
key_and_public = KeyIdentifier.identify(key)

if key_and_public[1] is False:
public_key = key_and_public[0].public_key()
key_and_public = identify_key(key=key)
pk: PrivateKey
pub: PublicKey

if key_and_public[1]:
pub = key_and_public[0]
else:
public_key = key_and_public[0]
pk = key_and_public[0]
pub = pk.public_key()


# TODO: add all of the other transaction parameters
transaction = (
AccountCreateTransaction()
.set_key(public_key)
.set_key(pub)
# .set_initial_balance(int(initialBalance))
.set_receiver_signature_required(receiverSignatureRequired)
# .set_receiver_signature_required(receiverSignatureRequired)
# .set_auto_renew_period(0, int(autoRenewPeriod))
.set_account_memo(memo)
.freeze_with(utils.__client)
# .set_account_memo(memo)
# .freeze_with(utils.__client)
)

# transaction = AccountCreateTransaction().set_key(pub)


transaction.sign(utils.__operatorPrivateKey)
receipt = transaction.execute(utils.__client)

Expand Down
17 changes: 0 additions & 17 deletions tck/key_identifier.py

This file was deleted.

3 changes: 2 additions & 1 deletion tck/server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging
from jsonrpcserver import serve
import utils, account_create

# NOTE: enable if you want to see the logs
# logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.DEBUG)

if __name__ == '__main__':
serve(port=8544) # Specify your desired port here
53 changes: 37 additions & 16 deletions tck/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import logging

from hiero_sdk_python import Network
from hiero_sdk_python.account.account_id import AccountId
from hiero_sdk_python.client.client import Client
from jsonrpcserver import Success, method, InvalidParams
from jsonrpcserver import Success, method, InvalidParams, JsonRpcError
from hiero_sdk_python.crypto.private_key import PrivateKey

__operatorAccountId: AccountId
Expand Down Expand Up @@ -33,27 +35,46 @@ def reset():
})

@method
def generateKey(type: str=None, fromKey: str=None, threshold: int=None, keys: list=None):
if type == "ed25519PublicKey":
def generateKey(type: str, fromKey: str=None, threshold: int=None, keys: list=None):

Check warning on line 38 in tck/utils.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tck/utils.py#L38

Method generateKey has a cyclomatic complexity of 10 (limit is 8)
pk = None

if type == "ed25519PrivateKey":
return Success({
"key": PrivateKey.generate_ed25519().to_string_raw(),
})

elif type == "ed25519PublicKey":
if fromKey is None:
return Success({"key": PrivateKey.generate_ed25519().public_key().to_string_raw()})
pk = PrivateKey.generate()
else:
new_account_private_key = PrivateKey.from_string(fromKey)
new_account_public_key = new_account_private_key.public_key()
return Success({"key": new_account_public_key.to_string_raw()})
pk = PrivateKey.from_string(fromKey)
return Success({
"key": pk.public_key().to_string_raw(),
})

elif type == "ecdsaSecp256k1PrivateKey":
return Success({
"key": PrivateKey.generate_ecdsa().to_string_raw(),
})

elif type == "ecdsaSecp256k1PublicKey":
if fromKey is None:
return Success({"key": PrivateKey.generate_ecdsa().public_key().to_string_raw()})
pk = PrivateKey.generate_ecdsa()
else:
new_account_private_key = PrivateKey.from_string(fromKey)
new_account_public_key = new_account_private_key.public_key()
return Success({"key": new_account_public_key.to_string_raw()})
pk = PrivateKey.from_string(fromKey)
return Success({
"key": pk.public_key().to_string_raw(),
})

elif type == "ed25519PrivateKey":
new_account_private_key = PrivateKey.generate()
return Success({"key": new_account_private_key.to_string_raw()})
elif type == "thresholdKey":
return JsonRpcError(code=-32001, message="Not implemented")

else:
return InvalidParams("Unknown type")
elif type == "keyList":
return JsonRpcError(code=-32001, message="Not implemented")

elif type == "evmAddress":
return JsonRpcError(code=-32001, message="Not implemented")


else:
return JsonRpcError(code=-32001, message="Unknown key type")

0 comments on commit 1543e42

Please sign in to comment.