|
| 1 | +from crypto.enums.abi_function import AbiFunction |
| 2 | +from crypto.enums.contract_abi_type import ContractAbiType |
| 3 | +from crypto.utils.abi_encoder import AbiEncoder |
| 4 | + |
| 5 | + |
| 6 | +class TransactionDataEncoder: |
| 7 | + @staticmethod |
| 8 | + def multi_payment(recipients, amounts): |
| 9 | + return AbiEncoder(ContractAbiType.MULTIPAYMENT).encode_function_call_hex( |
| 10 | + AbiFunction.MULTIPAYMENT.value, [recipients, amounts] |
| 11 | + ) |
| 12 | + |
| 13 | + @staticmethod |
| 14 | + def update_validator(validator_public_key): |
| 15 | + key = validator_public_key |
| 16 | + if not key.startswith('0x'): |
| 17 | + key = '0x' + key |
| 18 | + return AbiEncoder(ContractAbiType.CONSENSUS).encode_function_call_hex( |
| 19 | + AbiFunction.UPDATE_VALIDATOR.value, [key] |
| 20 | + ) |
| 21 | + |
| 22 | + @staticmethod |
| 23 | + def username_registration(username): |
| 24 | + return AbiEncoder(ContractAbiType.USERNAMES).encode_function_call_hex( |
| 25 | + AbiFunction.USERNAME_REGISTRATION.value, [username] |
| 26 | + ) |
| 27 | + |
| 28 | + @staticmethod |
| 29 | + def username_resignation(): |
| 30 | + return AbiEncoder(ContractAbiType.USERNAMES).encode_function_call_hex( |
| 31 | + AbiFunction.USERNAME_RESIGNATION.value, [] |
| 32 | + ) |
| 33 | + |
| 34 | + @staticmethod |
| 35 | + def validator_registration(validator_public_key): |
| 36 | + key = validator_public_key |
| 37 | + if not key.startswith('0x'): |
| 38 | + key = '0x' + key |
| 39 | + return AbiEncoder(ContractAbiType.CONSENSUS).encode_function_call_hex( |
| 40 | + AbiFunction.VALIDATOR_REGISTRATION.value, [key] |
| 41 | + ) |
| 42 | + |
| 43 | + @staticmethod |
| 44 | + def validator_resignation(): |
| 45 | + return AbiEncoder(ContractAbiType.CONSENSUS).encode_function_call_hex( |
| 46 | + AbiFunction.VALIDATOR_RESIGNATION.value, [] |
| 47 | + ) |
| 48 | + |
| 49 | + @staticmethod |
| 50 | + def token_transfer(recipient_address, amount): |
| 51 | + return AbiEncoder(ContractAbiType.TOKEN).encode_function_call_hex( |
| 52 | + AbiFunction.TRANSFER.value, [recipient_address, amount] |
| 53 | + ) |
| 54 | + |
| 55 | + @staticmethod |
| 56 | + def vote(vote_address): |
| 57 | + return AbiEncoder(ContractAbiType.CONSENSUS).encode_function_call_hex( |
| 58 | + AbiFunction.VOTE.value, [vote_address] |
| 59 | + ) |
| 60 | + |
| 61 | + @staticmethod |
| 62 | + def unvote(): |
| 63 | + return AbiEncoder(ContractAbiType.CONSENSUS).encode_function_call_hex( |
| 64 | + AbiFunction.UNVOTE.value, [] |
| 65 | + ) |
0 commit comments