Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nucleo
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
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
blockchain
nucleo
Commits
a881b85e
Commit
a881b85e
authored
6 years ago
by
Robert Martin-Legene
Browse files
Options
Downloads
Plain Diff
Merge branch 'distillery' into 'master'
Distillery See merge request
!1
parents
fd5b8c3e
2bfbe2c7
No related branches found
No related tags found
1 merge request
!1
Distillery
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+3
-2
3 additions, 2 deletions
.gitignore
bin/MasterDistiller.js
+15
-3
15 additions, 3 deletions
bin/MasterDistiller.js
bin/libbfa.js
+43
-33
43 additions, 33 deletions
bin/libbfa.js
src/Sealers.sol
+8
-12
8 additions, 12 deletions
src/Sealers.sol
with
69 additions
and
50 deletions
.gitignore
+
3
−
2
View file @
a881b85e
...
@@ -2,5 +2,6 @@
...
@@ -2,5 +2,6 @@
*/status
*/status
cache
cache
*/cache
*/cache
network/node
network*/node
network/bootnode
network*/bootnode
network*/contracts/*
This diff is collapsed.
Click to expand it.
bin/MasterDistiller.js
+
15
−
3
View file @
a881b85e
#!/usr/bin/node
#!/usr/bin/node
"
use strict
"
const
Libbfa
=
require
(
process
.
env
.
BFAHOME
+
'
/bin/libbfa.js
'
);
const
Libbfa
=
require
(
process
.
env
.
BFAHOME
+
'
/bin/libbfa.js
'
);
const
rl
=
require
(
'
readline
'
).
createInterface
(
const
rl
=
require
(
'
readline
'
).
createInterface
(
{
input
:
process
.
stdin
,
output
:
process
.
stdout
}
{
input
:
process
.
stdin
,
output
:
process
.
stdout
}
...
@@ -11,7 +13,7 @@ var notation = [ 6 ];
...
@@ -11,7 +13,7 @@ var notation = [ 6 ];
function
init
()
function
init
()
{
{
notation
.
push
(
10
**
notation
[
0
]
);
notation
.
push
(
Math
.
pow
(
10
,
notation
[
0
]
)
);
switch
(
notation
[
0
]
)
{
switch
(
notation
[
0
]
)
{
case
6
:
case
6
:
notation
.
push
(
"
Mwei
"
);
notation
.
push
(
"
Mwei
"
);
...
@@ -20,11 +22,13 @@ function init()
...
@@ -20,11 +22,13 @@ function init()
notation
.
push
(
"
Gwei
"
);
notation
.
push
(
"
Gwei
"
);
break
;
break
;
default
:
default
:
notation
=
[
6
,
10
**
6
,
"
Mwei
"
];
notation
=
[
6
,
Math
.
pow
(
10
,
6
)
,
"
Mwei
"
];
}
}
bfa
=
new
Libbfa
();
bfa
=
new
Libbfa
();
web3
=
bfa
.
newweb3
();
web3
=
bfa
.
newweb3
();
Distillery
=
bfa
.
contract
(
web3
,
'
Distillery
'
);
Distillery
=
bfa
.
contract
(
web3
,
'
Distillery
'
);
if
(
undefined
==
Distillery
)
fatal
(
'
Can not initialise Distillery contact.
'
);
web3
.
eth
.
getBalance
(
Distillery
.
contractaddress
).
then
(
web3
.
eth
.
getBalance
(
Distillery
.
contractaddress
).
then
(
function
receivedOwnBalance
(
val
)
{
function
receivedOwnBalance
(
val
)
{
Distillery
.
contractbalance
=
val
;
Distillery
.
contractbalance
=
val
;
...
@@ -128,7 +132,7 @@ function editAccount( entry, pallet )
...
@@ -128,7 +132,7 @@ function editAccount( entry, pallet )
if
(
entry
==
"
x
"
)
if
(
entry
==
"
x
"
)
{
{
// trigger distribution
// trigger distribution
Distillery
.
methods
.
distribute
().
send
(
{
"
from
"
:
bfa
.
account
,
"
gas
"
:
1
000000
}
)
Distillery
.
methods
.
distribute
().
send
(
{
"
from
"
:
bfa
.
account
,
"
gas
"
:
4
000000
}
)
.
then
(
.
then
(
function
distOK
(
x
)
{
function
distOK
(
x
)
{
console
.
log
(
console
.
log
(
...
@@ -155,7 +159,15 @@ function editAccount( entry, pallet )
...
@@ -155,7 +159,15 @@ function editAccount( entry, pallet )
return
;
return
;
}
}
else
else
if
(
entry
==
""
)
{
// Do nothing, basically just update the display
return
;
}
else
{
bfa
.
fatal
(
"
I don't know what to do with
\"
"
+
entry
+
"
\"
.
"
);
bfa
.
fatal
(
"
I don't know what to do with
\"
"
+
entry
+
"
\"
.
"
);
}
rl
.
question
(
rl
.
question
(
"
Adjust the
"
"
Adjust the
"
+
notation
[
2
]
+
notation
[
2
]
...
...
This diff is collapsed.
Click to expand it.
bin/libbfa.js
+
43
−
33
View file @
a881b85e
// 20180724 Robert Martin-Legene <robert@nic.ar>
// 20180724 Robert Martin-Legene <robert@nic.ar>
"
use strict
"
module
.
exports
=
class
Libbfa
module
.
exports
=
class
Libbfa
{
{
constructor
()
{
constructor
()
{
this
.
fs
=
require
(
'
fs
'
);
this
.
fs
=
require
(
'
fs
'
);
this
.
Web3
=
require
(
'
web3
'
);
this
.
Web3
=
require
(
'
web3
'
);
//
//
// BFAHOME
// BFAHOME
if
(
undefined
==
process
.
env
.
BFAHOME
)
if
(
undefined
==
process
.
env
.
BFAHOME
)
fatal
(
"
$BFAHOME not set. Did you source bfa/bin/env ?
"
);
fatal
(
"
$BFAHOME not set. Did you source bfa/bin/env ?
"
);
// BFANETWORKID
// BFANETWORKID
this
.
home
=
process
.
env
.
BFAHOME
;
if
(
undefined
==
process
.
env
.
BFANETWORKID
)
if
(
undefined
==
process
.
env
.
BFANETWORKID
)
process
.
env
.
BFANETWORKID
=
47525974938
;
process
.
env
.
BFANETWORKID
=
47525974938
;
this
.
networkid
=
process
.
env
.
BFANETWORKID
;
// BFANETWORKDIR
// BFANETWORKDIR
if
(
undefined
==
process
.
env
.
BFANETWORKDIR
)
if
(
undefined
==
process
.
env
.
BFANETWORKDIR
)
process
.
env
.
BFANETWORKDIR
=
process
.
env
.
BFAHOME
+
'
/network
'
;
process
.
env
.
BFANETWORKDIR
=
process
.
env
.
BFAHOME
+
'
/network
'
;
this
.
networkdir
=
process
.
env
.
BFANETWORKDIR
;
// BFANODEDIR
// BFANODEDIR
if
(
undefined
==
process
.
env
.
BFANODEDIR
)
if
(
undefined
==
process
.
env
.
BFANODEDIR
)
process
.
env
.
BFANODEDIR
=
this
.
networkdir
+
"
/node
"
;
process
.
env
.
BFANODEDIR
=
this
.
networkdir
+
"
/node
"
;
this
.
nodedir
=
process
.
env
.
BFANODEDIR
;
// ACCOUNT
// ACCOUNT
if
(
undefined
==
process
.
env
.
BFAACCOUNT
)
if
(
undefined
==
process
.
env
.
BFAACCOUNT
)
{
{
var
files
=
new
Array
();
var
files
=
new
Array
();
this
.
fs
.
readdirSync
(
process
.
env
.
BFANODEDIR
+
'
/keystore
'
).
forEach
(
function
(
filename
)
{
if
(
this
.
fs
.
existsSync
(
process
.
env
.
BFANODEDIR
+
'
/keystore
'
)
)
if
(
filename
.
includes
(
'
--
'
)
)
{
files
.
push
(
filename
);
this
.
fs
.
readdirSync
(
process
.
env
.
BFANODEDIR
+
'
/keystore
'
).
forEach
(
function
(
filename
)
{
});
if
(
filename
.
includes
(
'
--
'
)
)
files
.
push
(
filename
);
});
}
// found none?
// found none?
if
(
files
.
length
==
0
)
if
(
files
.
length
>
0
)
fatal
(
"
Found no accounts in your keystore.
"
);
{
files
.
sort
();
files
.
sort
();
process
.
env
.
BFAACCOUNT
=
'
0x
'
+
files
[
0
].
replace
(
/^.*--/
,
''
);
process
.
env
.
BFAACCOUNT
=
'
0x
'
+
files
[
0
].
replace
(
/^.*--/
,
''
);
}
}
}
//
//
this
.
home
=
process
.
env
.
BFAHOME
;
this
.
netport
=
Number
.
parseInt
(
this
.
setfromfile
(
this
.
nodedir
+
'
/netport
'
,
30303
));
this
.
networkid
=
process
.
env
.
BFANETWORKID
;
this
.
rpcport
=
Number
.
parseInt
(
this
.
setfromfile
(
this
.
nodedir
+
'
/rpcport
'
,
8545
));
this
.
networkdir
=
process
.
env
.
BFANETWORKDIR
;
this
.
account
=
process
.
env
.
BFAACCOUNT
;
this
.
nodedir
=
process
.
env
.
BFANODEDIR
;
this
.
netport
=
Number
.
parseInt
(
this
.
setfromfile
(
this
.
nodedir
+
'
/netport
'
,
30303
);
this
.
rpcport
=
Number
.
parseInt
(
this
.
setfromfile
(
this
.
nodedir
+
'
/rpcport
'
,
8545
);
this
.
account
=
process
.
env
.
BFAACCOUNT
;
}
}
contract
(
w3
,
name
)
contract
(
w3
,
name
)
{
{
this
.
_networkdir
();
var
contractdir
=
[
this
.
networkdir
,
'
contracts
'
,
name
].
join
(
'
/
'
);
var
contractdir
=
[
this
.
networkdir
,
'
contracts
'
,
name
].
join
(
'
/
'
);
if
(
!
this
.
fs
.
existsSync
(
contractdir
)
)
var
contractaddress
=
this
.
fs
.
realpathSync
(
contractdir
).
replace
(
/^.*
\/
/
,
''
);
return
;
var
contractaddress
=
this
.
fs
.
realpathSync
(
contractdir
).
replace
(
/^.*
\/
/
,
''
);
if
(
undefined
==
contractaddress
)
if
(
undefined
==
contractaddress
)
return
;
return
;
var
abi
=
JSON
.
parse
(
var
abistr
=
this
.
fs
.
readFileSync
(
contractdir
+
'
/abi
'
).
toString
();
this
.
fs
.
readFileSync
(
contractdir
+
'
/abi
'
).
toString
()
if
(
undefined
==
abistr
)
);
return
;
var
abi
=
JSON
.
parse
(
abistr
);
if
(
undefined
==
abi
)
if
(
undefined
==
abi
)
return
;
return
;
var
c
=
new
w3
.
eth
.
Contract
(
abi
,
contractaddress
);
var
c
=
new
w3
.
eth
.
Contract
(
abi
,
contractaddress
);
c
.
abi
=
abi
;
c
.
abi
=
abi
;
c
.
contractaddress
=
contractaddress
;
c
.
contractaddress
=
contractaddress
;
return
c
;
return
c
;
}
}
...
@@ -68,9 +76,8 @@ module.exports = class Libbfa
...
@@ -68,9 +76,8 @@ module.exports = class Libbfa
newweb3
()
newweb3
()
{
{
this
.
_nodedir
();
var
provider
=
'
http://127.0.0.1:
'
+
this
.
rpcport
;
var
provider
=
'
http://127.0.0.1:
'
+
this
.
rpcport
;
var
w3
=
new
this
.
Web3
(
provider
);
var
w3
=
new
this
.
Web3
(
provider
);
w3
.
eth
.
extend
({
w3
.
eth
.
extend
({
//property: 'bfaclique',
//property: 'bfaclique',
methods
:
[{
methods
:
[{
...
@@ -79,6 +86,9 @@ module.exports = class Libbfa
...
@@ -79,6 +86,9 @@ module.exports = class Libbfa
params
:
0
params
:
0
}]
}]
});
});
if
(
undefined
!=
process
.
env
.
BFAACCOUNT
)
{
w3
.
eth
.
defaultAccount
=
this
.
account
;
}
return
w3
;
return
w3
;
}
}
isNumeric
(
n
)
{
isNumeric
(
n
)
{
...
@@ -91,7 +101,7 @@ module.exports = class Libbfa
...
@@ -91,7 +101,7 @@ module.exports = class Libbfa
setfromfile
(
filename
,
defval
)
setfromfile
(
filename
,
defval
)
{
{
if
(
this
.
fs
.
stat
Sync
(
filename
)
.
isFile
()
)
if
(
this
.
fs
.
exists
Sync
(
filename
)
)
return
this
.
fs
.
readFileSync
(
filename
);
return
this
.
fs
.
readFileSync
(
filename
);
return
defval
;
return
defval
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/Sealers.sol
+
8
−
12
View file @
a881b85e
...
@@ -13,16 +13,16 @@ contract Sealers {
...
@@ -13,16 +13,16 @@ contract Sealers {
struct Proposal {
struct Proposal {
address victim; // Whom are we voting about.
address victim; // Whom are we voting about.
uint votestart; // In which block did this vote begin?
uint votestart; // In which block did this vote begin?
bool
promotion; // true=promotion, false=demotion
bool promotion; // true=promotion, false=demotion
address[]
voters; // List of voters.
address[] voters; // List of voters.
}
}
address[] p
ublic
sealers;
address[] p
rivate
sealers;
Proposal[] p
ublic
sealerproposals;
Proposal[] p
rivate
sealerproposals;
event voteCast( address voter, address victim, bool promotionOrDemotion );
event voteCast( address voter, address victim, bool promotionOrDemotion );
event adminChange( address admin, bool promotionOrDemotion );
event adminChange( address admin, bool promotionOrDemotion );
constructor()
public
constructor() public
{
{
sealers.push( msg.sender );
sealers.push( msg.sender );
}
}
...
@@ -47,11 +47,6 @@ contract Sealers {
...
@@ -47,11 +47,6 @@ contract Sealers {
return ( _findAddressInList( sealers, subject ) > 0 );
return ( _findAddressInList( sealers, subject ) > 0 );
}
}
function requireSealer( address subject ) public view
{
require( isSealer(subject), "Not sealer" );
}
// Returns an index to the position of the needle inside haystack.
// Returns an index to the position of the needle inside haystack.
// Beware that:
// Beware that:
// 0 = not found.
// 0 = not found.
...
@@ -197,12 +192,13 @@ contract Sealers {
...
@@ -197,12 +192,13 @@ contract Sealers {
// Is already Sealer and want to promote him?
// Is already Sealer and want to promote him?
// Can't promote someone who is already a sealer.
// Can't promote someone who is already a sealer.
if ( isSealer(victim) && promotion )
bool victimSealer = isSealer( victim );
if ( victimSealer && promotion )
return false;
return false;
// Is not Sealer and want to demote him?
// Is not Sealer and want to demote him?
// Can't demote someone who is not a sealer.
// Can't demote someone who is not a sealer.
if ( !
isSealer(victim)
&& !promotion )
if ( !
victimSealer
&& !promotion )
return false;
return false;
// See if the voter is already in the list of voters for this [victim,promotion] tuple
// See if the voter is already in the list of voters for this [victim,promotion] tuple
...
...
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