Exemple #1
0
class GetLogRequest(Serializable):
    FIELDS = [
        ("branch", Branch),
        ("addresses", PrependedSizeListSerializer(4, Address)),
        (
            "topics",
            PrependedSizeListSerializer(
                4, PrependedSizeListSerializer(4,
                                               FixedSizeBytesSerializer(32))),
        ),
        ("start_block", uint64),
        ("end_block", uint64),
    ]

    def __init__(
        self,
        branch: Branch,
        addresses: List[Address],
        topics: List[List[bytes]],
        start_block: int,
        end_block: int,
    ):
        self.branch = branch
        self.addresses = addresses
        self.topics = topics
        self.start_block = start_block
        self.end_block = end_block
Exemple #2
0
class AddMinorBlockHeaderListRequest(Serializable):
    """ Notify master about a list of successfully added minor block.
    Mostly used for minor block sync triggered by root block sync
    """

    FIELDS = [
        ("minor_block_header_list", PrependedSizeListSerializer(4, MinorBlockHeader)),
        ("coinbase_amount_map_list", PrependedSizeListSerializer(4, TokenBalanceMap)),
    ]

    def __init__(self, minor_block_header_list, coinbase_amount_map_list):
        self.minor_block_header_list = minor_block_header_list
        self.coinbase_amount_map_list = coinbase_amount_map_list
Exemple #3
0
class ConnectToSlavesRequest(Serializable):
    """ Master instructs a slave to connect to other slaves """

    FIELDS = [("slave_info_list", PrependedSizeListSerializer(4, SlaveInfo))]

    def __init__(self, slave_info_list):
        self.slave_info_list = slave_info_list
class HelloCommand(Serializable):
    FIELDS = [
        ("version", uint32),
        ("network_id", uint32),
        ("peer_id", hash256),
        ("peer_ip", uint128),
        ("peer_port", uint16),
        (
            "chain_mask_list",
            PrependedSizeListSerializer(4, uint32),
        ),  # TODO create shard mask object
        ("root_block_header", RootBlockHeader),
    ]

    def __init__(
        self,
        version,
        network_id,
        peer_id,
        peer_ip,
        peer_port,
        chain_mask_list,
        root_block_header,
    ):
        fields = {k: v for k, v in locals().items() if k != "self"}
        super(type(self), self).__init__(**fields)
Exemple #5
0
class NewTransactionListCommand(Serializable):
    """ Broadcast transactions """

    FIELDS = [("transaction_list", PrependedSizeListSerializer(4, TypedTransaction))]

    def __init__(self, transaction_list=None):
        self.transaction_list = transaction_list if transaction_list is not None else []
Exemple #6
0
class GetLogResponse(Serializable):
    FIELDS = [("error_code", uint32),
              ("logs", PrependedSizeListSerializer(4, Log))]

    def __init__(self, error_code: int, logs: List[Log]):
        self.error_code = error_code
        self.logs = logs
Exemple #7
0
class BatchAddXshardTxListRequest(Serializable):
    FIELDS = [(
        "add_xshard_tx_list_request_list",
        PrependedSizeListSerializer(4, AddXshardTxListRequest),
    )]

    def __init__(self, add_xshard_tx_list_request_list):
        self.add_xshard_tx_list_request_list = add_xshard_tx_list_request_list
class GetRootBlockHeaderListResponse(Serializable):
    FIELDS = [
        ("root_tip", RootBlockHeader),
        ("block_header_list", PrependedSizeListSerializer(4, RootBlockHeader)),
    ]

    def __init__(self, root_tip, block_header_list):
        self.root_tip = root_tip
        self.block_header_list = block_header_list
Exemple #9
0
class GetEcoInfoListResponse(Serializable):
    FIELDS = [
        ("error_code", uint32),
        ("eco_info_list", PrependedSizeListSerializer(4, EcoInfo)),
    ]

    def __init__(self, error_code, eco_info_list):
        self.error_code = error_code
        self.eco_info_list = eco_info_list
Exemple #10
0
class HeadersInfo(Serializable):
    FIELDS = [
        ("branch", Branch),
        ("header_list", PrependedSizeListSerializer(4, MinorBlockHeader)),
    ]

    def __init__(self, branch, header_list):
        self.branch = branch
        self.header_list = header_list
Exemple #11
0
class GetAccountDataResponse(Serializable):
    FIELDS = [
        ("error_code", uint32),
        ("account_branch_data_list", PrependedSizeListSerializer(4, AccountBranchData)),
    ]

    def __init__(self, error_code, account_branch_data_list):
        self.error_code = error_code
        self.account_branch_data_list = account_branch_data_list
Exemple #12
0
class GetUnconfirmedHeadersResponse(Serializable):
    FIELDS = [
        ("error_code", uint32),
        ("headers_info_list", PrependedSizeListSerializer(4, HeadersInfo)),
    ]

    def __init__(self, error_code, headers_info_list):
        self.error_code = error_code
        self.headers_info_list = headers_info_list
class GetRootBlockListRequest(Serializable):
    """ RPC to get a root block list.  The RPC should be only fired by root chain
    """

    FIELDS = [("root_block_hash_list", PrependedSizeListSerializer(4,
                                                                   hash256))]

    def __init__(self, root_block_hash_list=None):
        self.root_block_hash_list = (root_block_hash_list if
                                     root_block_hash_list is not None else [])
Exemple #14
0
class ConnectToSlavesResponse(Serializable):
    """ result_list must have the same size as salve_info_list in the request.
    Empty result means success otherwise it would a serialized error message.
    """

    FIELDS = [("result_list",
               PrependedSizeListSerializer(4,
                                           PrependedSizeBytesSerializer(4)))]

    def __init__(self, result_list):
        self.result_list = result_list
class GetMinorBlockListRequest(Serializable):
    """ RPCP to get a minor block list.  The RPC should be only fired by a shard, and
    all minor blocks should be from the same shard.
    """

    FIELDS = [("minor_block_hash_list",
               PrependedSizeListSerializer(4, hash256))]

    def __init__(self, minor_block_hash_list=None):
        self.minor_block_hash_list = (
            minor_block_hash_list if minor_block_hash_list is not None else [])
Exemple #16
0
class GetTransactionListByAddressResponse(Serializable):
    FIELDS = [
        ("error_code", uint32),
        ("tx_list", PrependedSizeListSerializer(4, TransactionDetail)),
        ("next", PrependedSizeBytesSerializer(4)),
    ]

    def __init__(self, error_code, tx_list, next):
        self.error_code = error_code
        self.tx_list = tx_list
        self.next = next
Exemple #17
0
class SyncMinorBlockListRequest(Serializable):
    FIELDS = [
        ("minor_block_hash_list", PrependedSizeListSerializer(4, hash256)),
        ("branch", Branch),
        ("cluster_peer_id", uint64),
    ]

    def __init__(self, minor_block_hash_list, branch, cluster_peer_id):
        self.minor_block_hash_list = minor_block_hash_list
        self.branch = branch
        self.cluster_peer_id = cluster_peer_id
Exemple #18
0
class Pong(Serializable):
    FIELDS = [
        ("id", PrependedSizeBytesSerializer(4)),
        ("shard_mask_list", PrependedSizeListSerializer(4, ShardMask)),
    ]

    def __init__(self, id, shard_mask_list):
        """ Empty slave_id and 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
Exemple #19
0
class Pong(Serializable):
    FIELDS = [
        ("id", PrependedSizeBytesSerializer(4)),
        ("full_shard_id_list", PrependedSizeListSerializer(4, uint32)),
    ]

    def __init__(self, id, full_shard_id_list):
        """ Empty slave_id and full_shard_id_list means root """
        if isinstance(id, bytes):
            self.id = id
        else:
            self.id = bytes(id, "ascii")
        self.full_shard_id_list = full_shard_id_list
Exemple #20
0
class SlaveInfo(Serializable):
    FIELDS = [
        ("id", PrependedSizeBytesSerializer(4)),
        ("host", PrependedSizeBytesSerializer(4)),
        ("port", uint16),
        ("full_shard_id_list", PrependedSizeListSerializer(4, uint32)),
    ]

    def __init__(self, id, host, port, full_shard_id_list):
        self.id = id if isinstance(id, bytes) else bytes(id, "ascii")
        self.host = host if isinstance(host, bytes) else bytes(host, "ascii")
        self.port = port
        self.full_shard_id_list = full_shard_id_list
Exemple #21
0
class AccountBranchData(Serializable):
    FIELDS = [
        ("branch", Branch),
        ("transaction_count", uint256),
        ("token_balances", PrependedSizeListSerializer(4, TokenBalancePair)),
        ("is_contract", boolean),
    ]

    def __init__(self, branch, transaction_count, token_balances, is_contract):
        self.branch = branch
        self.transaction_count = transaction_count
        self.token_balances = token_balances
        self.is_contract = is_contract
Exemple #22
0
class SlaveInfo(Serializable):
    FIELDS = [
        ("id", PrependedSizeBytesSerializer(4)),
        ("host", PrependedSizeBytesSerializer(4)),
        ("port", uint16),
        ("chain_mask_list", PrependedSizeListSerializer(4, ChainMask)),
    ]

    def __init__(self, id, host, port, chain_mask_list):
        self.id = id if isinstance(id, bytes) else bytes(id, "ascii")
        self.host = host if isinstance(host, bytes) else bytes(host, "ascii")
        self.port = port
        self.chain_mask_list = chain_mask_list
Exemple #23
0
class NewMinorBlockHeaderListCommand(Serializable):
    """RPC to inform peers about new root or minor blocks with the following constraints
    - If the RPC is sent to root, then the minor block header list must be empty.
    - If the RPC is sent to a shard, then all minor block headers must be in the shard.
    """

    FIELDS = [
        ("root_block_header", RootBlockHeader),
        ("minor_block_header_list", PrependedSizeListSerializer(4, MinorBlockHeader)),
    ]

    def __init__(self, root_block_header, minor_block_header_list):
        self.root_block_header = root_block_header
        self.minor_block_header_list = minor_block_header_list
Exemple #24
0
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
Exemple #25
0
class SlaveInfo(Serializable):
    FIELDS = [
        ("id", PrependedSizeBytesSerializer(4)),
        ("ip", uint128),
        ("port", uint16),
        ("shard_mask_list", PrependedSizeListSerializer(4, ShardMask)),
    ]

    def __init__(self, id, ip, port, shard_mask_list):
        if isinstance(id, bytes):
            self.id = id
        else:
            self.id = bytes(id, "ascii")
        self.ip = ip
        self.port = port
        self.shard_mask_list = shard_mask_list
Exemple #26
0
class LastMinorBlockHeaderList(Serializable):
    FIELDS = [("header_list", PrependedSizeListSerializer(4,
                                                          MinorBlockHeader))]

    def __init__(self, header_list):
        self.header_list = header_list
class HashList(Serializable):
    FIELDS = [("hlist", PrependedSizeListSerializer(4, hash256))]

    def __init__(self, hlist):
        self.hlist = hlist
class GetRootBlockListResponse(Serializable):
    FIELDS = [("root_block_list", PrependedSizeListSerializer(4, RootBlock))]

    def __init__(self, root_block_list=None):
        self.root_block_list = root_block_list if root_block_list is not None else []
class GetMinorBlockListResponse(Serializable):
    FIELDS = [("minor_block_list", PrependedSizeListSerializer(4, MinorBlock))]

    def __init__(self, minor_block_list=None):
        self.minor_block_list = minor_block_list if minor_block_list is not None else []
class GetPeerListResponse(Serializable):
    FIELDS = [("peer_info_list", PrependedSizeListSerializer(4, PeerInfo))]

    def __init__(self, peer_info_list=None):
        self.peer_info_list = peer_info_list if peer_info_list is not None else []