# Smart Contract

Để tương tác trực tiếp với hợp đồng thông minh KurateDAO, API như sau. Hợp đồng thông minh có thể được tìm thấy trên [Github](https://github.com/KurateDAO/KurateDAO/blob/main/src/contracts/Kurate.sol) .

Cơ sở dữ liệu

### Databases (Cơ sở dữ liệu)

#### mintDatabase

```
function mintDatabase(
    string memory title, 
    string memory description, 
    string memory curatorName, 
    string memory curatorUrl, 
    uint timeoutCrowd, 
    uint timeoutCurator, 
    uint thresholdCurator,
    string memory jsonSchema
) public payable
```

#### getDatabasesAll

```
function getDatabasesAll() public view returns(DatabaseSimple[] memory)
```

###

### Schema (lược đồ)

Một [JSON Schema](https://json-schema.org/) được lưu trữ trong hợp đồng thông minh để khách hàng biết liệu các hàng có phù hợp với cấu trúc của cơ sở dữ liệu hay không.

```
{
     "$schema": "http://json-schema.org/draft-04/schema#",
     "description": "VIPs",
     "type": "object",
     "properties": {
         "name": {
             "type": "string"
         },
         "guests": {
             "type": "number"
         }
     },
     "required": ["name","guests"]
}
```

### Row Method (Phương pháp hàng)

#### Mint Row ( phải trả)

```
function mintRow(uint databaseId, string memory json) public payable
```

#### Get Rows

```
function getRows(uint databaseId) view public returns ( RowSimple[] memory)
```

#### Stake Row (phải trả)

```
function stakeRow(uint databaseId, uint rowId, Decision decision) public payable
```

#### Adjudicate Row

```
function adjudicateRow(uint databaseId, uint rowId, Decision decision) public
```

#### Burn Row

```
function burnRow(uint databaseId, uint rowId) public
```

Cơ sở dữ liệu là một [living document](https://en.wikipedia.org/wiki/Living_document). Cũng giống như người quản lý có khả năng thêm một hàng vào cơ sở dữ liệu, họ cũng có khả năng loại bỏ (ghi) một hàng khi nó bây giờ còn hữu ích.

### Khác <a href="#other" id="other"></a>

#### Chạy Cron Job <a href="#run-cron-job" id="run-cron-job"></a>

`function cron() public`

Để phân xử các phần tử đã vượt quá khoảng thời gian chờ của đám đông và người quản lý, một hàm cron (bộ lập lịch) cần được gọi khoảng một lần mỗi phút. Ai gọi điều này đầu tiên trong mỗi chu kỳ khối sẽ nhận được một phần thưởng nhỏ

## Events (Sự kiện)

```
event MintedDatabase(uint databaseId);
event MintedRow(uint databaseId, uint rowId);
event Staked(uint databaseId, uint rowId);
event Adjudicated(uint databaseId, uint rowId, Decision decision);
event BurntRow(uint databaseId, uint rowId);
event Croned();
```

## Structs (cấu trúc)

#### Database (cơ sở dữ liệu)

```
struct Database {
    uint                            id;
    string                          title;
    string                          description;
    string                          curatorName;
    string                          curatorUrl;
    uint                            timeoutCrowd;
    uint                            timeoutCurator;
    uint                            thresholdCurator;
    string                          jsonSchema;
    address                         owner;
    uint                            timestamp;
    Row[]                           rows;
}
```

#### Row

```
struct Row {
    uint                            id;
    string                          json;
    uint                            timestamp;
    mapping(uint => Stake)          stakes;
    uint                            stakeLength;
    address                         owner;
}
```

#### Stake

```
struct Stake {
    uint                            amount;
    Decision                        decision;
    Stage                           stage;
    address                         owner;
    uint                            timestamp;
}
```

#### Decision

```
enum Decision { 
    INCLUDE, 
    EXCLUDE, 
    TBD 
}
```

#### Stage

```
enum Stage { 
    CROWD, 
    CURATOR, 
    DATABASE 
}
```
