Skip to content

Commit 8b8cbde

Browse files
committed
fix
1 parent 3d3605d commit 8b8cbde

File tree

3 files changed

+55
-51
lines changed

3 files changed

+55
-51
lines changed

packages/neuron-ui/src/locales/zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,7 @@
11861186
"cancel": "取消",
11871187
"export": "导出交易"
11881188
},
1189+
"nervos-dao": "Nervos DAO",
11891190
"multisig-script-update-notice": "由于<0>多签脚本升级</0>,我们建议重新生成多签地址,并将资产从旧地址转移,以确保正常使用。",
11901191
"regenerate-dialog": {
11911192
"title": "重新生成",

packages/neuron-wallet/src/services/cells.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,13 +1328,14 @@ export default class CellsService {
13281328
CAST(SUM(CAST(multisig_output.capacity AS UNSIGNED BIG INT)) AS VARCHAR) as balance,
13291329
lockArgs,
13301330
lockCodeHash,
1331-
lockHashType
1331+
lockHashType,
1332+
lockHash
13321333
from
13331334
multisig_output
13341335
where
13351336
multisig_output.lockHash in (:...lockHashes) AND
13361337
status in (:...statuses)
1337-
group by multisig_output.lockArgs
1338+
group by multisig_output.lockHash
13381339
`,
13391340
{
13401341
lockHashes,

packages/neuron-wallet/src/services/multisig.ts

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,24 @@ export default class MultisigService {
7979
.createQueryBuilder()
8080
.orderBy('id', 'DESC')
8181
.getMany()
82-
return result
82+
const existMultisigLockHash: Set<string> = new Set()
83+
const uniqueMultisigConfigs: MultisigConfig[] = []
84+
for (const multisigConfig of result) {
85+
const multisigLockHash = Multisig.getMultisigScript(
86+
multisigConfig.blake160s,
87+
multisigConfig.r,
88+
multisigConfig.m,
89+
multisigConfig.n,
90+
multisigConfig.lockCodeHash
91+
).computeHash()
92+
if (existMultisigLockHash.has(multisigLockHash)) {
93+
await this.deleteConfig(multisigConfig.id)
94+
} else {
95+
existMultisigLockHash.add(multisigLockHash)
96+
uniqueMultisigConfigs.push(multisigConfig)
97+
}
98+
}
99+
return uniqueMultisigConfigs
83100
}
84101

85102
async getMultisigConfigById(id: number) {
@@ -141,7 +158,7 @@ export default class MultisigService {
141158
},
142159
'desc',
143160
'0x64',
144-
addressCursorMap.get(script.args),
161+
addressCursorMap.get(scriptToHash(script)),
145162
],
146163
}
147164
})
@@ -151,7 +168,7 @@ export default class MultisigService {
151168
if (!v.error && v?.result?.objects?.length) {
152169
const config = currentMultisigConfigs[idx]
153170
const script = Multisig.getMultisigScript(config.blake160s, config.r, config.m, config.n, config.lockCodeHash)
154-
addressCursorMap.set(script.args, v?.result?.last_cursor)
171+
addressCursorMap.set(scriptToHash(script), v?.result?.last_cursor)
155172
cells.push(...v.result.objects)
156173
nextMultisigConfigs.push(currentMultisigConfigs[idx])
157174
}
@@ -176,54 +193,39 @@ export default class MultisigService {
176193
}
177194

178195
static async saveMultisigDaoTx(multisigConfigs: MultisigConfig[]) {
179-
const cells = await MultisigService.getCells(multisigConfigs)
180-
if (cells.length) {
181-
const daoTxHash = new Set<string>()
182-
cells.forEach(cell => {
183-
if (cell.output?.type?.code_hash === SystemScriptInfo.DAO_CODE_HASH) {
184-
daoTxHash.add(cell.out_point.tx_hash)
185-
}
186-
})
187-
188-
const network = NetworksService.getInstance().getCurrent()
189-
const rpcService = new RpcService(network.remote, network.type)
190-
191-
const getTx = async (txHash: string) => {
192-
const txWithStatus: TransactionWithStatus | undefined | { transaction: null; txStatus: TxStatus } =
193-
await rpcService.getTransaction(txHash)
194-
if (txWithStatus?.transaction) {
195-
const tx = Transaction.fromSDK(txWithStatus.transaction)
196-
tx.blockHash = txWithStatus.txStatus.blockHash || undefined
197-
if (tx.blockHash) {
198-
const header = await rpcService.getHeader(tx.blockHash)
199-
tx.timestamp = header?.timestamp
200-
tx.blockNumber = header?.number
201-
}
202-
return tx
196+
const network = NetworksService.getInstance().getCurrent()
197+
const rpcService = new RpcService(network.remote, network.type)
198+
const getTx = async (txHash: string) => {
199+
const txWithStatus: TransactionWithStatus | undefined | { transaction: null; txStatus: TxStatus } =
200+
await rpcService.getTransaction(txHash)
201+
if (txWithStatus?.transaction) {
202+
const tx = Transaction.fromSDK(txWithStatus.transaction)
203+
tx.blockHash = txWithStatus.txStatus.blockHash || undefined
204+
if (tx.blockHash) {
205+
const header = await rpcService.getHeader(tx.blockHash)
206+
tx.timestamp = header?.timestamp
207+
tx.blockNumber = header?.number
203208
}
209+
return tx
204210
}
205-
206-
if (daoTxHash.size > 0) {
207-
for (const txHash of daoTxHash) {
208-
const tx = await getTx(txHash)
209-
if (tx) {
210-
const previousTxHashes: string[] = []
211-
tx.outputs.forEach((output, index) => {
212-
if (output.type?.codeHash === SystemScriptInfo.DAO_CODE_HASH) {
213-
output.daoData = tx.outputsData[index]
214-
if (tx.outputsData[index] !== DAO_DATA) {
215-
const previousTxHash = tx.inputs[index].previousOutput!.txHash
216-
previousTxHashes.push(previousTxHash)
217-
output.setDepositOutPoint(new OutPoint(previousTxHash, tx.inputs[index].previousOutput!.index))
218-
}
211+
}
212+
const multisigTxHashList = await MultisigService.getMultisigTransactionHashList(multisigConfigs)
213+
for (const txHash of [...multisigTxHashList].reverse()) {
214+
const tx = await getTx(txHash)
215+
if (tx) {
216+
if (tx.inputs.some(input => input.since && +input.since > 0)) {
217+
await TransactionPersistor.saveFetchTx(tx)
218+
} else if (tx.outputs.some(output => output.type?.codeHash === SystemScriptInfo.DAO_CODE_HASH)) {
219+
tx.outputs.forEach((output, index) => {
220+
if (output.type?.codeHash === SystemScriptInfo.DAO_CODE_HASH) {
221+
output.daoData = tx.outputsData[index]
222+
if (tx.outputsData[index] !== DAO_DATA) {
223+
const previousTxHash = tx.inputs[index].previousOutput!.txHash
224+
output.setDepositOutPoint(new OutPoint(previousTxHash, tx.inputs[index].previousOutput!.index))
219225
}
220-
})
221-
for (const previousTxHash of previousTxHashes) {
222-
const previousTx = await getTx(previousTxHash)
223-
if (previousTx) await TransactionPersistor.saveFetchTx(previousTx)
224226
}
225-
await TransactionPersistor.saveFetchTx(tx)
226-
}
227+
})
228+
await TransactionPersistor.saveFetchTx(tx)
227229
}
228230
}
229231
}
@@ -255,7 +257,7 @@ export default class MultisigService {
255257
},
256258
'desc',
257259
'0x64',
258-
addressCursorMap.get(script.args),
260+
addressCursorMap.get(scriptToHash(script)),
259261
],
260262
}
261263
})
@@ -265,7 +267,7 @@ export default class MultisigService {
265267
if (!v.error && v?.result?.objects?.length) {
266268
const config = currentMultisigConfigs[idx]
267269
const script = Multisig.getMultisigScript(config.blake160s, config.r, config.m, config.n, config.lockCodeHash)
268-
addressCursorMap.set(script.args, v?.result?.last_cursor)
270+
addressCursorMap.set(scriptToHash(script), v?.result?.last_cursor)
269271
v.result.objects.forEach((obj: any) => {
270272
multisigOutputTxHashList.add(obj.tx_hash || obj.transaction?.hash)
271273
})

0 commit comments

Comments
 (0)