Skip to content

Commit

Permalink
Merge branch 'anylock' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpiotzh committed Jun 13, 2024
2 parents 8ba8273 + f4aa159 commit 59b4c9f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
16 changes: 15 additions & 1 deletion block_parser/action_did_cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,22 @@ func (b *BlockParser) ActionEditDidCellOwner(req *FuncTransactionHandleReq) (res
LockCodeHash: req.Tx.Outputs[didEntity.Target.Index].Lock.CodeHash.Hex(),
}

var recordsInfos []tables.TableRecordsInfo
recordList := didEntity.DidCellWitnessDataV0.Records
for _, v := range recordList {
recordsInfos = append(recordsInfos, tables.TableRecordsInfo{
AccountId: accountId,
Account: account,
Key: v.Key,
Type: v.Type,
Label: v.Label,
Value: v.Value,
Ttl: strconv.FormatUint(uint64(v.TTL), 10),
})
}

oldOutpoint := common.OutPointStruct2String(req.Tx.Inputs[0].PreviousOutput)
if err := b.DbDao.EditDidCellOwner(oldOutpoint, didCellInfo); err != nil {
if err := b.DbDao.EditDidCellOwner(oldOutpoint, didCellInfo, recordsInfos); err != nil {
log.Error("EditDidCellOwner err:", err.Error())
resp.Err = fmt.Errorf("EditDidCellOwner err: %s", err.Error())
}
Expand Down
12 changes: 10 additions & 2 deletions dao/t_did_cell_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,23 @@ func (d *DbDao) CreateDidCellRecordsInfos(outpoint string, didCellInfo tables.Ta
})
}

func (d *DbDao) EditDidCellOwner(outpoint string, didCellInfo tables.TableDidCellInfo) error {
func (d *DbDao) EditDidCellOwner(outpoint string, didCellInfo tables.TableDidCellInfo, recordsInfos []tables.TableRecordsInfo) error {
return d.db.Transaction(func(tx *gorm.DB) error {
if err := tx.Select("outpoint", "block_number", "args", "lock_code_hash").
Where("outpoint = ?", outpoint).
Updates(didCellInfo).Error; err != nil {
return err
}
if err := tx.Where("account_id = ?", didCellInfo.AccountId).
Delete(&tables.TableRecordsInfo{}).Error; err != nil {
return err
}
if len(recordsInfos) > 0 {
if err := tx.Create(&recordsInfos).Error; err != nil {
return err
}
}
return nil

})
}

Expand Down

0 comments on commit 59b4c9f

Please sign in to comment.