python - How to store "complex" data structure as a Persistent Data Structures using ethereum & serpent -


my work concerning smart contract dev. using (py)ethereum , serpent,

when reading "a programmer’s guide ethereum , serpent", saw on point 5.9 :

[...] persistent data structures can declared using data declaration. allows declaration of arrays , tuples. [...]

and:

[...] simple storage, self.storage[] useful, larger contracts, recommend use of data (unless need key- value storage, of course) [...]

code example:

#!/usr/bin/env python # -*- coding: utf-8 -*-  import serpent ethereum import tester, utils, abi  serpent_code = ''' data mystorage[]   def test_data_storage(key,value):     if not self.mystorage[key]:         self.mystorage[key]=value         return(1)     else:         return(0)   def get_value_mystorage(key):     if not self.mystorage[key]:         return(0)     else:         return(self.mystorage[key])    def test_self_storage(key,value):     if not self.storage[key]:         self.storage[key]=value         return(1)     else:         return(0)   def get_value_self_storage(key):     if not self.storage[key]:         return(0)     else:         return(self.storage[key])  '''   s = tester.state() c = s.abi_contract(serpent_code)  #example self storage c.test_self_storage("keya",1) print c.get_value_self_storage("keya") #store , access data works in self.storage!  #example mystorage c.test_data_storage("keyb",2) print c.get_value_mystorage("keyb") #store , access data works in data persistant data storage!  #fail example complex data my_complex_data={"keya":1,"keyb":2, "keyc":[1,2,3], "keyd":{"a":1,"b":2}} c.test_data_storage("keycomplex",my_complex_data)   #don't store because error: # ethereum.abi.valueoutofbounds: {'keyc': [1, 2, 3], 'keyb': 2, 'keya': 1, 'keyd': {'a': 1, 'b': 2}} 

my question : best way , how store complex data (see my_complex_data variable in code) dictionary contain others dict. (or arrays key value) persistant data structures ?

and know if possible , how store class structure persistant data structures ?


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -