FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
multimerchant-python/examples/sweeper.py at master · 3Thiago/multimerchant-python · GitHub
3Thiago
/
multimerchant-python
Public
forked from
BlockIo/multimerchant-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
multimerchant-python
/
examples
/
sweeper.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
98 lines (74 loc) · 4.64 KB
Breadcrumbs
multimerchant-python
/
examples
/
sweeper.py
Copy path
File metadata and controls
98 lines (74 loc) · 4.64 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from
multimerchant
.
wallet
import
Wallet
import
time
from
block_io
import
BlockIo
import
six
import
os
import
sys
try
:
os
.
environ
[
"HD_PRIVKEY"
]
except
KeyError
:
print
"Please generate an HD wallet first. See README.rst on https://github.com/blockio/multimerchant-python"
print
"Or do this:"
print
"
\t
$ python"
print
"
\t
>> from multimerchant.wallet import Wallet"
print
"
\t
>> print
\"
My HD Private Key:
\"
, Wallet.new_generate_wallet(network=
\"
DOGETEST
\"
)"
print
"
\t
>> quit()"
print
"
\t
$ HD_PRIVKEY=STRING_FROM_ABOVE python sweeper.py"
print
"... where sweeper.py is this file."
sys
.
exit
(
1
)
# Please use the Dogecoin Testnet here -- you have free coins on sign up at Block.io
# Dogecoin Testnet because of the static demo amount for withdrawals/sweeps below
block_io
=
BlockIo
(
'Your Dogecoin Testnet API Key'
,
'Your Secret PIN'
,
2
)
network
=
block_io
.
get_balance
()[
'data'
][
'network'
]
# extract the network of our API Key
# create a wallet using a master secret -- this one is super insecure, but it's an example
# don't have an HD privkey yet? Create one by using:
#
# $ python
# >> from multimerchant.wallet import Wallet
# >> hd_privkey = Wallet.new_random_wallet(network="DOGETEST").serialize()
# >> print "My Super Secret HD Wallet:", hd_privkey
#
# The 'network' value above can be: BTC, BTCTEST, DOGE, DOGETEST, LTC, LTCTEST
# Get the relevant network's API Key at Block.io for use in this example
w
=
Wallet
.
deserialize
(
os
.
environ
[
'HD_PRIVKEY'
],
network
=
network
)
# or generate an insecure version like this:
# w = Wallet.from_master_secret("correct horse battery staple", network=network)
# BIP32 wallets are children derived from a single master seed (you generated this with the instructions above)
# You can specify a child by an ID. For instance, for child_id=1:
# let's generate 5 wallets
addresses
=
[]
children
=
[]
# the payment addresses we'll generate from the seed
for
child_id
in
range
(
1
,
6
):
child
=
w
.
get_child
(
child_id
,
is_prime
=
True
,
as_private
=
True
)
addresses
.
insert
(
len
(
addresses
),
child
.
to_address
())
children
.
insert
(
len
(
children
),
child
)
six
.
print_
(
"Child No."
,
child_id
,
". Address="
+
child
.
to_address
(),
"PrivKey="
+
child
.
export_to_wif
())
# check the balance for these addresses using Block.io
all_addresses
=
','
.
join
(
str
(
x
)
for
x
in
addresses
)
response
=
block_io
.
get_address_balance
(
addresses
=
all_addresses
)
# the addresses parameter can be a comma-separated list of addresses here
# NOTE: Amounts deposited into addresses through Block.io green addresses will be immediately available
# even with 0 confirmations
six
.
print_
(
">> Total Balance in All Addresses:"
,
response
[
'data'
][
'available_balance'
],
network
)
for
addrinfo
in
response
[
'data'
][
'balances'
]:
six
.
print_
(
" >> Balances in"
,
addrinfo
[
'address'
])
six
.
print_
(
" >>> Available:"
,
addrinfo
[
'available_balance'
],
network
)
# either confirmed or from a green address
six
.
print_
(
" >>> Pending:"
,
addrinfo
[
'pending_received_balance'
],
network
)
# is neither from a green address, nor is it confirmed
# let's transfer some testnet coins into the first child address
amounts
=
"500.0"
# DOGETEST
response
=
block_io
.
withdraw
(
to_addresses
=
children
[
0
].
to_address
(),
amounts
=
amounts
)
six
.
print_
(
"* Depositing"
,
amounts
,
network
,
"into"
,
children
[
0
].
to_address
())
six
.
print_
(
">> Deposit Proof Transaction ID:"
,
response
[
'data'
][
'txid'
])
# you can view this on https://chain.so immediately
time
.
sleep
(
2
)
# let the transaction propagate on the network for a bit
# so far so good. Let's sweep the coins out of the first child, and into the second child
# NOTE: While you can specify the number of confirmations required for coins to be swept,
# please beware that deposits from green addresses will show as available in get_address_balance calls.
# This might cause confusion when the sweep_from_address call returns an error when sweeping amounts with
# confirmations > 0
six
.
print_
(
"* Sweeping all funds (confirmed and unconfirmed) from"
,
children
[
0
].
to_address
(),
"to"
,
children
[
1
].
to_address
())
response
=
block_io
.
sweep_from_address
(
from_address
=
children
[
0
].
to_address
(),
private_key
=
children
[
0
].
export_to_wif
(),
to_address
=
children
[
1
].
to_address
())
six
.
print_
(
">> Amount swept from"
,
children
[
0
].
to_address
(),
"into"
,
children
[
1
].
to_address
(),
"="
,
response
[
'data'
][
'amount_sent'
],
network
)
six
.
print_
(
">> Transaction ID:"
,
response
[
'data'
][
'txid'
])
# Note: the swept amount does not need to be confirmed. In the above case, the amount was not confirmed
# but was swept into the destination address immediately
# You can sweep only confirmed amounts if you wish by adding "confirmations=X" to the sweep_from_address call,
# where X is the number of confirmations
Back
|
FazBrowse Home
|
New Git URL