1
1
import { getConnection , In , ObjectLiteral } from 'typeorm'
2
2
import { ReplaySubject } from 'rxjs'
3
3
import { OutPoint , Transaction , TransactionWithoutHash , Input , Cell , TransactionStatus } from '../types/cell-types'
4
- import CellsService from './cells'
4
+ import CellsService , { MIN_CELL_CAPACITY } from './cells'
5
5
import InputEntity from '../database/chain/entities/input'
6
6
import OutputEntity from '../database/chain/entities/output'
7
7
import TransactionEntity from '../database/chain/entities/transaction'
8
8
import NodeService from './node'
9
9
import LockUtils from '../models/lock-utils'
10
+ import { CapacityTooSmall } from '../exceptions'
10
11
11
12
const { core } = NodeService . getInstance ( )
12
13
@@ -504,11 +505,15 @@ export default class TransactionsService {
504
505
. map ( o => BigInt ( o . capacity ) )
505
506
. reduce ( ( result , c ) => result + c , BigInt ( 0 ) )
506
507
507
- const { inputs , capacities } = await CellsService . gatherInputs ( needCapacities . toString ( ) , lockHashes )
508
+ const minCellCapacity = BigInt ( MIN_CELL_CAPACITY )
508
509
509
510
const outputs : Cell [ ] = targetOutputs . map ( o => {
510
511
const { capacity, address } = o
511
512
513
+ if ( BigInt ( capacity ) < minCellCapacity ) {
514
+ throw new CapacityTooSmall ( )
515
+ }
516
+
512
517
const blake160 : string = LockUtils . addressToBlake160 ( address )
513
518
514
519
const output : Cell = {
@@ -523,6 +528,8 @@ export default class TransactionsService {
523
528
return output
524
529
} )
525
530
531
+ const { inputs, capacities } = await CellsService . gatherInputs ( needCapacities . toString ( ) , lockHashes , fee )
532
+
526
533
// change
527
534
if ( BigInt ( capacities ) > needCapacities + BigInt ( fee ) ) {
528
535
const changeBlake160 : string = LockUtils . addressToBlake160 ( changeAddress )
0 commit comments