While creating a simple blockchain in Python to understand the behind-the-scenes working myself, I came accross the pyrlp
module. Using it is great for RLP serialization of transactions and accounts, and then they are stored in tries. However, an account's balance must be mutable, as does the nonce. I find that the rlp.Serializable class does not allow for mutable attributes in fields
. Let me present some relevant application code using this class:
rlp.Serializable
objects are created as follows:
import rlp
from rlp.sedes import binary, big_endian_int, List
class Account(rlp.Serializable):
fields = (
('nonce', big_endian_int),
('address', binary),
('balance', big_endian_int)
)
account = Account(nonce=0, address='0x927492', balance=0)
I expect to increase the balance by one (eg when receiving a transaction) through account.balance += 1
However, trying to do this returns:
AttributeError: can't set attribute
Is there a way to change this seemingly immutable attribute?