Account - zoobc/zoobc-core GitHub Wiki
Zoobc core account is stored in account_balance table, this means an account is created when it has (receive) balance.
account_balance table:
| No | field | type |
|---|---|---|
| 1 | account_address | blob |
| 2 | block_height | integer |
| 3 | spendable_balance | integer |
| 4 | balance | integer |
| 5 | pop_revenue | integer |
| 6 | latest | boolean |
-
Address Format
The account address is in the form of a database blob (bynary data) and is composed by:
- Account address type: first 4 bytes
- Account address public key: the length depends on the account type. for default account type (ZooBC), it is 32 bytes long
Every address type has its own way to encode the public key in human readable, string, format. For instance bitcoin encodes to an hexadecimal string.
Following is described the native account address encoding for ZooBC account type.
-
encoding for default account type (ZooBC)
The address encoding on zoobc is calculated in the following steps by providing
prefixandpublic_keyas input:-
restrictions:
prefixmust be length of 3 characters all uppercase.public_keymust be 32 bytes long.
-
steps:
-
copy the
public_keyand append theprefixto the end of the copied bytes, resulting in35 bytesbuffer.[public_key, prefix[0], prefix[1], prefix[2]]. -
calculate
checksumby hashing (sha3_256) thebufferresult on first step. -
replace the
last 3 bytesof buffer withfirst 3 bytesof thechecksum. -
encode
bufferwithbase32(rfc6468). -
The result is split into
8 characters segments, append to theprefixand separated by_(underscore). -
The final result will looks like:
ZBC_AQTEH7K4_L45WJPLL_HCEC65ZH_7XC5N3XD_YNKPHK45_POH7PQME_AFAFBDWM=[prefix_seg1_seg2_..._seg7]
-
-
-
decoding for default account type (ZooBC)
To decode the address as original
public_key:-
restrictions:
prefixmust be length of 3 characters all uppercase.public_keymust be 32 bytes long.addressmust be 8 segments (when splitted by_(underscore))- each segment of the address (except prefix) must be
8 characterslong.
-
steps:
- split the
prefixandbody(8 character segments). - remove
_and join thebodysegment as single string. - decode (base32 [rfc6468]) the string and assign to
buffer - extract
input_checksumby taking thelast 3 bytesofbuffer. - replace the
bufferlast 3 byteswithprefix - calculate checksum by hashing (sha3_256) the
buffer. - compare
input_checksumand calculatedchecksum, if it doesn't match, then it's wrong address. - if the checksum match, return the
first 32 bytesof thebuffer
- split the
-
Current implementation separate the account address format into 2 separated only by their prefix:
-
account addresses
ZooBC Account address is the default address that any user on zoobc can have, this account address have
ZBCprefix.Other supported account types are:
- Bitcoin (BTC)
-
node public key
Node public key's string representation is calculated in the same function but with the
ZNKprefix. This address is used in one of node configuration in node registration
-
Account Creation
New account is created in the
account_balancetable when:- An account receive a payment (
SendZBC) transaction from existing user. - An account created in genesis transactions, which mean the account is included in the genesis fund receiver (hardcoded). In this case the account balance will be zero because token distribution is achieved via coinbase and not at genesis as in POS blockchains
- An account receive a payment (