Storage

將數據儲存在交易中的區塊鏈中

  • August 11, 2016

這個問題與thisthis有關。我正在嘗試將數據儲存在交易數據欄位內的區塊鏈中:

第二個問題提供了使用合約的解決方案,但是否可以僅使用交易欄位。在 pyethapp 中定義如下:

class Transaction(rlp.Serializable):

   """
   A transaction is stored as:
   [nonce, gasprice, startgas, to, value, data, v, r, s]

   nonce is the number of transactions already sent by that account, encoded
   in binary form (eg.  0 -> '', 7 -> '\x07', 1000 -> '\x03\xd8').

   (v,r,s) is the raw Electrum-style signature of the transaction without the
   signature made with the private key corresponding to the sending account,
   with 0 <= v <= 3. From an Electrum-style signature (65 bytes) it is
   possible to extract the public key, and thereby the address, directly.

   A valid transaction is one where:
   (i) the signature is well-formed (ie. 0 <= v <= 3, 0 <= r < P, 0 <= s < N,
       0 <= r < P - N if v >= 2), and
   (ii) the sending account has enough funds to pay the fee and the value.
   """

   fields = [
       ('nonce', big_endian_int),
       ('gasprice', big_endian_int),
       ('startgas', big_endian_int),
       ('to', utils.address),
       ('value', big_endian_int),
       ('data', binary),
       ('v', big_endian_int),
       ('r', big_endian_int),
       ('s', big_endian_int),
   ]

   _sender = None

   def __init__(self, nonce, gasprice, startgas, to, value, data, v=0, r=0, s=0):
       self.data = None

       to = utils.normalize_address(to, allow_blank=True)
       assert len(to) == 20 or len(to) == 0
       super(Transaction, self).__init__(nonce, gasprice, startgas, to, value, data, v, r, s)
       self.logs = []

       if self.gasprice >= TT256 or self.startgas >= TT256 or \
               self.value >= TT256 or self.nonce >= TT256:
           raise InvalidTransaction("Values way too high!")
       if self.startgas < self.intrinsic_gas_used:
           raise InvalidTransaction("Startgas too low")

       log.debug('deserialized tx', tx=encode_hex(self.hash)[:8])

我不確定該欄位在大小方面是否有上限。

一個事務中可以儲存多少數據?

欄位的大小data取決於塊氣體限制。

在乙太坊公共區塊鏈中,截至 2016 年 2 月 7 日,該data欄位的限制為89kb 。來源。您現在可以使用類似的方法來檢查限制。

但是,在私有區塊鏈中,數據欄位沒有限制。您可以在創世文件中設置塊氣體限制值。來源

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