Skip to content
Snippets Groups Projects
Commit 080f32dd authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] #1248 Could not have chained txs in a block

parent e843c8e0
Branches
Tags
2 merge requests!12331.6,!1230Fix/1.6/tx chaining
...@@ -865,42 +865,42 @@ export class Indexer { ...@@ -865,42 +865,42 @@ export class Indexer {
} }
})) }))
// BR_G46 const getInputLocalFirstOrFallbackGlobally = async (sindex:SindexEntry[], ENTRY:SindexEntry) => {
await Promise.all(_.where(sindex, { op: constants.IDX_UPDATE }).map(async (ENTRY: SindexEntry) => { let source = _.filter(sindex, (src:SindexEntry) =>
src.identifier == ENTRY.identifier
&& src.pos == ENTRY.pos
&& src.conditions
&& src.op === constants.IDX_CREATE)[0];
if (!source) {
const reducable = await dal.sindexDAL.sqlFind({ const reducable = await dal.sindexDAL.sqlFind({
identifier: ENTRY.identifier, identifier: ENTRY.identifier,
pos: ENTRY.pos, pos: ENTRY.pos,
amount: ENTRY.amount, amount: ENTRY.amount,
base: ENTRY.base base: ENTRY.base
}); });
ENTRY.conditions = reduce(reducable).conditions; // We valuate the input conditions, so we can map these records to a same account source = reduce(reducable)
ENTRY.available = reduce(reducable).consumed === false; }
return source
}
// BR_G46
await Promise.all(_.where(sindex, { op: constants.IDX_UPDATE }).map(async (ENTRY: SindexEntry) => {
const source = await getInputLocalFirstOrFallbackGlobally(sindex, ENTRY)
ENTRY.conditions = source.conditions; // We valuate the input conditions, so we can map these records to a same account
ENTRY.available = source.consumed === false;
})) }))
// BR_G47 // BR_G47
await Promise.all(_.where(sindex, { op: constants.IDX_UPDATE }).map(async (ENTRY: SindexEntry) => { await Promise.all(_.where(sindex, { op: constants.IDX_UPDATE }).map(async (ENTRY: SindexEntry) => {
let source = _.filter(sindex, (src:SindexEntry) => src.identifier == ENTRY.identifier && src.pos == ENTRY.pos && src.conditions && src.op === constants.IDX_CREATE)[0]; const source = await getInputLocalFirstOrFallbackGlobally(sindex, ENTRY)
if (!source) {
const reducable = await dal.sindexDAL.sqlFind({
identifier: ENTRY.identifier,
pos: ENTRY.pos,
amount: ENTRY.amount,
base: ENTRY.base
});
source = reduce(reducable);
}
ENTRY.conditions = source.conditions; ENTRY.conditions = source.conditions;
ENTRY.isLocked = !txSourceUnlock(ENTRY, source, HEAD); ENTRY.isLocked = !txSourceUnlock(ENTRY, source, HEAD);
})) }))
// BR_G48 // BR_G48
await Promise.all(_.where(sindex, { op: constants.IDX_UPDATE }).map(async (ENTRY: SindexEntry) => { await Promise.all(_.where(sindex, { op: constants.IDX_UPDATE }).map(async (ENTRY: SindexEntry) => {
ENTRY.isTimeLocked = ENTRY.written_time - reduce(await dal.sindexDAL.sqlFind({ const source = await getInputLocalFirstOrFallbackGlobally(sindex, ENTRY)
identifier: ENTRY.identifier, ENTRY.isTimeLocked = ENTRY.written_time - source.written_time < ENTRY.locktime;
pos: ENTRY.pos,
amount: ENTRY.amount,
base: ENTRY.base
})).written_time < ENTRY.locktime;
})) }))
return HEAD; return HEAD;
......
...@@ -2244,7 +2244,7 @@ Else: ...@@ -2244,7 +2244,7 @@ Else:
####### BR_G102 - ENTRY.age ####### BR_G102 - ENTRY.age
For each ENTRY in local IINDEX where `op = 'UPDATE'`: For each ENTRY in local SINDEX where `op = 'UPDATE'`:
REF_BLOCK = HEAD~<HEAD~1.number + 1 - NUMBER(ENTRY.hash)>[hash=HASH(ENTRY.created_on)] REF_BLOCK = HEAD~<HEAD~1.number + 1 - NUMBER(ENTRY.hash)>[hash=HASH(ENTRY.created_on)]
...@@ -2266,17 +2266,31 @@ EndIf ...@@ -2266,17 +2266,31 @@ EndIf
For each `LOCAL_SINDEX[op='UPDATE'] as ENTRY`: For each `LOCAL_SINDEX[op='UPDATE'] as ENTRY`:
INPUT = REDUCE(GLOBAL_SINDEX[identifier=ENTRY.identifier,pos=ENTRY.pos,amount=ENTRY.amount,base=ENTRY.base]) INPUT_ENTRIES = LOCAL_SINDEX[op='CREATE',identifier=ENTRY.identifier,pos=ENTRY.pos,amount=ENTRY.amount,base=ENTRY.base]
If COUNT(INPUT_ENTRIES) == 0 Then
INPUT_ENTRIES = GLOBAL_SINDEX[identifier=ENTRY.identifier,pos=ENTRY.pos,amount=ENTRY.amount,base=ENTRY.base]
EndIf
INPUT = REDUCE(INPUT_ENTRIES)
ENTRY.conditions = INPUT.conditions ENTRY.conditions = INPUT.conditions
ENTRY.available = INPUT.consumed == false ENTRY.available = INPUT.consumed == false
####### BR_G47 - ENTRY.isLocked ####### BR_G47 - ENTRY.isLocked
ENTRY.isLocked = TX_SOURCE_UNLOCK(REDUCE(GLOBAL_SINDEX[identifier=ENTRY.identifier,pos=ENTRY.pos,amount=ENTRY.amount,base=ENTRY.base]).conditions, ENTRY) INPUT_ENTRIES = LOCAL_SINDEX[op='CREATE',identifier=ENTRY.identifier,pos=ENTRY.pos,amount=ENTRY.amount,base=ENTRY.base]
If COUNT(INPUT_ENTRIES) == 0 Then
INPUT_ENTRIES = GLOBAL_SINDEX[identifier=ENTRY.identifier,pos=ENTRY.pos,amount=ENTRY.amount,base=ENTRY.base]
EndIf
INPUT = REDUCE(INPUT_ENTRIES)
ENTRY.isLocked = TX_SOURCE_UNLOCK(INPUT.conditions, ENTRY)
####### BR_G48 - ENTRY.isTimeLocked ####### BR_G48 - ENTRY.isTimeLocked
ENTRY.isTimeLocked = ENTRY.written_time - REDUCE(GLOBAL_SINDEX[identifier=ENTRY.identifier,pos=ENTRY.pos,amount=ENTRY.amount,base=ENTRY.base]).written_time < ENTRY.locktime INPUT_ENTRIES = LOCAL_SINDEX[op='CREATE',identifier=ENTRY.identifier,pos=ENTRY.pos,amount=ENTRY.amount,base=ENTRY.base]
If COUNT(INPUT_ENTRIES) == 0 Then
INPUT_ENTRIES = GLOBAL_SINDEX[identifier=ENTRY.identifier,pos=ENTRY.pos,amount=ENTRY.amount,base=ENTRY.base]
EndIf
INPUT = REDUCE(INPUT_ENTRIES)
ENTRY.isTimeLocked = ENTRY.written_time - INPUT.written_time < ENTRY.locktime
##### Rules ##### Rules
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment