EOS系統合約鏈賬戶介紹

BSN研習社發表於2023-09-28

一、目的

本檔案圍繞EOS系統合約的九種基本鏈賬戶在原始碼中的使用情況進行介紹,適用於想要了解系統合約鏈賬戶的初學者和開發者,幫助其快速瞭解和上手EOS系統合約鏈賬戶建立與使用。

二、鏈賬戶介紹

EOS賬戶是儲存在區塊鏈中的可讀識別符號。由許可權配置決定,該賬戶是個人授權還是多人授權擁有。EOS賬戶有12個字元的限制(允許字元a~z、1~5),該字元由64位整數的base-32編碼衍生而來。

EOS短賬戶是透過賬戶之間競拍購買得到的賬戶,如:com、a等,短賬戶非常稀少。由競拍獲得的短賬戶建立的二級賬戶也是短賬戶,類似於網站域名,比如:com賬戶可以建立a.com、1.com等子賬戶。短賬戶可以參與賬戶競拍獲得,但是拍賣成交價一般在數千到數萬EOS不等。也可以向短賬戶擁有者購買二級賬戶,如:向e賬戶購買e.e賬戶。

三、系統鏈賬戶介紹

1、系統賬戶介紹

在基於EOSIO的區塊鏈的起源當中,只有一個賬戶存在,也就是eosio賬戶。它是主要的系統賬戶,還有一些其他的系統賬戶,都由它建立。以下是幾個重要的系統賬戶:

帳戶 特權 合約 描述
eosio eosio.system 合約 基於 EOSIO 的區塊鏈上的主系統帳戶。
eosio.msig eosio.msig 合約 如果所有需要的各方在到期時間之前簽署提案,則允許簽署多重簽名交易提案以供以後執行。
eosio.wrap eosio.wrap 合約 透過使它們更具可讀性和更易於稽核來簡化塊生產者超級使用者的操作。
eosio.token eosio.token 合約 定義允許使用者在基於 EOSIO 的區塊鏈上建立、發行和管理令牌的結構和操作。
eosio.names 持有名稱空間拍賣資金的帳戶。
eosio.bpay 支付區塊生產者生產區塊的賬戶。它根據區塊生產者在過去 24 小時內建立的區塊數量分配 0.25% 的通貨膨脹。
eosio.ram 根據使用者購買或出售 RAM 的行為跟蹤 SYS 餘額的帳戶。
eosio.ramfee 跟蹤從使用者 RAM 交易行為中收取的費用的賬戶:每筆交易價值的 0.5% 進入該賬戶。
eosio.saving 持有 4% 網路通脹的賬戶。
eosio.stake 跟蹤已為 NET 或 CPU 頻寬抵押的所有 SYS 代幣的帳戶。
eosio.vpay 根據贏得的選票相應地支付區塊生產者的賬戶。它根據區塊生產者在過去 24 小時內贏得的票數分配 0.75% 的通貨膨脹率。
eosio.rex 跟蹤 REX 相關操作執行產生的費用和餘額的帳戶。

2、鏈賬戶在原始碼中的使用

(1)eosio.msig

在EOS中,eosio.msig是一個特殊的鏈賬戶,用於管理多簽名 (multisig)操作,部署提案合約。

多簽名(Multisig):多簽名是一種安全機制,其中需要多個賬戶的授權才能執行某些敏感操作或交易。對於eosio.msig賬戶來說,多個賬戶可以被配置為需要授權才能執行事務。

eosio.msig賬戶功能:eosio.msig賬戶是EOS.0軟體平臺中的一個特殊賬戶,負責管理和執行多簽名操作。

多簽名交易執行過程:

  • 建立提案:使用eosio.msig賬戶建立一個提案(proposal),其中包括待執行的交易和所需的簽名授權列表。

  • 授權簽名:參與多簽名的賬戶根據規定的授權列表對提案進行簽名。一旦所有所的簽名被授權,提案就可以準備執行。

  • 執行提案:eosio.msig賬戶可以執行已收集足夠授權簽名的提案,從而觸發交易的執行。

(2)eosio.names

eosio.names:持有名稱空間拍賣資金的帳戶。投標名稱操作,允許帳戶 bidder 為名稱 newname 出價。引數如下:

  • bidder:獲得退款的帳戶;

  • newname:投標的名稱;

  • bid:為投標支付的系統代幣數量;

賬戶在原始碼eosio.system.hpp中的別名定義:

` static constexpr eosio::name names_account{"eosio.names"_n};`

在原始碼eosio.system/src/namebidding.cpp中的使用:


void 
system_contract::bidname( 
const 
name
& 
bidder, 
const 
name
& 
newname, 
const 
asset
& 
bid ) {

     ...... //other code
       
      require_auth( bidder ); check( ( bool) newname
      check( newname. suffix() == newname, "you can only bid on top-level suffix" );

      check( ( bool) newname, "the empty name is not a valid account name to bid on" );
      check( ( newname. value & 0xFull) == 0, "13 character names are not valid account names to bid on" );
      check( ( newname. value & 0x1F0ull) == 0, "accounts with 12 character names and no dots can be created without bidding required" );
      check( ! is_account( newname ), "account already exists" );
      check( bid. symbol == core_symbol(), "asset must be system token" );
      check( bid. amount > 0, "insufficient bid" );
   
      //代幣從bidder轉移到names_account
      token::transfer_action transfer_act{ token_account, { { bidder, active_permission} } };
      transfer_act. send( bidder, names_account, bid, std::string( "bid name ") + newname. to_string() );
}

出價退款操作,允許帳戶 bidder 取回到目前為止對 newname 名稱出價的金額。引數如下:

  • bidder:獲得退款的帳戶;

  • newname:投標的名稱;現在可以退款;

在原始碼eosio.system/src/namebidding.cpp中的使用:


void 
system_contract::bidrefund( 
const 
name
& 
bidder, 
const 
name
& 
newname ) {

      bid_refund_table refunds_table( get_self(), newname. value);
      auto it = refunds_table. find( bidder. value );
      check( it != refunds_table. end(), "refund not found" );

      //代幣從names_account轉移到bidder
      token::transfer_action transfer_act{ token_account, { { names_account, active_permission}, { bidder, active_permission} } };
      transfer_act. send( names_account, bidder, asset( it -> amount), std::string( "refund bid on name") +( name{ newname}). to_string() );
      refunds_table. erase( it );
  }
(3)eosio.saving、eosio.bpay和eosio.vpay使用

eosio.saving:持有4%網路通脹的賬戶。

eosio.bpay:支付塊生產者生產塊的賬戶,根據區塊生產者過去24小時內建立的區塊數量分配0.25%的通脹。

eosio.vpay:用贏得的選票向區塊生產者支付相應費用的賬戶。根據區塊生產者在過去24小時內贏得的票數分配0.75%的通貨膨脹率。

賬戶在原始碼eosio.system.hpp中的別名定義:


static 
constexpr 
eosio::
name 
saving_account{
"eosio.saving"
_n};

static constexpr eosio:: name bpay_account{ "eosio.bpay" _n};
static constexpr eosio:: name vpay_account{ "eosio.vpay" _n};

在原始碼eosio.system/src/producer_pay.cpp中的使用:

  
if( 
new_tokens 
> 
0 ) {

           {
              token:: issue_action issue_act{ token_account, { { get_self(), active_permission} } };
              issue_act. send( get_self(), asset( new_tokens, core_symbol()), "issue tokens for producer pay and savings" );
           }
           {
              token:: transfer_action transfer_act{ token_account, { { get_self(), active_permission} } };
              if( to_savings > 0 ) {
                  transfer_act. send( get_self(), saving_account, asset( to_savings, core_symbol()), "unallocated inflation" );
              }
              if( to_per_block_pay > 0 ) {
                  transfer_act. send( get_self(), bpay_account, asset( to_per_block_pay, core_symbol()), "fund per-block bucket" );
              }
              if( to_per_vote_pay > 0 ) {
                  transfer_act. send( get_self(), vpay_account, asset( to_per_vote_pay, core_symbol()), "fund per-vote bucket" );
              }
           }
        }
(4)eosio.ram和eosio.ramfee使用

eosio.ram:根據使用者購買或出售ram的行為跟蹤SYS餘額的賬戶。

eosio.ramfee:跟蹤從使用者ram交易行為收取的費用的賬戶,每筆交易價值的0.5%進入該賬戶。

賬戶在原始碼eosio.system.hpp中的別名定義:


static 
constexpr 
eosio::
name 
ram_account{
"eosio.ram"
_n};

static constexpr eosio:: name ramfee_account{ "eosio.ramfee" _n};

當購買ram時,付款人不可逆地將數量轉移到系統合約,只有接收者可以透過sellram操作收回代幣。接收方支付與此操作相關聯的所有資料庫記錄的儲存費用。RAM是一種稀缺資源,其供應量由全域性屬性max_RAM_size定義。RAM使用bancor演演算法定價,使得每個位元組的價格具有100:1的恆定儲備比。

在原始碼eosio.system/src/delegate_bandwidth.cpp中的使用:

     
// 如果quant.amount>1,則quant_after_fee.amount應>0。如果quant.amaunt==1,則quant_after_fee.amount==0,並且下一次內聯傳輸將失敗,導致buyram操作失敗。

     {
        token:: transfer_action transfer_act{ token_account, { { payer, active_permission}, { ram_account, active_permission} } };
        transfer_act. send( payer, ram_account, quant_after_fee, "buy ram" );
     }
      if ( fee. amount > 0 ) {
        token:: transfer_action transfer_act{ token_account, { { payer, active_permission} } };
        transfer_act. send( payer, ramfee_account, fee, "ram fee" );
        channel_to_rex( ramfee_account, fee );
     }
(5)eosio.stake使用

eosio.stake:跟蹤所有為NET或CPU寬頻質押的SYS代幣的賬戶。

賬戶在原始碼eosio.system.hpp中的別名定義:

static constexpr eosio::name stake_account{"eosio.stake"_n};

在原始碼eosio.system/src/delegate_bandwidth.cpp中的使用:

auto transfer_amount = net_balance + cpu_balance;//NET或CPU
         if ( 0 < transfer_amount.amount ) {
            token::transfer_action transfer_act{ token_account, { {source_stake_from, active_permission} } };
            transfer_act.send( source_stake_from, stake_account, asset(transfer_amount), "stake bandwidth" );
         }
(6)eosio.rex使用

eosio.rex:跟蹤費用和餘額的賬戶是由REX相關操作執行產生的。

賬戶在原始碼eosio.system.hpp中的別名定義:

static constexpr eosio::name rex_account{"eosio.rex"_n};

在原始碼eosio.system\src\rex.cpp中的使用:


const 
asset 
payment 
= 
from_net 
+ 
from_cpu;

      // inline transfer from stake_account to rex_account 從stake_account到rex_account的內聯轉賬
     {
        token:: transfer_action transfer_act{ token_account, { stake_account, active_permission } };
        transfer_act. send( stake_account, rex_account, payment, "buy REX with staked tokens" ); //使用賭注代幣購買REX
     }
      const asset rex_received = add_to_rex_pool( payment );
      add_to_rex_balance( owner, payment, rex_received );
      runrex( 2);
      update_rex_account( owner, asset( 0, core_symbol() ), asset( 0, core_symbol() ), true );
      // dummy action added so that amount of REX tokens purchased shows up in action trace 新增了虛擬操作,以便購買的REX代幣數量顯示在操作跟蹤中
      rex_results:: buyresult_action buyrex_act( rex_account, std:: vector < eosio:: permission_level >{ } );
      buyrex_act. send( rex_received );


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70012206/viewspace-2986633/,如需轉載,請註明出處,否則將追究法律責任。

相關文章