Commit 5489c408 authored by szh's avatar szh

add uuid

parent 62e87db6
......@@ -10,6 +10,7 @@ import (
"ffie-admin/server/service"
"ffie-admin/server/utils"
"fmt"
"time"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil/psbt"
......@@ -144,7 +145,7 @@ func (brcLockApi *BrcLockApi) UpdateBrcLock(c *gin.Context) {
}
}
// UpdateLock 更新BrcLock
// UpdateLock 更新BrcLock Hash
// @Tags BrcLock
// @Summary 更新BrcLock
// @accept application/json
......@@ -162,11 +163,15 @@ func (brcLockApi *BrcLockApi) UpdateLock(c *gin.Context) {
verify := utils.Rules{
"Status": {utils.NotEmpty()},
}
if brcLock.ID == 0 && brcLock.Uuid == "" {
response.FailWithMessage("参数错误", c)
return
}
if err := utils.Verify(brcLock, verify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := brcLockService.UpdateBrcLock(brcLock); err != nil {
if err := brcLockService.UpdateLockHashByUuid(brcLock.Uuid, brcLock.Hash); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Error(err))
response.FailWithMessage("更新失败", c)
} else {
......@@ -394,6 +399,9 @@ func (brcLockApi *BrcLockApi) BuildBrc20Tx(c *gin.Context) {
"Ticker": {utils.NotEmpty()},
"Amount": {utils.NotEmpty()},
"UTXOs": {utils.NotEmpty()},
"Period": {utils.NotEmpty()},
"StartTime": {utils.NotEmpty()},
"Uuid": {utils.NotEmpty()},
}
if err := utils.Verify(req, verify); err != nil {
response.FailWithMessage(err.Error(), c)
......@@ -405,6 +413,19 @@ func (brcLockApi *BrcLockApi) BuildBrc20Tx(c *gin.Context) {
response.FailWithMessage(err.Error(), c)
return
}
psbtStr.Uuid = req.Uuid
period := int(req.Period)
startTime := time.Unix(int64(req.StartTime), 0)
if err := brcLockService.CreateBrcLock(brc.BrcLock{
Period: &period,
LockAddr: req.ToAddress,
Addr: req.FromAddress,
StartTime: &startTime,
Uuid: req.Uuid,
}); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithData(psbtStr, c)
}
......
......@@ -2194,6 +2194,11 @@ var doc = `{
"description": "更新时间",
"name": "updatedAt",
"in": "query"
},
{
"type": "string",
"name": "uuid",
"in": "query"
}
],
"responses": {
......@@ -2309,6 +2314,11 @@ var doc = `{
"description": "更新时间",
"name": "updatedAt",
"in": "query"
},
{
"type": "string",
"name": "uuid",
"in": "query"
}
],
"responses": {
......@@ -2419,6 +2429,11 @@ var doc = `{
"description": "更新时间",
"name": "updatedAt",
"in": "query"
},
{
"type": "string",
"name": "uuid",
"in": "query"
}
],
"responses": {
......@@ -5756,6 +5771,9 @@ var doc = `{
"updatedAt": {
"description": "更新时间",
"type": "string"
},
"uuid": {
"type": "string"
}
}
},
......@@ -7008,6 +7026,14 @@ var doc = `{
"fromAddress": {
"type": "string"
},
"period": {
"description": "锁定周期",
"type": "integer"
},
"startTime": {
"description": "锁定时间",
"type": "integer"
},
"ticker": {
"description": "代币符号FFFF",
"type": "string"
......@@ -7021,6 +7047,9 @@ var doc = `{
"items": {
"type": "string"
}
},
"uuid": {
"type": "string"
}
}
},
......
......@@ -2178,6 +2178,11 @@
"description": "更新时间",
"name": "updatedAt",
"in": "query"
},
{
"type": "string",
"name": "uuid",
"in": "query"
}
],
"responses": {
......@@ -2293,6 +2298,11 @@
"description": "更新时间",
"name": "updatedAt",
"in": "query"
},
{
"type": "string",
"name": "uuid",
"in": "query"
}
],
"responses": {
......@@ -2403,6 +2413,11 @@
"description": "更新时间",
"name": "updatedAt",
"in": "query"
},
{
"type": "string",
"name": "uuid",
"in": "query"
}
],
"responses": {
......@@ -5740,6 +5755,9 @@
"updatedAt": {
"description": "更新时间",
"type": "string"
},
"uuid": {
"type": "string"
}
}
},
......@@ -6992,6 +7010,14 @@
"fromAddress": {
"type": "string"
},
"period": {
"description": "锁定周期",
"type": "integer"
},
"startTime": {
"description": "锁定时间",
"type": "integer"
},
"ticker": {
"description": "代币符号FFFF",
"type": "string"
......@@ -7005,6 +7031,9 @@
"items": {
"type": "string"
}
},
"uuid": {
"type": "string"
}
}
},
......
......@@ -49,6 +49,8 @@ definitions:
updatedAt:
description: 更新时间
type: string
uuid:
type: string
type: object
config.AliyunOSS:
properties:
......@@ -924,6 +926,12 @@ definitions:
type: integer
fromAddress:
type: string
period:
description: 锁定周期
type: integer
startTime:
description: 锁定时间
type: integer
ticker:
description: 代币符号FFFF
type: string
......@@ -934,6 +942,8 @@ definitions:
items:
type: string
type: array
uuid:
type: string
type: object
request.Login:
properties:
......@@ -2964,6 +2974,9 @@ paths:
in: query
name: updatedAt
type: string
- in: query
name: uuid
type: string
produces:
- application/json
responses:
......@@ -3035,6 +3048,9 @@ paths:
in: query
name: updatedAt
type: string
- in: query
name: uuid
type: string
produces:
- application/json
responses:
......@@ -3106,6 +3122,9 @@ paths:
in: query
name: updatedAt
type: string
- in: query
name: uuid
type: string
produces:
- application/json
responses:
......
......@@ -17,6 +17,7 @@ type BrcLock struct {
LockAddr string `json:"lockAddr" form:"lockAddr" gorm:"column:lock_addr;comment:;size:72;"`
Hash string `json:"hash" form:"hash" gorm:"column:hash;comment:;size:96;"`
UnsignTx string `json:"unsignTx" form:"unsignTx" gorm:"column:unsign_tx;comment:;"`
Uuid string `json:"uuid" form:"uuid" gorm:"column:uuid;comment:;size:32;"`
}
// TableName BrcLock 表名
......
......@@ -28,13 +28,17 @@ type CreateBrx20TxReq struct {
type InscriptionTransferRequest struct {
FromAddress string `json:"fromAddress"`
ToAddress string `json:"toAddress"`
Ticker string `json:"ticker"` // 代币符号FFFF
Amount uint64 `json:"amount"` // 转移数量
FeeRate uint64 `json:"feeRate"` // sat/byte
UTXOs []string `json:"utxos"` // 铭文UTXO的txid:vout
Ticker string `json:"ticker"` // 代币符号FFFF
Amount uint64 `json:"amount"` // 转移数量
FeeRate uint64 `json:"feeRate"` // sat/byte
UTXOs []string `json:"utxos"` // 铭文UTXO的txid:vout
Period uint64 `json:"period"` // 锁定周期
StartTime uint64 `json:"startTime"` // 锁定时间
Uuid string `json:"uuid"`
}
type PSBTResponse struct {
Uuid string `json:"uuid"`
UnsignedPSBT string `json:"unsignedPSBT"`
UsedUTXOs []string `json:"usedUTXOs"`
ChangeAmount int64 `json:"changeAmount"` // 找零金额
......@@ -47,3 +51,12 @@ type InscriptionUTXO struct {
BTCAmt int64 `json:"btcAmt"` // 比特币金额(546聪)
Script string `json:"script"` // 铭文脚本
}
const (
LockStatusCommit = 0 // 提交
LockStatusHash = 1 // 上链
LockStatusHashSucc = 2 //上链成功质押中
LockStatusHashFail = 3 // 上链失败
LockStatusApplyUnLock = 4 // 申请解锁
LockStatusUnlock = 5 //解锁成功
)
......@@ -38,6 +38,16 @@ func (brcLockService *BrcLockService) UpdateBrcLock(brcLock brc.BrcLock) (err er
return err
}
func (brcLockService *BrcLockService) UpdateLockStatusByUuid(uuid string, status int) (err error) {
err = global.GVA_DB.Where("uuid = ?", uuid).UpdateColumn("status", status).Error
return err
}
func (brcLockService *BrcLockService) UpdateLockHashByUuid(uuid string, hash string) (err error) {
err = global.GVA_DB.Where("uuid = ?", uuid).UpdateColumn("hash", hash).Error
return err
}
// GetBrcLock 根据id获取BrcLock记录
// Author [piexlmax](https://github.com/piexlmax)
func (brcLockService *BrcLockService) GetBrcLock(id uint) (brcLock brc.BrcLock, err error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment