Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dutch_auction' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	go.mod
#	go.sum
  • Loading branch information
457813723 committed Nov 13, 2023
2 parents ce51194 + dc19f08 commit e7958b8
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
86 changes: 86 additions & 0 deletions block_parser/action_account_cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,92 @@ func (b *BlockParser) ActionRenewAccount(req FuncTransactionHandleReq) (resp Fun
return
}

func (b *BlockParser) ActionBidExpiredAccountAuction(req FuncTransactionHandleReq) (resp FuncTransactionHandleResp) {
if isCV, err := isCurrentVersionTx(req.Tx, common.DasContractNameAccountCellType); err != nil {
resp.Err = fmt.Errorf("isCurrentVersion err: %s", err.Error())
return
} else if !isCV {
log.Warn("not current version transfer account tx")
return
}
log.Info("BidExpiredAccountAuction:", req.BlockNumber, req.TxHash)

builder, err := witness.AccountCellDataBuilderFromTx(req.Tx, common.DataTypeNew)
if err != nil {
resp.Err = fmt.Errorf("AccountCellDataBuilderFromTx err: %s", err.Error())
return
}
account := builder.Account
accountId := common.Bytes2Hex(common.GetAccountIdByAccount(account))
oHex, mHex, err := b.dasCore.Daf().ArgsToHex(req.Tx.Outputs[builder.Index].Lock.Args)
if err != nil {
resp.Err = fmt.Errorf("ArgsToHex err: %s", err.Error())
return
}

res, err := b.dasCore.Client().GetTransaction(b.ctx, req.Tx.Inputs[builder.Index].PreviousOutput.TxHash)
if err != nil {
resp.Err = fmt.Errorf("GetTransaction err: %s", err.Error())
return
}

oldHex, _, err := b.dasCore.Daf().ArgsToHex(res.Transaction.Outputs[req.Tx.Inputs[builder.Index].PreviousOutput.Index].Lock.Args)
if err != nil {
resp.Err = fmt.Errorf("ArgsToHex err: %s", err.Error())
return
}
transactionInfos := make([]dao.TableTransactionInfo, 0)

transactionInfos = append(transactionInfos, dao.TableTransactionInfo{
BlockNumber: req.BlockNumber,
AccountId: accountId,
Account: account,
Action: common.DasActionTransferAccount,
ServiceType: dao.ServiceTypeRegister,
ChainType: oldHex.ChainType,
Address: oldHex.AddressHex,
Capacity: 0,
Outpoint: common.OutPoint2String(req.TxHash, uint(builder.Index)),
BlockTimestamp: req.BlockTimestamp,
})
transactionInfos = append(transactionInfos, dao.TableTransactionInfo{
BlockNumber: req.BlockNumber,
AccountId: accountId,
Account: account,
Action: common.DasActionTransferAccount,
ServiceType: dao.ServiceTypeRegister,
ChainType: oHex.ChainType,
Address: oHex.AddressHex,
Capacity: 0,
Outpoint: common.OutPoint2String(req.TxHash, uint(builder.Index)),
BlockTimestamp: req.BlockTimestamp,
})

accountInfo := dao.TableAccountInfo{
BlockNumber: req.BlockNumber,
Outpoint: common.OutPoint2String(req.TxHash, uint(builder.Index)),
AccountId: accountId,
Account: account,
OwnerChainType: oHex.ChainType,
Owner: oHex.AddressHex,
OwnerAlgorithmId: oHex.DasAlgorithmId,
OwnerSubAid: oHex.DasSubAlgorithmId,
ManagerChainType: mHex.ChainType,
Manager: mHex.AddressHex,
ManagerAlgorithmId: mHex.DasAlgorithmId,
ManagerSubAid: mHex.DasSubAlgorithmId,
ExpiredAt: builder.ExpiredAt,
RegisteredAt: builder.RegisteredAt,
}
log.Info("ActionBidExpiredAccountAuction:", accountInfo)

if err := b.dbDao.BidExpiredAccountAuction(accountInfo, transactionInfos); err != nil {
log.Error("ActionBidExpiredAccountAuction err:", err.Error(), toolib.JsonString(accountInfo))
resp.Err = fmt.Errorf("ActionBidExpiredAccountAuction err: %s", err.Error())
}
return
}

func (b *BlockParser) ActionTransferAccount(req FuncTransactionHandleReq) (resp FuncTransactionHandleResp) {
if isCV, err := isCurrentVersionTx(req.Tx, common.DasContractNameAccountCellType); err != nil {
resp.Err = fmt.Errorf("isCurrentVersion err: %s", err.Error())
Expand Down
2 changes: 2 additions & 0 deletions block_parser/block_parser_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func (b *BlockParser) registerTransactionHandle() {
b.mapTransactionHandle[common.DasActionDelayApproval] = b.DasActionDelayApproval
b.mapTransactionHandle[common.DasActionRevokeApproval] = b.DasActionRevokeApproval
b.mapTransactionHandle[common.DasActionFulfillApproval] = b.DasActionFulfillApproval
b.mapTransactionHandle[common.DasBidExpiredAccountAuction] = b.ActionBidExpiredAccountAuction

Check failure on line 74 in block_parser/block_parser_handle.go

View workflow job for this annotation

GitHub Actions / ci

undefined: common.DasBidExpiredAccountAuction

}

func isCurrentVersionTx(tx *types.Transaction, name common.DasContractName) (bool, error) {
Expand Down
26 changes: 26 additions & 0 deletions dao/dao_account_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,32 @@ func (d *DbDao) GetAccountInfoByParentAccountId(parentAccountId string) (account
return
}

func (d *DbDao) BidExpiredAccountAuction(accountInfo TableAccountInfo, transactionInfos []TableTransactionInfo) error {
return d.db.Transaction(func(tx *gorm.DB) error {
//update account_info
if err := tx.Select("expired_at", "registered_at", "block_number", "outpoint", "owner_chain_type", "owner", "owner_algorithm_id", "owner_sub_aid", "manager_chain_type", "manager", "manager_algorithm_id", "manager_sub_aid").
Where("account_id = ?", accountInfo.AccountId).
Updates(accountInfo).Error; err != nil {
return err
}

if err := tx.Clauses(clause.OnConflict{
DoUpdates: clause.AssignmentColumns([]string{
"account_id", "account", "service_type",
"chain_type", "address", "capacity", "status",
}),
}).Create(&transactionInfos).Error; err != nil {
return err
}

//delete record
if err := tx.Where("account_id=?", accountInfo.AccountId).Delete(&TableRecordsInfo{}).Error; err != nil {
return err
}
return nil
})
}

func (d *DbDao) RecycleExpiredAccount(accountInfo TableAccountInfo, transactionInfo TableTransactionInfo, accountId string, enableSubAccount uint8) error {
return d.db.Transaction(func(tx *gorm.DB) error {
if err := tx.Select("block_number", "outpoint").
Expand Down

0 comments on commit e7958b8

Please sign in to comment.