Example #1
0
 def setWallet(self, _walletWrapper):
     validate.objectMember(self.agent, "wallet")
     validate.objectMember(self.agent, "uses_wallet", bool, True)
     self.walletWrapper = _walletWrapper
     validate.objectType(self.walletWrapper, walletWrapper.WalletWrapper,
                         "Agent Wallet")
     self.agent.wallet = self.walletWrapper.wallet
Example #2
0
 def __initSecrets(self, _secrets):
     if hasattr(self.wallet, "uses_secret_variables"):
         validate.objectMember(self.wallet, "secrets")
         validate.objectMember(self.wallet, "uses_secret_variables", list)
         if len(self.wallet.uses_secret_variables) > 0:
             for i in self.wallet.uses_secret_variables:
                 validate.objectType(i, str,
                                     "Wallet Secrets Variable Request")
             secrets = _secrets.get(*self.wallet.uses_secret_variables)
             self.secrets = secrets
             self.wallet.secrets = secrets
Example #3
0
    def __init__(self, _wallet, _configuration, _secrets):
        self.wallet = _wallet
        self.configuration = _configuration

        self.type = type(self.wallet).__name__
        self.name = self.configuration["name"]
        validate.objectType(self.name, str, "Wallet Name")

        validate.objectMember(self.wallet, "start", MethodType)
        validate.objectMember(self.wallet, "checkBalance", MethodType)
        validate.objectMember(self.wallet, "send", MethodType)
        validate.objectMember(self.wallet, "getReceiveAddress", MethodType)
        validate.objectMember(self.wallet, "getLatestTransactions", MethodType)

        self.__initOptions()
        self.__initSecrets(_secrets)
        self.__checkDependencies()
Example #4
0
    def __initSecrets(self, _secrets):
        if "uses_secret_variables" in self.configuration:
            validate.dictMember(self.configuration, "uses_secret_variables",
                                list)
            if not hasattr(self.agent, "uses_secret_variables"):
                self.agent.uses_secret_variables = []
            else:
                validate.objectMember(self.agent, "uses_secret_variables",
                                      list)
            for varName in self.configuration["uses_secret_variables"]:
                self.agent.uses_secret_variables.append(varName)

        if hasattr(self.agent, "uses_secret_variables"):
            validate.objectMember(self.agent, "uses_secret_variables", list)
            if len(self.agent.uses_secret_variables) > 0:
                for i in self.agent.uses_secret_variables:
                    validate.objectType(i, str,
                                        "Agent Secrets Variable Request")
                self.secrets = _secrets.get(*self.agent.uses_secret_variables)
                self.agent.secrets = self.secrets
Example #5
0
    def prepareToStart(self, secrets):
        self.secrets = secrets

        self.wallets = [walletWrapper.WalletWrapper(self.__parseWallet(w), w, secrets) for w in self.walletsJson]
        self.agents = [agentWrapper.AgentWrapper(self.__parseAgent(a), a, secrets) for a in self.agentsJson]

        for wLink in self.wallet_links:
            validate.objectType(wLink, dict, "Wallet Link")
            validate.dictMember(wLink, "source", int)
            validate.dictMember(wLink, "target", int)
            w = self.wallets[wLink["source"]]
            a = self.agents[wLink["target"]]
            a.setWallet(w)

        for eLink in self.event_links:
            validate.objectType(eLink, dict, "Event Link")
            validate.dictMember(eLink, "source", int)
            validate.dictMember(eLink, "target", int)
            source = self.agents[eLink["source"]]
            receiver = self.agents[eLink["target"]]
            receiver.receiveEventsFrom(source)

        for cLink in self.control_links:
            validate.objectType(cLink, dict, "Control Link")
            validate.dictMember(cLink, "source", int)
            validate.dictMember(cLink, "target", int)
            source = self.agents[cLink["source"]]
            receiver = self.agents[cLink["target"]]
            receiver.setControllerAgent(source)
Example #6
0
 def loadFromFile(path):
     with open(path, "r") as read_file:
         secretsValues = json.load(read_file)
         validate.objectType(secretsValues, dict,
                             "The contents of '%s'" % path)
         return SecretsManager(secretsValues)
Example #7
0
 def setControllerAgent(self, _sender):
     validate.objectMember(self.agent, "check", MethodType)
     validate.objectType(_sender, AgentWrapper, "Agent Controller")
     pipeObserver.observerInstance.listen(None, "Event", _sender.__id,
                                          self.__receiveControlEvent)
Example #8
0
 def receiveEventsFrom(self, _sender):
     validate.objectMember(self.agent, "receive", MethodType)
     validate.objectType(_sender, AgentWrapper, "Agent Event Sender")
     pipeObserver.observerInstance.listen(None, "Event", _sender.__id,
                                          self.__receiveEvent)