Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	go.mod
#	go.sum
  • Loading branch information
scorpiotzh committed Jul 18, 2022
2 parents e90e8e0 + 1802c7e commit ec40962
Show file tree
Hide file tree
Showing 42 changed files with 1,281 additions and 374 deletions.
141 changes: 115 additions & 26 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
* [Transaction Status](#transaction-status)
* [Task Status](#task-status)
* [Sub Account Mint Status](#sub-account-mint-status)
* [Custom Script Set](#custom-script-set)
* [Custom Script Info](#custom-script-info)
* [Custom Script Price](#custom-script-price)
* [Owner Profit](#owner-profit)
* [INTERNAL API LIST](#internal-api-list)
* [Internal Create Sub Account](#internal-create-sub-account)
* [Internal Mint Sub Account](#internal-mint-sub-account)
* [Internal Mint Sub Account](#internal-mint-sub-account)
* [Internal Check Smt Info](#internal-check-smt-info)
* [Internal Update Smt](#internal-update-smt)

Expand All @@ -24,7 +27,7 @@ Please familiarize yourself with the meaning of some common parameters before re
| param | description |
| :------------------------- | :------------------------------------------------------------------ |
| type | Filled with "blockchain" for now |
| coin\_type <sup>[1](https://github.com/satoshilabs/slips/blob/master/slip-0044.md)</sup> | 60: eth, 195: trx, 714: bnb, 966: matic |
| coin\_type <sup>[1](https://github.com/satoshilabs/slips/blob/master/slip-0044.md)</sup> | 60: eth, 195: trx, 9006: bsc, 966: matic |
| chain\_id <sup>[2](https://github.com/ethereum-lists/chains)</sup> | 1: eth, 56: bsc, 137: polygon; 5: goerli, 97: bsct, 80001: mumbai |
| account | Contains the suffix `.bit` in it |
| key | Generally refers to the blockchain address for now |
Expand Down Expand Up @@ -59,6 +62,7 @@ _You can provide either `coin_type` or `chain_id`. The `coin_type` will be used,
#### Request

* path: /v1/account/list
* category: 1-main account 2-sub account 6-enable sub account

```json
{
Expand All @@ -68,7 +72,8 @@ _You can provide either `coin_type` or `chain_id`. The `coin_type` will be used,
"key_info": {
"coin_type": "60",
"chain_id": "1",
"key": "0x111..."
"key": "0x111...",
"category": 6
}
}
```
Expand Down Expand Up @@ -200,6 +205,8 @@ _You can provide either `coin_type` or `chain_id`. The `coin_type` will be used,

#### Response

* status:0-normal, 1-on sale, 2-on auction, 3-cross opensea

```json
{
"errno": 0,
Expand Down Expand Up @@ -583,54 +590,136 @@ _You can provide either `coin_type` or `chain_id`. The `coin_type` will be used,
}
```

## INTERNAL API LIST

### Internal Create Sub Account
### Custom Script Set

#### Request

* path: /v1/internal/sub/account/create
* path: /v1/custom/script/set

```json
{
"type": "blockchain",
"key_info": {
"coin_type": "60",
"chain_id": "1",
"key": "0x111"
"key": "0x111..."
},
"account": "",
"sub_account_list": [
"account": "test.bit",
"custom_script_args": "",
"custom_script_config": {
"1": {
"new": 5000000,
"renew": 5000000
},
"2": {
"new": 1000000,
"renew": 1000000
}
}
}
```

#### Response

```json
{
"action": "config_sub_account_custom_script",
"sign_key": "",
"list": [
{
"account": "",
"register_years": 1,
"type": "blockchain",
"key_info": {
"coin_type": "60",
"chain_id": "1",
"key": "0x111..."
}
"sign_list": [
{
"sign_type": 3,
"sign_msg": "0x123"
}
]
}
]
}
```

### Custom Script Info

#### Request

* path: /custom/script/info

```json
{
"account": "test.bit"
}
```

#### Response

```json
{
"errno": 0,
"errmsg": "",
"data": {
"task_ids": [
""
]
"custom_script_args": "",
"custom_script_config": {
"1": {
"new": 5000000,
"renew": 5000000
},
"2": {
"new": 1000000,
"renew": 1000000
}
}
}
```

### Custom Script Price

#### Request

* path: /custom/script/price

```json
{
"sub_account": "123.test.bit"
}
```

#### Response

```json
{
"custom_script_price": {
"new": 1000000,
"renew": 1000000
}
}
```

### Owner Profit

#### Request

* path: /owner/profit

```json
{
"type": "blockchain",
"key_info": {
"coin_type": "60",
"chain_id": "1",
"key": "0x111..."
},
"account": "tzh2022070601.bit"
}
```

#### Response

```json
{
"owner_profit": "256.8"
}
```

## INTERNAL API LIST

### Internal Mint Sub Account
### Internal Mint Sub Account

#### Request

Expand Down
86 changes: 77 additions & 9 deletions dao/t_account_info.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dao

import (
"das_sub_account/config"
"das_sub_account/tables"
"github.com/dotbitHQ/das-lib/common"
"time"
Expand All @@ -27,7 +28,11 @@ func (d *DbDao) GetSubAccountListByParentAccountId(parentAccountId string, chain
db = db.Where("expired_at>=? AND expired_at<=?", expiredAt, expiredAt30Days)
case tables.CategoryToBeRecycled:
expiredAt := time.Now().Unix()
db = db.Where("expired_at<=?", expiredAt)
recycledAt := time.Now().Add(-time.Hour * 24 * 90).Unix()
if config.Cfg.Server.Net != common.DasNetTypeMainNet {
recycledAt = time.Now().Add(-time.Hour * 24 * 3).Unix()
}
db = db.Where("expired_at<=? AND expired_at>=?", expiredAt, recycledAt)
}
if keyword != "" {
db = db.Where("account LIKE ?", "%"+keyword+"%")
Expand Down Expand Up @@ -61,7 +66,11 @@ func (d *DbDao) GetSubAccountListTotalByParentAccountId(parentAccountId string,
db = db.Where("expired_at>=? AND expired_at<=?", expiredAt, expiredAt30Days)
case tables.CategoryToBeRecycled:
expiredAt := time.Now().Unix()
db = db.Where("expired_at<=?", expiredAt)
recycledAt := time.Now().Add(-time.Hour * 24 * 90).Unix()
if config.Cfg.Server.Net != common.DasNetTypeMainNet {
recycledAt = time.Now().Add(-time.Hour * 24 * 3).Unix()
}
db = db.Where("expired_at<=? AND expired_at>=?", expiredAt, recycledAt)
}
if keyword != "" {
db = db.Where("account LIKE ?", "%"+keyword+"%")
Expand All @@ -81,16 +90,75 @@ func (d *DbDao) GetSubAccountListTotalByParentAccountId(parentAccountId string,
//return
}

func (d *DbDao) GetAccountList(chainType common.ChainType, address string, limit, offset int) (list []tables.TableAccountInfo, err error) {
err = d.parserDb.Where(" owner_chain_type=? AND owner=? ", chainType, address).
Or(" manager_chain_type=? AND manager=? ", chainType, address).
Order("account").Limit(limit).Offset(offset).Find(&list).Error
func (d *DbDao) GetAccountList(chainType common.ChainType, address string, limit, offset int, category tables.Category) (list []tables.TableAccountInfo, err error) {
//err = d.parserDb.Where(" owner_chain_type=? AND owner=? ", chainType, address).
// Or(" manager_chain_type=? AND manager=? ", chainType, address).
// Order("account").Limit(limit).Offset(offset).Find(&list).Error
//return

db := d.parserDb.Where("((owner_chain_type=? AND owner=?)OR(manager_chain_type=? AND manager=?))", chainType, address, chainType, address)
db = db.Where("status!=?", tables.AccountStatusOnCross)

switch category {
//case tables.CategoryDefault:
case tables.CategoryMainAccount:
db = db.Where("parent_account_id=''")
case tables.CategorySubAccount:
db = db.Where("parent_account_id!=''")
//case tables.CategoryOnSale:
// db = db.Where("status=?", tables.AccountStatusOnSale)
//case tables.CategoryExpireSoon:
// expiredAt := time.Now().Unix()
// expiredAt30Days := time.Now().Add(time.Hour * 24 * 30).Unix()
// db = db.Where("expired_at>=? AND expired_at<=?", expiredAt, expiredAt30Days)
//case tables.CategoryToBeRecycled:
// expiredAt := time.Now().Unix()
// recycledAt := time.Now().Add(-time.Hour * 24 * 90).Unix()
// if config.Cfg.Server.Net != common.DasNetTypeMainNet {
// recycledAt = time.Now().Add(-time.Hour * 24 * 3).Unix()
// }
// db = db.Where("expired_at<=? AND expired_at>=?", expiredAt, recycledAt)
case tables.CategoryEnableSubAccount:
db = db.Where("parent_account_id='' AND enable_sub_account=?", tables.AccountEnableStatusOn)
}

err = db.Order("account").Limit(limit).Offset(offset).Find(&list).Error

return
}

func (d *DbDao) GetAccountListTotal(chainType common.ChainType, address string) (count int64, err error) {
err = d.parserDb.Model(tables.TableAccountInfo{}).Where(" owner_chain_type=? AND owner=? ", chainType, address).
Or(" manager_chain_type=? AND manager=? ", chainType, address).Count(&count).Error
func (d *DbDao) GetAccountListTotal(chainType common.ChainType, address string, category tables.Category) (count int64, err error) {
//err = d.parserDb.Model(tables.TableAccountInfo{}).Where(" owner_chain_type=? AND owner=? ", chainType, address).
// Or(" manager_chain_type=? AND manager=? ", chainType, address).Count(&count).Error
//return
db := d.parserDb.Model(tables.TableAccountInfo{}).Where("((owner_chain_type=? AND owner=?)OR(manager_chain_type=? AND manager=?))", chainType, address, chainType, address)
db = db.Where("status!=?", tables.AccountStatusOnCross)

switch category {
//case tables.CategoryDefault:
case tables.CategoryMainAccount:
db = db.Where("parent_account_id=''")
case tables.CategorySubAccount:
db = db.Where("parent_account_id!=''")
//case tables.CategoryOnSale:
// db = db.Where("status=?", tables.AccountStatusOnSale)
//case tables.CategoryExpireSoon:
// expiredAt := time.Now().Unix()
// expiredAt30Days := time.Now().Add(time.Hour * 24 * 30).Unix()
// db = db.Where("expired_at>=? AND expired_at<=?", expiredAt, expiredAt30Days)
//case tables.CategoryToBeRecycled:
// expiredAt := time.Now().Unix()
// recycledAt := time.Now().Add(-time.Hour * 24 * 90).Unix()
// if config.Cfg.Server.Net != common.DasNetTypeMainNet {
// recycledAt = time.Now().Add(-time.Hour * 24 * 3).Unix()
// }
// db = db.Where("expired_at<=? AND expired_at>=?", expiredAt, recycledAt)
case tables.CategoryEnableSubAccount:
db = db.Where("parent_account_id='' AND enable_sub_account=?", tables.AccountEnableStatusOn)
}

err = db.Count(&count).Error

return
}

Expand Down
8 changes: 8 additions & 0 deletions dao/t_custom_script_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dao

import "das_sub_account/tables"

func (d *DbDao) GetCustomScriptInfo(accountId string) (info tables.TableCustomScriptInfo, err error) {
err = d.parserDb.Where("account_id=?", accountId).Find(&info).Error
return
}
27 changes: 27 additions & 0 deletions dao/t_task_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,33 @@ func (d *DbDao) UpdateSmtRecordToRollbackComplete(taskId string, list []tables.T
})
}

func (d *DbDao) UpdateTaskCompleteWithDiffCustomScriptHash(taskId string, list []tables.TableSmtRecordInfo) error {
return d.db.Transaction(func(tx *gorm.DB) error {
if err := tx.Model(tables.TableTaskInfo{}).
Where("task_id=? AND smt_status=?", taskId, tables.SmtStatusNeedToWrite).
Updates(map[string]interface{}{
"smt_status": tables.SmtStatusRollbackComplete,
}).Error; err != nil {
return err
}
for i, _ := range list {
if err := tx.Where("account_id=? AND nonce=? AND record_type=? AND task_id!=?",
list[i].AccountId, list[i].Nonce, tables.RecordTypeClosed, taskId).
Delete(&tables.TableSmtRecordInfo{}).Error; err != nil {
return err
}
}
if err := tx.Model(tables.TableSmtRecordInfo{}).
Where("task_id=?", taskId).
Updates(map[string]interface{}{
"record_type": tables.RecordTypeClosed,
}).Error; err != nil {
return err
}
return nil
})
}

func (d *DbDao) UpdateSmtRecordToNeedToWrite(taskId string, retry int) error {
return d.db.Model(tables.TableTaskInfo{}).
Where("task_id=? AND smt_status=?", taskId, tables.SmtStatusNeedToRollback).
Expand Down
Loading

0 comments on commit ec40962

Please sign in to comment.