mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
Cleanup
This commit is contained in:
parent
6f3857a8c8
commit
013c435f92
1 changed files with 12 additions and 29 deletions
|
|
@ -3,12 +3,15 @@
|
||||||
contract Swarm
|
contract Swarm
|
||||||
{
|
{
|
||||||
|
|
||||||
enum Status {Clean, Suspect, Guilty}
|
uint constant GRACE = 50; // grace period for lost information in blocks
|
||||||
|
|
||||||
|
bytes32 constant MAGIC_NUMBER = "Swarm receipt";
|
||||||
|
|
||||||
struct Bee {
|
struct Bee {
|
||||||
uint deposit;
|
uint deposit; // amount deposited by this member
|
||||||
uint expiry;
|
uint expiry; // expiration time of the deposit
|
||||||
Status status;
|
uint256 missing; // member accused of losing this swarm chunk
|
||||||
|
uint deadline; // block number before which chunk must be presented
|
||||||
}
|
}
|
||||||
|
|
||||||
mapping (address => Bee) swarm;
|
mapping (address => Bee) swarm;
|
||||||
|
|
@ -27,7 +30,7 @@ contract Swarm
|
||||||
/// @param time term of Swarm membership in seconds from now.
|
/// @param time term of Swarm membership in seconds from now.
|
||||||
function signup(uint time) {
|
function signup(uint time) {
|
||||||
Bee b = swarm[msg.sender];
|
Bee b = swarm[msg.sender];
|
||||||
if(b.status == Status.Clean && now + time > now) {
|
if(isClean(msg.sender) && now + time > now) {
|
||||||
b.expiry = max(b.expiry, now + time);
|
b.expiry = max(b.expiry, now + time);
|
||||||
}
|
}
|
||||||
b.deposit += msg.value;
|
b.deposit += msg.value;
|
||||||
|
|
@ -38,7 +41,7 @@ contract Swarm
|
||||||
/// @dev Only allowed with clean status and expired term.
|
/// @dev Only allowed with clean status and expired term.
|
||||||
function withdraw() {
|
function withdraw() {
|
||||||
Bee b = swarm[msg.sender];
|
Bee b = swarm[msg.sender];
|
||||||
if(now > b.expiry && b.status == Status.Clean) {
|
if(now > b.expiry && isClean(msg.sender)) {
|
||||||
msg.sender.send(b.deposit);
|
msg.sender.send(b.deposit);
|
||||||
b.deposit = 0;
|
b.deposit = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -60,34 +63,14 @@ contract Swarm
|
||||||
/// @notice Determine clean status of address `addr`.
|
/// @notice Determine clean status of address `addr`.
|
||||||
/// No change in state.
|
/// No change in state.
|
||||||
///
|
///
|
||||||
|
/// @dev Defined as no signed receipt has been presented for missing chunk.
|
||||||
|
///
|
||||||
/// @param addr queried address.
|
/// @param addr queried address.
|
||||||
///
|
///
|
||||||
/// @return true if status is "Clean".
|
/// @return true if status is "Clean".
|
||||||
function isClean(address addr) returns (bool s) {
|
function isClean(address addr) returns (bool s) {
|
||||||
Bee b = swarm[addr];
|
Bee b = swarm[addr];
|
||||||
return b.status == Status.Clean;
|
return b.missing == 0; // nothing they signed is missing
|
||||||
}
|
|
||||||
|
|
||||||
/// @notice Determine suspect status of address `addr`.
|
|
||||||
/// No change in state.
|
|
||||||
///
|
|
||||||
/// @param addr queried address.
|
|
||||||
///
|
|
||||||
/// @return true if status is "Suspect".
|
|
||||||
function isSuspect(address addr) returns (bool s) {
|
|
||||||
Bee b = swarm[addr];
|
|
||||||
return b.status == Status.Suspect;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @notice Determine guilty status of address `addr`.
|
|
||||||
/// No change in state.
|
|
||||||
///
|
|
||||||
/// @param addr queried address.
|
|
||||||
///
|
|
||||||
/// @return true if status is "Guilty".
|
|
||||||
function isGuilty(address addr) returns (bool s) {
|
|
||||||
Bee b = swarm[addr];
|
|
||||||
return b.status == Status.Guilty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice Determine if the deposit for `addr` is unaccessible until `time`.
|
/// @notice Determine if the deposit for `addr` is unaccessible until `time`.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue