-
Notifications
You must be signed in to change notification settings - Fork 3
Account
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 |
-
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.
-
The address encoding on zoobc is calculated in the following steps by providing
prefix
andpublic_key
as input:-
-
prefix
must be length of 3 characters all uppercase. -
public_key
must be 32 bytes long.
-
-
-
copy the
public_key
and append theprefix
to the end of the copied bytes, resulting in35 bytes
buffer.[public_key, prefix[0], prefix[1], prefix[2]]
. -
calculate
checksum
by hashing (sha3_256) thebuffer
result on first step. -
replace the
last 3 bytes
of buffer withfirst 3 bytes
of thechecksum
. -
encode
buffer
withbase32
(rfc6468). -
The result is split into
8 characters segments
, append to theprefix
and separated by_
(underscore). -
The final result will looks like:
ZBC_AQTEH7K4_L45WJPLL_HCEC65ZH_7XC5N3XD_YNKPHK45_POH7PQME_AFAFBDWM
=[prefix_seg1_seg2_..._seg7]
-
-
-
To decode the address as original
public_key
:-
-
prefix
must be length of 3 characters all uppercase. -
public_key
must be 32 bytes long. -
address
must be 8 segments (when splitted by_
(underscore)) - each segment of the address (except prefix) must be
8 characters
long.
-
-
- split the
prefix
andbody
(8 character segments). - remove
_
and join thebody
segment as single string. - decode (base32 [rfc6468]) the string and assign to
buffer
- extract
input_checksum
by taking thelast 3 bytes
ofbuffer
. - replace the
buffer
last 3 bytes
withprefix
- calculate checksum by hashing (sha3_256) the
buffer
. - compare
input_checksum
and calculatedchecksum
, if it doesn't match, then it's wrong address. - if the checksum match, return the
first 32 bytes
of thebuffer
- split the
-
Current implementation separate the account address format into 2 separated only by their prefix:
-
ZooBC Account address is the default address that any user on zoobc can have, this account address have
ZBC
prefix.Other supported account types are:
- Bitcoin (BTC)
-
Node public key's string representation is calculated in the same function but with the
ZNK
prefix. This address is used in one of node configuration in node registration
-
New account is created in the
account_balance
table 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 (