EOS - 개발자 일지 항성력 201707.7

in #eoskorea7 years ago

이번 주에 EOS의 아키텍처를 개선하고 개발자 API를 정의하는 데에 있어서 큰 발전이 있었습니다. 특히, 사용의 용이성과 코드의 명확성을 최대화하면서 병렬 처리를 가능하게하는 프로그래밍 모델을 확인했습니다.

업데이트된 예제 계약(Example Contracts)

github를 팔로우 하는 분들은 아키텍처를 테스트하고 원하는 사용 사례들을 커버 할 수 있도록 우리가 많은 예제 계약들을 모으기 시작했다는 것을 알고 있을지도 모르겠습니다.

이것은 오늘날 볼 수 있는 단순한 화폐 계약(currency contract)입니다:

/**
 *  Transfer requires that the sender and receiver be the first two
 *  accounts notified and that the sender has provided authorization.
 */
struct Transfer {
  AccountName from;
  AccountName to;
  uint64_t    amount = 0;
  char        memo[]; /// extra bytes are treated as a memo and ignored by logic
};

struct CurrencyAccount {
   CurrencyAccount( uint64_t b = 0 ):balance(b){}

   uint64_t balance = 0;

   /** used as a hint to Db::store to tell it which table name within the current 
    *  scope to use.  Data is stored in tables under a structure like
    *
    *  scope/code/table/key->value
    *
    *  In this case the "singleton" table is designed for constant named keys that
    *  refer to a unique object type. User account balances are stored here:
    *  
    *  username/currency/singleton/account -> CurrencyAccount
    */ 
   static Name tableId() { return NAME("singleton"); }
};


void apply_currency_transfer() {
   const auto& transfer  = currentMessage<Transfer>();

   /** will call apply_currency_transfer() method in code defined by transfer.to and transfer.from */
   requireNotice( transfer.to, transfer.from );
   requireAuth( transfer.from );

   static CurrencyAccount from_account;
   static CurrencyAccount to_account;

   Db::get( transfer.from, NAME("account"), from_account );
   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 == 0 )
      Db::remove<CurrencyAccount>( transfer.from, NAME("account") );
   else
      Db::store( transfer.from, NAME("account"), from_account ); 

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

이 화폐 계약(currency contract)에는 몇 가지 주목할만한 점이 있습니다:

  1. 일반적인 순차코드(sequential code)처럼 보입니다.
  2. 하지만 두 쌍의 사용자들이 병렬로 전송할 수 있습니다.

이것은 무슨 뜻일까요? Alice가 Bob에게 전송하는 동안 Sam은 Jill에게 전송할 수 있음을 의미합니다. 이 화폐 계약의 성능은 이제 이전 화폐 계약의 단일 스레드 성능에 제한되지 않습니다.

계약 체결

우리는 또한 두 가지 다른 화폐 계약으로부터 입금과 출금을 수락하는 간단한 교환 계약을 구현했습니다.

struct Account {
   uint64_t   a = 0;
   uint64_t   b = 0;
   int        open_orders = 0;

   bool isEmpty()const { return !(a|b|open_orders); }
   /**
    *  Balance records for all exchange users are stored here
    *  exchange/exchange/balance/username -> Balance
    */
   static Name tableId() { return Name("balance"); }
};



/**
 *  This method is called after the "transfer" action of code
 *  "currencya" is called and "exchange" is listed in the notifiers.
 */
void apply_currencya_transfer() {
   const auto& transfer  = currentMessage<Transfer>();

   if( transfer.to == "exchange" ) {
      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" ) {
      requireAuth( transfer.to ); /// require the reciever of funds (account owner) to authorize this transfer

      static Balance to_balance;
      auto 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 {
      assert( false, "notified on transfer that is not relevant to this exchange" );
   }
}

/**
 *  This method is called after the "transfer" action of code
 *  "currencya" is called and "exchange" is listed in the notifiers.
 */
void apply_currencyb_transfer() {
   const auto& transfer  = currentMessage<Transfer>();

   if( transfer.to == "exchange" ) {
      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" ) {
      requireAuth( transfer.to ); /// require the reciever of funds (account owner) to authorize this transfer

      static Balance to_balance;
      auto 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 {
      assert( false, "notified on transfer that is not relevant to this exchange" );
   }
}

이 구현에서 흥미로운 점은 비동기 콜백(asynchronous callback)이나 기타 복잡한 보류 상태없이 입금과 출금이 발생한다는 것입니다. 교환을 요구하는 사용자가 자금을 출금하기 위해 화폐 계약을 하도록 요청하는 대신, 교환은 모든 사람에게 교환 핸들러(exchange's handler)가 전송을 위해 입금과 출금 ​​모두에 대해 호출된다는 경고와 함께 교환에서 전송으로 권한을 부여합니다. 만약 사용자가 교환 계약에서 잔액 이상의 금액을 출금하려고 시도하면 핸들러는 전송 시도를 거부합니다.

우리는 아직 교환 계약 입출금의 테스트를 구현하지는 않았지만, 다음주 의제로 포함했습니다. 우리는 또한 존재하는 사용 사례들을 모두 포함한다는 것을 입증하기 위해 기본적인 소셜 미디어 어플리케이션을 구현할 것입니다.

동기 호출 (Synchronous Calls)

이번 주 가장 큰 발전 중 하나는 밀착결합된(tightly coupled) 어플리케이션간에 동기 호출을 허용하면서도 동시에 병렬 처리의 이점 대부분을 유지할 수있는 구조입니다. 앞으로 블로그 포스트에서 우리의 메모리와 병렬 실행 구조에 대해 자세히 설명할 것입니다.

스토리지 비용 (Cost of Storage)

어떤 사람들은 만약 토큰이 300억 달러의 가치가 있고 스토리지 용량이 1TB 밖에 되지 않아 스토리지 비용이 너무 높을 것이라고 우려합니다. 저는 이 문제를 어떻게 다루고 어떻게 토큰 가격과는 독립적으로 스토리지 비용을 유지하는지 설명하는 글을 준비했습니다.

EOS.IO 개발은 진일보하고 있습니다!


원문: https://steemit.com/eos/@dan/eos-developer-log-stardate-201707-7
@nand 님께서 번역해주신 글입니다. 번역자를 위한 투표는 이 링크에서 하실 수 있습니다.

Sort:  

Hi, great post ! for a follow and upvote please reply to this message and follow and upvote my latest post @rafkimuhammad

Eos is the best man :)

I try to understand using google translate because i am Myanmar.But i know this post is about code for developer .Comming next post i will better understand your korean language by using google translatr. I follow you for more information.

Great post. Really like potential of EOS. Will invest greatly in this coin. Post is very informative and useful in my research of EOS. Thnx. Keep up the good work.

EOS 멋져요 ㅎㅎ

Coin Marketplace

STEEM 0.29
TRX 0.11
JST 0.030
BTC 68433.35
ETH 3735.63
USDT 1.00
SBD 3.66