Events

如何下載字元串數組

  • August 24, 2017

EOS要求代幣持有者通過在其智能合約中使用其“註冊”功能來生成公鑰並進行註冊。這是函式(從Etherscan複製):

mapping (address => string) public keys;
...
event LogRegister (address user, string key);    
...
// Value should be a public key.  Read full key import policy.
// Manually registering requires a base58
// encoded using the STEEM, BTS, or EOS public key format.
function register(string key) {
   assert(today() <=  numberOfDays + 1);
   assert(bytes(key).length <= 64);

   keys[msg.sender] = key;

   LogRegister(msg.sender, key);
}

他們將公鑰儲存在:

keys[msg.sender] = key;

我正在考慮做類似的事情,但我看不到 EOS 如何提取和下載“keys”數組。EOS 沒有遍歷這個數組並返回值的函式。如何下載“keys”數組?

是否可以從 Etherscan 的“鍵”中獲取所有值(因為 LogRegister 事件)?如果是這樣,怎麼做?

在變數的聲明中,public使用了關鍵字:

mapping (address => string) public keys;

不是:

mapping (address => string) keys;

當這樣設置 public` 關鍵字時,Solidity 會在編譯時自動生成一個與變數同名的 getter 函式。

因此,在 Etherscan 中查看 EOS 合約時,在“讀取智能合約”選項卡下,有一個“密鑰”選項。但是,它不會向您呈現整個地圖;您必須知道要查找的地址才能獲得該值。出於 EOS 應用程序的目的,它不一定需要每個人的密鑰的詳盡列表,它通常只關心與其互動的帳戶的密鑰,因此預設的 getter 可以很好地用於該目的。

要獲取該映射中所有記錄的列表,是的,您可以使用 JSON-RPC 方法或 web3js 方法來查詢所有LogRegister事件,並建構完整列表。

引用自:https://ethereum.stackexchange.com/questions/25031