From c05c34d96824670711a326607b4a09de626d3be7 Mon Sep 17 00:00:00 2001 From: Trinketer22 Date: Wed, 26 Jul 2023 14:27:52 +0300 Subject: [PATCH] TxIterator parent fix --- utils.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/utils.ts b/utils.ts index 6a8d82d..43609fe 100644 --- a/utils.ts +++ b/utils.ts @@ -491,15 +491,18 @@ export const filterTransaction = (txs: BlockchainTransaction[], match: FlatTrans return txs.filter(x => compareTransaction(flattenTransaction(x), match)); } +type MsgQueued = { + msg: Message, + parent?: BlockchainTransaction +}; + export class Txiterator implements AsyncIterator { - private msqQueue: Message[]; + private msqQueue: MsgQueued[]; private blockchain: Blockchain; - private parentTx: BlockchainTransaction | undefined; constructor(bc:Blockchain, msg: Message) { - this.msqQueue = [msg]; + this.msqQueue = [{msg}]; this.blockchain = bc; - this.parentTx = undefined; } public async next(): Promise> { @@ -507,24 +510,25 @@ export class Txiterator implements AsyncIterator { return {done: true, value: undefined}; } const curMsg = this.msqQueue.shift()!; - if(curMsg.info.type !== "internal") + const inMsg = curMsg.msg; + if(inMsg.info.type !== "internal") throw(Error("Internal only")); - const smc = await this.blockchain.getContract(curMsg.info.dest); - const res = smc.receiveMessage(curMsg, {now: this.blockchain.now}); - for(let i = 0; i < res.outMessagesCount; i++) { - const outMsg = res.outMessages.get(i)!; - // Only add internal for now - if(outMsg.info.type === "internal") { - this.msqQueue.push(outMsg) - } - } + const smc = await this.blockchain.getContract(inMsg.info.dest); + const res = smc.receiveMessage(inMsg, {now: this.blockchain.now}); const bcRes = { ...res, events: extractEvents(res), - parent: this.parentTx, + parent: curMsg.parent, children: [], externals: [] } + for(let i = 0; i < res.outMessagesCount; i++) { + const outMsg = res.outMessages.get(i)!; + // Only add internal for now + if(outMsg.info.type === "internal") { + this.msqQueue.push({msg:outMsg, parent: bcRes}) + } + } return {done: false, value: bcRes}; } };