@app.route('/node/<node_url>', methods=['DELETE'])
def remove_node(node_url):
    if node_url == '' or node_url == None:
        response = {'message': 'No data found.'}
        return jsonify(response), 400
    blockchain.remove_peer_node(node_url)
    response = {
        'message': 'Node removed',
        'all_nodes': blockchain.get_peer_nodes()
    }
    return jsonify(response), 200


@app.route('/nodes', methods=['GET'])
def get_nodes():
    nodes = blockchain.get_peer_nodes()
    response = {'all_nodes': nodes}
    return jsonify(response), 200


if __name__ == '__main__':
    from argparse import ArgumentParser
    parser = ArgumentParser()
    parser.add_argument('-p', '--port', type=int, default=5000)
    args = parser.parse_args()
    port = args.port
    wallet = Wallet(port)
    blockchain = Blockchain(wallet.public_key, port)
    app.run(host='0.0.0.0', port=port)
Exemple #2
0
from wallet import Wallet

wallet = Wallet()
account = wallet.getaccount()

toaddress = raw_input("Enter the address to send coins to: ")
amount = int(input("Enter the balance to transfer to address: "))

balance = 0
for subaccount in account.itervalues():
    balance = balance + subaccount['balance']

if balance < amount:
    print("Not enough balance")
    exit(1)

print "Transferring: ", amount, " \tto: ", toaddress
wallet.connection.sendtoaddress(toaddress, amount)
Exemple #3
0
import yaml
import json
import urllib.request
import time
from wallet import Wallet
from database.database import Database

config = yaml.safe_load(open("config.yml"))

f = open('dataset.txt', 'r')
dataset = f.readlines()
dataset = [float(i) for i in dataset]

walletBitcoin = 0.0
cash_wallet = Wallet()
firstrun = True
transection = 0.002

print ('Starting simulator...')

def getSellPrice():
    with urllib.request.urlopen('https://api.bitfinex.com/v1/pubticker/btcusd') as response:
        html = response.read()
    return float(json.loads(html)['last_price'])


oldPrice = currentPrice = initPrice = dataset[0]



def getTransectionfee():
Exemple #4
0
 def __init__(self):
     #  in order to write this to the file it has to be string.
     # self.id=str(uuid4())
     self.wallet = Wallet()
     self.wallet.create_keys()
     self.blockchain = Blockchain(self.wallet.public_key)
 def __init__(self):
     self.wallet = Wallet()
     self.wallet.create_keys()
     self.blockchain = Blockchain(self.wallet.public_key)
def test_negative_wallet():
    with pytest.raises(NegativeAmount):
        wallet = Wallet(-10)
Exemple #7
0
 def test_wallets_have_different_addresses(self):
     w1 = Wallet(self.UTXOs)
     w2 = Wallet(self.UTXOs)
     self.assertNotEqual(w1.address, w2.address)
def test_setting_initial_amount():
    wallet = Wallet(100)
    assert wallet.balance == 100
Exemple #9
0
 def get_wallet(self, chat_id):
     wallet = self.usr_wallets.get(chat_id)
     if wallet is None:
         wallet = Wallet(chat_id)
     return wallet
def test_wallet_spend_cash_raises_exception_on_insufficient_amount():
    wallet = Wallet()
    with pytest.raises(InsufficientAmount):
        wallet.spend_cash(100)
def test_default_initial_amount():
    wallet = Wallet()
    assert wallet.balance == 0
def test_wallet_spend_cash():
    wallet = Wallet(20)
    wallet.spend_cash(10)
    assert wallet.balance == 10
def test_wallet_add_cash():
    wallet = Wallet(10)
    wallet.add_cash(90)
    assert wallet.balance == 100
def test_setting_negative_amount():
    wallet = Wallet(-100)
    assert wallet.balance == -100
def wallet():
    """Returns a Wallet instance with a balance of 20"""
    return Wallet(20)
Exemple #16
0
from wallet import Wallet
from transaction import Transaction
from mx_crypto import MxCrypto

wallet = Wallet(1024, True)
guy_wallet = Wallet(1024, True)

my_address = wallet.address
guy_address = guy_wallet.address

value = 10


def test_signature():
    # creation of a transaction with my wallet.
    transaction = Transaction(sender_address=my_address,
                              recipient_address=guy_address,
                              value=value)

    transaction.sign(wallet)

    assert transaction.verify_signature() == True

    # guy sign my transaction...
    transaction.sign(guy_wallet)
    is_valid = transaction.verify_signature()

    assert is_valid == False
def empty_wallet():
    """Returns a Wallet instance with a zero balance"""
    return Wallet()
Exemple #18
0
    def __init__(self, account_id, private_key, provider, dev=False):
        self.plugin = PluginManager()
        self.plugin.load(PLUGINS_PATH)
        self.plugin.set_default_solverclass('gcs_solver.py')

        self.dev = dev
        self.account_id = account_id
        self.web3 = Web3(provider)
        self.interest = ''
        self.trusted_users = []
        self.web3.eth.defaultAccount = account_id

        # PoA であれば geth_poa_middleware を利用
        try:
            self.web3.eth.getBlock("latest")
        except ExtraDataLengthError:
            self.web3.middleware_onion.inject(geth_poa_middleware, layer=0)

        if private_key:
            self.web3.middleware_onion.add(
                construct_sign_and_send_raw_middleware(private_key))
        self.deploy_erc1820()

        self.__observer = None
        self.__state = None
        self.assets = None
        # Wallet の情報
        self.wallet = Wallet(self.web3, self.account_id)

        # オペレータ(トークンの交換などを担当)のコントラクト
        self.operator_address = None
        self.load_config()

        self.operator_address = self._fix_config_address(
            self.config['operator']['address'])
        if self.config['operator']['solver_pluginfile']:
            self.plugin.set_solverclass(
                self.operator_address,
                self.config['operator']['solver_pluginfile'])

        self.contracts = Contracts(self.web3)
        self.deploy_metemcyberutil()

        self.fetch_trusted_users()

        self.event_listener = BasicEventListener('')
        self.event_listener.start()

        # inventory (トークン・カタログの管理)のインスタンス生成
        catalog_address = self._fix_config_address(
            self.config['catalog']['address'])
        broker_address = self._fix_config_address(
            self.config['broker']['address'])
        self.inventory = Inventory(self.contracts, self.account_id,
                                   self.event_listener, catalog_address,
                                   broker_address)

        # Seeker (チャレンジの依頼者)のインスタンス
        self.seeker = Seeker(self.contracts)

        # Solver (チャレンジの受領者)としてのインスタンス
        if self.operator_address:
            solverclass = self.plugin.get_solverclass(self.operator_address)
            self.solver = solverclass(self.contracts, self.account_id,
                                      self.operator_address)
        else:
            self.solver = None

        # MISP設定のinsert
        self.load_misp_config(MISP_INI_FILEPATH)
Exemple #19
0
 def __init__(self):
     # self.id = str(uuid4())
     self.wallet = Wallet()
     self.wallet.create_keys()
     self.blockchain = Blockchain(self.wallet.public_key)
Exemple #20
0
 def test_create_wallet(self):
     w = Wallet(self.UTXOs)