@@ -9,6 +9,7 @@ import {CommonConstants} from "../common-libs/constants"
9
9
import { IdentityDTO } from "../dto/IdentityDTO"
10
10
import { hashf } from "../common"
11
11
import { Indexer } from "../indexer"
12
+ import { DBTx } from "../dal/sqliteDAL/TxsDAL"
12
13
13
14
const _ = require ( 'underscore' )
14
15
@@ -80,7 +81,7 @@ export const GLOBAL_RULES_FUNCTIONS = {
80
81
return true ;
81
82
} ,
82
83
83
- checkSourcesAvailability : async ( block :{ transactions :TransactionDTO [ ] , medianTime : number } , conf :ConfDTO , dal :FileDAL , alsoCheckPendingTransactions : boolean ) => {
84
+ checkSourcesAvailability : async ( block :{ transactions :TransactionDTO [ ] , medianTime : number } , conf :ConfDTO , dal :FileDAL , findSourceTx : ( txHash : string ) => Promise < DBTx | null > ) => {
84
85
const txs = block . transactions
85
86
const current = await dal . getCurrentBlockOrNull ( ) ;
86
87
for ( const tx of txs ) {
@@ -98,12 +99,12 @@ export const GLOBAL_RULES_FUNCTIONS = {
98
99
let src = inputs [ k ] ;
99
100
let dbSrc = await dal . getSource ( src . identifier , src . pos ) ;
100
101
logger . debug ( 'Source %s:%s:%s:%s = %s' , src . amount , src . base , src . identifier , src . pos , dbSrc && dbSrc . consumed ) ;
101
- if ( ! dbSrc && alsoCheckPendingTransactions ) {
102
+ if ( ! dbSrc ) {
102
103
// For chained transactions which are checked on sandbox submission, we accept them if there is already
103
104
// a previous transaction of the chain already recorded in the pool
104
105
dbSrc = await ( async ( ) => {
105
106
let hypotheticSrc :any = null ;
106
- let targetTX = await dal . getTxByHash ( src . identifier ) ;
107
+ let targetTX = await findSourceTx ( src . identifier ) ;
107
108
if ( targetTX ) {
108
109
let outputStr = targetTX . outputs [ src . pos ] ;
109
110
if ( outputStr ) {
@@ -193,10 +194,15 @@ export const GLOBAL_RULES_HELPERS = {
193
194
194
195
checkExistsPubkey : ( pub :string , dal :FileDAL ) => dal . getWrittenIdtyByPubkey ( pub ) ,
195
196
196
- checkSingleTransaction : ( tx :TransactionDTO , block :{ medianTime : number } , conf :ConfDTO , dal :FileDAL , alsoCheckPendingTransactions :boolean = false ) => GLOBAL_RULES_FUNCTIONS . checkSourcesAvailability ( {
197
+ checkSingleTransaction : (
198
+ tx :TransactionDTO ,
199
+ block :{ medianTime : number } ,
200
+ conf :ConfDTO ,
201
+ dal :FileDAL ,
202
+ findSourceTx :( txHash :string ) => Promise < DBTx | null > ) => GLOBAL_RULES_FUNCTIONS . checkSourcesAvailability ( {
197
203
transactions : [ tx ] ,
198
204
medianTime : block . medianTime
199
- } , conf , dal , alsoCheckPendingTransactions ) ,
205
+ } , conf , dal , findSourceTx ) ,
200
206
201
207
checkTxBlockStamp : async ( tx :TransactionDTO , dal :FileDAL ) => {
202
208
const number = parseInt ( tx . blockstamp . split ( '-' ) [ 0 ] )
0 commit comments