Skip to content

Commit 60a9a35

Browse files
committed
Merge branch 'anylock'
2 parents f041464 + 1162c5d commit 60a9a35

16 files changed

+750
-64
lines changed

block_parser/action_account_cell.go

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,26 @@ func (b *BlockParser) ActionRenewAccount(req FuncTransactionHandleReq) (resp Fun
209209

210210
log.Info("ActionRenewAccount:", builder.Account, builder.ExpiredAt, transactionInfo.Capacity)
211211

212-
if err := b.dbDao.RenewAccount(inputsOutpoints, incomeCellInfos, accountInfo, transactionInfo); err != nil {
212+
//renew did cell
213+
var didCellInfo dao.TableDidCellInfo
214+
var oldDidCellOutpoint string
215+
if didCellAction, err := b.dasCore.TxToDidCellAction(req.Tx); err != nil {
216+
if err != core.ErrorNotExistDidCell {
217+
log.Error("TxToDidCellAction err :", err.Error())
218+
}
219+
} else if didCellAction == common.DidCellActionRenew {
220+
txDidEntity, err := witness.TxToDidEntity(req.Tx)
221+
if err != nil {
222+
resp.Err = fmt.Errorf("witness.TxToDidEntity err: %s", err.Error())
223+
} else {
224+
oldDidCellOutpoint = common.OutPointStruct2String(req.Tx.Inputs[txDidEntity.Inputs[0].Target.Index].PreviousOutput)
225+
didCellInfo.Outpoint = common.OutPoint2String(req.Tx.Hash.Hex(), uint(txDidEntity.Outputs[0].Target.Index))
226+
didCellInfo.ExpiredAt = accountInfo.ExpiredAt
227+
didCellInfo.BlockNumber = accountInfo.BlockNumber
228+
}
229+
}
230+
231+
if err := b.dbDao.RenewAccount(inputsOutpoints, incomeCellInfos, accountInfo, transactionInfo, oldDidCellOutpoint, didCellInfo); err != nil {
213232
log.Error("RenewAccount err:", err.Error(), toolib.JsonString(transactionInfo))
214233
resp.Err = fmt.Errorf("RenewAccount err: %s", err.Error())
215234
}
@@ -358,6 +377,55 @@ func (b *BlockParser) ActionTransferAccount(req FuncTransactionHandleReq) (resp
358377
Outpoint: common.OutPoint2String(req.TxHash, uint(builder.Index)),
359378
BlockTimestamp: req.BlockTimestamp,
360379
}
380+
381+
// transfer accCell to didCell (for passkey)
382+
if builder.Status == common.AccountStatusOnUpgrade {
383+
txDidEntity, err := witness.TxToDidEntity(req.Tx)
384+
if err != nil {
385+
resp.Err = fmt.Errorf("witness.TxToDidEntity err: %s", err.Error())
386+
return
387+
}
388+
389+
if len(txDidEntity.Inputs) == 0 && len(txDidEntity.Outputs) == 1 {
390+
didCellArgs := common.Bytes2Hex(req.Tx.Outputs[txDidEntity.Outputs[0].Target.Index].Lock.Args)
391+
accountInfo := dao.TableAccountInfo{
392+
BlockNumber: req.BlockNumber,
393+
Outpoint: common.OutPoint2String(req.TxHash, uint(builder.Index)),
394+
AccountId: builder.AccountId,
395+
Status: builder.Status,
396+
}
397+
398+
didCellInfo := dao.TableDidCellInfo{
399+
BlockNumber: req.BlockNumber,
400+
Outpoint: common.OutPoint2String(req.TxHash, uint(txDidEntity.Outputs[0].Target.Index)),
401+
AccountId: builder.AccountId,
402+
Account: builder.Account,
403+
Args: didCellArgs,
404+
ExpiredAt: builder.ExpiredAt,
405+
LockCodeHash: req.Tx.Outputs[txDidEntity.Outputs[0].Target.Index].Lock.CodeHash.Hex(),
406+
}
407+
408+
var recordsInfos []dao.TableRecordsInfo
409+
recordList := txDidEntity.Outputs[0].DidCellWitnessDataV0.Records
410+
for _, v := range recordList {
411+
recordsInfos = append(recordsInfos, dao.TableRecordsInfo{
412+
AccountId: accountId,
413+
Account: account,
414+
Key: v.Key,
415+
Type: v.Type,
416+
Label: v.Label,
417+
Value: v.Value,
418+
Ttl: strconv.FormatUint(uint64(v.TTL), 10),
419+
})
420+
}
421+
if err := b.dbDao.TransferAccountToDid(accountInfo, didCellInfo, transactionInfo, recordsInfos); err != nil {
422+
log.Error("TransferAccountToDid err:", err.Error(), toolib.JsonString(transactionInfo))
423+
resp.Err = fmt.Errorf("TransferAccountToDid err: %s", err.Error())
424+
}
425+
return
426+
}
427+
}
428+
361429
accountInfo := dao.TableAccountInfo{
362430
BlockNumber: req.BlockNumber,
363431
Outpoint: common.OutPoint2String(req.TxHash, uint(builder.Index)),
@@ -607,3 +675,79 @@ func (b *BlockParser) ActionAccountCrossChain(req FuncTransactionHandleReq) (res
607675

608676
return
609677
}
678+
679+
func (b *BlockParser) ActionAccountUpgrade(req FuncTransactionHandleReq) (resp FuncTransactionHandleResp) {
680+
if isCV, err := isCurrentVersionTx(req.Tx, common.DasContractNameAccountCellType); err != nil {
681+
resp.Err = fmt.Errorf("isCurrentVersion err: %s", err.Error())
682+
return
683+
} else if !isCV {
684+
log.Warn("not current version account cross chain tx")
685+
return
686+
}
687+
fmt.Println("aaaaaaaaaaaaaaaaa")
688+
log.Info("ActionAccountCrossChain:", req.BlockNumber, req.TxHash, req.Action)
689+
690+
builder, err := witness.AccountCellDataBuilderFromTx(req.Tx, common.DataTypeNew)
691+
if err != nil {
692+
resp.Err = fmt.Errorf("AccountCellDataBuilderFromTx err: %s", err.Error())
693+
return
694+
}
695+
ownerHex, _, err := b.dasCore.Daf().ArgsToHex(req.Tx.Outputs[0].Lock.Args)
696+
if err != nil {
697+
resp.Err = fmt.Errorf("ArgsToHex err: %s", err.Error())
698+
return
699+
}
700+
didEntity, err := witness.TxToOneDidEntity(req.Tx, witness.SourceTypeOutputs)
701+
if err != nil {
702+
resp.Err = fmt.Errorf("TxToOneDidEntity err: %s", err.Error())
703+
return
704+
}
705+
didCellArgs := common.Bytes2Hex(req.Tx.Outputs[didEntity.Target.Index].Lock.Args)
706+
accountInfo := dao.TableAccountInfo{
707+
BlockNumber: req.BlockNumber,
708+
Outpoint: common.OutPoint2String(req.TxHash, 0),
709+
AccountId: builder.AccountId,
710+
Status: builder.Status,
711+
}
712+
713+
didCellInfo := dao.TableDidCellInfo{
714+
BlockNumber: req.BlockNumber,
715+
Outpoint: common.OutPoint2String(req.TxHash, 0),
716+
AccountId: builder.AccountId,
717+
Args: didCellArgs,
718+
LockCodeHash: req.Tx.Outputs[didEntity.Target.Index].Lock.CodeHash.Hex(),
719+
}
720+
721+
transactionInfo := dao.TableTransactionInfo{
722+
BlockNumber: req.BlockNumber,
723+
AccountId: builder.AccountId,
724+
Account: builder.Account,
725+
Action: req.Action,
726+
ServiceType: dao.ServiceTypeRegister,
727+
ChainType: ownerHex.ChainType,
728+
Address: ownerHex.AddressHex,
729+
Capacity: 0,
730+
Outpoint: common.OutPoint2String(req.TxHash, 0),
731+
BlockTimestamp: req.BlockTimestamp,
732+
}
733+
734+
var recordsInfos []dao.TableRecordsInfo
735+
recordList := didEntity.DidCellWitnessDataV0.Records
736+
for _, v := range recordList {
737+
recordsInfos = append(recordsInfos, dao.TableRecordsInfo{
738+
AccountId: builder.AccountId,
739+
Account: builder.Account,
740+
Key: v.Key,
741+
Type: v.Type,
742+
Label: v.Label,
743+
Value: v.Value,
744+
Ttl: strconv.FormatUint(uint64(v.TTL), 10),
745+
})
746+
}
747+
if err = b.dbDao.AccountUpgrade(accountInfo, didCellInfo, transactionInfo, recordsInfos); err != nil {
748+
log.Error("AccountCrossChain err:", err.Error(), req.TxHash, req.BlockNumber)
749+
resp.Err = fmt.Errorf("AccountCrossChain err: %s ", err.Error())
750+
return
751+
}
752+
return
753+
}

block_parser/action_did_cell.go

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
package block_parser
2+
3+
import (
4+
"context"
5+
"das_database/config"
6+
"das_database/dao"
7+
"fmt"
8+
"github.com/dotbitHQ/das-lib/common"
9+
"github.com/dotbitHQ/das-lib/witness"
10+
"github.com/nervosnetwork/ckb-sdk-go/address"
11+
"strconv"
12+
)
13+
14+
func (b *BlockParser) ActionEditDidCellRecords(req FuncTransactionHandleReq) (resp FuncTransactionHandleResp) {
15+
if isCV, err := isCurrentVersionTx(req.Tx, common.DasContractNameDidCellType); err != nil {
16+
resp.Err = fmt.Errorf("isCurrentVersion err: %s", err.Error())
17+
return
18+
} else if !isCV {
19+
log.Warn("not current version edit didcell records tx")
20+
return
21+
}
22+
log.Info("ActionEditDidCellRecords:", req.BlockNumber, req.TxHash, req.Action)
23+
24+
txDidEntity, err := witness.TxToDidEntity(req.Tx)
25+
if err != nil {
26+
resp.Err = fmt.Errorf("witness.TxToDidEntity err: %s", err.Error())
27+
return
28+
}
29+
30+
account, _, err := witness.GetAccountAndExpireFromDidCellData(req.Tx.OutputsData[txDidEntity.Outputs[0].Target.Index])
31+
if err != nil {
32+
resp.Err = fmt.Errorf("config.GetDidCellAccountAndExpire err: %s", err.Error())
33+
return
34+
}
35+
36+
//account := didCellData.Account
37+
accountId := common.Bytes2Hex(common.GetAccountIdByAccount(account))
38+
var recordsInfos []dao.TableRecordsInfo
39+
recordList := txDidEntity.Outputs[0].DidCellWitnessDataV0.Records
40+
for _, v := range recordList {
41+
recordsInfos = append(recordsInfos, dao.TableRecordsInfo{
42+
AccountId: accountId,
43+
Account: account,
44+
Key: v.Key,
45+
Type: v.Type,
46+
Label: v.Label,
47+
Value: v.Value,
48+
Ttl: strconv.FormatUint(uint64(v.TTL), 10),
49+
})
50+
}
51+
oldDidCellOutpoint := common.OutPointStruct2String(req.Tx.Inputs[txDidEntity.Inputs[0].Target.Index].PreviousOutput)
52+
var didCellInfo dao.TableDidCellInfo
53+
didCellInfo.AccountId = accountId
54+
didCellInfo.BlockNumber = req.BlockNumber
55+
didCellInfo.Outpoint = common.OutPoint2String(req.Tx.Hash.Hex(), uint(txDidEntity.Outputs[0].Target.Index))
56+
57+
mode := address.Mainnet
58+
if config.Cfg.Server.Net != common.DasNetTypeMainNet {
59+
mode = address.Testnet
60+
}
61+
anyLockAddr, err := address.ConvertScriptToAddress(mode, req.Tx.Outputs[txDidEntity.Outputs[0].Target.Index].Lock)
62+
if err != nil {
63+
resp.Err = fmt.Errorf("address.ConvertScriptToAddress err: %s", err.Error())
64+
return
65+
}
66+
txInfo := dao.TableTransactionInfo{
67+
BlockNumber: req.BlockNumber,
68+
AccountId: accountId,
69+
Account: account,
70+
Action: common.DidCellActionEditRecords,
71+
ServiceType: dao.ServiceTypeRegister,
72+
ChainType: common.ChainTypeAnyLock,
73+
Address: anyLockAddr,
74+
Capacity: 0,
75+
Outpoint: didCellInfo.Outpoint,
76+
BlockTimestamp: req.BlockTimestamp,
77+
}
78+
79+
if err := b.dbDao.CreateDidCellRecordsInfos(oldDidCellOutpoint, didCellInfo, recordsInfos, txInfo); err != nil {
80+
log.Error("CreateDidCellRecordsInfos err:", err.Error())
81+
resp.Err = fmt.Errorf("CreateDidCellRecordsInfos err: %s", err.Error())
82+
}
83+
84+
return
85+
}
86+
87+
func (b *BlockParser) ActionEditDidCellOwner(req FuncTransactionHandleReq) (resp FuncTransactionHandleResp) {
88+
if isCV, err := isCurrentVersionTx(req.Tx, common.DasContractNameDidCellType); err != nil {
89+
resp.Err = fmt.Errorf("isCurrentVersion err: %s", err.Error())
90+
return
91+
} else if !isCV {
92+
log.Warn("not current version edit didcell owner")
93+
return
94+
}
95+
log.Info("ActionEditDidCellOwner:", req.BlockNumber, req.TxHash, req.Action)
96+
97+
txDidEntity, err := witness.TxToDidEntity(req.Tx)
98+
if err != nil {
99+
resp.Err = fmt.Errorf("TxToDidEntity err: %s", err.Error())
100+
return
101+
}
102+
103+
account, _, err := witness.GetAccountAndExpireFromDidCellData(req.Tx.OutputsData[txDidEntity.Outputs[0].Target.Index])
104+
if err != nil {
105+
resp.Err = fmt.Errorf("config.GetDidCellAccountAndExpire err: %s", err.Error())
106+
return
107+
}
108+
109+
didCellArgs := common.Bytes2Hex(req.Tx.Outputs[txDidEntity.Outputs[0].Target.Index].Lock.Args)
110+
accountId := common.Bytes2Hex(common.GetAccountIdByAccount(account))
111+
didCellInfo := dao.TableDidCellInfo{
112+
BlockNumber: req.BlockNumber,
113+
Outpoint: common.OutPoint2String(req.TxHash, uint(txDidEntity.Outputs[0].Target.Index)),
114+
AccountId: accountId,
115+
Args: didCellArgs,
116+
LockCodeHash: req.Tx.Outputs[txDidEntity.Outputs[0].Target.Index].Lock.CodeHash.Hex(),
117+
}
118+
119+
oldOutpoint := common.OutPointStruct2String(req.Tx.Inputs[txDidEntity.Inputs[0].Target.Index].PreviousOutput)
120+
121+
preInput := req.Tx.Inputs[txDidEntity.Inputs[0].Target.Index].PreviousOutput
122+
preTx, err := b.dasCore.Client().GetTransaction(context.Background(), preInput.TxHash)
123+
if err != nil {
124+
resp.Err = fmt.Errorf("GetTransaction err: %s", err.Error())
125+
return
126+
}
127+
mode := address.Mainnet
128+
if config.Cfg.Server.Net != common.DasNetTypeMainNet {
129+
mode = address.Testnet
130+
}
131+
anyLockAddr, err := address.ConvertScriptToAddress(mode, preTx.Transaction.Outputs[preInput.Index].Lock)
132+
if err != nil {
133+
resp.Err = fmt.Errorf("address.ConvertScriptToAddress err: %s", err.Error())
134+
return
135+
}
136+
txInfo := dao.TableTransactionInfo{
137+
BlockNumber: req.BlockNumber,
138+
AccountId: accountId,
139+
Account: account,
140+
Action: common.DidCellActionEditOwner,
141+
ServiceType: dao.ServiceTypeRegister,
142+
ChainType: common.ChainTypeAnyLock,
143+
Address: anyLockAddr,
144+
Capacity: 0,
145+
Outpoint: didCellInfo.Outpoint,
146+
BlockTimestamp: req.BlockTimestamp,
147+
}
148+
149+
var recordsInfos []dao.TableRecordsInfo
150+
recordList := txDidEntity.Outputs[0].DidCellWitnessDataV0.Records
151+
for _, v := range recordList {
152+
recordsInfos = append(recordsInfos, dao.TableRecordsInfo{
153+
AccountId: accountId,
154+
Account: account,
155+
Key: v.Key,
156+
Type: v.Type,
157+
Label: v.Label,
158+
Value: v.Value,
159+
Ttl: strconv.FormatUint(uint64(v.TTL), 10),
160+
})
161+
}
162+
163+
if err := b.dbDao.EditDidCellOwner(oldOutpoint, didCellInfo, txInfo, recordsInfos); err != nil {
164+
log.Error("EditDidCellOwner err:", err.Error())
165+
resp.Err = fmt.Errorf("EditDidCellOwner err: %s", err.Error())
166+
}
167+
return
168+
}
169+
170+
func (b *BlockParser) ActionDidCellRecycle(req FuncTransactionHandleReq) (resp FuncTransactionHandleResp) {
171+
didEntity, err := witness.TxToOneDidEntity(req.Tx, witness.SourceTypeInputs)
172+
if err != nil {
173+
resp.Err = fmt.Errorf("TxToOneDidEntity err: %s", err.Error())
174+
return
175+
}
176+
preTx, err := b.dasCore.Client().GetTransaction(b.ctx, req.Tx.Inputs[didEntity.Target.Index].PreviousOutput.TxHash)
177+
if err != nil {
178+
resp.Err = fmt.Errorf("GetTransaction err: %s", err.Error())
179+
return
180+
}
181+
182+
if isCV, err := isCurrentVersionTx(preTx.Transaction, common.DasContractNameDidCellType); err != nil {
183+
resp.Err = fmt.Errorf("isCurrentVersion err: %s", err.Error())
184+
return
185+
} else if !isCV {
186+
log.Warn("not current version didcell recycle")
187+
return
188+
}
189+
log.Info("ActionDidCellRecycle:", req.BlockNumber, req.TxHash, req.Action)
190+
account, _, err := witness.GetAccountAndExpireFromDidCellData(preTx.Transaction.OutputsData[req.Tx.Inputs[didEntity.Target.Index].PreviousOutput.Index])
191+
if err != nil {
192+
resp.Err = fmt.Errorf("config.GetDidCellAccountAndExpire err: %s", err.Error())
193+
return
194+
}
195+
196+
accountId := common.Bytes2Hex(common.GetAccountIdByAccount(account))
197+
oldOutpoint := common.OutPointStruct2String(req.Tx.Inputs[0].PreviousOutput)
198+
199+
mode := address.Mainnet
200+
if config.Cfg.Server.Net != common.DasNetTypeMainNet {
201+
mode = address.Testnet
202+
}
203+
anyLockAddr, err := address.ConvertScriptToAddress(mode, preTx.Transaction.Outputs[req.Tx.Inputs[didEntity.Target.Index].PreviousOutput.Index].Lock)
204+
if err != nil {
205+
resp.Err = fmt.Errorf("address.ConvertScriptToAddress err: %s", err.Error())
206+
return
207+
}
208+
txInfo := dao.TableTransactionInfo{
209+
BlockNumber: req.BlockNumber,
210+
AccountId: accountId,
211+
Account: account,
212+
Action: common.DidCellActionRecycle,
213+
ServiceType: dao.ServiceTypeRegister,
214+
ChainType: common.ChainTypeAnyLock,
215+
Address: anyLockAddr,
216+
Capacity: 0,
217+
Outpoint: common.OutPoint2String(req.TxHash, 0),
218+
BlockTimestamp: req.BlockTimestamp,
219+
}
220+
221+
if err := b.dbDao.DidCellRecycle(oldOutpoint, accountId, txInfo); err != nil {
222+
log.Error("DidCellRecycle err:", err.Error())
223+
resp.Err = fmt.Errorf("DidCellRecycle err: %s", err.Error())
224+
}
225+
return
226+
}

0 commit comments

Comments
 (0)