class GetTotalBalanceRequest(Serializable): FIELDS = [ ("branch", Branch), ("start", Optional(hash256)), ("token_id", uint64), # TODO: double check max token ID ("limit", uint32), ("minor_block_hash", hash256), ("root_block_hash", Optional(hash256)), ] def __init__( self, branch: Branch, start: typing.Optional[bytes], token_id: int, limit: int, minor_block_hash: bytes, root_block_hash: typing.Optional[bytes], ): self.branch = branch self.start = start self.token_id = token_id self.limit = limit self.minor_block_hash = minor_block_hash self.root_block_hash = root_block_hash
class TransactionDetail(Serializable): FIELDS = [ ("tx_hash", hash256), ("from_address", Address), ("to_address", Optional(Address)), ("value", uint256), ("block_height", uint64), ("timestamp", uint64), # block timestamp ("success", boolean), ("gas_token_id", uint64), ("transfer_token_id", uint64), ] def __init__( self, tx_hash, from_address, to_address, value, block_height, timestamp, success, gas_token_id, transfer_token_id, ): self.tx_hash = tx_hash self.from_address = from_address self.to_address = to_address self.value = value self.block_height = block_height self.timestamp = timestamp self.success = success self.gas_token_id = gas_token_id self.transfer_token_id = transfer_token_id
class GetWorkRequest(Serializable): FIELDS = [("branch", Branch), ("coinbase_addr", Optional(Address))] def __init__(self, branch: Branch, coinbase_addr: typing.Optional[Address]): self.branch = branch self.coinbase_addr = coinbase_addr
class GetCodeRequest(Serializable): FIELDS = [("address", Address), ("block_height", Optional(uint64))] def __init__(self, address: Address, block_height: typing.Optional[int] = None): self.address = address self.block_height = block_height
class ExecuteTransactionRequest(Serializable): FIELDS = [ ("tx", Transaction), ("from_address", Address), ("block_height", Optional(uint64)), ] def __init__(self, tx, from_address, block_height: typing.Optional[int]): self.tx = tx self.from_address = from_address self.block_height = block_height
class GetMinorBlockResponse(Serializable): FIELDS = [ ("error_code", uint32), ("minor_block", MinorBlock), ("extra_info", Optional(MinorBlockExtraInfo)), ] def __init__(self, error_code, minor_block, extra_info=None): self.error_code = error_code self.minor_block = minor_block self.extra_info = extra_info
class SyncMinorBlockListResponse(Serializable): FIELDS = [ ("error_code", uint32), ("block_coinbase_map", PrependedSizeMapSerializer(4, hash256, TokenBalanceMap)), ("shard_stats", Optional(ShardStats)), ] def __init__(self, error_code, block_coinbase_map=None, shard_stats=None): self.error_code = error_code self.block_coinbase_map = block_coinbase_map or {} self.shard_stats = shard_stats
class GetTransactionListByAddressRequest(Serializable): FIELDS = [ ("address", Address), ("transfer_token_id", Optional(uint64)), ("start", PrependedSizeBytesSerializer(4)), ("limit", uint32), ] def __init__(self, address, transfer_token_id, start, limit): self.address = address self.transfer_token_id = transfer_token_id self.start = start self.limit = limit
class GetStorageRequest(Serializable): FIELDS = [ ("address", Address), ("key", uint256), ("block_height", Optional(uint64)), ] def __init__( self, address: Address, key: int, block_height: typing.Optional[int] = None ): self.address = address self.key = key self.block_height = block_height
class Ping(Serializable): FIELDS = [ ("id", PrependedSizeBytesSerializer(4)), ("shard_mask_list", PrependedSizeListSerializer(4, ShardMask)), ("root_tip", Optional(RootBlock)), # Initialize ShardState if not None ] def __init__(self, id, shard_mask_list, root_tip): """ Empty shard_mask_list means root """ if isinstance(id, bytes): self.id = id else: self.id = bytes(id, "ascii") self.shard_mask_list = shard_mask_list self.root_tip = root_tip
class SubmitWorkRequest(Serializable): FIELDS = [ ("branch", Branch), ("header_hash", hash256), ("nonce", uint64), ("mixhash", hash256), ("signature", Optional(signature65)), ] def __init__( self, branch: Branch, header_hash: bytes, nonce: int, mixhash: bytes, signature: bytes, ): self.branch = branch self.header_hash = header_hash self.nonce = nonce self.mixhash = mixhash self.signature = signature
class Uint32Optional(Serializable): FIELDS = [("value", Optional(uint32))] def __init__(self, value): self.value = value
class SyncMinorBlockListResponse(Serializable): FIELDS = [("error_code", uint32), ("shard_stats", Optional(ShardStats))] def __init__(self, error_code, shard_stats=None): self.error_code = error_code self.shard_stats = shard_stats