Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nucleo
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nelson Lombardo
nucleo
Commits
615b3d66
Commit
615b3d66
authored
4 years ago
by
Robert Martin-Legene
Browse files
Options
Downloads
Patches
Plain Diff
Mejoras en MasterDistiller
parent
5cdfb88f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/MasterDistiller.py
+86
-53
86 additions, 53 deletions
bin/MasterDistiller.py
with
86 additions
and
53 deletions
bin/MasterDistiller.py
+
86
−
53
View file @
615b3d66
...
@@ -2,13 +2,16 @@
...
@@ -2,13 +2,16 @@
import
sys
import
sys
import
os
import
os
if
not
os
.
environ
.
get
(
'
BFAHOME
'
):
print
(
"
$BFAHOME not set. Did you source bfa/bin/env ?
"
,
file
=
sys
.
stderr
)
exit
(
1
)
import
json
import
json
import
re
import
re
import
decimal
import
decimal
os
.
environ
[
'
BFAHOME
'
]
=
'
/home/bfa/bfa
'
import
argparse
sys
.
path
.
append
(
os
.
path
.
join
(
os
.
environ
[
'
BFAHOME
'
],
'
bin
'
))
sys
.
path
.
append
(
os
.
path
.
join
(
os
.
environ
[
'
BFAHOME
'
],
'
bin
'
))
import
libbfa
import
libbfa
bfa
=
libbfa
.
Bfa
(
'
prod
'
)
bfa
=
None
notation
=
dict
()
notation
=
dict
()
janitor
=
None
janitor
=
None
distillery
=
None
distillery
=
None
...
@@ -16,7 +19,15 @@ distillery = None
...
@@ -16,7 +19,15 @@ distillery = None
def
distbalance
()
->
int
:
def
distbalance
()
->
int
:
return
bfa
.
w3
.
eth
.
getBalance
(
distillery
.
address
)
return
bfa
.
w3
.
eth
.
getBalance
(
distillery
.
address
)
def
editAccount
(
entry
:
str
,
pallet
:
list
):
def
distribute
():
# trigger distribution
beforeBal
=
distbalance
()
rcpt
=
janitor
.
transact
(
web3
=
bfa
.
w3
,
function
=
distillery
.
functions
.
distribute
,
extragas
=
4000000
)
print
(
'
Distribute returned succesfully in block# {} using {} gas.
'
.
format
(
rcpt
.
blockNumber
,
rcpt
.
gasUsed
))
afterBal
=
distbalance
()
print
(
'
Distributed {} {}.
'
.
format
(
int
(
decimal
.
Decimal
(
beforeBal
-
afterBal
)
/
notation
[
'
num
'
]),
notation
[
'
name
'
]))
def
editAccount
(
entry
:
str
,
beneflist
:
list
):
acct
=
None
acct
=
None
# is it an account address?
# is it an account address?
if
entry
==
''
:
if
entry
==
''
:
...
@@ -25,15 +36,10 @@ def editAccount(entry:str, pallet:list):
...
@@ -25,15 +36,10 @@ def editAccount(entry:str, pallet:list):
elif
re
.
search
(
'
^0x[0-9a-fA-F]{40}$
'
,
entry
):
elif
re
.
search
(
'
^0x[0-9a-fA-F]{40}$
'
,
entry
):
acct
=
entry
.
lower
()
acct
=
entry
.
lower
()
# is it a known account address?
# is it a known account address?
elif
re
.
search
(
'
^[0-9]+$
'
,
entry
)
and
int
(
entry
)
<
len
(
palle
t
):
elif
re
.
search
(
'
^[0-9]+$
'
,
entry
)
and
int
(
entry
)
<
len
(
beneflis
t
):
acct
=
palle
t
[
int
(
entry
)].
addr
acct
=
beneflis
t
[
int
(
entry
)].
addr
elif
entry
==
'
x
'
:
elif
entry
==
'
x
'
:
# trigger distribution
distribute
()
beforeBal
=
distbalance
()
rcpt
=
janitor
.
transact
(
web3
=
bfa
.
w3
,
function
=
distillery
.
functions
.
distribute
,
extragas
=
4000000
)
print
(
'
Distribute returned succesfully in block# {} using {} gas.
'
.
format
(
rcpt
.
blockNumber
,
rcpt
.
gasUsed
))
afterBal
=
distbalance
()
print
(
'
Distributed {} {}.
'
.
format
(
int
(
decimal
.
Decimal
(
beforeBal
-
afterBal
)
/
notation
[
'
num
'
]),
notation
[
'
name
'
]))
else
:
else
:
print
(
'
I do not know what to do with
"
{}
"
.
'
.
format
(
entry
),
file
=
sys
.
stderr
)
print
(
'
I do not know what to do with
"
{}
"
.
'
.
format
(
entry
),
file
=
sys
.
stderr
)
exit
(
1
)
exit
(
1
)
...
@@ -51,27 +57,27 @@ def editAccount(entry:str, pallet:list):
...
@@ -51,27 +57,27 @@ def editAccount(entry:str, pallet:list):
else
:
else
:
print
(
'
Update failed.
'
)
print
(
'
Update failed.
'
)
def
get
Pallet
()
->
list
:
def
get
Beneficiaries
()
->
list
:
count
=
distillery
.
functions
.
numberOfBeneficiaries
().
call
()
count
=
distillery
.
functions
.
numberOfBeneficiaries
().
call
()
pallet
=
list
()
beneflist
=
list
()
# Fetch addresses from the list in the contract.
# Fetch addresses from the list in the contract.
for
i
in
range
(
count
):
for
i
in
range
(
count
):
print
(
"
Indexing accounts ({}/{})...
\x1B
[J
\r
"
.
format
(
i
,
count
),
end
=
''
)
print
(
"
Indexing accounts ({}/{})...
\x1B
[J
\r
"
.
format
(
i
,
count
),
end
=
''
)
(
addr
,
topuplimit
)
=
distillery
.
functions
.
atPosition
(
i
).
call
()
(
addr
,
topuplimit
)
=
distillery
.
functions
.
atPosition
(
i
).
call
()
bal
=
bfa
.
w3
.
eth
.
getBalance
(
addr
)
bal
=
bfa
.
w3
.
eth
.
getBalance
(
addr
)
palle
t
.
append
(
{
"
addr
"
:
addr
,
"
topuplimit
"
:
topuplimit
,
"
balance
"
:
bal
}
)
beneflis
t
.
append
(
{
"
addr
"
:
addr
,
"
topuplimit
"
:
topuplimit
,
"
balance
"
:
bal
}
)
print
(
"
\r\x1B
[J
"
.
format
(
i
,
count
),
end
=
''
)
print
(
"
\r\x1B
[J
"
.
format
(
i
,
count
),
end
=
''
)
s
=
lambda
x
:
x
[
'
addr
'
].
lower
()
s
=
lambda
x
:
x
[
'
addr
'
].
lower
()
palle
t
.
sort
(
key
=
s
)
beneflis
t
.
sort
(
key
=
s
)
return
palle
t
return
beneflis
t
def
print
Pallet
(
palle
t
:
list
):
def
print
_beneficiary_list
(
beneflis
t
:
list
):
# find the length of the longest number-string
# find the length of the longest number-string
longestlimit
=
1
longestlimit
=
1
longestbalance
=
1
longestbalance
=
1
numformat
=
notation
[
'
strformat
'
].
format
numformat
=
notation
[
'
strformat
'
].
format
for
i
in
range
(
len
(
palle
t
)):
for
i
in
range
(
len
(
beneflis
t
)):
entry
=
palle
t
[
i
]
entry
=
beneflis
t
[
i
]
numstr
=
numformat
(
decimal
.
Decimal
(
entry
[
'
topuplimit
'
])
/
notation
[
'
num
'
])
numstr
=
numformat
(
decimal
.
Decimal
(
entry
[
'
topuplimit
'
])
/
notation
[
'
num
'
])
thislen
=
len
(
numstr
)
thislen
=
len
(
numstr
)
if
thislen
>
longestlimit
:
if
thislen
>
longestlimit
:
...
@@ -81,9 +87,18 @@ def printPallet(pallet:list):
...
@@ -81,9 +87,18 @@ def printPallet(pallet:list):
if
thislen
>
longestbalance
:
if
thislen
>
longestbalance
:
longestbalance
=
thislen
longestbalance
=
thislen
# print them all
# print them all
theformat
=
'
{:
'
+
str
(
len
(
str
(
len
(
pallet
)
-
1
)))
+
'
}: {} fills to {:
'
+
str
(
longestlimit
)
+
'
.
'
+
str
(
notation
[
'
potency
'
])
+
'
f} {} (has {:
'
+
str
(
longestbalance
)
+
'
.
'
+
str
(
notation
[
'
potency
'
])
+
'
f}).
'
theformat
=
'
{:
'
+
str
(
len
(
str
(
len
(
beneflist
)
-
1
)))
+
\
for
i
in
range
(
len
(
pallet
)):
'
}: {} fills to {:
'
+
\
entry
=
pallet
[
i
]
str
(
longestlimit
)
+
\
'
.
'
+
\
str
(
notation
[
'
potency
'
])
+
\
'
f} {} (has {:
'
+
\
str
(
longestbalance
)
+
\
'
.
'
+
\
str
(
notation
[
'
potency
'
])
+
\
'
f}).
'
for
i
in
range
(
len
(
beneflist
)):
entry
=
beneflist
[
i
]
numstr
=
numformat
(
decimal
.
Decimal
(
entry
[
'
topuplimit
'
])
/
notation
[
'
num
'
])
numstr
=
numformat
(
decimal
.
Decimal
(
entry
[
'
topuplimit
'
])
/
notation
[
'
num
'
])
while
len
(
numstr
)
<
longestlimit
:
while
len
(
numstr
)
<
longestlimit
:
numstr
=
'
'
+
numstr
numstr
=
'
'
+
numstr
...
@@ -96,36 +111,29 @@ def printPallet(pallet:list):
...
@@ -96,36 +111,29 @@ def printPallet(pallet:list):
))
))
def
overview
():
def
overview
():
print
(
"
The contract
'
s account ({}) has {} {}.
"
.
format
(
while
True
:
distillery
.
address
,
print
(
"
The contract
'
s account ({}) has {} {}.
"
.
format
(
int
(
decimal
.
Decimal
(
distbalance
())
/
notation
[
'
num
'
]),
distillery
.
address
,
notation
[
'
name
'
]
int
(
decimal
.
Decimal
(
distbalance
())
/
notation
[
'
num
'
]),
))
notation
[
'
name
'
]
pallet
=
getPallet
()
))
printPallet
(
pallet
)
beneflist
=
getBeneficiaries
()
answer
=
input
(
"
\n
[ Q=quit x=distribute ]
\n
Which account to edit (enter index number or full account number)?:
"
)
print_beneficiary_list
(
beneflist
)
if
answer
is
None
or
answer
.
upper
()
==
'
Q
'
:
answer
=
input
(
"
\n
[ Q=quit x=distribute ]
\n
"
+
exit
(
0
)
"
Which account to edit (enter index number or full account number)?:
"
)
editAccount
(
answer
,
pallet
)
if
answer
is
None
or
answer
.
upper
()
==
'
Q
'
:
exit
(
0
)
editAccount
(
answer
,
beneflist
)
def
init
():
def
init
(
**
kwargs
):
global
janitor
,
notation
,
distillery
;
global
janitor
,
notation
,
distillery
,
bfa
;
janitor
=
libbfa
.
Account
(
'
0xd15dd6dbbe722b451156a013c01b29d91e23c3d6
'
)
bfa
=
libbfa
.
Bfa
(
kwargs
.
get
(
'
uri
'
))
table
=
dict
([
janitor
=
libbfa
.
Account
(
kwargs
.
get
(
'
sender_addr
'
))
(
6
,
'
Mwei
'
),
table
=
(
'
Kwei
'
,
'
Mwei
'
,
'
Gwei
'
,
'
micro
'
,
'
finney
'
,
'
ether
'
,
(
9
,
'
Gwei
'
),
'
kether
'
,
'
grand
'
,
'
mether
'
,
'
gether
'
,
'
tether
'
)
(
12
,
'
micro
'
),
(
15
,
'
finney
'
),
(
18
,
'
ether
'
),
(
21
,
'
kether
'
),
(
24
,
'
grand
'
),
(
27
,
'
mether
'
),
(
30
,
'
gether
'
),
(
33
,
'
tether
'
),
])
potency
=
18
potency
=
18
notation
[
'
potency
'
]
=
potency
notation
[
'
potency
'
]
=
potency
notation
[
'
name
'
]
=
table
[
potency
]
notation
[
'
name
'
]
=
table
[
int
(
potency
/
3
-
1
)
]
notation
[
'
num
'
]
=
pow
(
10
,
potency
)
notation
[
'
num
'
]
=
pow
(
10
,
potency
)
notation
[
'
strformat
'
]
=
'
{
'
+
'
:.{}f
'
.
format
(
potency
)
+
'
}
'
notation
[
'
strformat
'
]
=
'
{
'
+
'
:.{}f
'
.
format
(
potency
)
+
'
}
'
abifile
=
''
abifile
=
''
...
@@ -137,9 +145,34 @@ def init():
...
@@ -137,9 +145,34 @@ def init():
with
open
(
abifile
,
'
rt
'
,
encoding
=
'
utf-8
'
)
as
infile
:
with
open
(
abifile
,
'
rt
'
,
encoding
=
'
utf-8
'
)
as
infile
:
abitxt
=
infile
.
read
()
abitxt
=
infile
.
read
()
abi
=
json
.
loads
(
abitxt
)
abi
=
json
.
loads
(
abitxt
)
addr
=
'
0xECB6aFF6e38dC58C4d9AaE2F7927A282bcB77AC2
'
distillery
=
bfa
.
w3
.
eth
.
contract
(
address
=
kwargs
.
get
(
'
sc_addr
'
),
abi
=
abi
)
distillery
=
bfa
.
w3
.
eth
.
contract
(
address
=
addr
,
abi
=
abi
)
init
()
parser
=
argparse
.
ArgumentParser
(
description
=
"
Command interface for BFA2018 distillery1.
"
)
while
True
:
parser
.
add_argument
(
'
--uri
'
,
metavar
=
'
URI
'
,
nargs
=
1
,
default
=
'
prod
'
,
help
=
'
URI of node to connect to.
'
)
parser
.
add_argument
(
'
--sender-addr
'
,
metavar
=
'
ADDR
'
,
nargs
=
1
,
default
=
'
0xd15dd6dbbe722b451156a013c01b29d91e23c3d6
'
,
help
=
'
Address of controller of the smart contract.
'
)
parser
.
add_argument
(
'
--sc-addr
'
,
metavar
=
'
ADDR
'
,
nargs
=
1
,
default
=
'
0xECB6aFF6e38dC58C4d9AaE2F7927A282bcB77AC2
'
,
help
=
'
Address of smart contract.
'
)
parser
.
add_argument
(
'
--distribute
'
,
action
=
'
store_true
'
,
help
=
'
Run distribute once and then exit.
'
)
parsed
=
parser
.
parse_args
()
init
(
uri
=
parsed
.
uri
,
sc_addr
=
parsed
.
sc_addr
,
sender_addr
=
parsed
.
sender_addr
)
if
parsed
.
distribute
:
distribute
()
else
:
overview
()
overview
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment