diff --git a/block_parser/action_did_cell.go b/block_parser/action_did_cell.go index 88bab9e..7d7b0f5 100644 --- a/block_parser/action_did_cell.go +++ b/block_parser/action_did_cell.go @@ -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 @@ -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, @@ -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 { diff --git a/go.mod b/go.mod index 129253e..a76b462 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 1bf1ad3..0772fb6 100644 --- a/go.sum +++ b/go.sum @@ -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=