blob = response.response_items[0].get_account_state_response.account_state_with_proof.blob.blob
info = get_account_resource(blob)
print(info)
The blob variable has bytes format as we see from the .proto file:
message AccountStateBlob { bytes blob = 1; }
Next, I am trying to unpack these bytes to a python’s namedtuple:
AccountResource = namedtuple('AccountResource',
'balance sequence_number authentication_key sent_events_count received_events_count')
def get_account_resource(data):
print(data)
print(data.hex())
s = Struct('< I I s I I')
o = AccountResource._make(s.unpack(data[:s.size]))
print(o)
return {}
And here I have a problem, it is how to correctly unpack these bytes. The unpack’s format from above code returned this result:
fair question, an address is serialized as a vector of bytes. First 32 bits (4 bytes) are the count of bytes, next are all the bytes. The unsigned32 count is in Little Endian format.
Hope this helps
Pay attention to the address:
000000000000000000000000000000000000000000000000000000000000
You need to consider byte offset before asset_type . Authentication_key not always the address.
Format for AccountResource:
But with the address, there are other parameters also provided such as module, name, type_params. These parameters also must be in the returned array of bytes.
01000000: 1 (mapEntryCount)
21000000: 33 (no of bytes for the map key)
01217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97 (map key)
44000000: 68 (no of bytes for the map value)
the rest is the map value, which can be broken down into:
20000000: 32 (length of auth key in bytes)
8cd377191fe0ef113455c8e8d769f0c0147d5bb618bf195c0af31a05fbfd0969 (auth key)
a0acb90300000000: 62500000 (balance)
0100000000000000: 1 (received events)
0400000000000000: 4 (sent events)
0400000000000000: 4 (sequence no)
It seems that the AccountResource has changed in the las update, anybody knows the new order of bytes? it seems that some new property is changed or something, when I decoded it return very huge numbers