Example #1
0
    def voteDelegate(self, up=[], down=[]):
        """
		Up or down vote for delegates. Delegates name are listed in `wallet.candidates` attribute.
		Automatically filters usernames that are already voted up/down ore are invalid.

		Argument:
		up   (list) -- list of username to be upvoted
		down (list) -- list of username to be downvoted
		"""
        votes = self.votes
        # first filter
        up = [u for u in up if u not in votes and u in Wallet.candidates]
        down = [u for u in down if u in votes]
        #second filter
        up = [
            d1['publicKey']
            for d1 in [d0 for d0 in Wallet.delegates if d0['username'] in up]
        ]
        down = [
            d1['publicKey'] for d1 in
            [d0 for d0 in Wallet.delegates if d0['username'] in down]
        ]
        # concatenate votes
        usernames = ['+' + c for c in up] + ['-' + c for c in down]
        # send votes
        if len(usernames):
            mgmt.push(
                self._generate_tx(type=3,
                                  recipientId=self.address,
                                  asset=ArkyDict(votes=usernames)))
        else:
            cfg.__LOG__.put({"API info": "no one to up/down vote"})
Example #2
0
    def sendArk(self, amount, recipientId, vendorField=None):
        """
		Send ARK amount to recipientId.

		Argument:
		amount      (float) -- amount you want to send in ARK (not in SATOSHI !)
		recipientId (str) -- valid ARK address you want to send to
		vendorField (str) -- 64-char-max message you want to send with (None by default)
		"""
        mgmt.push(
            self._generate_tx(type=0,
                              amount=int(amount * 100000000.),
                              recipientId=recipientId,
                              vendorField=vendorField))
Example #3
0
    def registerAsDelegate(self, username):
        """
		Register wallet as a delegate (this enables forging).

		Arguments:
		username (str) -- a utf-8 valid username
		"""
        if not self.delegate:
            mgmt.push(
                self._generate_tx(
                    type=2,
                    asset=ArkyDict(delegate=ArkyDict(
                        username=username, publicKey=self.publicKey))))
        else:
            cfg.__LOG__.put({
                "API info":
                "%s already registered as delegate" % self.publicKey
            })
Example #4
0
    def registerSecondSignature(self, secondSecret):
        """
		Register a second signature. This is permanent and the two secrets have to be given to
		open the wallet. When second signature is registered on blockchain side, it automatically
		register the second key into the wallet.

		Argument:
		secondSecret (str) -- a valid utf-8 encoded string
		"""
        if not self.account.get('secondSignature'):
            newPublicKey = binascii.hexlify(core.getKeys(secondSecret).public)
            newPublicKey = newPublicKey.decode() if isinstance(
                newPublicKey, bytes) else newPublicKey
            mgmt.push(
                self._generate_tx(type=1,
                                  asset=ArkyDict(signature=ArkyDict(
                                      publicKey=newPublicKey))))
            # automaticaly set secondSignature when transaction is applied

            @setInterval(10)
            def _setter(obj, passphrase):
                if obj.account.get('secondSignature', False):
                    obj.secondSecret = passphrase
                    obj._stop_setter_daemon.set()
                    delattr(obj, "_stop_setter_daemon")
                    cfg.__LOG__.put(
                        {"API info": "Second signature set for %s" % self})

            if hasattr(self, "_stop_setter_daemon"):
                self._stop_setter_daemon.set()
                delattr(self, "_stop_setter_daemon")
            self._stop_setter_daemon = _setter(self, secondSecret)
        else:
            cfg.__LOG__.put({
                "API info":
                "second signature already registered to %s" % self.publicKey
            })