def test_utxo_enumeration(self):
        """Load wallet with a bunch of txs and check some of the snapshots."""
        for i, utxos in enumerate(wallet.Wallet('MineField.BitcoinLab.org')):
            if i == 0:
                self.assertEqual(len(utxos), 1)
                txid = utxos[0][0]
                output_index = utxos[0][1]
                amt_satoshis = utxos[0][2]
                self.assertEqual(
                    txid, ('8f3fbb758556b8fbe99d5cf6ab19707d42524a7a839b'
                           '08d19adf34153a38d369'))
                self.assertEqual(output_index, 0)
                self.assertEqual(amt_satoshis, 25500)
            if i == 10:
                #this transaction has an input with a value that would match
                #multiple outputs in the previous tx. This must be correctly
                #resolved with an additional call to the /tx API endpoint.
                txid = utxos[10][0]
                output_index = utxos[10][1]
                amt_satoshis = utxos[10][2]
                self.assertEqual(txid, (
                    '500b5af07919e9693c4124c4ba4fba68a991487c40f1e116b64fed31e'
                    'bd303ee'))
                self.assertEqual(output_index, 14)
                self.assertEqual(amt_satoshis, 10000)
            if i == 24:
                #first send transaction, has no change outputs only 2 sends
                #after 24 receives, 19 utxos are shed as inputs
                self.assertEqual(len(utxos), 5)
                self.assertEqual(utxos[0][0], (
                    'b8d8a24adc428d1d8c54d2f57f68d2dcf393465de1e201ef81900beb6'
                    'db5e8dc'))
                self.assertEqual(utxos[0][1], 0)
                self.assertEqual(utxos[0][2], 3000000)

                self.assertEqual(utxos[1][0], (
                    '4a0acc2be3761b575b5b9ad82bec6b81bf519609bcfeb1eef624a98ea'
                    '564a854'))
                self.assertEqual(utxos[1][1], 0)
                self.assertEqual(utxos[1][2], 3700000)

                self.assertEqual(utxos[2][0], (
                    '500b5af07919e9693c4124c4ba4fba68a991487c40f1e116b64fed31e'
                    'bd303ee'))
                self.assertEqual(utxos[2][1], 14)
                self.assertEqual(utxos[2][2], 10000)

                self.assertEqual(utxos[3][0], (
                    '010f833ec2bbcfc8d492fb4dc8a1b25c711b374f488161002d20bd719'
                    '02fe523'))
                self.assertEqual(utxos[3][1], 0)
                self.assertEqual(utxos[3][2], 200000)

                self.assertEqual(utxos[4][0], (
                    '0b596a8c22693d727931850225ffddb48d9953e7472a167475de87bed'
                    '0068677'))
                self.assertEqual(utxos[4][1], 3)
                self.assertEqual(utxos[4][2], 10000)
            if i == 25:
                break
Esempio n. 2
0
def create_wallet():
    my_wallet = wallet.Wallet()
    response = {
        'private_key': my_wallet.private_key,
        'public_key': my_wallet.public_key,
        'blockchain_address': my_wallet.blockchain_address}
    return jsonify(response), 200
Esempio n. 3
0
    def __init__(self, start_val, type, USD, CRY, qua, thresh, analy, auth):
        #set analyzer
        self.ana = analy
        #set wallet
        self.wal = wallet.Wallet(type, USD, CRY, start_val)
        #set quantity to be traded
        self.quantity = qua
        #set client to trade with
        self.client = auth
        #set internal count
        self.pacer = 0
        #set recenty trade price
        self.trade_value = 0.0
        #set last action status
        self.status = 'none'
        #set the threshhold
        self.thresh = thresh
        #upper thresh
        self.Uthreshhold = 1.0 + thresh
        #lower thresh
        self.Lthreshhold = 1.0 - thresh

        #all orders are put on their respective lists for tracking
        self.buyList = []
        self.sellList = []
Esempio n. 4
0
def get_blockchain():
    """
    Blockの情報を取得する

    blockchainの情報は本来DBに入れる
    今回はglobalに格納する

    See Also
    --------
    cache : dict
    """
    cached_blockchain = cache.get("blockchain")
    # 1度しか呼ばれない
    if not cached_blockchain:
        miners_wallet = wallet.Wallet()
        cache["blockchain"] = blockchain.BlockChain(
            blockchain_address=miners_wallet.blockchain_address,
            port=app.config["port"])
        app.logger.warning({
            "private_key":
            miners_wallet.private_key,
            "public_key":
            miners_wallet.public_key,
            "blockchain_address":
            miners_wallet.blockchain_address
        })
    return cache["blockchain"]
Esempio n. 5
0
def create_wallet():
    my_wallet = wallet.Wallet()
    response = {
        "private_key": my_wallet.private_key,
        "public_key": my_wallet.public_key,
        "blockchain_address": my_wallet.blockchain_address,
    }
    return jsonify(response), 200
Esempio n. 6
0
def new_wallet():
    wallet_dict = wallet.Wallet(uuid4()).dict

    response = {
        'notice': 'Remember to save your keys in a secure location!',
        'private_key': wallet_dict['private_key'],
        'public_key': wallet_dict['public_key']
    }
    return jsonify(response), 201
    def __init__(self, rules, play_strategy, name=''):
        """Constructor.

    Args:
      rules: table_rules.TableRules, rules of the table.
    """
        super(Player, self).__init__(name)

        # Player needs to know about the rules in order to play and bet.
        self.table_rules = rules

        # How to play hands.
        self.play_strategy = play_strategy

        # Give the player some default wallets to compare betting strategies.
        self.wallets = {}
        self.AddWallet(
            wallet.Wallet(
                self.WALLET_TABLE_MIN,
                strategy.StrategyTableMinimum(
                    self.table_rules.min_money_units)))
        self.AddWallet(
            wallet.Wallet(
                self.WALLET_PROGRESSIVE,
                strategy.StrategyProgressive(
                    self.table_rules.min_money_units,
                    self.table_rules.max_money_units)))
        self.AddWallet(
            wallet.Wallet(
                self.WALLET_PROGRESSIVE_RESET,
                strategy.StrategyProgressive(self.table_rules.min_money_units,
                                             self.table_rules.max_money_units,
                                             reset_after_max=True)))
        self.AddWallet(
            wallet.Wallet(
                self.WALLET_COUNT_BASIC,
                strategy.StrategyCount(self.table_rules.min_money_units,
                                       self.table_rules.max_money_units)))
        self.AddWallet(
            wallet.Wallet(self.WALLET_BJ_OPTIMIZED,
                          strategy.StrategyBlackjackOptimized()))

        self.num_split = 0
        self.num_double = 0
Esempio n. 8
0
 def __init__(self, controller, phoneNumber, captcha, orderId, appchannel,
              privatekey, paths):
     self.controller = controller
     self.general = gen.General(controller, appchannel, privatekey, paths)
     self.order = order.Order(controller, paths)
     self.payment = pay.Payment(controller, paths)
     self.wallet = wal.Wallet(controller, paths)
     self.phoneNumber = phoneNumber
     self.captcha = captcha
     self.orderId = orderId
Esempio n. 9
0
def get_blockchain():
    cached_blockchain = cache.get('blockchain')
    if not cached_blockchain:
        miners_wallet = wallet.Wallet()
        cache['blockchain'] = blockchain.BlockChain(
            blockchain_address=miners_wallet.blockchain_address,
            port=app.config['port'])
        app.logger.warning({
            'private_key': miners_wallet.private_key,
            'public_key': miners_wallet.public_key,
            'blockchain_address': miners_wallet.blockchain_address})
    return cache['blockchain']
Esempio n. 10
0
    def __init__(self, genisus_node=False):
        """

        :param genisus_node: 判断是否是创世节点,如果是则读取本地(genisus_public.pem和genisus_private.pem)密钥对,
                            创始区块的第一笔交易就是奖励给genisus_public.pem
        """
        self.difficulty = 4
        self.current_transactions = []
        self.wallet = wallet.Wallet(genisus_node)
        genius_block = self.get_genius_block()  # 创世区块
        db.write_to_db(self.wallet.address, genius_block)
        self.candidate_blocks = {}
Esempio n. 11
0
def rec_wall():
    if not request.json:
        abort(400)
    #print(request.json)
    data = json.loads(json.dumps(request.json))  # list
    for wall in data:
        print(wall)
    for wall in data:
        temp_wall = wl.Wallet(None, wall['public_key'], wall['utxos'])
        st.wallets.append(temp_wall)
    print(st.wallets)
    return json.dumps(data)
Esempio n. 12
0
def create_portfolio():
    num_wallets = input(
        colored(
            '   How many wallets would you like to create in this portfolio?',
            'cyan',
            'on_grey',
            attrs=['bold', 'dark'])).strip(' ')
    fiat = input(
        colored(
            '   Enter the fiat currency to output to. Id est, Euro is EUR. Only one per portfolio: \n',
            'cyan',
            'on_grey',
            attrs=['bold', 'dark'])).upper().strip(' ')
    portfolio_start = input(
        colored(
            "   Enter the date on which you'd like to have purchased all them cryptocoins (please "
            f"use format dd-mm-yyy): \n",
            'cyan',
            'on_grey',
            attrs=['bold', 'dark'])).upper().strip(' ')
    high_or_low = input(
        colored(
            "   Enter 'high' to calculate value based on the coin's daily high, else enter 'low': "
            "\n",
            'cyan',
            'on_grey',
            attrs=['bold', 'dark']))

    with open('portfolio.json', 'w+', newline='\n') as f:

        # to format it for proper .json
        new_portfolio = []
        for i in range(int(num_wallets)):
            print(colored(f'   Wallet {i + 1}:', 'red', 'on_white'))
            coin = input(
                colored(
                    '   Enter the cryptocoin of choice. Id est, Monero is XMR: \n',
                    'cyan',
                    'on_grey',
                    attrs=['bold', 'dark'])).upper().strip(' ')
            amount = input(
                colored(
                    '   Enter number of coins to fictitiously purchase: \n',
                    'cyan',
                    'on_grey',
                    attrs=['bold', 'dark']))
            wallet = w.Wallet(coin, amount, fiat)
            new_portfolio.append(wallet.to_dict())

        json.dump(new_portfolio, f, indent=2, separators=(',', ': '))

        return new_portfolio, portfolio_start, high_or_low
Esempio n. 13
0
def express():
    express = w.Wallet()
    express.fiat = input(
        colored(
            '   Enter the fiat currency to output to. Id est, Euro is EUR: \n  ',
            'cyan',
            'on_grey',
            attrs=['bold', 'dark'])).upper().strip(' ')
    express.coin = input(
        colored(
            '   Enter the cryptocoin of choice. Id est, Monero is XMR: \n  ',
            'cyan',
            'on_grey',
            attrs=['bold', 'dark'])).upper().strip(' ')
    express_fiat_amount = int(
        float(
            input(
                colored('   Enter amount of fiat to fictitiously spend: \n',
                        'cyan',
                        'on_grey',
                        attrs=['bold', 'dark'])).strip(' ')))
    express_start = input(
        colored(
            f"   Enter the date you'd like to have purchased all that {express.coin} (please use"
            f" format dd-mm-yyy): \n",
            'cyan',
            'on_grey',
            attrs=['bold', 'dark'])).strip(' ')
    express_high_low = input(
        colored(
            "   Enter 'high' to calculate value based on the coin's daily high, else enter "
            "'low': \n",
            'cyan',
            'on_grey',
            attrs=['bold', 'dark'])).lower().strip(' ')

    print(
        colored('. . . Calculating . . .',
                'red',
                'on_white',
                attrs=['bold', 'dark', 'underline', 'blink']))

    fiat_amount_spent, fiat, todays_coin_price, coin, coin_amount, new_fiat_amount_spent, start, current_coin_amount,\
        historical_coin_price = calc.calculate_all_prices(express.fiat, express.coin, express_start, express_high_low,
                                                          express_fiat_amount)

    calc.calculate_single_profit_loss(fiat_amount_spent, fiat, coin,
                                      coin_amount, new_fiat_amount_spent,
                                      start)

    return
 def test_get_current_desired_spend(self):
     """Confirm that desired spend works correctly."""
     test_wallet = wallet.Wallet('MineField.BitcoinLab.org',
                                 iterate_until_send=True)
     for i, utxos in enumerate(test_wallet):
         if i == 0:
             #first send transaction, has no change outputs only 2 sends
             #after 24 receives, 19 utxos are shed as inputs
             #spend = 0.01000001 BTC + 0.1365 BTC = 14650001 satoshis
             desired_spend = test_wallet.get_current_desired_spend()
             self.assertEqual(desired_spend, 14650001)
         if i == 1:
             #second send transaction, spend = 0.1 BTC
             desired_spend = test_wallet.get_current_desired_spend()
             self.assertEqual(desired_spend, 10000000)
             break
Esempio n. 15
0
    def __init__(self, genisus_node=False):
        """

        :param genisus_node: 判断是否是创世节点,如果是则读取本地(genisus_public.pem和genisus_private.pem)密钥对,
                            创始区块的第一笔交易就是奖励给genisus_public.pem
        """
        self.difficulty = 4
        self.current_transactions = []  #收集节点交换的交易
        self.received_transactions = []  #用户发送的交易
        self.send_transactions = []  # sendalltx时发送的交易
        self.wallet = wallet.Wallet(genisus_node)
        genius_block = self.get_genius_block()  # 创世区块
        db.write_to_db(self.wallet.address, genius_block)
        self.candidate_blocks = {}
        self.prepareMessages = []
        self.commitMessages = []
Esempio n. 16
0
def rec_key():
    if not request.json:
        abort(400)
    #print(request.json)
    data = json.loads(json.dumps(request.json))  # dictionary
    temp_wall = wl.Wallet(None, data['public_key'], data['utxos'])
    st.ids.append(data['node_id'])
    print(vars(temp_wall))
    st.wallets.append(temp_wall)
    if (len(st.wallets) == st.n):
        for wall in st.wallets:
            print(vars(wall))
            init.wall_list.append(vars(wall))
        print(st.ids)
    #    return st.broadcast(init.wall_list, "wallet/all", st.ips[st.my_id])
    return "Wallet ok"
Esempio n. 17
0
 def __init__(self, start_val, ty, USD, CRY, qua, thresh, auth=None):
     #set crypto type for obeject
     self.type = ty
     #set analyzer
     self.ana2 = analyzer2.Analyzer2(start_val)
     #set wallet
     self.USDstart = USD
     self.wal = wallet.Wallet(ty, USD, CRY, start_val)
     #set quantity to be traded
     self.quantity = qua
     #set client to trade with
     self.client = auth
     #set internal count
     self.count = 0 
     #set the threshhold
     self.thresh = thresh
     self.buyTrack = 0
    def test_iterate_until_send(self):
        """This should iterate until just before it hits a send transaction."""
        for i, utxos in enumerate(
                wallet.Wallet('MineField.BitcoinLab.org',
                              iterate_until_send=True)):
            if i == 0:
                #just before first send transaction, after 24 receives
                self.assertEqual(len(utxos), 24)
                self.assertEqual(utxos[0][0], (
                    '8f3fbb758556b8fbe99d5cf6ab19707d42524a7a839b08d19adf34153'
                    'a38d369'))
                self.assertEqual(utxos[0][1], 0)
                self.assertEqual(utxos[0][2], 25500)

                self.assertEqual(utxos[23][0], (
                    '0b596a8c22693d727931850225ffddb48d9953e7472a167475de87bed'
                    '0068677'))
                self.assertEqual(utxos[23][1], 3)
                self.assertEqual(utxos[23][2], 10000)

                break
Esempio n. 19
0
def new_wallet():
    return wallet.Wallet()
Esempio n. 20
0
def coin_data_span():
    which_span = input(
        colored(
            "   Enter 'alltime' for the coin's entire history or 'specific' for a span between two "
            "given dates: \n",
            'cyan',
            'on_grey',
            attrs=['bold', 'dark']))
    if which_span == 'alltime':
        alltime = w.Wallet()
        alltime.fiat = input(
            colored(
                '   Enter the fiat currency to output to. Id est, Euro is EUR: '
                '\n  ',
                'cyan',
                'on_grey',
                attrs=['bold', 'dark'])).upper().strip(' ')
        alltime.coin = input(
            colored(
                '   Enter the cryptocoin of choice. Id est, Monero is XMR: \n  ',
                'cyan',
                'on_grey',
                attrs=['bold', 'dark'])).upper().strip(' ')
        alltime_high_or_low = input(
            colored(
                "   Enter 'high' to calculate value based on the coin's daily high, else "
                "enter 'low': \n",
                'cyan',
                'on_grey',
                attrs=['bold', 'dark'])).lower().strip(' ')

        coin_historical_data, start_date, end_date = caches.get_historical_price_cache(
            alltime.fiat, alltime.coin)
        calc.output_coin_histdata(coin_historical_data, alltime_high_or_low,
                                  alltime.coin, start_date, end_date,
                                  alltime.fiat)

    elif which_span == 'specific':
        specific = w.Wallet()
        specific.fiat = input(
            colored(
                '   Enter the fiat currency to output to. Id est, Euro is EUR: \n ',
                'cyan',
                'on_grey',
                attrs=['bold', 'dark'])).upper().strip(' ')
        specific.coin = input(
            colored(
                '   Enter the cryptocoin of choice. Id est, Monero is XMR: \n  ',
                'cyan',
                'on_grey',
                attrs=['bold', 'dark'])).upper().strip(' ')
        specific_start = input(
            colored(
                f"   Enter the date you'd like to have purchased all that {specific.coin} (please "
                f"use format dd-mm-yyy): \n",
                'cyan',
                'on_grey',
                attrs=['bold', 'dark'])).strip(' ')
        specific_end = input(
            colored(
                "   Enter the end date for your historical coin span in the format dd-mm-yyy: \n",
                'cyan',
                'on_grey',
                attrs=['bold', 'dark'])).strip(' ')
        specific_high_or_low = input(
            colored(
                "   Enter 'high' to calculate value based on the coin's daily high, else "
                "enter 'low': \n",
                'cyan',
                'on_grey',
                attrs=['bold', 'dark'])).lower().strip(' ')

        coin_historical_data, start_date, end_date = caches.get_historical_price_cache(
            specific.fiat, specific.coin, specific_start, specific_end)
        calc.output_coin_histdata(coin_historical_data, specific_high_or_low,
                                  specific.coin, start_date, end_date,
                                  specific.fiat)
Esempio n. 21
0
 def create_wallet(self):
     ##create a wallet for this node, with a public key and a private key
     return wallet.Wallet()
 def test_max_txs_download(self):
     """Confirm that huge wallets aren't downloaded."""
     with self.assertRaises(http.MaxTransactionsExceededError):
         test_wallet = wallet.Wallet('MineField.BitcoinLab.org',
                                     max_txs_download=100)
 def test_apparent_coinjoin(self):
     """Test that no exception is thrown for wallet that has a CoinJoin."""
     test_wallet = wallet.Wallet('923197ea09681d34',
                                 iterate_until_send=True)
     for utxos in enumerate(test_wallet):
         pass
Esempio n. 24
0
	def create_wallet(self):
		#create a wallet for this node, with a public key and a private key
		return wallet.Wallet(self.address, []) # TODO Add constructor fields
Esempio n. 25
0
    def test_open(self):
        w = wallet.Wallet("test/files/wallet", "wallet.dat")

        self.assertEqual(w.version, 159900)
        self.assertEqual(w.minimum_version, 159900)
        self.assertEqual(len(w.keys), 39)
Esempio n. 26
0
 def create_wallet(*args, **kwargs):
     WalletManager.exit_wallet()
     WalletManager.__wallet_instance = wallet.Wallet(*args, **kwargs)
     WalletManager.__wallet_instance.start_updating()
import json
import time
from BlockChain import Blockchain
import wallet
from Good import Land, Vehicle
from flask import Flask, jsonify, abort, make_response, request

app = Flask(__name__)

blockchain = Blockchain()
users = []
currentUser = 0
walletAlice = wallet.Wallet(
    [Vehicle(1, 1, 53451162589, "red", "wolkswagen")], [
        Land(1, 37, 38, "29 rue parc dounia", [(37.01, 38.002),
                                               (37.2, 36, 2)], 100, 1),
        Land(2, 37, 38, "28 rue parc dounia", [(37.01, 38.002),
                                               (37.2, 36, 2)], 200, 2)
    ])
walletBob = wallet.Wallet([], [
    Land(1, 37, 38, "29 rue parc dounia", [(37.01, 38.002),
                                           (37.2, 36, 2)], 400, 0)
])


@app.route('/login', methods=['POST'])
def login():
    login_data = request.get_json()
    required_fields = ["email", "password"]

    for field in required_fields:
Esempio n. 28
0
 def create_wallet(self):
     return wallet.Wallet()
Esempio n. 29
0
import wallet
from tkinter import *

btc_wallet = wallet.Wallet()
filename = 'credentials.txt'

with open(filename, 'w') as f:
    f.write('currency: ' + btc_wallet.coin + '\n')
    f.write('private key: ' + btc_wallet.private_key + '\n')
    f.write('public key: ' + btc_wallet.public_key + '\n')
    f.write('address: ' + btc_wallet.address + '\n')
    f.write('seed: ' + btc_wallet.seed + '\n')
f.close()

root = Tk()

label_currency = Label(root, text='Currency: ' + btc_wallet.coin)
label_currency.grid(row=0, sticky='w')

label_address = Label(root, text='Address: ' + btc_wallet.address)
label_address.grid(row=1, sticky='w')

label_private_key = Label(root, text='Private Key: ' + btc_wallet.private_key)
label_private_key.grid(row=2, sticky='w')

label_public_key = Label(root, text='Public Key: ' + btc_wallet.public_key)
label_public_key.grid(row=3, sticky='w')

label_seed = Label(root, text='seed: ' + btc_wallet.seed)
label_seed.grid(row=4, sticky='w')