# Lottery(獎勵) Service
[TOC]
url = https://1tki5qqdxk.execute-api.us-east-2.amazonaws.com
version = v1
### Create lottery
| Parameters| Required | Type | Description |
|-----------|--------|---------|--------|
|lottery_name|Yes|String|Lottery name|
|lottery_description|Yes|String|Lottery description|
|lottery_probability|Yes|Float|Probability of winning lottery (between 0 and 1)|
lottery_exp_time|Yes|String|Lottery expire date(format : YYYY-MM-DD HH:MM:SS)|
#### API endpoint
```
[POST] {url}/{version}/lottery
```
#### Body
```json=
{
"lottery_name": "Lottery2",
"lottery_description": "123AAAAAwtwudewdbAAAA",
"lottery_probability": 0.5,
"lottery_exp_time": "2020-10-10 23:59:59"
}
```
#### Example Response
```json=
{
"status": "true",
"code": "0",
"msg": "OK",
"data": {
"lottery_id": "168"
}
}
```
### Read lottery
| Parameters| Required | Type | Description |
|-----------|--------|---------|--------|
|lottery_id|Yes|String|Lottery id|
#### API end point
```
[GET] {url}/{version}/lottery/{lottery_id}
```
#### Example Response
```json=
{
"status": "true",
"code": "0",
"msg": "OK",
"data":{
"lottery_id" : "7",
"lottery_name" : "lottery2",
"lottery_description" : "lottery for 7",
"lottery_probability" : 0.5,
"lottery_exp_time" : "2020-12-12 23:24:25",
"rewards":[
{
"reward_id" : "9",
"reward_name" : "Reward3",
"reward_description" : "Reward for lottery 7",
"reward_asset" : 20,
"reward_asset_name" : "ABC"
},
{
"reward_id" : "10",
"reward_name" : "Reward5",
"reward_description" : "Reward for lottery 7",
"reward_asset" : 15,
"reward_asset_name" : "ABC"
},
{
"reward_id" : "11",
"reward_name" : "Reward7",
"reward_description" : "Reward for lottery 7",
"reward_asset" : 10,
"reward_asset_name" : "ABC"
}
]
}
}
```
### Update lottery
| Parameters| Required | Type | Description |
|-----------|--------|---------|--------|
|id|Yes|String|Lottery Id|
|lottery_name|Yes|String|Lottery name|
|lottery_description|Yes|String|Lottery description|
|lottery_probability|Yes|Float|Probability of winning lottery (between 0 and 1)|
lottery_exp_time|Yes|String|Lottery expire date (format : YYYY-MM-DD HH:MM:SS) |
#### API endpoint
```
[PUT] {url}/{version}/lottery
```
#### Body
```json=
{
"id": "79",
"lottery_name" : "Lottery3",
"lottery_description" : "This lottery is updated",
"lottery_probability" : 1.0,
"lottery_exp_time" : "2022-05-03 12:13:14"
}
```
#### Example Response
```json=
{
"status": "true",
"code": "0",
"msg": "OK"
}
```
### Delete lottery
| Parameters| Required | Type | Description |
|-----------|--------|---------|--------|
|lottery_id|Yes|String|lottery ID|
#### API end point
```
[DELETE] {url}/{version}/lottery/{lottery_id}
```
#### Example Response
```json=
{
"status": "true",
"code": "0",
"msg": "OK"
}
```
### Create reward
| Parameters| Required | Type | Description |
|-----------|--------|---------|--------|
|id|Yes|String|Lottery ID
|reward_name|Yes|String|Reward name|
|reward_description|Yes|String|Reward description|
|reward_asset|Yes|Int|Total asset to be rewarded|
|reward_asset_name|Yes|String|Rewarded token name|
#### API endpoint
```
[POST] {url}/{version}/reward
```
#### Body
```json=
{
"id": "93",
"rewards":[{
"reward_name" : "Reward1",
"reward_description" : "Reward for lottery 4",
"reward_asset" : 800,
"reward_asset_name" : "ABC"
},
{
"reward_name" : "Reward2",
"reward_description" : "Reward for lottery 4",
"reward_asset" : 500,
"reward_asset_name" : "ABC"
}]
}
```
#### Example Response
```json=
{
"status": "true",
"code": "0",
"msg": "OK"
}
```
### Get lottery reward
Get reward
| Parameters| Required | Type | Description |
|-----------|--------|---------|--------|
|winner|Yes|String|Winner wallet address|
|lottery_id | Yes | String | lottery ID|
#### API end point
```
[GET] {url}/{version}/lotteryreward/{winner}/{lottery_id}
```
#### Example response
```json=
{
"status": "true",
"code": "0",
"msg": "OK",
"data": {
"reward_id": "51"
}
}
```
### Reward transaction
#### Transfer reward to wallet address
| Parameters| Required | Type | Description |
|-----------|--------|---------|--------|
|winner|Yes|String|Winner wallet address|
| lottery_id | Yes | String | lottery ID|
|reward_id|Yes|String|reward ID|
#### API end point
```
[GET] {url}/{version}/save-reward/{winner}/{lottery_id}/{reward_id}
```
#### Example response
```json=
{
"status": "true",
"code": "0",
"msg": "OK",
"data": {
"reward_id": "21",
"create_time": "2020-07-03 05:57:18",
"winner": "1FgKByFhq3wgDmzKL3mG68kWXBRdxaTrAH",
"lottery_id": "3",
"tx_id": "2020-07-03T10:58:52.016018243Z",
"before_balance": 1153,
"current_balance": 1173
}
}
```
### Read reward
#### Read reward by reward id
| Parameters| Required | Type | Description |
|-----------|--------|---------|--------|
|reward_id|Yes|String|Reward id|
#### API end point
```
[GET] {url}/{version}/reward/{reward_id}
```
#### Example response
```json=
{
"status": "true",
"code": "0",
"msg": "OK",
"data": {
"reward_id": "60",
"lottery_id": "66",
"reward_name": "Reward4",
"reward_description": "Reward for lottery 49",
"reward_asset": 500,
"reward_asset_name": "ABC"
}
}
```
### Update reward
| Parameters| Required | Type | Description |
|-----------|--------|---------|--------|
|id|Yes|String|Lottery ID|
|reward_id|Yes|String|Reward ID|
|reward_name|Yes|String|Reward name|
|reward_description|Yes|String|Reward Description|
|reward_asset|Yes|Int|Total asset to be rewarded|
|reward_asset_name|Yes|String|Name of rewarding asset|
#### API end point
```
[PUT] {url}/{version}/reward
```
#### Body
```json=
{
"id": "93",
"rewards": [{
"reward_id" : "73",
"reward_name" : "Reward3",
"reward_description" : "Reward for lottery 7",
"reward_asset" : 20,
"reward_asset_name" : "AC"
},
{
"reward_id" : "74",
"reward_name" : "Reward9",
"reward_description" : "Reward for lottery 7",
"reward_asset" : 15,
"reward_asset_name" : "AC"
}]
}
```
#### Example Response
```json=
{
"status": "true",
"code": "0",
"msg": "OK"
}
```