Beispiel #1
0
    def __init__(self,
                 full_node,
                 solidity_node,
                 event_server=None,
                 private_key=None):
        """Connect to the Tron network.

        Args:
            full_node (:obj:`str`): A provider connected to a valid full node
            solidity_node (:obj:`str`): A provider connected to a valid solidity node
            event_server (:obj:`str`, optional): Optional for smart contract events. Expects a valid event server URL
            private_key (str): Optional default private key used when signing transactions

        """

        self._default_address = AttributeDict({})

        # The node manager allows you to automatically determine the node
        # on the router or manually refer to a specific node.
        # solidity_node, full_node or event_server
        self.manager = TronManager(
            self,
            dict(full_node=full_node,
                 solidity_node=solidity_node,
                 event_server=event_server))

        if private_key is not None:
            self.private_key = private_key

        for module_name, module_class in DEFAULT_MODULES.items():
            module_class.attach(self, module_name)

        self.transaction = TransactionBuilder(self)
Beispiel #2
0
    def __init__(self, **kwargs):
        """Connect to the Tron network.

        Args:
            kwargs (Any): We fill the most necessary parameters
            for working with blockchain Tron

        """

        # We check the obtained nodes, if the necessary parameters
        # are not specified, then we take the default
        kwargs.setdefault('full_node', constants.DEFAULT_NODES['full_node'])
        kwargs.setdefault('solidity_node',
                          constants.DEFAULT_NODES['solidity_node'])
        kwargs.setdefault('event_server',
                          constants.DEFAULT_NODES['event_server'])

        # The node manager allows you to automatically determine the node
        # on the router or manually refer to a specific node.
        # solidity_node, full_node or event_server
        self.manager = TronManager(
            self,
            dict(full_node=kwargs.get('full_node'),
                 solidity_node=kwargs.get('solidity_node'),
                 event_server=kwargs.get('event_server')))

        # If the parameter of the private key is not empty,
        # then write to the variable
        if 'private_key' in kwargs:
            self.private_key = kwargs.get('private_key')

        # We check whether the default wallet address is set when
        # defining the class, and then written to the variable
        if 'default_address' in kwargs:
            self.default_address = kwargs.get('default_address')

        # If custom methods are not declared,
        # we take the default from the list
        modules = kwargs.setdefault('modules', DEFAULT_MODULES)
        for module_name, module_class in modules.items():
            module_class.attach(self, module_name)

        self.transaction_builder = TransactionBuilder(self)