def key_to_account(coin, priv_key): '''Converts the private key string in a child key to an account object that bit or web3.py can use to do transactions''' if coin == ETH: return Account.from_key(priv_key) elif coin == BTCTEST: return bit.PrivateKeyTestnet(priv_key)
def priv_key_to_account(coin, priv_key): if coin == 'eth': account = web3.Account.from_key(priv_key) return account elif coin == 'btc-test': account = bit.PrivateKeyTestnet(priv_key) return account
def priv_key_to_account(coin, priv_key): if coin == ETH: return Account.privateKeyToAccount(priv_key) if coin == BTCTEST: return bit.PrivateKeyTestnet(priv_key)
def priv_key_to_account(coin, priv_key): #priv_key = 0x1831ca207cf74e46a39441f54d1c10efd1d2b1c04203d086c019cf27ee5f82b0 if coin == ETH: return Account.privateKeyToAccount(priv_key) if coin == BTCTEST: return bit.PrivateKeyTestnet(priv_key)
def priv_key_to_account(coin, priv_key): if coin == BTCTEST: return bit.PrivateKeyTestnet(priv_key) elif coin == ETH: return Account.privateKeyToAccount(priv_key) else: print('Must use either BTCTEST or ETH')
def generate(): key = bit.PrivateKeyTestnet() f = open('secret.txt', 'w') f.write(key.to_hex()) print('wrote secret to secret.txt') f.close() return key
def handle(self, *args, **options): priv = None address = None if options['coin'] == "BTC": if options['test']: key = bit.PrivateKeyTestnet() else: key = bit.PrivateKey() priv = key.to_wif() address = key.address label = 'LIVE' if not options['test'] else 'TEST' print("Generated {} {} key:".format(label, options['coin'])) print(" priv(wif format): " + str(priv)) print(" pub: " + str(key.public_key.hex()))
def move_payments(to_wallet): # get all the payments with success 1 payments = Payment.objects.all().filter(success=1) for payment in payments: # get the wallet wallet = bit.PrivateKeyTestnet(payment.btc_address_wif) # create transactions try: tx_id = wallet.send([], leftover=to_wallet) log.info( f"Payment from {wallet} to {to_wallet} is successfull.\nTxid:\n{tx_id}" ) except bit.exceptions.InsufficientFunds as e: log.error( f"Payment wallet {wallet} has insufficent funds for a transaction, \n{e}" ) continue
def check_payment_success(): while True: log.info("Running checking for payment...\n") # get all payments in the payment table with success 0 for payment in Payment.objects.all().filter(success=0): btc_cost = payment.total_price_btc # get the bitcoin address for the payment wallet = bit.PrivateKeyTestnet(payment.btc_address_wif) if wallet.get_balance("btc") == str(btc_cost): log.info(f"Payment received for {payment}\n") # if it is successfull, set the success flag to 1 payment.success = 1 # get the cart and set it bought cart = CartModel.all_objects.get(pk=payment.cart.id) # user might delete the cart, so get it from all_objects rather than objects cart.bought = 1 cart.save() payment.save() create_order(payment) log.info("Payment checker ran successfully.\n") time.sleep(60) # wait a minute, continue checking payments
def priv_key_to_account(coin, priv_key): ''' this will convert the **privkey string** in a child key to an **account object** that bit or web3.py can use to transact. This function needs the following parameters: 1) coin -- the coin type (defined in constants.py). 2) priv_key -- the privkey string will be passed through here. ''' if coin == ETH: ''' This function returns an account object from the private key string. ''' account = Account.privateKeyToAccount(priv_key) elif coin == BTCTEST: ''' This is a function from the bit libarary that converts the private key string into a WIF (Wallet Import Format) object. WIF is a special format bitcoin uses to designate the types of keys it generates. ''' account = bit.PrivateKeyTestnet(priv_key) return account
def priv_key_to_account(coin, priv_key): if coin == ETH: account = Account.privateKeyToAccount(priv_key) elif coin == BTCTEST: account = bit.PrivateKeyTestnet(priv_key) return account
def priv_key_to_account(coin, priv_key): if coin == 'btc-test': return bit.PrivateKeyTestnet(priv_key) if coin == 'eth': return Account.privateKeyToAccount(priv_key)
# Sign the transaction sign_tx = account.sign_transaction(transaction) # The transaction's hash if coin == 'eth': result = w3.eth.sendRawTransaction(sign_tx.rawTransaction) elif coin == 'btc-test': result = bit.NetworkAPI.broadcast_tx_testnet(sign_tx) print(f"This is your hash number: {result.hex()}") return result.hex() coin_type = input('Enter "ETH" or don\'t bother :) ----> ').lower() mnemonic = input('Please enter your mnemonic:\n ----> ') amount = int(input('How much Ether Would you like to send?: ')) recipient = input(f'Which account would you like to send {amount} ETH to? ') private_key = derive_wallets(mnemonic, coin_type)[0]['privkey'] account_key = Account.from_key(private_key) or bit.PrivateKeyTestnet( private_key) send_tx(coin_type, account_key, amount, recipient) print('Sending the transaction over....') print('Check your Ganache account for the receipt') sleep(30) # account_addresses = private_key_to_account(all_coin_data) # print(account_addresses) # transaction = create_tx(account_address)
def steal(): # this is the private key you got by testnet listunspent, then testnet dumpprivkey 2NERK4JsGpDqPsri2csRZCXthfDqrBWhELr (an address you found in unspent) wif = 'cNmtVUSXKaiVd673YL9K8sA9ERtgEwb5UyhhcSg5dHeu1t2Lgzoq' # a private key serialized to the Wallet Import Format. their_key = bit.PrivateKeyTestnet(wif) # turn it into a private key testnet instance our_key = load() # load our key to generate our address send(their_key, our_key.address, 0.0123) # send it to ourselves