-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
470 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package model | ||
|
||
import ( | ||
"nft-collect/internal/app/global" | ||
) | ||
|
||
type CollectionSolana struct { | ||
global.MODEL | ||
Status uint8 `gorm:"default:0;" json:"status" form:"status"` // 显示状态(0:初始状态 1:隐藏 2:显示) | ||
NFTScanSolana | ||
} | ||
|
||
type NFTScanSolana struct { | ||
Collection string `gorm:"column:collection" json:"collection" form:"collection"` // Collection 地址 | ||
TokenAddress string `gorm:"column:token_address;unique" json:"token_address" form:"token_address"` // Token 地址 | ||
Minter string `json:"minter" form:"minter"` | ||
Owner string `json:"owner" form:"owner"` | ||
MintTimestamp int64 `json:"mint_timestamp"` | ||
MintTransactionHash string `json:"mint_transaction_hash"` | ||
TokenURI string `json:"token_uri"` | ||
MetadataJSON string `json:"metadata_json"` | ||
Name string `json:"name"` | ||
ContentType string `json:"content_type"` | ||
ContentURI string `json:"content_uri"` | ||
ImageURI string `json:"image_uri"` | ||
ExternalLink string `json:"external_link"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package model | ||
|
||
import ( | ||
"nft-collect/internal/app/global" | ||
) | ||
|
||
type ContractSolana struct { | ||
global.MODEL | ||
Chain string `gorm:"default:'solana'" json:"chain" form:"chain"` // 区块链的简称 | ||
ContractAddress string `gorm:"default:''" json:"contract_address" form:"contract_address"` // 合约地址 | ||
ContractName string `gorm:"default:'';not null" json:"contract_name" form:"contract_name"` // 合约名称 | ||
ContractLogo string `gorm:"default:''" json:"contract_logo" form:"contract_logo"` // 合约Logo | ||
ContractBanner string `gorm:"default:''" json:"contract_banner" form:"contract_banner"` // 合约Banner | ||
ContractDescription string `gorm:"default:''" json:"contract_description" form:"contract_description"` // 合约Description | ||
ContractWebsite string `gorm:"default:''" json:"contract_website" form:"contract_website"` // 合约Website | ||
ContractOwner string `gorm:"default:''" json:"contract_owner" form:"contract_owner"` // 合约Owner | ||
Status uint8 `gorm:"default:1;" json:"-" form:"-"` // 显示状态(1:未获取 2:已获取) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package receive | ||
|
||
type SolanaCollection struct { | ||
Code int `json:"code"` | ||
Msg interface{} `json:"msg"` | ||
Data struct { | ||
Total int `json:"total"` | ||
Next interface{} `json:"next"` | ||
Content []struct { | ||
BlockNumber int `json:"block_number"` | ||
InteractProgram string `json:"interact_program"` | ||
Collection string `json:"collection"` | ||
TokenAddress string `json:"token_address"` | ||
Minter string `json:"minter"` | ||
Owner string `json:"owner"` | ||
MintTimestamp int64 `json:"mint_timestamp"` | ||
MintTransactionHash string `json:"mint_transaction_hash"` | ||
MintPrice int `json:"mint_price"` | ||
TokenURI string `json:"token_uri"` | ||
MetadataJSON string `json:"metadata_json"` | ||
Name string `json:"name"` | ||
ContentType string `json:"content_type"` | ||
ContentURI string `json:"content_uri"` | ||
ImageURI string `json:"image_uri"` | ||
ExternalLink string `json:"external_link"` | ||
LatestTradePrice interface{} `json:"latest_trade_price"` | ||
LatestTradeTimestamp interface{} `json:"latest_trade_timestamp"` | ||
LatestTradeTransactionHash interface{} `json:"latest_trade_transaction_hash"` | ||
} `json:"content"` | ||
} `json:"data"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package service | ||
|
||
import ( | ||
"gorm.io/gorm" | ||
"nft-collect/internal/app/global" | ||
"nft-collect/internal/app/model" | ||
"nft-collect/internal/app/model/response" | ||
) | ||
|
||
// GetSolanaContract 获取 Solana 合约 | ||
func GetSolanaContract(address, account string) (res []response.GetSolanaContractRes, err error) { | ||
db := global.DB | ||
var user model.Account | ||
|
||
errFirst := db.Model(&model.Account{}).Where("address = ?", address).First(&user).Error | ||
if errFirst != nil && errFirst != gorm.ErrRecordNotFound { | ||
return res, errFirst | ||
} | ||
// 初始化账户 | ||
if errFirst == gorm.ErrRecordNotFound { | ||
initSolanaAccount(address) | ||
if err = db.Model(&model.Account{}).Where("address = ?", address).First(&user).Error; err != nil { | ||
return | ||
} | ||
} | ||
|
||
//if len(user.ContractIDs) != len(user.Counts) { | ||
// updateSolanaContractCount(address) | ||
//} | ||
// TODO 查询默认合约 | ||
dealList := []string{"Decert Badge"} | ||
contractMap := make(map[string]int64) | ||
for _, name := range dealList { | ||
// TODO 优化 | ||
var count int64 | ||
err = db.Model(&model.Collection{}). | ||
Raw("SElECT COUNT(1) FROM collection_solana a JOIN contract_solana b ON a.collection=b.contract_name WHERE b.contract_name = ? AND minter= ?", name, address). | ||
Scan(&count).Error | ||
contractMap[name] = count | ||
} | ||
// show different counts | ||
if address == account { | ||
for i, _ := range user.ContractIDs { | ||
contractMap[user.ContractIDs[i]] = user.Counts[i] | ||
} | ||
} else { | ||
for i, _ := range user.ContractIDs { | ||
contractMap[user.ContractIDs[i]] = user.CountsShow[i] | ||
} | ||
} | ||
// slice as query | ||
var contractIDs []string | ||
for _, c := range dealList { | ||
contractIDs = append(contractIDs, c) | ||
} | ||
for _, c := range user.ContractIDs { | ||
contractIDs = append(contractIDs, c) | ||
} | ||
// get contract detail | ||
var contract []model.ContractSolana | ||
err = db.Model(&model.ContractSolana{}).Where("contract_name", contractIDs).Find(&contract).Error | ||
if err != nil { | ||
return res, err | ||
} | ||
res = append(res, response.GetSolanaContractRes{ContractSolana: contract[0], Count: contractMap[contract[0].ContractName]}) | ||
return res, err | ||
} | ||
|
||
// initSolanaAccount | ||
func initSolanaAccount(address string) (err error) { | ||
var uuidList []string | ||
// 创建 | ||
var id string | ||
db := global.DB.Model(&model.ContractSolana{}).Select("id") | ||
errFirst := db.First(&id).Error | ||
if errFirst != nil { | ||
if errFirst != gorm.ErrRecordNotFound { | ||
return errFirst | ||
} | ||
return errFirst | ||
} | ||
uuidList = append(uuidList, id) | ||
|
||
user := &model.Account{Address: address} | ||
err = global.DB.Model(&model.Account{}).Create(&user).Error | ||
if err != nil { | ||
return err | ||
} | ||
//updateSolanaAllCollection(address, uuidList, true, false) | ||
return err | ||
} | ||
|
||
/* | ||
// updateSolanaContractCount | ||
func updateSolanaContractCount(address string) (err error) { | ||
db := global.DB | ||
var user model.Account | ||
if err = db.Model(&model.Account{}).Select("contract_ids").Where("address", address).First(&user).Error; err != nil { | ||
return err | ||
} | ||
var counts []int64 | ||
var countsShow []int64 | ||
var contractIDs []string | ||
for _, v := range user.ContractIDs { | ||
var nftContract model.ContractSolana | ||
if errErrFind := db.Model(&model.ContractSolana{}).Where("id", v).First(&nftContract).Error; errErrFind != nil { | ||
continue | ||
} | ||
var count int64 | ||
var countShow int64 | ||
// TODO: 添加状态 需要确定是否过滤 | ||
err = db.Model(&model.CollectionSolana{}). | ||
Where("collection", nftContract.ContractName).Where("minter", address). | ||
Count(&count).Error | ||
if err != nil { | ||
return err | ||
} | ||
err = db.Model(&model.CollectionSolana{}). | ||
Where("collection", nftContract.ContractName).Where("minter", address).Where("status", 2). | ||
Count(&countShow).Error | ||
if err != nil { | ||
return err | ||
} | ||
contractIDs = append(contractIDs, v) | ||
counts = append(counts, count) | ||
countsShow = append(countsShow, countShow) | ||
} | ||
if err = db.Model(&model.Account{}).Where("address", address).Updates(model.Account{ContractIDs: contractIDs, Counts: counts, CountsShow: countsShow}).Error; err != nil { | ||
return err | ||
} | ||
// TODO: 清除零数量的合约 | ||
return nil | ||
} | ||
*/ |
Oops, something went wrong.