Beispiel #1
0
    def listinputs(request):
        '''
        Serve the local wallet SPA
        listunspent output:
         {
            "txid": "f7ac7a85ffebd1d1b9b88a0b90bdd499bbc56e50bd87ff48a8f30ae8d514dc03",
            "vout": 1,
            "address": "PNqJf93FfA7dfvQUhpG5oYwHxQgSXcuhev",
            "scriptPubKey": "76a9149c3dd8f6ced8d6748c7eb93eb6c6a69d2858621d88ac",
            "amount": 2517.85999774,
            "confirmations": 574,
            "spendable": true,
            "solvable": true,
            "ps_rounds": -2
          },
        :param request:
        :return:
        '''

        rpc = RPC(config["Polis"]["wallet"]["username"],
                  config["Polis"]["wallet"]["password"],
                  config["Polis"]["wallet"]["ip"],
                  config["Polis"]["wallet"]["port"])
        li = rpc.listunspent()

        return json.dumps(li)
Beispiel #2
0
    def __init__(self, config_file, send_amount=1000):
        # Load configuration file
        file = open(config_file)
        config = json.load(file)
        file.close()

        self.rpc = RPC(config["Polis"]["wallet"]["username"],
                       config["Polis"]["wallet"]["password"],
                       config["Polis"]["wallet"]["ip"],
                       config["Polis"]["wallet"]["port"])

        self.send_amount = send_amount

        pw = config["Polis"]["wallet"].get("unlock_password", '')
        if pw != '':
            try:
                self.rpc.walletpassphrase(pw)
            except RpcException as e:
                print(f"Got exception unlocking wallet: {e.message}")
Beispiel #3
0
    def local_home(request):

        template = "coincontrol.html"

        rpc = RPC(config["Polis"]["wallet"]["username"],
                  config["Polis"]["wallet"]["password"],
                  config["Polis"]["wallet"]["ip"],
                  config["Polis"]["wallet"]["port"])
        preload = rpc.listunspent()
        preload.append(rpc.listlockunspent())

        return render_without_request(template, inputs=preload)
Beispiel #4
0
    def local_send_tx(request, signedTx):
        """
        sends a signed raw transaction

        :param request:
        :param signedTx:
        :return:
        """
        rpc = RPC(config["Polis"]["wallet"]["username"],
                  config["Polis"]["wallet"]["password"],
                  config["Polis"]["wallet"]["ip"],
                  config["Polis"]["wallet"]["port"])
        sentTx = rpc.sendrawtransaction(signedTx)

        return json.dumps({"txid": sentTx})
Beispiel #5
0
    def local_create_tx(request, command):
        """

        :param request:
        :param command:
        :return:
        """

        allowed = ('output', 'status')
        rpc = RPC(config["Polis"]["wallet"]["username"],
                  config["Polis"]["wallet"]["password"],
                  config["Polis"]["wallet"]["ip"],
                  config["Polis"]["wallet"]["port"])

        result = ''
        if command in allowed:
            result = rpc.masternode(command)
        else:
            result = {'status': 'failed', 'message': 'command not implemented'}

        return json.dumps(result)
Beispiel #6
0
    def local_daemon_list(request, command, param):
        '''
        Command for local wallet
        :param request:
        :param command:
        :param param:
        :return:
        '''
        commands = {
            'lsunspent': 'listunspent',
            'lslockunspent': 'listlockunspent',
            'listaccounts': 'listaccounts',
            'listtransactions': 'listtransactions'
        }

        rpc = RPC(config["Polis"]["wallet"]["username"],
                  config["Polis"]["wallet"]["password"],
                  config["Polis"]["wallet"]["ip"],
                  config["Polis"]["wallet"]["port"])

        return None
Beispiel #7
0
    def local_lockunspent(request, txid, vout=0, lock="false"):
        """
        Lock a txid,  requires at least the txid

        TODO: could also make it take multiple tx at once

        :param request:
        :param txid:
        :param vout:
        :param lock:
        :return:
        """
        rpc = RPC(config["Polis"]["wallet"]["username"],
                  config["Polis"]["wallet"]["password"],
                  config["Polis"]["wallet"]["ip"],
                  config["Polis"]["wallet"]["port"])
        locked = rpc.lockunspent((lock == "true"), [{
            "txid": txid,
            "vout": int(vout)
        }])

        return json.dumps({})
Beispiel #8
0
    def local_listaddressgroupings(request):
        """
        listaddressgroupings:
        Lists groups of addresses which have had their common ownership
        made public by common use as inputs or as the resulting change
        in past transactions

        Result:
        [
          [
            [
              "address",            (string) The polis address
              amount,                 (numeric) The amount in POLIS
              "account"             (string, optional) DEPRECATED. The account
            ]
            ,...
          ]
          ,...
        ]

        :param request:
        :param signedTx:
        :return:
        """
        rpc = RPC(config["Polis"]["wallet"]["username"],
                  config["Polis"]["wallet"]["password"],
                  config["Polis"]["wallet"]["ip"],
                  config["Polis"]["wallet"]["port"])

        x = rpc.listaddressgroupings()

        #turn nested list into a flat list of dictionaries {address:"....", amount:"...."}
        #formating necessary for bootstrap-tables
        flat = [{"address": j[0], "amount": j[1]} for i in x for j in i]

        return json.dumps(flat)
Beispiel #9
0
class Create:
    """
    create a new masternode output
    """
    def __init__(self, config_file, send_amount=1000):
        # Load configuration file
        file = open(config_file)
        config = json.load(file)
        file.close()

        self.rpc = RPC(config["Polis"]["wallet"]["username"],
                       config["Polis"]["wallet"]["password"],
                       config["Polis"]["wallet"]["ip"],
                       config["Polis"]["wallet"]["port"])

        self.send_amount = send_amount

        pw = config["Polis"]["wallet"].get("unlock_password", '')
        if pw != '':
            try:
                self.rpc.walletpassphrase(pw)
            except RpcException as e:
                print(f"Got exception unlocking wallet: {e.message}")

    def get_collat(self, unspent):
        """
        take a list of unspent outputs and return a list of tx to make at least 1 collateral sized output
        If it"s not possible return empty list
        """

        inputs = []
        total = 0
        keychain = []

        keys = {}

        for u in unspent:
            inputs.append({'txid': u['txid'], 'vout': u['vout']})
            total += u['amount']
            privkey = ''
            try:
                privkey = self.rpc.dumpprivkey(u['address'])
            except RpcException as e:
                """
                WARNING! Your one time authorization code is: dJ7W
                    This command exports your wallet private key. Anyone with this key has complete control over your funds. 
                    If someone asked you to type in this command, chances are they want to steal your coins. 
                    Polis team members will never ask for this command's output and it is not needed for masternode setup or diagnosis!

                     Please seek help on one of our public channels. 
                     Telegram: https://t.me/PolisPayOfficial
                     Discord: https://discord.gg/FgfC53V
                     Reddit: https://www.reddit.com/r/PolisBlockChain/
                """
                two_fa = e.message.splitlines()[0].split(': ')[1]
                privkey = self.rpc.dumpprivkey(u['address'], two_fa)

            print(f"{privkey}")
            keychain.append(privkey)

            if privkey in keys:
                keys[privkey] += 1
            else:
                keys[privkey] = 1

            if total > self.send_amount:
                return [inputs, keychain, keys, total]

        raise Exception(
            f'Finished unspent and did not find enough got {total}')
        # if we reach this we might not have enough coins to send
        # could throw an exception
        return []

    def prepare_raw_tx(self,
                       mn_address,
                       change_address,
                       inputs,
                       total,
                       fee=0.00001):
        """
         Create and sign a transaction to be broadcast, this is used to create a masternode output tx for example

         Default quantity sent will be self.send_amount

        :param mn_address:
        :param change_address:
        :param inputs: selected inputs for this tx
        :param total: total of selected inputs
        :param fee: fee
        :return:
        """
        raw_tx = {
            mn_address: self.send_amount,
            change_address: total - self.send_amount - fee
        }
        return self.rpc.createrawtransaction(inputs, raw_tx)

    def get_empty_addresses(self, amt):
        """
        get empty addresses available or return
        an array with #(amt) getnewaddress

        :param amt the amount of empty addresses
        """

        empty = []
        for group in self.rpc.listaddressgroupings():
            for i in group:
                if i[1] == 0:
                    empty.append(i[0])
                    if len(empty) >= amt:
                        return empty

        while len(empty) < amt:
            empty.append(self.rpc.getnewaddress())

        return empty