@@ -4,11 +4,15 @@ import {
44 BlockResult as PrismaBlockResult ,
55 Transaction as PrismaTransaction ,
66 TransactionExecutionResult as PrismaTransactionExecutionResult ,
7+ StateTransition as PrismaStateTransition ,
8+ StateTransitionBatch as PrismaStateTransitionBatch ,
79} from "@prisma/client" ;
810import {
911 BlockMapper ,
1012 BlockResultMapper ,
1113 TransactionExecutionResultMapper ,
14+ StateTransitionMapper ,
15+ StateTransitionBatchArrayMapper ,
1216} from "@proto-kit/persistance" ;
1317import { log } from "@proto-kit/common" ;
1418import { injectable } from "tsyringe" ;
@@ -23,10 +27,16 @@ export interface BlockFetchingConfig {
2327export interface BlockResponse {
2428 data : {
2529 findFirstBlock : PrismaBlock & {
26- result : PrismaBlockResult ;
30+ beforeBlockStateTransitions : PrismaStateTransition [ ] ;
31+ result : PrismaBlockResult & {
32+ afterBlockStateTransitions : PrismaStateTransition [ ] ;
33+ } ;
2734 } & {
2835 transactions : ( PrismaTransactionExecutionResult & {
2936 tx : PrismaTransaction ;
37+ stateTransitionBatch : ( PrismaStateTransitionBatch & {
38+ stateTransitions : PrismaStateTransition [ ] ;
39+ } ) [ ] ;
3040 } ) [ ] ;
3141 } ;
3242 } ;
@@ -37,7 +47,9 @@ export class BlockFetching extends ProcessorModule<BlockFetchingConfig> {
3747 public constructor (
3848 public blockMapper : BlockMapper ,
3949 public blockResultMapper : BlockResultMapper ,
40- public transactionResultMapper : TransactionExecutionResultMapper
50+ public transactionResultMapper : TransactionExecutionResultMapper ,
51+ private readonly stateTransitionBatchMapper : StateTransitionBatchArrayMapper ,
52+ private readonly stateTransitionMapper : StateTransitionMapper
4153 ) {
4254 super ( ) ;
4355 }
@@ -63,6 +75,14 @@ export class BlockFetching extends ProcessorModule<BlockFetchingConfig> {
6375 fromMessagesHash
6476 toMessagesHash
6577 transactionsHash
78+ StateTransitionBatch {
79+ applied,
80+ StateTransition {
81+ path,
82+ from,
83+ to,
84+ }
85+ }
6686 parent {
6787 hash
6888 }
@@ -73,13 +93,27 @@ export class BlockFetching extends ProcessorModule<BlockFetchingConfig> {
7393 blockHashWitness,
7494 blockStateTransitions,
7595 blockHash,
96+ StateTransitionBatch {
97+ StateTransition {
98+ path,
99+ from,
100+ to,
101+ }
102+ }
76103 }
77104 transactions {
78105 stateTransitions
79106 protocolTransitions
80107 status
81108 statusMessage
82109 events
110+ StateTransitionBatch {
111+ StateTransition {
112+ path,
113+ from,
114+ to,
115+ }
116+ }
83117 tx {
84118 hash
85119 methodId
@@ -115,13 +149,39 @@ export class BlockFetching extends ProcessorModule<BlockFetchingConfig> {
115149 return undefined ;
116150 }
117151
118- const block = this . blockMapper . mapIn ( parsedResponse ?. data . findFirstBlock ) ;
119- const result = this . blockResultMapper . mapIn (
120- parsedResponse ?. data . findFirstBlock . result
121- ) ;
152+ const block = {
153+ ...this . blockMapper . mapIn ( parsedResponse ?. data . findFirstBlock ) ,
154+ beforeBlockStateTransitions :
155+ parsedResponse . data . findFirstBlock . beforeBlockStateTransitions . map (
156+ ( st ) => this . stateTransitionMapper . mapIn ( st )
157+ ) ,
158+ } ;
159+ const result = {
160+ ...this . blockResultMapper . mapIn (
161+ parsedResponse ?. data . findFirstBlock . result
162+ ) ,
163+ afterBlockStateTransitions :
164+ parsedResponse . data . findFirstBlock . result . afterBlockStateTransitions . map (
165+ ( st ) => this . stateTransitionMapper . mapIn ( st )
166+ ) ,
167+ } ;
168+
122169 const transactions = parsedResponse ?. data . findFirstBlock . transactions . map (
123170 ( tx ) => {
124- return this . transactionResultMapper . mapIn ( [ tx , tx . tx ] ) ;
171+ const txMapped = this . transactionResultMapper . mapIn ( [ tx , tx . tx ] ) ;
172+ const stBatch = tx . stateTransitionBatch . map <
173+ [
174+ Omit <
175+ PrismaStateTransitionBatch ,
176+ "txExecutionResultId" | "id" | "blockId" | "blockResultId"
177+ > ,
178+ Omit < PrismaStateTransition , "batchId" | "id" > [ ] ,
179+ ]
180+ > ( ( batch ) => [ { applied : batch . applied } , batch . stateTransitions ] ) ;
181+ return {
182+ ...txMapped ,
183+ stateTransitions : this . stateTransitionBatchMapper . mapIn ( stBatch ) ,
184+ } ;
125185 }
126186 ) ;
127187
@@ -138,7 +198,9 @@ export class BlockFetching extends ProcessorModule<BlockFetchingConfig> {
138198 ...block ,
139199 transactions,
140200 } ,
141- result,
201+ result : {
202+ ...result ,
203+ } ,
142204 } ;
143205 }
144206
0 commit comments