Skip to content

Commit

Permalink
TxIterator parent fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinketer22 committed Jul 26, 2023
1 parent 75e6b91 commit c05c34d
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,40 +491,44 @@ 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<BlockchainTransaction> {
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<IteratorResult<BlockchainTransaction>> {
if(this.msqQueue.length == 0) {
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};
}
};
Expand Down

0 comments on commit c05c34d

Please sign in to comment.