11import { getConnection , In , ObjectLiteral } from 'typeorm'
22import { ReplaySubject } from 'rxjs'
33import { OutPoint , Transaction , TransactionWithoutHash , Input , Cell , TransactionStatus } from '../types/cell-types'
4- import CellsService from './cells'
4+ import CellsService , { MIN_CELL_CAPACITY } from './cells'
55import InputEntity from '../database/chain/entities/input'
66import OutputEntity from '../database/chain/entities/output'
77import TransactionEntity from '../database/chain/entities/transaction'
88import NodeService from './node'
99import LockUtils from '../models/lock-utils'
10+ import { CapacityTooSmall } from '../exceptions'
1011
1112const { core } = NodeService . getInstance ( )
1213
@@ -504,11 +505,15 @@ export default class TransactionsService {
504505 . map ( o => BigInt ( o . capacity ) )
505506 . reduce ( ( result , c ) => result + c , BigInt ( 0 ) )
506507
507- const { inputs , capacities } = await CellsService . gatherInputs ( needCapacities . toString ( ) , lockHashes )
508+ const minCellCapacity = BigInt ( MIN_CELL_CAPACITY )
508509
509510 const outputs : Cell [ ] = targetOutputs . map ( o => {
510511 const { capacity, address } = o
511512
513+ if ( BigInt ( capacity ) < minCellCapacity ) {
514+ throw new CapacityTooSmall ( )
515+ }
516+
512517 const blake160 : string = LockUtils . addressToBlake160 ( address )
513518
514519 const output : Cell = {
@@ -523,6 +528,8 @@ export default class TransactionsService {
523528 return output
524529 } )
525530
531+ const { inputs, capacities } = await CellsService . gatherInputs ( needCapacities . toString ( ) , lockHashes , fee )
532+
526533 // change
527534 if ( BigInt ( capacities ) > needCapacities + BigInt ( fee ) ) {
528535 const changeBlake160 : string = LockUtils . addressToBlake160 ( changeAddress )
0 commit comments