Skip to content

Commit 1543e42

Browse files
committed
rewritting to fix missing stuff
should I default value theme to None? Signed-off-by: LukeBair <[email protected]>
1 parent ccabc08 commit 1543e42

File tree

5 files changed

+68
-45
lines changed

5 files changed

+68
-45
lines changed

src/hiero_sdk_python/account/account_create_transaction.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Union
22

3+
from hiero_sdk_python.hapi.services.duration_pb2 import Duration
34
from hiero_sdk_python.transaction.transaction import Transaction
45
from hiero_sdk_python.hapi.services import crypto_create_pb2, duration_pb2
56
from hiero_sdk_python.response_code import ResponseCode
@@ -137,7 +138,7 @@ def build_transaction_body(self):
137138
key=self.key.to_proto(),
138139
initialBalance=initial_balance_tinybars,
139140
receiverSigRequired=self.receiver_signature_required,
140-
autoRenewPeriod=duration_pb2.Duration(seconds=self.auto_renew_period),
141+
autoRenewPeriod=Duration(seconds=self.auto_renew_period),
141142
memo=self.account_memo
142143
)
143144

tck/account_create.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import utils
2-
32
from jsonrpcserver import method, Success
3+
4+
from hiero_sdk_python import PrivateKey, PublicKey
45
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
5-
from key_identifier import KeyIdentifier
6+
7+
def identify_key(key: str) -> (PrivateKey | PublicKey, bool) :
8+
try:
9+
return PrivateKey.from_string(key), False
10+
except ValueError:
11+
try:
12+
return PublicKey.from_string(key), True
13+
except Exception as e:
14+
raise e
615

716
@method
817
def createAccount(key: str = None, initialBalance: str = None, receiverSignatureRequired: bool = None, autoRenewPeriod: str = None,
@@ -24,24 +33,32 @@ def createAccount(key: str = None, initialBalance: str = None, receiverSignature
2433
:return accountId: string, The ID of the created account.
2534
:return status: string, The status of the submitted AccountCreateTransaction (from a TransactionReceipt).
2635
"""
27-
key_and_public = KeyIdentifier.identify(key)
2836

29-
if key_and_public[1] is False:
30-
public_key = key_and_public[0].public_key()
37+
key_and_public = identify_key(key=key)
38+
pk: PrivateKey
39+
pub: PublicKey
40+
41+
if key_and_public[1]:
42+
pub = key_and_public[0]
3143
else:
32-
public_key = key_and_public[0]
44+
pk = key_and_public[0]
45+
pub = pk.public_key()
46+
3347

3448
# TODO: add all of the other transaction parameters
3549
transaction = (
3650
AccountCreateTransaction()
37-
.set_key(public_key)
51+
.set_key(pub)
3852
# .set_initial_balance(int(initialBalance))
39-
.set_receiver_signature_required(receiverSignatureRequired)
53+
# .set_receiver_signature_required(receiverSignatureRequired)
4054
# .set_auto_renew_period(0, int(autoRenewPeriod))
41-
.set_account_memo(memo)
42-
.freeze_with(utils.__client)
55+
# .set_account_memo(memo)
56+
# .freeze_with(utils.__client)
4357
)
4458

59+
# transaction = AccountCreateTransaction().set_key(pub)
60+
61+
4562
transaction.sign(utils.__operatorPrivateKey)
4663
receipt = transaction.execute(utils.__client)
4764

tck/key_identifier.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

tck/server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import logging
22
from jsonrpcserver import serve
3+
import utils, account_create
34

45
# NOTE: enable if you want to see the logs
5-
# logging.basicConfig(level=logging.DEBUG)
6+
logging.basicConfig(level=logging.DEBUG)
67

78
if __name__ == '__main__':
89
serve(port=8544) # Specify your desired port here

tck/utils.py

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import logging
2+
13
from hiero_sdk_python import Network
24
from hiero_sdk_python.account.account_id import AccountId
35
from hiero_sdk_python.client.client import Client
4-
from jsonrpcserver import Success, method, InvalidParams
6+
from jsonrpcserver import Success, method, InvalidParams, JsonRpcError
57
from hiero_sdk_python.crypto.private_key import PrivateKey
68

79
__operatorAccountId: AccountId
@@ -33,27 +35,46 @@ def reset():
3335
})
3436

3537
@method
36-
def generateKey(type: str=None, fromKey: str=None, threshold: int=None, keys: list=None):
37-
if type == "ed25519PublicKey":
38+
def generateKey(type: str, fromKey: str=None, threshold: int=None, keys: list=None):
39+
pk = None
40+
41+
if type == "ed25519PrivateKey":
42+
return Success({
43+
"key": PrivateKey.generate_ed25519().to_string_raw(),
44+
})
45+
46+
elif type == "ed25519PublicKey":
3847
if fromKey is None:
39-
return Success({"key": PrivateKey.generate_ed25519().public_key().to_string_raw()})
48+
pk = PrivateKey.generate()
4049
else:
41-
new_account_private_key = PrivateKey.from_string(fromKey)
42-
new_account_public_key = new_account_private_key.public_key()
43-
return Success({"key": new_account_public_key.to_string_raw()})
50+
pk = PrivateKey.from_string(fromKey)
51+
return Success({
52+
"key": pk.public_key().to_string_raw(),
53+
})
54+
55+
elif type == "ecdsaSecp256k1PrivateKey":
56+
return Success({
57+
"key": PrivateKey.generate_ecdsa().to_string_raw(),
58+
})
4459

4560
elif type == "ecdsaSecp256k1PublicKey":
4661
if fromKey is None:
47-
return Success({"key": PrivateKey.generate_ecdsa().public_key().to_string_raw()})
62+
pk = PrivateKey.generate_ecdsa()
4863
else:
49-
new_account_private_key = PrivateKey.from_string(fromKey)
50-
new_account_public_key = new_account_private_key.public_key()
51-
return Success({"key": new_account_public_key.to_string_raw()})
64+
pk = PrivateKey.from_string(fromKey)
65+
return Success({
66+
"key": pk.public_key().to_string_raw(),
67+
})
5268

53-
elif type == "ed25519PrivateKey":
54-
new_account_private_key = PrivateKey.generate()
55-
return Success({"key": new_account_private_key.to_string_raw()})
69+
elif type == "thresholdKey":
70+
return JsonRpcError(code=-32001, message="Not implemented")
5671

57-
else:
58-
return InvalidParams("Unknown type")
72+
elif type == "keyList":
73+
return JsonRpcError(code=-32001, message="Not implemented")
74+
75+
elif type == "evmAddress":
76+
return JsonRpcError(code=-32001, message="Not implemented")
5977

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

0 commit comments

Comments
 (0)