@@ -7,6 +7,7 @@ import WalletsService from '../services/wallets'
77import { Controller as ControllerDecorator , CatchControllerError } from '../decorators'
88import { Channel , ResponseCode } from '../utils/const'
99import { TransactionNotFound , CurrentWalletNotSet , ServiceHasNoResponse } from '../exceptions'
10+ import LockUtils from '../models/lock-utils'
1011
1112/**
1213 * @class TransactionsController
@@ -60,6 +61,31 @@ export default class TransactionsController {
6061
6162 if ( ! transaction ) throw new TransactionNotFound ( hash )
6263
64+ const wallet = WalletsService . getInstance ( ) . getCurrent ( )
65+ if ( ! wallet ) throw new CurrentWalletNotSet ( )
66+ const addresses : string [ ] = ( await AddressService . allAddressesByWalletId ( wallet . id ) ) . map ( addr => addr . address )
67+ const lockHashes : string [ ] = await Promise . all (
68+ addresses . map ( async addr => {
69+ return LockUtils . addressToLockHash ( addr )
70+ } )
71+ )
72+
73+ const outputCapacities : bigint = transaction
74+ . outputs ! . filter ( o => lockHashes . includes ( o . lockHash ! ) )
75+ . map ( o => BigInt ( o . capacity ) )
76+ . reduce ( ( result , c ) => result + c , BigInt ( 0 ) )
77+ const inputCapacities : bigint = transaction
78+ . inputs ! . filter ( i => {
79+ if ( i . lockHash ) {
80+ return lockHashes . includes ( i . lockHash )
81+ }
82+ return false
83+ } )
84+ . map ( i => BigInt ( i . capacity ) )
85+ . reduce ( ( result , c ) => result + c , BigInt ( 0 ) )
86+ const value : bigint = outputCapacities - inputCapacities
87+ transaction . value = value . toString ( )
88+
6389 return {
6490 status : ResponseCode . Success ,
6591 result : transaction ,
0 commit comments