|
| 1 | +import utils |
| 2 | + |
| 3 | +from jsonrpcserver import method, Success |
| 4 | +from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction |
| 5 | +from key_identifier import KeyIdentifier |
| 6 | + |
| 7 | +# NOTE: The problem is I need to use a string to identify whether or not a key is ecdsa, ed25519, public or private |
| 8 | +# The PrivateKey class has a 'from_string' class which I can take advantage of easily |
| 9 | +# The PublicKey doesnt have anything helpful, once you have a reference to it you can check if it is ed25519 or ecdsa |
| 10 | +# So I will likely have to add a way to check for the public key, this can be done outside of the PublicKey class, |
| 11 | +# but to keep consistency with the PrivateKey class it would be really nice to have a 'from_string' class in there |
| 12 | +# Ill take a look into it rn to see if it is something I am capable of doing well (I know a way I could but its dookie) |
| 13 | +# It doesnt look like something that I really have any right doing, Im not really sure where to start with the ec key, |
| 14 | +# I'll look into it again |
| 15 | +# Ignoring KeyLists right now |
| 16 | +# The """...""" block is taken directly from the tck AccountCreateTransaction.md & combined with the intellij |
| 17 | +# autogenerated """...""" block |
| 18 | +@method |
| 19 | +def createAccount(key: str = None, initialBalance: str = None, receiverSignatureRequired: bool = None, autoRenewPeriod: str = None, |
| 20 | + memo: str = None, maxAutoTokenAssociations: int = None, stakedAccountId: str = None, stakedNodeId: str = None, |
| 21 | + declineStakingReward: bool = None, alias: str = None, commonTransactionParams: dict = None): |
| 22 | + """ |
| 23 | + :param key: string, optional, DER-encoded hex string representation for private or public keys. Keylists and threshold keys are the hex of the serialized protobuf bytes. |
| 24 | + :param initialBalance: Units of tinybars, optional |
| 25 | + :param receiverSignatureRequired: bool, optional |
| 26 | + :param autoRenewPeriod: string, Units of seconds, optional |
| 27 | + :param memo: string, optional |
| 28 | + :param maxAutoTokenAssociations: int32, optional |
| 29 | + :param stakedAccountId: string, optional |
| 30 | + :param stakedNodeId: string, optional |
| 31 | + :param declineStakingReward: bool, optional |
| 32 | + :param alias: string, optional, Hex string representation of the keccak-256 hash of an ECDSAsecp256k1 public key type. |
| 33 | + :param commonTransactionParams: JSON object, optional |
| 34 | +
|
| 35 | + :return accountId: string, The ID of the created account. |
| 36 | + :return status: string, The status of the submitted AccountCreateTransaction (from a TransactionReceipt). |
| 37 | + """ |
| 38 | + key_and_public = KeyIdentifier.identify(key) |
| 39 | + |
| 40 | + if key_and_public[1] is False: |
| 41 | + public_key = key_and_public[0].public_key() |
| 42 | + else: |
| 43 | + public_key = key_and_public[0] |
| 44 | + |
| 45 | + # TODO: add all of the other transaction parameters |
| 46 | + transaction = ( |
| 47 | + AccountCreateTransaction() |
| 48 | + .set_key(public_key) |
| 49 | + .set_account_memo(memo) |
| 50 | + .freeze_with(utils.__client) |
| 51 | + ) |
| 52 | + # WARNING: I believe that this is right, but im not sure what the case is if the key parameter is a Private Key |
| 53 | + # why the heck are they giving me a private key anyways... |
| 54 | + transaction.sign(utils.__operatorPrivateKey) |
| 55 | + receipt = transaction.execute(utils.__client) |
| 56 | + |
| 57 | + return Success({ |
| 58 | + "accountId": receipt.accountId, |
| 59 | + "status": receipt.status, |
| 60 | + }) |
0 commit comments