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 prefix and public_key as input:

      • restrictions:

        • prefix must be length of 3 characters all uppercase.
        • public_key must be 32 bytes long.
      • steps:

        • copy the public_key and append the prefix to the end of the copied bytes, resulting in 35 bytes buffer.

          [public_key, prefix[0], prefix[1], prefix[2]].

        • calculate checksum by hashing (sha3_256) the buffer result on first step.

        • replace the last 3 bytes of buffer with first 3 bytes of the checksum.

        • encode buffer with base32 (rfc6468).

        • The result is split into 8 characters segments, append to the prefix and 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:

        • 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.
      • steps:

        • split the prefix and body (8 character segments).
        • remove _ and join the body segment as single string.
        • decode (base32 [rfc6468]) the string and assign to buffer
        • extract input_checksum by taking the last 3 bytes of buffer.
        • replace the buffer last 3 bytes with prefix
        • calculate checksum by hashing (sha3_256) the buffer.
        • compare input_checksum and calculated checksum, if it doesn't match, then it's wrong address.
        • if the checksum match, return the first 32 bytes of the buffer

    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 ZBC prefix.

      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 ZNK prefix. This address is used in one of node configuration in node registration

  • Account Creation

    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