EOS - Developer Log, Stardate 2017 .07.7

in #eos7 years ago


This we tend to tend toek we tend to created nice strides toward process the look of Greek deity and method the developer API. particularly we have got celebrated a programming model that need to modify similarity whereas increasing straightforward use and clarity of the code.


Updated Example Contracts

Those who ar following github may have detected that we have got began to integrate kind of example contracts to examine our style and guarantee we'll cowl the desired use cases.


This is what a simple currency contract appears like today:


/**

* Transfer desires that the sender and receiver be the first a pair of

* accounts notified that the sender has provided authorization.

*/

struct Transfer amount = 0;

char note[]; /// further bytes unit of measurement treated as a memoranda and neglected by logic

};


struct CurrencyAccount zero ):balance(b)


uint64_t balance = 0;


/** used as slightly to Db::store to tell it that table name among this 

* scope to use. info is hold on in tables below a structure like

*

* scope/code/table/key->value

*

* throughout this case the "singleton" table is meant for constant named keys that

* sit down with a unique object kind. User account balances ar hold on here:

* username/currency/singleton/account -> CurrencyAccount

*/ 

static Name tableId() 

};



void apply_currency_transfer() Db::get( transfer.to, NAME("account"), to_account );


assert( from_account.balance >= transfer.amount, "insufficient funds" );

from_account.balance -= transfer.amount;

to_account.balance += transfer.amount;


if( from_account.balance == zero )

Db::remove<CurrencyAccount>( transfer.from, NAME("account") );

else

Db::store( transfer.from, NAME("account"), from_account ); 


Db::store( transfer.to, NAME("account"), to_account ); 

">


There are several notable aspects about this currency contract:


it looks like normal sequential code

but it can transfer among two pairs of users in parallel

What does this mean? It means that while Alice is transferring to Bob, Sam can be transferring to Jill. The performance of this currency contract is no longer limited by the single threaded performance constraints of prior currency contracts.


Start of Exchange Contract

We have conjointly enforced a straightforward exchange contract that accepts deposits and withdraws from 2 totally different currency contracts:


struct Account come back !(a|b|open_orders); }

/**

* Balance records for all exchange users square measure hold on here

* exchange/exchange/balance/username -> Balance

*/

static Name tableId() come Name("balance"); }

};




/**

* This technique is named once the "transfer" action of code

* "currencya" is named and "exchange" is listed within the notifiers.

*/

void apply_currencya_transfer() static Balance to_balance;

Db::get( transfer.from, to_balance );

to_balance.a += transfer.amount;

Db::store( transfer.from, to_balance );

"> else if( transfer.from == "exchange" ) need the reciever of funds (account owner) to authorize this transfer


static Balance to_balance;

motorcar balance = Db::get( transfer.to, to_balance );

assert( balance.a >= transfer.amount, "insufficient funds to withdraw" );

balance.a -= transfer.amount;


if( balance.isEmpty() )

Db::remove<Balance>( transfer.to );

else

Db::store( transfer.to, to_balance );

} else that's not relevant to the present exchange" );

}

}


/**

* This technique is named once the "transfer" action of code

* "currencya" is named and "exchange" is listed within the notifiers.

*/

void apply_currencyb_transfer() static Balance to_balance;

Db::get( transfer.from, to_balance );

to_balance.b += transfer.amount;

Db::store( transfer.from, to_balance );

"> else if( transfer.from == "exchange" ) need the reciever of funds (account owner) to authorize this transfer


static Balance to_balance;

motorcar balance = Db::get( transfer.to, to_balance );

assert( balance.b >= transfer.amount, "insufficient funds to withdraw" );

balance.b -= transfer.amount;


if( balance.isEmpty() )

Db::remove<Balance>( transfer.to );

else

Db::store( transfer.to, to_balance );

} else ">

}

What is interesting about this implementation is that deposits and withdraws occur without any asynchronous callbacks or other complex pending states. Rather than the user asking the exchange to tell the currency contract to withdraw funds, the exchange offers everybody permission to transfer from the exchange with the caveat that the exchange's handler for transfers is named on each deposits and withdraws. If a user try|tries} to withdraw over their balance with the exchange contract the handler can reject the transfer attempt.


We have approximately nonetheless enforced operating tests of the exchange contract deposit and withdraw, however that's on the agenda for next week. we'll even be implementing a basic social media application to prove that we've got all the present use cases lined.


Synchronous Calls

One of the most important developments on as associate degree design that enables synchronous calls among tightly coupled applications whereas still retentive most of the advantages of correspondence. A future web log post can get in larger detail on our memory and parallel execution structure.


Cost of Storage

Some folks have expressed considerations that if tokens ar value $30 billion bucks and there's just one TB of storage capability that the price of storage are going to be too high. I even have prepared a piece of writing that explains but we tend to tend to deal with this and keep worth} of storage mostly freelance from token value.


EOS.IO development is making nice strides!

« Back Rewrite once more

Sort:  

New Followers get 0.001 SBD$ and an upvote for free!!

Just follow @getvotes and...

  • we follow back
  • send you 0.001 SBD to your wallet
  • upvote your newest posting

Coin Marketplace

STEEM 0.19
TRX 0.16
JST 0.030
BTC 65578.21
ETH 2613.33
USDT 1.00
SBD 2.67