## High Level Components
### Database
The database package integrates redis/ipfs and exposes the following interface. Every key in the database will be namespaced using the pcr input
- **Load**: returns a value stored against the key else returns the error
```
- inputs: pcr, key // string, string
- outputs: (value, cost) // (string, int)
```
- **Store**: store/update a key value pair in the database for the given duration
```
- inputs: pcr, key, value, expiry // string, string, []byte, duration
- outputs: cost // int
```
- **Exists**: check if key exists
```
- inputs: pcr, key // string, string
- outputs: cost, true/false // int, bool
```
- **List**: get all keys matching a given prefix.
```
- inputs: pcr, prefix, recursive // string, string, bool
- outputs: (list of keys, cost) // ([]string, int)
```
- **Stat**: returns information about a specific key
```
- inputs: pcr, key // string, string
- outputs: keyInfo, cost // {Key string, Modified time.Time, Size int64, IsTerminal bool}, int
```
- **Delete**: delete the key value pair from the database.
```
- inputs: pcr, key // string, string
- outputs: cost // int
```
- **Lock**: obtain a lock for a given key
```
- inputs: pcr, key // string, string
- outputs: lock_id, cost // vec<u8>, int
```
- **Unlock**: release the lock for a given key
```
- inputs: pcr, key, lock_id // string, string, vec<u8>
- outputs: cost // int
```
## Router
Router implements the api calls that will be exposed by this storage server. It will implement the following api calls.
Every request will have the following **header**:
`Attestation: <base64 encoded attestation document>`
- GET /**ping**: this is a health check for the server
```
- response:
- version: "1.0.0"
```
- POST /**load**: this will return the value stored against the given key in the database
```
- request:
- data: key // string
- response:
- data: value // string
```
- POST /**store**: this will store/update the value for the given key in the database
```
- request:
- data:
- key: "key" //string
- value: "value" // string
- expiry: -1 // in nanoseconds, -1 for kEEPTTL as previous. Cannot be equal to 0, no expiry is not supported
```
- POST /**exists**: this will check if the given key exists in the database
```
- requests:
- data: key //string
- response:
- data: true/false //bool
```
- POST /**list**: this will return the list of keys matching a particular prefix
```
- requests:
- data:
- prefix // string
- is_recursive //bool
- response:
- data : keys_ist //[]string
```
- POST /**stat**: this will return the information stored against the given key in the database
```
- request:
- data: key //string
- response:
- data:
- key //string
- modified //Time
- size //int64
- terminal //bool
```
- POST /**delete**: this will delete the value for the given key in the database
```
- request:
- data: key //string
```
- POST /**lock**: this will obtain lock for the given key in the database
```
- request:
- data: key //string
- response:
- lock_id: vec<u8>
```
- POST /**unlock**: this will release lock for the given key in the database
```
- request:
- data: key //string
- lock_id: vec<u8>
```
## Example flow for storing and loading data

## Pricing Model
Following parameters were identified based on the AWS and GCP pricing model
- **Storage cost**: data stored per second. If the data is deleted before its expiry, 'early delete' charges will be applied. This cost will be computed on each store call as (keysize + valuesize) * ttl * 8796.
- **Operation cost**: operations are divided into three classes. Class A(list), Class B(lock, unlock) and class C(store, load, stats, delete). Each Class is charged differently with class C being least. This cost will be computed on each request
- **Network cost**: Network ingress, i.e, data coming into the server is not charged. Network egress, i.e, data going out of the server is charged. This cost will be computed only on load, stat, list request.
## Limits
some limits that may be imposed.
- size of Key
- size of Value
- number of keys under a namespace
## Payments
https://docs.google.com/document/d/18xGFJRNs-peucN5s9lmhiGKipW3XMOkO7NYIB3eTtJ4/edit