@@ -3,8 +3,10 @@ package verificationApp
33import (
44 "context"
55 "encoding/base64"
6+ "fmt"
67 "sort"
78
9+ validatorpass_tracker "github.com/Openmesh-Network/nft-authorise/tracker"
810 abcitypes "github.com/cometbft/cometbft/abci/types"
911 nm "github.com/cometbft/cometbft/node"
1012 comettype "github.com/cometbft/cometbft/types"
@@ -31,6 +33,8 @@ type VerificationApp struct {
3133 Node * nm.Node
3234 CurrentMempool []comettype.Tx
3335 Currblockno int64
36+ PolygonCheckpoint uint64
37+ Tracker * validatorpass_tracker.Tracker
3438}
3539
3640const VALIDATOR_PREALLOCATED_COUNT = 2000
@@ -96,8 +100,26 @@ func (app *VerificationApp) PrepareProposal(_ context.Context, proposal *abcityp
96100 }
97101 log .Debug ("Marshaling Done" )
98102 transactions := comettype .Tx (transactionBytes [:])
99- proposal .Txs = append (othertx , transactions )
100103
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 )
101123 return & abcitypes.ResponsePrepareProposal {Txs : proposal .Txs }, nil
102124}
103125func (app * VerificationApp ) ProcessProposal (_ context.Context , proposal * abcitypes.RequestProcessProposal ) (* abcitypes.ResponseProcessProposal , error ) {
@@ -143,6 +165,7 @@ func (app *VerificationApp) ProcessProposal(_ context.Context, proposal *abcityp
143165
144166 if code := app .isValid (tx ); code != 0 {
145167 // log.Error("Error: invalid transaction index %v", i)
168+ log .Error ("A transaction got error" )
146169 return & abcitypes.ResponseProcessProposal {Status : abcitypes .ResponseProcessProposal_REJECT }, nil
147170 } else {
148171 var transaction types.Transaction
@@ -151,8 +174,9 @@ func (app *VerificationApp) ProcessProposal(_ context.Context, proposal *abcityp
151174 log .Error ("Error unmarshaling transaction data:" , err )
152175 return & abcitypes.ResponseProcessProposal {Status : abcitypes .ResponseProcessProposal_REJECT }, nil
153176 }
154-
177+ log . Debug ( transaction . Type )
155178 switch transaction .Type {
179+
156180 case types .TransactionType_SummaryTransaction :
157181
158182 summaryData := & types.SummaryTransactionData {}
@@ -168,6 +192,20 @@ func (app *VerificationApp) ProcessProposal(_ context.Context, proposal *abcityp
168192 }
169193 log .Debug ("they are similar" )
170194
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 )
171209 default :
172210 log .Debug (transaction .Type )
173211 log .Debug ("Unknown transaction type" )
@@ -286,6 +324,12 @@ func (app *VerificationApp) FinalizeBlock(_ context.Context, req *abcitypes.Requ
286324 log .Debug ("Node succesfully registered: " , len (validatorupdates ))
287325 // log.Debug("Node Registration Transaction Data:", registrationData)
288326
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 {}
289333 case types .TransactionType_SummaryTransaction :
290334 txs [i ] = & abcitypes.ExecTxResult {}
291335 default :
@@ -485,6 +529,17 @@ func (app *VerificationApp) isValid(tx []byte) uint32 {
485529 // log.Debug("Resource Transaction Data:", nodeRegistrationData)
486530 return 0
487531
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+
488543 default :
489544 log .Error ("Unknown transaction type" )
490545 return 1
0 commit comments