-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallet.py
69 lines (55 loc) · 2.1 KB
/
wallet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import subprocess
import json
from constants import BTC, ETH, BTCTEST
import os
from pprint import pprint
from web3 import Web3, middleware
from web3.gas_strategies.time_based import medium_gas_price_strategy
mnemonic = os.getenv('MNEMONIC', 'letter floor critic cluster step soda helmet odor news mercy wise enhance explain empower speak')
def derive_wallets(coin, mnemonic):
command = f'php derive -g --mnemonic="{mnemonic}" --cols=path,address,privkey,pubkey --coin="{coin}" --numderive=3 --format=json'
p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
output, err = p.communicate()
p_status = p.wait()
keys = json.loads(output)
return keys
def priv_key_to_account(coin, priv_key):
if coin == ETH:
return Account.privateKeyToAccount(priv_key)
elif coin == BTCTEST:
return PrivateKeyTestnet(priv_key)
def create_tx(coin, account, to, amount):
value = Web3.toWei(amount, "ether")
gas_estimate = web3.eth.estimateGas({'to': to,
'from': account["address"],
'value': amount})
gas_price = web3.eth.gasPrice
if coin == ETH:
return {"to": to,
"from": account,
"value": value,
"gas": gas_estimate,
"gasPrice": gas_price,
"nonce": 1,
"chainID": 972}
if coin == BTCTEST:
return PrivateKeyTestnet.prepare_transaction(account.address, [(to, amount, BTC)])
def send_tx(coin, account, to, amount):
if coin == ETH:
return w3.eth.sendRawTransaction(signed.rawTransaction)
if coin == BTCTEST:
return NetworkAPI.broadcast_tx_testnet(signed)
def raw_tx(creat_tx):
if coin == ETH:
return w3.eth.sendRawTransaction(signed.rawTransaction)
if coin == BTCTEST:
return NetworkAPI.broadcast_tx_testnet(signed)
#create_tx(ETH, account = coins[ETH][0]["address"], to, 50)
coins = {ETH: derive_wallets(ETH, mnemonic),
BTCTEST: derive_wallets(BTCTEST, mnemonic)
}
#print(coins[ETH][0]["address"])
pprint(coins)
#print(create_tx)
from web3.middleware import geth_poa_middleware
w3.middleware_onion.inject(geth_poa_middleware, layer=0)