예제 #1
0
async def generate_seed():
    '''generate a new seed. \n 
       use its private key \n
       for prototyping only, use proper seed generation in prod 
    '''
    seed = Wallet().key.hex
    return seed
예제 #2
0
def get_testnet_wallet_address():
    try:
        wallet_address_info = Wallet(testnet=True)
        wallet_address_data = {
            'private_key_hex':
            wallet_address_info.key.hex,
            "private_key_wif":
            wallet_address_info.key.mainnet.wif,
            "private_key_wic":
            wallet_address_info.key.mainnet.wifc,
            "publick_key":
            wallet_address_info.address.pubkey,
            "publick_key_compressed":
            wallet_address_info.address.pubkeyc,
            "publick_address_1":
            wallet_address_info.address.mainnet.pubaddr1,
            "publick_address_1_compressed":
            wallet_address_info.address.mainnet.pubaddr1c,
            "publick_address_3":
            wallet_address_info.address.mainnet.pubaddr3,
            "publick_address_bc1_p2wpkh":
            wallet_address_info.address.mainnet.pubaddrbc1_P2WPKH,
            "publick_address_bc1_p2wsh":
            wallet_address_info.address.mainnet.pubaddrbc1_P2WSH
        }

        return wallet_address_data

    except Exception as e:
        print(e.message)
예제 #3
0
def check_btc_wallet():
    """A pointless Celery task to demonstrate usage."""

    BASE_URL_CHECK = "https://blockchain.info/address/%(btcaddr)s?format=json"

    wallet = Wallet()

    pubkey = wallet.address.pubaddr1
    prvkey = wallet.address.privkey.wif

    reading_state = True
    reading_count = 0
    blockhain_info = {}
    while reading_state and reading_count < 4:
        try:
            r = requests.get(BASE_URL_CHECK % {
                "btcaddr": pubkey
            }, timeout=10)
            blockhain_info = r.json()
            reading_state = False
        except Exception:
            reading_count += 1
            sleep(60 * reading_count)

    MyCheckerModel.objects.get_or_create(
        name="{}".format(prvkey[:5]),
        prvkey=prvkey,
        pubkey=pubkey,
        balance=float(blockhain_info['final_balance'])
    )

    return "Balance: {}".format(float(blockhain_info['final_balance']))
예제 #4
0
def get_keys():

    wallet = Wallet()
    public_key = wallet.address.__dict__['pubkeyc'][:24]
    private_key = wallet.key.__dict__['hex'][:24]

    keys = [{'public_key': public_key, 'private_key': private_key}]

    response = jsonify(keys)
    response.headers.add("Access-Control-Allow-Origin", "*")
    return response
예제 #5
0
def generate_and_add_address(seed: Optional[str] = None):
    '''
    generate new address, random or for given seed.
    '''
    # this is no proper address generation
    # for prototyping purposes only

    wallet = Wallet()
    key = wallet.address.pubkey
    new_address = Address(address=key, seed=seed)
    session.add(new_address)
    session.commit()
    return key
예제 #6
0
    hash = hashlib.sha256(binascii.unhexlify(hash)).hexdigest()
    print("Hash#", x, " : ", hash)
print("--------------------------------------")
if(checksum == hash[:8]):
    print("[VERDADERO] checksum es valido!")
else:
    print("[FALSO] checksum no es valido!")
print("--------------------------------------")


print()
print('-----------------------------------------------------------------------------')
print('-----COMPARANDO SI LAS LLAVES SON GENERADAS CORRECTAMENTE--------------------')
print('-------------- CON LA LIBRERIA BITCOINADDRESS--------------------------------')
from bitcoinaddress import Wallet
wallet = Wallet(WIF.decode('utf-8'))
print()
print("DIRECCION PUBLICA 1: ",wallet.address.__dict__['mainnet'].__dict__['pubaddr1'])
print("DIRECCION PUBLICA Compress: ",wallet.address.__dict__['mainnet'].__dict__['pubaddr1c'])
print("DIRECCION PUBLICA 3: ",wallet.address.__dict__['mainnet'].__dict__['pubaddr3'])
print("DDIRECCION PUBLICA bc1 P2WPKH: ",wallet.address.__dict__['mainnet'].__dict__['pubaddrbc1_P2WPKH'])
print("DIRECCION PUBLICA bc1 P2WSH: ",wallet.address.__dict__['mainnet'].__dict__['pubaddrbc1_P2WSH'])
print()
print("LLAVE PRIVADA HEX: ",wallet.key.__dict__['hex'])
print("LLAVE PRIVADA WIF: ",wallet.key.__dict__['mainnet'].__dict__['wif'])
print("LLAVE PRIVADA WIFC: ",wallet.key.__dict__['mainnet'].__dict__['wifc'])

generarcodigoqr(wallet.address.__dict__['mainnet'].__dict__['pubaddr1'],"PublicAddress1.eps",wallet.address.__dict__['mainnet'].__dict__['pubaddr1'])
generarcodigoqr(wallet.address.__dict__['mainnet'].__dict__['pubaddr1c'],"PublicAddressC.eps",wallet.address.__dict__['mainnet'].__dict__['pubaddr1c'])
generarcodigoqr(wallet.address.__dict__['mainnet'].__dict__['pubaddr3'],"PublicAddress3.eps",wallet.address.__dict__['mainnet'].__dict__['pubaddr3'])
generarcodigoqr(wallet.address.__dict__['mainnet'].__dict__['pubaddrbc1_P2WSH'],"PublicAddressBC1-P2WSH.eps",wallet.address.__dict__['mainnet'].__dict__['pubaddrbc1_P2WSH'])
예제 #7
0
def blockchain_wallet():
    wallet = Wallet()
    return wallet
    print("Usage: %s <wallet_file>" % sys.argv[0])
    sys.exit(1)

db = DB()
db.open(sys.argv[1], "main", DB_BTREE, DB_RDONLY)

items = db.items()


def getBetween(start, end, s):
    return (s.split(start))[1].split(end)[0]


for item in items:
    k, v = item

    vAsHexStr = v.hex()
    if (part1Compressed in vAsHexStr):
        between = getBetween(part1Compressed, part3, vAsHexStr)
        wallet = Wallet(between)
        print(wallet.key.mainnet.wif)
        print(wallet.key.mainnet.wifc)

    if (part1Uncompressed in vAsHexStr):
        between = getBetween(part1Uncompressed, part3, vAsHexStr)
        wallet = Wallet(between)
        print(wallet.key.mainnet.wif)
        print(wallet.key.mainnet.wifc)

db.close()
예제 #9
0
def exec(dlt, num_agents, num_steps):
    results_df = pd.DataFrame(
        columns=['steps', 'agents', 'dlt', 'mean', 'max', 'min'])
    d_t_gens = int(0.3 * num_agents)

    demand, price, supply = create_synthetic_data(num_steps, num_agents,
                                                  d_t_gens)
    steps_vec = np.linspace(0, num_steps, num_steps + 1)

    times_vec = []
    num_agents = demand.shape[0]
    steps = demand.shape[1]

    a_series = (supply != 0).any(axis=1)
    new_df = supply.loc[a_series]
    gen_nodes = np.array(new_df.index)

    addresses = []
    for i in tqdm(range(0, num_agents)):
        wallet = Wallet()
        addresses.append(wallet.key.__dict__['mainnet'].__dict__['wif'])
    wrapper = Wrapper()
    agents = []
    print('Created addresses')
    for index in tqdm(range(0, num_agents)):
        agents.append(
            Agent(np.array(demand.iloc[index]),
                  np.array(supply.iloc[index]), index, addresses[index],
                  np.array(price.iloc[index]), wrapper))
    nodes = list(np.linspace(0, num_agents - 1, num_agents, dtype=np.int))
    steps_vec = list(np.linspace(0, steps - 1, steps, dtype=np.int))
    times_vec = []
    for step in tqdm(steps_vec):
        start = time.time()
        step_energy_info = []
        for index, agent in enumerate(agents):
            node, info_dict = agent.publish_energy_info(step)
            step_energy_info.append(info_dict)
        supply_df, ED, auction_price = single_sided_auction(
            step_energy_info, supply, demand, price, agents)
        pf_result = micro_grid_exec(step, supply, demand, price, agents)
        supply_df.set_index('Agents', inplace=True)
        gen_values = pf_result['p_mw']
        gen_dict = dict(zip(gen_nodes, gen_values))
        total_demand = sum(supply_df['Demand'])
        total_supply = sum(gen_dict.values())
        losses = total_supply - total_demand
        payment_setup(step, auction_price, wrapper, supply, demand, price,
                      agents)
        wrapper.mine_unconfirmed_transactions()
        times_vec.append(time.time() - start)
    new_df = pd.DataFrame(
        data={
            'steps': [d_steps],
            'agents': [d_num_agents],
            'dlt': ['blockchain'],
            'mean': [np.mean(times_vec)],
            'max': [np.max(times_vec)],
            'min': [np.min(times_vec)]
        })
    results_df = results_df.append(new_df, ignore_index=True)
예제 #10
0
def getNewKeypair():
    return getKeypairFromPrivateKey(encodeKey(Wallet().key.digest) + KEY_PRIVATE)
예제 #11
0
 def generatePublicKey(self):
     wif = base58.b58encode_check(
         base58.b58decode_check(self.priv.key)[:-1]).decode()
     wallet = Wallet(wif)
     self.pub = BaseKey(KEY_PUBLIC, base58.b58encode(codecs.decode(
         wallet.address.pubkeyc, "hex")).decode())