Skip to content

Commit

Permalink
feat: update did cell data
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpiotzh committed Jun 5, 2024
1 parent e553840 commit 966f6d0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 18 deletions.
76 changes: 61 additions & 15 deletions block_parser/action_did_cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,27 @@ func (b *BlockParser) ActionEditDidCellRecords(req *FuncTransactionHandleReq) (r
return
}

var didCellData witness.DidCellData
if err := didCellData.BysToObj(req.Tx.OutputsData[txDidEntity.Outputs[0].Target.Index]); err != nil {
resp.Err = fmt.Errorf("didCellData.BysToObj err: %s", err.Error())
//var didCellData witness.DidCellData
//if err := didCellData.BysToObj(req.Tx.OutputsData[txDidEntity.Outputs[0].Target.Index]); err != nil {
// resp.Err = fmt.Errorf("didCellData.BysToObj err: %s", err.Error())
// return
//}
sporeData, didCellData, err := witness.BysToDidCellData(req.Tx.OutputsData[txDidEntity.Outputs[0].Target.Index])
if err != nil {
resp.Err = fmt.Errorf("witness.BysToDidCellData err: %s", err.Error())
return
}

account := didCellData.Account
account := ""
if sporeData != nil {
didCellDataLV, err := sporeData.ContentToDidCellDataLV()
if err != nil {
resp.Err = fmt.Errorf("sporeData.ContentToDidCellDataLV err: %s", err.Error())
return
}
account = didCellDataLV.Account
} else if didCellData != nil {
account = didCellData.Account
}
accountId := common.Bytes2Hex(common.GetAccountIdByAccount(account))
var recordsInfos []tables.TableRecordsInfo
recordList := txDidEntity.Outputs[0].DidCellWitnessDataV0.Records
Expand Down Expand Up @@ -67,20 +81,35 @@ func (b *BlockParser) ActionEditDidCellOwner(req *FuncTransactionHandleReq) (res
return
}
log.Info("ActionEditDidCellOwner:", req.BlockNumber, req.TxHash, req.Action)
//transfer:获取output里didcell的args
//renew:获取input里的didcell的args(更新t_did_cell 的expired_at)

didEntity, err := witness.TxToOneDidEntity(req.Tx, witness.SourceTypeOutputs)
if err != nil {
resp.Err = fmt.Errorf("TxToOneDidEntity err: %s", err.Error())
return
}
var didCellData witness.DidCellData
if err := didCellData.BysToObj(req.Tx.OutputsData[didEntity.Target.Index]); err != nil {
resp.Err = fmt.Errorf("didCellData.BysToObj err: %s", err.Error())
//var didCellData witness.DidCellData
//if err := didCellData.BysToObj(req.Tx.OutputsData[didEntity.Target.Index]); err != nil {
// resp.Err = fmt.Errorf("didCellData.BysToObj err: %s", err.Error())
// return
//}
sporeData, didCellData, err := witness.BysToDidCellData(req.Tx.OutputsData[didEntity.Target.Index])
if err != nil {
resp.Err = fmt.Errorf("witness.BysToDidCellData err: %s", err.Error())
return
}
account := ""
if sporeData != nil {
didCellDataLV, err := sporeData.ContentToDidCellDataLV()
if err != nil {
resp.Err = fmt.Errorf("sporeData.ContentToDidCellDataLV err: %s", err.Error())
return
}
account = didCellDataLV.Account
} else if didCellData != nil {
account = didCellData.Account
}

didCellArgs := common.Bytes2Hex(req.Tx.Outputs[didEntity.Target.Index].Lock.Args)
account := didCellData.Account
accountId := common.Bytes2Hex(common.GetAccountIdByAccount(account))
didCellInfo := tables.TableDidCellInfo{
BlockNumber: req.BlockNumber,
Expand Down Expand Up @@ -120,12 +149,29 @@ func (b *BlockParser) ActionDidCellRecycle(req *FuncTransactionHandleReq) (resp
log.Info("ActionDidCellRecycle:", req.BlockNumber, req.TxHash, req.Action)
preTxDidEntity, err := witness.TxToOneDidEntity(preTx.Transaction, witness.SourceTypeOutputs)

var preDidCellData witness.DidCellData
if err := preDidCellData.BysToObj(preTx.Transaction.OutputsData[preTxDidEntity.Target.Index]); err != nil {
resp.Err = fmt.Errorf("didCellData.BysToObj err: %s", err.Error())
//var preDidCellData witness.DidCellData
//if err := preDidCellData.BysToObj(preTx.Transaction.OutputsData[preTxDidEntity.Target.Index]); err != nil {
// resp.Err = fmt.Errorf("didCellData.BysToObj err: %s", err.Error())
// return
//}

sporeData, didCellData, err := witness.BysToDidCellData(preTx.Transaction.OutputsData[preTxDidEntity.Target.Index])
if err != nil {
resp.Err = fmt.Errorf("witness.BysToDidCellData err: %s", err.Error())
return
}
account := preDidCellData.Account
account := ""
if sporeData != nil {
didCellDataLV, err := sporeData.ContentToDidCellDataLV()
if err != nil {
resp.Err = fmt.Errorf("sporeData.ContentToDidCellDataLV err: %s", err.Error())
return
}
account = didCellDataLV.Account
} else if didCellData != nil {
account = didCellData.Account
}

accountId := common.Bytes2Hex(common.GetAccountIdByAccount(account))
oldOutpoint := common.OutPointStruct2String(req.Tx.Inputs[0].PreviousOutput)
if err := b.DbDao.DidCellRecycle(oldOutpoint, accountId); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module das-account-indexer
go 1.18

require (
github.com/dotbitHQ/das-lib v1.1.1-0.20240602180324-e83b7dcd57e0
github.com/dotbitHQ/das-lib v1.1.1-0.20240605105128-8e6bed6ce412
github.com/fsnotify/fsnotify v1.5.4
github.com/gin-gonic/gin v1.9.1
github.com/go-redis/redis v6.15.9+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5O
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
github.com/dotbitHQ/das-lib v1.1.1-0.20240602180324-e83b7dcd57e0 h1:eUYjTci/pDZOTHVA0pMvET1NXW6ypxkwQ7XaI3La14Y=
github.com/dotbitHQ/das-lib v1.1.1-0.20240602180324-e83b7dcd57e0/go.mod h1:XrDous4HH3jze59GLdmdKZaAQ8h3unTFUBsppph7IF8=
github.com/dotbitHQ/das-lib v1.1.1-0.20240605105128-8e6bed6ce412 h1:MAUu8kuhf4161zKb2TDwHi0ER84RmoxsTXta9qq8ATs=
github.com/dotbitHQ/das-lib v1.1.1-0.20240605105128-8e6bed6ce412/go.mod h1:XrDous4HH3jze59GLdmdKZaAQ8h3unTFUBsppph7IF8=
github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts=
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0=
Expand Down

0 comments on commit 966f6d0

Please sign in to comment.