Exemple #1
0
def wallet(node):
    with Wallet(node.get_chain_id(), node.rpc_endpoint, node.genesis.get_accounts()) as w:
        w.login("", "")
        w.get_api_by_name('database_api')
        w.get_api_by_name('network_broadcast_api')
        w.get_block(1, wait_for_block=True)
        yield w
Exemple #2
0
def test_wallet_spend_cash_raises_exception_on_insufficient_amount():
    """
        Asserts one cant spend more money than what's in the wallet
    """
    wallet = Wallet()
    with pytest.raises(InsufficientAmount):
        wallet.spend_cash(100)
Exemple #3
0
 def setUp(self):
     self.blockchain = Blockchain()
     self.chain = self.blockchain.chain
     self.mempool = self.blockchain.mempool
     self.network = self.blockchain.network
     self.wallet = Wallet()
     self.initial_address = self.wallet.addresses[0]
Exemple #4
0
def test_wallet_spend_cash():
    """
    Testing Spending cash
    """
    wallet = Wallet(20)
    wallet.spend_cash(10)
    assert wallet.balance == 10
Exemple #5
0
def post_comment(post_kwargs, node):
    with Wallet(node.get_chain_id(), node.rpc_endpoint,
                node.genesis.get_accounts()) as w:
        w.login("", "")
        w.get_api_by_name('database_api')
        w.get_api_by_name('network_broadcast_api')
        return w.post_comment(**post_kwargs)
Exemple #6
0
def test_wallet_add_cash():
    """
    Testing adding cash
    """

    wallet = Wallet(10)
    wallet.add_cash(90)
    assert wallet.balance == 100
def get_posts(address):
    with Wallet(CHAIN_ID, address) as wallet:
        posts = {
            "%s:%s" % (p["author"], p["permlink"]): p
            for p in wallet.get_posts_and_comments()
        }
        logging.info("Total number of posts and comments: %d", len(posts))
        return posts
Exemple #8
0
 def __init__(self, moneyExpected, stages):
     self.stages = stages  # list of percentages ordered by index
     self.moneyExpected = moneyExpected
     self.totalMoneyReceived = 0
     self.currentMoney = 0
     self.backers = 0
     self.currentStage = 0
     self.wallet = Wallet()
Exemple #9
0
def read_wallet(id=None):
    w = Wallet()
    if id == None:
        response = {'mensagem':'Falda nome da wallet!'}
    elif w.read_wallet(id):
        response = {'nome':id,
                    'wallet':w.public}
    else:
        response = {'mensagem':f'Não existe cateira para: {id}, Favor criar!'}
    return jsonify(response), 200
Exemple #10
0
def create_wallet():
    response_cod = None
    json = request.get_json()
    if json  == None:
        response_cod = 400
        response = {'mensagem':'Falta wallet_id!'}
    elif json['wallet_id'] != '':
        w = Wallet()
        w.create_wallet(json['wallet_id'])
        if w.read_wallet(json['wallet_id']):
            response = {'mensagem':'Carteira já existe!', 'carteira':w.public}
        response =  {'mensagem':f'wallet({json["wallet_id"]}) -> {w.public}'}
    else:
        response =  {'mensagem':'Falta wallet_id!'}
        response_cod =  400
    return jsonify(response), response_cod if response_cod else 201
Exemple #11
0
def generate_blocks(node, docker, num=1):
    """
    Run node, wait until N blocks will be generated, stop node.

    :param Node node: Node to run
    :param DockerController docker: Docker to run container
    :param int num: Number of blocks to generate
    :return int: Number of head block
    """
    with docker.run_node(node):
        with Wallet(node.get_chain_id(), node.rpc_endpoint,
                    node.genesis.get_accounts()) as w:
            w.get_block(
                num,
                wait_for_block=True,
                time_to_wait=3 * num  # 3 sec on each block
            )
            return w.get_dynamic_global_properties()['head_block_number']
Exemple #12
0
def mine_block(hosting):
    w = Wallet()
    if not w.read_wallet(hosting):
        return jsonify({'mensagem':'Falta hosting wallet!'})
    blockchain.wallet = w
    blockchain.hosting_node = w.public
    if blockchain.mine_block('bank'):
        block = blockchain.last_block()
        response = {'Mensagem': 'Parabéns, bloco minerado!',
                    'index': block['index'],
                    'timestamp': block['timestamp'],
                    'proof': block['proof'],
                    'previous_hash': block['previous_hash'],
                    'transactions': block['transactions']
                }
    else:
        response = {'mensagem':f'{blockchain.hosting_node}, você não tem importância suficiente para esta transação!'}
            
    return jsonify(response), 200
Exemple #13
0
def main():
    wallet = Wallet(70)
    wallet.add_cash(4)

    wallet = Wallet("ran")
    wallet.add_cash(4)
def get_accounts(names, address):
    with Wallet(CHAIN_ID, address) as wallet:
        accounts = wallet.get_accounts(names)
        logging.info("Total number of accounts; %d" % len(accounts))
        return {a["name"]: a for a in accounts}
def list_all_accounts(address):
    with Wallet(CHAIN_ID, address) as wallet:
        return wallet.list_all_accounts()
Exemple #16
0
def test_setting_initial_amount():
    """
    Testing setter of initial amount
    """
    wallet = Wallet(100)
    assert wallet.balance == 100
def get_operations_in_block(address, num):
    with Wallet(CHAIN_ID, address) as w:
        operations = w.get_ops_in_block(num, 2)
        save_to_file("all_operations.json", operations)
        return operations
Exemple #18
0
def test_default_initial_amount():
    """
    Testing initial amount is 0
    """
    wallet = Wallet()
    assert wallet.balance == 0  # Forcing Wallet object to have 'balance' property
def get_dynamic_global_properties(address):
    with Wallet(CHAIN_ID, address) as wallet:
        return wallet.get_dynamic_global_properties()
def wallet():
    '''Returns a Wallet instance with a balance of 20'''
    return Wallet(20)
def test_transactions(empty_wallet, earned, spent, expected):
    empty_wallet = Wallet()
    empty_wallet.add_cash(earned)
    empty_wallet.spend_cash(spent)
    assert empty_wallet.balance == expected
def empty_wallet():
    '''Returns a Wallet instance with a zero balance'''
    return Wallet()
Exemple #23
0
from flask import Flask, jsonify, request
from urllib.parse import urlparse

from src.blockchain import Blockchain
from src.proof_of_work import ProofOfWork
from src.wallet import Wallet

# Instantiate Node
node = Flask(__name__)

# Instantiate the blockchain
blockchain = Blockchain()

# Instantiate wallet
wallet = Wallet()


@node.route('/wallet/check_balance',
            defaults={'address': None},
            methods=['GET'])
@node.route('/wallet/check_balance/<address>', methods=['GET'])
def balance(address):
    # Update the balance of our wallet
    wallet.update_balances(blockchain.chain)

    if address:
        # Return the balance of a specific address
        if address in wallet.addresses:
            response = {'balance': wallet.address_to_balance[address]}
            return jsonify(response), 200
        else:
Exemple #24
0
def test_setting_wrong_type_raises_exception_on_type():
    """
        Asserts exception is raised when wrong input type is given
    """
    with pytest.raises(TypeError):
        wallet = Wallet("not int")
Exemple #25
0
 def setUp(self):
     self.acct = Wallet(1)
def get_chain_capital(address):
    with Wallet(CHAIN_ID, address) as wallet:
        return wallet.get_chain_capital()