Skip to content

Commit

Permalink
Merge pull request EOSIO#142 from enumivo/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
Enumivo authored May 23, 2018
2 parents 8d60fd5 + de9cc8f commit d961db0
Show file tree
Hide file tree
Showing 58 changed files with 1,490 additions and 683 deletions.
22 changes: 11 additions & 11 deletions Docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
FROM eosio/builder as builder
FROM enumivo/builder as builder
ARG branch=master

RUN git clone -b $branch https://github.com/enumivo/enumivo.git --recursive \
&& cd eos && echo "$branch:$(git rev-parse HEAD)" > /etc/eosio-version \
&& cd enumivo && echo "$branch:$(git rev-parse HEAD)" > /etc/enumivo-version \
&& cmake -H. -B"/tmp/build" -GNinja -DCMAKE_BUILD_TYPE=Release -DWASM_ROOT=/opt/wasm -DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/tmp/build -DSecp256k1_ROOT_DIR=/usr/local -DBUILD_MONGO_DB_PLUGIN=true \
&& cmake --build /tmp/build --target install && rm /tmp/build/bin/eosiocpp
&& cmake --build /tmp/build --target install && rm /tmp/build/bin/enumivocpp


FROM ubuntu:18.04

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install openssl && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/lib/* /usr/local/lib/
COPY --from=builder /tmp/build/bin /opt/eosio/bin
COPY --from=builder /tmp/build/bin /opt/enumivo/bin
COPY --from=builder /tmp/build/contracts /contracts
COPY --from=builder /eos/Docker/config.ini /
COPY --from=builder /etc/eosio-version /etc
COPY --from=builder /eos/Docker/nodeosd.sh /opt/eosio/bin/nodeosd.sh
ENV ENUMIVO_ROOT=/opt/eosio
RUN chmod +x /opt/eosio/bin/nodeosd.sh
COPY --from=builder /enumivo/Docker/config.ini /
COPY --from=builder /etc/enumivo-version /etc
COPY --from=builder /enumivo/Docker/enunoded.sh /opt/enumivo/bin/enunoded.sh
ENV ENUMIVO_ROOT=/opt/enumivo
RUN chmod +x /opt/enumivo/bin/enunoded.sh
ENV LD_LIBRARY_PATH /usr/local/lib
VOLUME /opt/eosio/bin/data-dir
ENV PATH /opt/eosio/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
VOLUME /opt/enumivo/bin/data-dir
ENV PATH /opt/enumivo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
2 changes: 1 addition & 1 deletion Docker/builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ubuntu:16.04

LABEL author="xiaobo <[email protected]>" maintainer="Xiaobo <[email protected]> Huang-Ming Huang <[email protected]>" version="0.1.1" \
description="This is a base image for building eosio/eos"
description="This is a base image for building enumivo/enumivo"

RUN echo 'APT::Install-Recommends 0;' >> /etc/apt/apt.conf.d/01norecommends \
&& echo 'APT::Install-Suggests 0;' >> /etc/apt/apt.conf.d/01norecommends \
Expand Down
24 changes: 12 additions & 12 deletions Docker/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
FROM eosio/builder
FROM enumivo/builder
ARG branch=master

RUN git clone -b $branch https://github.com/EOSIO/eos.git --recursive \
&& cd eos && echo "$branch:$(git rev-parse HEAD)" > /etc/eosio-version \
&& cmake -H. -B"/opt/eosio" -GNinja -DCMAKE_BUILD_TYPE=Release -DWASM_ROOT=/opt/wasm -DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/opt/eosio -DSecp256k1_ROOT_DIR=/usr/local -DBUILD_MONGO_DB_PLUGIN=true \
&& cmake --build /opt/eosio --target install \
&& mv /eos/Docker/config.ini / && mv /opt/eosio/contracts /contracts && mv /eos/Docker/nodeosd.sh /opt/eosio/bin/nodeosd.sh \
&& rm -rf /eos
RUN git clone -b $branch https://github.com/enumivo/enumivo.git --recursive \
&& cd enumivo && echo "$branch:$(git rev-parse HEAD)" > /etc/enumivo-version \
&& cmake -H. -B"/opt/enumivo" -GNinja -DCMAKE_BUILD_TYPE=Release -DWASM_ROOT=/opt/wasm -DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/opt/enumivo -DSecp256k1_ROOT_DIR=/usr/local -DBUILD_MONGO_DB_PLUGIN=true \
&& cmake --build /opt/enumivo --target install \
&& mv /enumivo/Docker/config.ini / && mv /opt/enumivo/contracts /contracts && mv /enumivo/Docker/enunoded.sh /opt/enumivo/bin/enunoded.sh \
&& rm -rf /enumivo

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install openssl && rm -rf /var/lib/apt/lists/*
ENV EOSIO_ROOT=/opt/eosio
RUN chmod +x /opt/eosio/bin/nodeosd.sh
ENV ENUMIVO_ROOT=/opt/enumivo
RUN chmod +x /opt/enumivo/bin/enunoded.sh
ENV LD_LIBRARY_PATH /usr/local/lib
VOLUME /opt/eosio/bin/data-dir
ENV PATH /opt/eosio/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
VOLUME /opt/enumivo/bin/data-dir
ENV PATH /opt/enumivo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places.
# The default value is: My Project.

PROJECT_NAME = "Eos"
PROJECT_NAME = "Enumivo"

# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
Expand Down
6 changes: 4 additions & 2 deletions contracts/enumivo.coin/enumivo.coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void token::issue( account_name to, asset quantity, string memo )
{
auto sym = quantity.symbol;
enumivo_assert( sym.is_valid(), "invalid symbol name" );
enumivo_assert( memo.size() <= 256, "memo has more than 256 bytes" );

auto sym_name = sym.name();
stats statstable( _self, sym_name );
Expand Down Expand Up @@ -61,7 +62,7 @@ void token::issue( account_name to, asset quantity, string memo )
void token::transfer( account_name from,
account_name to,
asset quantity,
string /*memo*/ )
string memo )
{
enumivo_assert( from != to, "cannot transfer to self" );
require_auth( from );
Expand All @@ -76,6 +77,7 @@ void token::transfer( account_name from,
enumivo_assert( quantity.is_valid(), "invalid quantity" );
enumivo_assert( quantity.amount > 0, "must transfer positive quantity" );
enumivo_assert( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );
enumivo_assert( memo.size() <= 256, "memo has more than 256 bytes" );


sub_balance( from, quantity, st );
Expand All @@ -85,7 +87,7 @@ void token::transfer( account_name from,
void token::sub_balance( account_name owner, asset value, const currency_stats& st ) {
accounts from_acnts( _self, owner );

const auto& from = from_acnts.get( value.symbol.name() );
const auto& from = from_acnts.get( value.symbol.name(), "no balance object found" );
enumivo_assert( from.balance.amount >= value.amount, "overdrawn balance" );


Expand Down
2 changes: 1 addition & 1 deletion contracts/enumivo.msig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Create a proposal

Storage changes are billed to 'proposer'

Aprrove a proposal
Approve a proposal
## enumivo.msig::approve proposer proposal_name level
- **proposer** account proposing a transaction
- **proposal_name** name of the proposal
Expand Down
34 changes: 0 additions & 34 deletions contracts/enumivo.system/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,40 +81,6 @@ namespace enumivosystem {
typedef enumivo::multi_index< N(refunds), refund_request> refunds_table;


/**
* Called after a new account is created. This code enforces resource-limits rules
* for new accounts as well as new account naming conventions.
*
* 1. accounts cannot contain '.' symbols which forces all acccounts to be 12
* characters long without '.' until a future account auction process is implemented
* which prevents name squatting.
*
* 2. new accounts must stake a minimal number of tokens (as set in system parameters)
* therefore, this method will execute an inline buyram from receiver for newacnt in
* an amount equal to the current new account creation fee.
*/
void native::newaccount( account_name creator,
account_name newact
/* no need to parse authorites
const authority& owner,
const authority& active*/ ) {
auto name_str = enumivo::name{newact}.to_string();

enumivo_assert( name_str.size() == 12 || creator == N(enumivo), "account names must be 12 chars long" );
enumivo_assert( name_str.find_first_of('.') == std::string::npos || creator == N(enumivo), "account names cannot contain '.' character");

user_resources_table userres( _self, newact);

userres.emplace( newact, [&]( auto& res ) {
res.owner = newact;
});

set_resource_limits( newact,
0,// r->ram_bytes,
0, 0 );
// r->net_weight.amount,
// r->cpu_weight.amount );
}

/**
* This action will buy an exact amount of ram and bill the payer the current market price.
Expand Down
16 changes: 15 additions & 1 deletion contracts/enumivo.system/enumivo.system.abi
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
{"name":"key", "type":"public_key"},
{"name":"weight", "type":"weight_type"}
]
},{
"name": "bidname",
"base": "",
"fields": [
{"name":"bidder", "type":"account_name"},
{"name":"newname", "type":"account_name"},
{"name":"bid", "type":"asset"}
]
},{
"name": "permission_level_weight",
"base": "",
Expand Down Expand Up @@ -254,8 +262,10 @@
{"name":"savings", "type":"int64"},
{"name":"total_unpaid_blocks", "type":"uint32"},
{"name":"total_activated_stake", "type":"int64"},
{"name":"thresh_activated_stake_time", "type":"uint64"},
{"name":"last_producer_schedule_id", "type":"checksum160"},
{"name":"total_producer_vote_weight", "type":"float64"}
{"name":"total_producer_vote_weight", "type":"float64"},
{"name":"last_name_close", "type":"block_timestamp_type"}
]
},{
"name": "producer_info",
Expand Down Expand Up @@ -439,6 +449,10 @@
"name": "setram",
"type": "setram",
"ricardian_contract": ""
},{
"name": "bidname",
"type": "bidname",
"ricardian_contract": ""
},{
"name": "unregprod",
"type": "unregprod",
Expand Down
87 changes: 87 additions & 0 deletions contracts/enumivo.system/enumivo.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,92 @@ namespace enumivosystem {
set_privileged( account, ispriv );
}

void system_contract::bidname( account_name bidder, account_name newname, asset bid ) {
require_auth( bidder );
enumivo_assert( enumivo::name_suffix(newname) == newname, "you can only bid on top-level suffix" );
enumivo_assert( !is_account( newname ), "account already exists" );
enumivo_assert( bid.symbol == asset().symbol, "asset must be system token" );
enumivo_assert( bid.amount > 0, "insufficient bid" );

INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {bidder,N(active)},
{ bidder, N(enumivo), bid, std::string("bid name ")+(name{newname}).to_string() } );

name_bid_table bids(_self,_self);
print( name{bidder}, " bid ", bid, " on ", name{newname}, "\n" );
auto current = bids.find( newname );
if( current == bids.end() ) {
bids.emplace( bidder, [&]( auto& b ) {
b.newname = newname;
b.high_bidder = bidder;
b.high_bid = bid.amount;
b.last_bid_time = current_time();
});
} else {
enumivo_assert( current->high_bid > 0, "this auction has already closed" );
enumivo_assert( bid.amount - current->high_bid > (current->high_bid / 10), "must increase bid by 10%" );
enumivo_assert( current->high_bidder != bidder, "account is already high bidder" );

INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enumivo.coin), {N(enumivo),N(active)},
{ N(enumivo), current->high_bidder, asset(current->high_bid),
std::string("refund bid on name ")+(name{newname}).to_string() } );

bids.modify( current, bidder, [&]( auto& b ) {
b.high_bidder = bidder;
b.high_bid = bid.amount;
b.last_bid_time = current_time();
});
}
}

/**
* Called after a new account is created. This code enforces resource-limits rules
* for new accounts as well as new account naming conventions.
*
* 1. accounts cannot contain '.' symbols which forces all acccounts to be 12
* characters long without '.' until a future account auction process is implemented
* which prevents name squatting.
*
* 2. new accounts must stake a minimal number of tokens (as set in system parameters)
* therefore, this method will execute an inline buyram from receiver for newacnt in
* an amount equal to the current new account creation fee.
*/
void native::newaccount( account_name creator,
account_name newact
/* no need to parse authorites
const authority& owner,
const authority& active*/ ) {

if( creator != _self ) {
auto tmp = newact;
bool has_dot = false;
for( uint32_t i = 0; i < 13; ++i ) {
has_dot |= (tmp >> 59);
tmp <<= 5;
}
auto suffix = enumivo::name_suffix(newact);
if( has_dot ) {
if( suffix == newact ) {
name_bid_table bids(_self,_self);
auto current = bids.find( newact );
enumivo_assert( current != bids.end(), "no active bid for name" );
enumivo_assert( current->high_bidder == creator, "only high bidder can claim" );
enumivo_assert( current->high_bid < 0, "auction for name is not closed yet" );
bids.erase( current );
} else {
enumivo_assert( creator == suffix, "only suffix may create this account" );
}
}
}

user_resources_table userres( _self, newact);

userres.emplace( newact, [&]( auto& res ) {
res.owner = newact;
});

set_resource_limits( newact, 0, 0, 0 );
}

} /// enumivo.system


Expand All @@ -93,5 +179,6 @@ ENUMIVO_ABI( enumivosystem::system_contract,
(onblock)
(newaccount)(updateauth)(deleteauth)(linkauth)(unlinkauth)(postrecovery)(passrecovery)(vetorecovery)(onerror)(canceldelay)
//this file
(bidname)
(setpriv)
)
23 changes: 22 additions & 1 deletion contracts/enumivo.system/enumivo.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ namespace enumivosystem {
ENULIB_SERIALIZE_DERIVED( enumivo_parameters, enumivo::blockchain_parameters, (max_ram_size) )
};

struct name_bid {
account_name newname;
account_name high_bidder;
int64_t high_bid = 0; ///< negative high_bid == closed auction waiting to be claimed
uint64_t last_bid_time = 0;

auto primary_key()const { return newname; }
uint64_t by_high_bid()const { return -high_bid; }
};

typedef enumivo::multi_index< N(namebids), name_bid,
indexed_by<N(highbid), const_mem_fun<name_bid, uint64_t, &name_bid::by_high_bid> >
> name_bid_table;




struct enumivo_global_state : enumivo_parameters {
uint64_t free_ram()const { return max_ram_size - total_ram_bytes_reserved; }

Expand All @@ -40,14 +57,17 @@ namespace enumivosystem {
int64_t savings = 0;
uint32_t total_unpaid_blocks = 0; /// all blocks which have been produced but not paid
int64_t total_activated_stake = 0;
uint64_t thresh_activated_stake_time = 0;
checksum160 last_producer_schedule_id;
double total_producer_vote_weight = 0; /// the sum of all producer votes
block_timestamp last_name_close;

// explicit serialization macro is not necessary, used here only to improve compilation time
ENULIB_SERIALIZE_DERIVED( enumivo_global_state, enumivo_parameters, (total_ram_bytes_reserved)(total_ram_stake)
(last_producer_schedule_update)
(last_pervote_bucket_fill)
(pervote_bucket)(perblock_bucket)(savings)(total_unpaid_blocks)(total_activated_stake)(last_producer_schedule_id)(total_producer_vote_weight) )
(pervote_bucket)(perblock_bucket)(savings)(total_unpaid_blocks)(total_activated_stake)(thresh_activated_stake_time)
(last_producer_schedule_id)(total_producer_vote_weight)(last_name_close) )
};

struct producer_info {
Expand Down Expand Up @@ -200,6 +220,7 @@ namespace enumivosystem {

void setpriv( account_name account, uint8_t ispriv );

void bidname( account_name bidder, account_name newname, asset bid );
private:
void update_elected_producers( block_timestamp timestamp );

Expand Down
Loading

0 comments on commit d961db0

Please sign in to comment.