@@ -3,8 +3,10 @@ package verificationApp
3
3
import (
4
4
"context"
5
5
"encoding/base64"
6
+ "fmt"
6
7
"sort"
7
8
9
+ validatorpass_tracker "github.com/Openmesh-Network/nft-authorise/tracker"
8
10
abcitypes "github.com/cometbft/cometbft/abci/types"
9
11
nm "github.com/cometbft/cometbft/node"
10
12
comettype "github.com/cometbft/cometbft/types"
@@ -31,6 +33,8 @@ type VerificationApp struct {
31
33
Node * nm.Node
32
34
CurrentMempool []comettype.Tx
33
35
Currblockno int64
36
+ PolygonCheckpoint uint64
37
+ Tracker * validatorpass_tracker.Tracker
34
38
}
35
39
36
40
const VALIDATOR_PREALLOCATED_COUNT = 2000
@@ -96,8 +100,26 @@ func (app *VerificationApp) PrepareProposal(_ context.Context, proposal *abcityp
96
100
}
97
101
log .Debug ("Marshaling Done" )
98
102
transactions := comettype .Tx (transactionBytes [:])
99
- proposal .Txs = append (othertx , transactions )
100
103
104
+ transactionMessage_checkpoint := types.Transaction {
105
+ Owner : "trial" ,
106
+ Signature : "" ,
107
+ Type : * types .TransactionType_PolygonCheckpointTransaction .Enum (),
108
+ }
109
+ transactionMessage_checkpoint .Data = & types.Transaction_PolygonCheckpointTransactionData {
110
+ PolygonCheckpointTransactionData : & types.PolygonCheckpointTransactionData {
111
+ Blockno : uint64 (app .Tracker .LastTrackerHeight ),
112
+ Blockhash : "xyz" , //not a necessary field just nice to have for record keeping
113
+ },
114
+ }
115
+ transactionBytes_Checkpoint , err := proto .Marshal (& transactionMessage_checkpoint )
116
+ if err != nil {
117
+ panic (err )
118
+ }
119
+
120
+ transactions_checkpoint := comettype .Tx (transactionBytes_Checkpoint [:])
121
+ proposal .Txs = append (othertx , transactions , transactions_checkpoint )
122
+ log .Debug (proposal .Txs )
101
123
return & abcitypes.ResponsePrepareProposal {Txs : proposal .Txs }, nil
102
124
}
103
125
func (app * VerificationApp ) ProcessProposal (_ context.Context , proposal * abcitypes.RequestProcessProposal ) (* abcitypes.ResponseProcessProposal , error ) {
@@ -143,6 +165,7 @@ func (app *VerificationApp) ProcessProposal(_ context.Context, proposal *abcityp
143
165
144
166
if code := app .isValid (tx ); code != 0 {
145
167
// log.Error("Error: invalid transaction index %v", i)
168
+ log .Error ("A transaction got error" )
146
169
return & abcitypes.ResponseProcessProposal {Status : abcitypes .ResponseProcessProposal_REJECT }, nil
147
170
} else {
148
171
var transaction types.Transaction
@@ -151,8 +174,9 @@ func (app *VerificationApp) ProcessProposal(_ context.Context, proposal *abcityp
151
174
log .Error ("Error unmarshaling transaction data:" , err )
152
175
return & abcitypes.ResponseProcessProposal {Status : abcitypes .ResponseProcessProposal_REJECT }, nil
153
176
}
154
-
177
+ log . Debug ( transaction . Type )
155
178
switch transaction .Type {
179
+
156
180
case types .TransactionType_SummaryTransaction :
157
181
158
182
summaryData := & types.SummaryTransactionData {}
@@ -168,6 +192,20 @@ func (app *VerificationApp) ProcessProposal(_ context.Context, proposal *abcityp
168
192
}
169
193
log .Debug ("they are similar" )
170
194
195
+ case types .TransactionType_PolygonCheckpointTransaction :
196
+ log .Debug ("polygon tx found" )
197
+ checkpointData := & types.PolygonCheckpointTransactionData {}
198
+ checkpointData = transaction .GetPolygonCheckpointTransactionData ()
199
+
200
+ if err != nil {
201
+ log .Error ("Cannot decode tx" )
202
+ return & abcitypes.ResponseProcessProposal {Status : abcitypes .ResponseProcessProposal_REJECT }, nil
203
+ }
204
+
205
+ if checkpointData .Blockno > uint64 (app .Tracker .LastTrackerHeight ) {
206
+ return & abcitypes.ResponseProcessProposal {Status : abcitypes .ResponseProcessProposal_REJECT }, nil
207
+ }
208
+ log .Debug ("the height is okay,the proposed height is " , checkpointData .Blockno , "the current height is" , app .Tracker .LastTrackerHeight )
171
209
default :
172
210
log .Debug (transaction .Type )
173
211
log .Debug ("Unknown transaction type" )
@@ -286,6 +324,12 @@ func (app *VerificationApp) FinalizeBlock(_ context.Context, req *abcitypes.Requ
286
324
log .Debug ("Node succesfully registered: " , len (validatorupdates ))
287
325
// log.Debug("Node Registration Transaction Data:", registrationData)
288
326
327
+ case types .TransactionType_PolygonCheckpointTransaction :
328
+ polygonData := & types.PolygonCheckpointTransactionData {}
329
+ polygonData = transaction .GetPolygonCheckpointTransactionData ()
330
+ app .PolygonCheckpoint = polygonData .Blockno
331
+ fmt .Println ("The polygon checkpoint is " , app .PolygonCheckpoint )
332
+ txs [i ] = & abcitypes.ExecTxResult {}
289
333
case types .TransactionType_SummaryTransaction :
290
334
txs [i ] = & abcitypes.ExecTxResult {}
291
335
default :
@@ -485,6 +529,17 @@ func (app *VerificationApp) isValid(tx []byte) uint32 {
485
529
// log.Debug("Resource Transaction Data:", nodeRegistrationData)
486
530
return 0
487
531
532
+ case types .TransactionType_PolygonCheckpointTransaction :
533
+ polygonData := & types.PolygonCheckpointTransactionData {}
534
+ polygonData = transaction .GetPolygonCheckpointTransactionData ()
535
+
536
+ if polygonData == nil {
537
+ log .Error ("Error unmarshaling resource transaction data:" , err )
538
+ return 1
539
+ }
540
+ // log.Debug("Resource Transaction Data:", nodeRegistrationData)
541
+ return 0
542
+
488
543
default :
489
544
log .Error ("Unknown transaction type" )
490
545
return 1
0 commit comments