示例#1
0
    def set_private_key(self, private_key, is_secret):
        if private_key:
            if not is_secret:
                validate_private_key(private_key)

            self._private_key = private_key
        else:
            self._private_key = None
示例#2
0
文件: params.py 项目: kvrban/siliqua
    def parse(self, val):
        if val is None or val.strip() == "":
            return None

        try:
            validate_private_key(val)
            return val
        except ValueError:
            raise ValueError("is not a valid private key")
示例#3
0
文件: wallet.py 项目: kvrban/siliqua
    def add_account_from_private_key(self, private_key):
        """
        Add a new account from a private key. If the account already
        exists as a watching-only account, private key will only be added
        instead.

        :param str private_key: Private key to add

        :raises AccountAlreadyExists: Account already exists with this private
                                      key
        :raises nanolib.exceptions.InvalidPrivateKey: Private key is invalid

        :returns: Created account
        :rtype: siliqua.wallet.accounts.Account
        """
        validate_private_key(private_key)

        key_pair = get_account_key_pair(private_key=private_key)
        account_id = get_account_id(private_key=private_key)

        if account_id in self.account_map:
            # If the account is already added but only as a watching-only
            # address, update the Account entry
            account = self.account_map[account_id]
            if not account.private_key:
                account.private_key = private_key
                account.source = AccountSource.PRIVATE_KEY
                account.encrypt_secrets(secret_key=self.secret_key)
                return account

            raise AccountAlreadyExists("Account already in the wallet")

        account = Account(account_id=account_id,
                          public_key=key_pair.public,
                          private_key=private_key,
                          source=AccountSource.PRIVATE_KEY)
        account.encrypt_secrets(secret_key=self.secret_key)

        return self.add_account(account)
示例#4
0
文件: params.py 项目: kvrban/siliqua
 def parse(self, val):
     try:
         validate_private_key(val)
         return val
     except ValueError:
         raise ValueError("is not a valid private key")
示例#5
0
def importConfig():
    #get worker api config
    try:
        with open('config/worker_config.json') as worker_config:
            data = json.load(worker_config)
        worker = {
            "account":
            data['reward_account'].replace("xrb_", "nano_"),
            "private_key":
            data['private_key'].upper(),
            "public_key":
            nanolib.get_account_key_pair(data['private_key']).public.upper(),
            "representative":
            data['representative'].replace("xrb_", "nano_"),
            "default_fee":
            data['fee'],
            "node":
            to_url(data['node']),
            "worker_node":
            to_url(data['worker']),
            "max_multiplier":
            data['max_multiplier'],
            "use_dynamic_pow":
            data['use_dynamic_pow'],
            "use_dynamic_fee":
            data['use_dynamic_fee'],
            "dynamic_pow_interval":
            data['dynamic_pow_interval'],
            "show_network_difficulty":
            data['show_network_difficulty'],
            "service_listen":
            data['listen'],
            "service_port":
            data['port'],
        }
        worker["default_fee"] = to_raws(str(
            worker["default_fee"]))  #convert mNano fee to raws
    except Exception as err:
        raise Exception("worker_config.json error: " + str(err))

    #Get worker registration config
    try:
        with open('config/register_config.json') as register_config:
            data_register = json.load(register_config)
        register_config = {
            "account":
            data_register['registration_account'].replace("xrb_", "nano_"),
            "register_code":
            int(data_register['register_code']),
            "get_ip": {
                "ipv4": to_url(data_register['get_ip']['ipv4']),
                "ipv6": to_url(data_register['get_ip']['ipv6'])
            },
            "default_ip_version":
            ip_version(data_register['default_ip_version'])
        }
    except Exception as err:
        raise Exception("worker_config.json error: " + str(err))

    #Check config file
    try:
        nanolib.validate_account_id(worker["account"])
        nanolib.validate_private_key(worker["private_key"])
        nanolib.validate_account_id(worker["representative"])
    except Exception as e:
        raise Exception(
            "Invalid config in worker_config.json found! Details: " + str(e))

    #Check config file
    try:
        nanolib.validate_account_id(register_config["account"])
    except Exception as e:
        raise Exception(
            "Invalid config in register_config.json found! Details: " + str(e))

    #Check if key pair is valid
    if worker["account"] != nanolib.get_account_id(
            private_key=worker["private_key"], prefix="nano_"):
        raise Exception("Invalid key pair")

    return {"worker_config": worker, "register_config": register_config}
示例#6
0
from flask import Flask, jsonify, request
from functions import block_create, balance, frontier, broadcast, get_difficulty, solve_work, get_my_ip, pending_filter, receive, check_history, register, encode_ip, worker, register_config
from nanolib import Block, validate_account_id, validate_private_key, get_account_id
import requests
import json
import waitress

app = Flask(__name__)

#Check config
try:
    validate_account_id(worker["account"])
    validate_private_key(worker["private_key"])
    validate_account_id(worker["representative"])
except Exception as e:
    print("Invalid worker_config.json settings found! Details: ")
    print(e)
    quit()

#Check if key pair is valid
if worker["account"] != get_account_id(private_key=worker["private_key"],
                                       prefix="nano_"):
    print("Invalid key pair")
    quit()
print("Configurations okay")

#Check if Node is online
try:
    r = requests.post(worker["node"], json={"action": "version"})
except:
    print("Node " + worker["node"] + " Offline! Exiting")