Skip to content

Commit f746ec4

Browse files
committed
fix: comments
1 parent ead8d57 commit f746ec4

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

packages/neuron-wallet/src/controllers/api.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -916,9 +916,12 @@ export default class ApiController {
916916
}
917917
)
918918

919-
handle('generate-recycle-udt-cell-tx', async (_, params) => {
920-
return this.#assetAccountController.generateRecycleUDTCellTx(params)
921-
})
919+
handle(
920+
'generate-recycle-udt-cell-tx',
921+
async (_, params: { walletId: string; holder: string; tokenID: string; receiver: string; udtType: UDTType }) => {
922+
return this.#assetAccountController.generateRecycleUDTCellTx(params)
923+
}
924+
)
922925

923926
handle('generate-destroy-asset-account-tx', async (_, params: { walletID: string; id: number }) => {
924927
return this.#assetAccountController.destroyAssetAccount(params)

packages/neuron-wallet/src/controllers/sudt.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import LiveCellService from '../services/live-cell-service'
22
import AssetAccountInfo from '../models/asset-account-info'
33
import Script, { ScriptHashType } from '../models/chain/script'
44
import parseSUDTTokenInfo from '../utils/parse_sudt_token_info'
5-
import { ResponseCode, UDTType, MIN_SUDT_CAPACITY } from '../utils/const'
5+
import { ResponseCode, UDTType } from '../utils/const'
66
import { SudtTokenInfo } from '../models/chain/transaction'
77
import SudtTokenInfoService from '../services/sudt-token-info'
88
import AssetAccountService from '../services/asset-account-service'
@@ -49,9 +49,11 @@ export default class SUDTController {
4949
}
5050
}
5151
const balance = await AssetAccountService.calculateUDTAccountBalance(holder, tokenID, udtType)
52-
const ckbBalance = await AssetAccountService.calculateAvailableCKBBalance(holder)
52+
const cells = await AssetAccountService.getACPCells(holder, tokenID, udtType)
5353

54-
const capacity = BigInt(MIN_SUDT_CAPACITY) + BigInt(ckbBalance)
54+
let capacity = cells.reduce((a, b) => {
55+
return a + BigInt(b.capacity as string)
56+
}, BigInt(0))
5557

5658
return {
5759
status: ResponseCode.Success,

packages/neuron-wallet/src/models/system-script-info.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export default class SystemScriptInfo {
1010
static SECP_CODE_HASH = process.env.SECP256K1_CODE_HASH!
1111
static DAO_CODE_HASH = process.env.DAO_CODE_HASH!
1212
static MULTI_SIGN_CODE_HASH = process.env.MULTISIG_CODE_HASH!
13-
static SUDT_SCRIPT_CODEHASH = process.env.MAINNET_SUDT_SCRIPT_CODEHASH!
1413

1514
static SECP_HASH_TYPE = ScriptHashType.Type
1615
static DAO_HASH_TYPE = ScriptHashType.Type

packages/neuron-wallet/src/services/asset-account-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { MIN_CELL_CAPACITY, UDTType } from '../utils/const'
1919
import SudtTokenInfoService from './sudt-token-info'
2020

2121
export default class AssetAccountService {
22-
private static async getACPCells(publicKeyHash: string, tokenId: string = 'CKBytes', udtType?: UDTType) {
22+
public static async getACPCells(publicKeyHash: string, tokenId: string = 'CKBytes', udtType?: UDTType) {
2323
const assetAccountInfo = new AssetAccountInfo()
2424
const anyoneCanPayLockHash = assetAccountInfo.generateAnyoneCanPayScript(publicKeyHash).computeHash()
2525
const outputs = await getConnection()
@@ -36,7 +36,7 @@ export default class AssetAccountService {
3636
return outputs
3737
}
3838

39-
public static async calculateAvailableCKBBalance(publicKeyHash: string) {
39+
private static async calculateAvailableCKBBalance(publicKeyHash: string) {
4040
const outputs = await this.getACPCells(publicKeyHash)
4141

4242
const totalBalance = outputs

packages/neuron-wallet/src/services/tx/transaction-generator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,14 +836,14 @@ export class TransactionGenerator {
836836
assetAccountInputs: Input[],
837837
changeBlake160: string,
838838
isCKBAccount: boolean,
839-
forceDestroy?: boolean
839+
isForceDestroy?: boolean
840840
) {
841841
const secpCellDep = await SystemScriptInfo.getInstance().getSecpCellDep()
842842
const assetAccountInfo = new AssetAccountInfo()
843843

844844
const cellDeps = [secpCellDep, assetAccountInfo.anyoneCanPayCellDep]
845845
if (assetAccountInputs.some(v => v.type && v.data !== '0x' && BigInt(v.data || 0) !== BigInt(0))) {
846-
if (!forceDestroy) {
846+
if (!isForceDestroy) {
847847
throw new SudtAcpHaveDataError()
848848
}
849849
}

0 commit comments

Comments
 (0)