Skip to content

Storing Data in KVS

adamant-al edited this page May 28, 2021 · 14 revisions

ADAMANT's Key-Value Storage (KVS) is a special type of transactions for storing private (encrypted) or public (plain value) data in ADAMANT's blockchain. Examples are contact list for private data and Ether address for public data.

Related information:

KVS Transactions

KVS transaction is of type 9 and contains asset field with state object:

  • key — describes contents of KVS record
  • value — is data for key. Can be private (encrypted) or public (plain value).
  • type — incremental data or full re-write of previous values.

Example transaction that writes public Ether address for U11977883563659338220:

{
    "transaction": {
        "type": 9,
        "amount": 0,
        "senderId": "U11977883563659338220",
        "senderPublicKey": "d2cbc26c2ef6...",
        "asset": {
            "state": {
                "key": "eth:address",
                "value": "0xf4a2d5997eb0575b7ad7c10b0b178524c336f9e9",
                "type": 0
            }
        },
        "timestamp": 45603372,
        "signature": "86cbe525042bf83802..."
    }
}

KVS keys

key field describes contents of KVS record. You can use own key to store special kind of data, or refer to known keys:

Examples for <coin>:address:

  • eth:address — Ethereum wallet address (ETH and ERC-20)
  • lsk:address — Lisk wallet address (LSK)
  • dash:address — Dash wallet address (DASH)
  • doge:address — Doge wallet address (DOGE)
  • btc:address — Bitcoin wallet address (BTC)

KVS data

Data for key is included in value field can be private (encrypted) or public (plain value).

Unencrypted values are stored as-is in value field. Private values [should be encrypted] and that way value represents object:

  • message: encrypted value for key
  • nonce: nonce

Any KVS value that is a valid JSON and has both nonce and message fields should be treated as encrypted.

Example:

{
    "transaction": {
        "type": 9,
        "amount": 0,
        "senderId": "U15677078342684640219",
        "senderPublicKey": "e16e624fd0...",
        "asset":{
            "state":{
            "key": "contact_list",
            "value":"{
                \"message\": \"6df8c172feef228d930130...\",
                \"nonce\": \"f6c7b76d55db945bb026cd221d5...\"}",
            "type": 0}
            },
        "timestamp": 45603645,
        "signature": "dbafce549f1..."
    }
}

KVS store types

Describes how to store value for key, incremental (1) or full re-write (0) of previous values. Default is 0. See AIP 11: Behavior for KVS data.

Storing and fetching KVS data

To fetch KVS data from ADAMANT blockchain, use /api/states/get endpoint.

To store KVS data in ADAMANT blockchain, use /api/states/store endpoint.

Clone this wiki locally