@@ -358,10 +358,10 @@ export class WalletService implements IWalletService {
358358
359359 const version = 0 ;
360360 const time = Date . now ( ) ;
361- const timestamp = BigInt ( time * 1000000 ) ;
361+ const timestamp = BigInt ( time * 1_000_000 ) ;
362362
363363 // Calculate the spending requirements
364- const consumedOutputs = this . determineOutputsToConsume ( sendFundsOptions ) ;
364+ const consumedOutputs = this . determineOutputsToConsume ( sendFundsOptions , settings . gofConfThreshold ) ;
365365
366366 const { inputs, consumedFunds } = this . buildInputs ( consumedOutputs ) ;
367367 const outputs = this . buildOutputs ( sendFundsOptions , consumedFunds ) ;
@@ -575,7 +575,7 @@ export class WalletService implements IWalletService {
575575 outputs : uo . outputs . filter ( o => o . output . type === "SigLockedColoredOutputType" ) . map ( uid => ( {
576576 id : uid . output . outputID . base58 ,
577577 balances : this . mapToArray ( uid . output . output . balances ) ,
578- inclusionState : uid . inclusionState
578+ gof : uid . gradeOfFinality
579579 } ) )
580580 } ) ) ) ;
581581 } while ( spentAddresses . length > BLOCK_COUNT - 2 ) ;
@@ -607,10 +607,11 @@ export class WalletService implements IWalletService {
607607
608608 /**
609609 * From all the inputs determine which ones we need to consume.
610- * @param sendFundOptions The request funds.
610+ * @param sendFundOptions The request funds options.
611+ * @param gofConfThreshold the grade of finality needed to consider the outputs as approved
611612 * @returns The output that we need to consume.
612613 */
613- private determineOutputsToConsume ( sendFundOptions : ISendFundsOptions ) : {
614+ private determineOutputsToConsume ( sendFundOptions : ISendFundsOptions , gofConfThreshold : number ) : {
614615 [ address : string ] : { [ outputID : string ] : IWalletOutput } ;
615616 } {
616617 const outputsToConsume : { [ address : string ] : { [ outputID : string ] : IWalletOutput } } = { } ;
@@ -637,9 +638,7 @@ export class WalletService implements IWalletService {
637638 const confirmedUnspentOutputs = unspentOutput . outputs . filter ( o =>
638639 ( ! this . _spentOutputTransactions ||
639640 ! this . _spentOutputTransactions . includes ( o . id ) ) &&
640- o . inclusionState . confirmed ) ;
641-
642-
641+ o . gof >= gofConfThreshold ) ;
643642 // scan the outputs on this address for required funds
644643 for ( const output of confirmedUnspentOutputs ) {
645644 // keeps track if the output contains any usable funds
@@ -895,14 +894,16 @@ export class WalletService implements IWalletService {
895894 const assetsMap : { [ id : string ] : IWalletAsset } = { } ;
896895 const addedAssets : IWalletAsset [ ] = [ ] ;
897896 const apiRegistryClient = await this . buildApiRegistryClient ( ) ;
897+ const settingsService = ServiceFactory . get < SettingsService > ( "settings" ) ;
898+ const settings = await settingsService . get ( ) ;
898899
899900 for ( let i = 0 ; i <= this . _wallet . lastAddressIndex ; i ++ ) {
900901 const addr = Seed . generateAddress ( Base58 . decode ( this . _wallet . seed ) , BigInt ( i ) ) ;
901902 const address : IWalletAddress = {
902903 index : BigInt ( i ) ,
903904 address : addr ,
904905 isSpent : this . _wallet &&
905- this . _wallet . spentAddresses . includes ( addr ) ? true : false
906+ this . _wallet . spentAddresses . includes ( addr ) ? true : false
906907 } ;
907908 addressMap [ address . address ] = address ;
908909 this . _addresses . push ( address ) ;
@@ -948,15 +949,13 @@ export class WalletService implements IWalletService {
948949 colorMap [ balance . color ] = {
949950 asset : assetsMap [ balance . color ] ,
950951 confirmed : BigInt ( 0 ) ,
951- unConfirmed : BigInt ( 0 ) ,
952- rejected : BigInt ( 0 )
952+ unConfirmed : BigInt ( 0 )
953953 } ;
954954 this . _balances . push ( colorMap [ balance . color ] ) ;
955955 }
956- if ( output . inclusionState . confirmed ) {
956+
957+ if ( output . gof >= settings . gofConfThreshold ) {
957958 colorMap [ balance . color ] . confirmed += balance . value ;
958- } else if ( output . inclusionState . rejected ) {
959- colorMap [ balance . color ] . rejected += balance . value ;
960959 } else {
961960 colorMap [ balance . color ] . unConfirmed += balance . value ;
962961 }
@@ -1040,4 +1039,4 @@ export class WalletService implements IWalletService {
10401039 const settings = await settingsService . get ( ) ;
10411040 return new ApiRegistryClient ( settings . apiRegistryEndpoint ) ;
10421041 }
1043- }
1042+ }
0 commit comments