@@ -789,6 +789,63 @@ func (o *OffchainAggregatorRoundConfirmer) Wait() error {
789789 }
790790}
791791
792+ // KeeperConsumerRoundConfirmer is a header subscription that awaits for a round of upkeeps
793+ type KeeperConsumerRoundConfirmer struct {
794+ instance KeeperConsumer
795+ upkeepsValue int
796+ doneChan chan struct {}
797+ context context.Context
798+ cancel context.CancelFunc
799+ }
800+
801+ // NewKeeperConsumerRoundConfirmer provides a new instance of a KeeperConsumerRoundConfirmer
802+ func NewKeeperConsumerRoundConfirmer (
803+ contract KeeperConsumer ,
804+ counterValue int ,
805+ timeout time.Duration ,
806+ ) * KeeperConsumerRoundConfirmer {
807+ ctx , ctxCancel := context .WithTimeout (context .Background (), timeout )
808+ return & KeeperConsumerRoundConfirmer {
809+ instance : contract ,
810+ upkeepsValue : counterValue ,
811+ doneChan : make (chan struct {}),
812+ context : ctx ,
813+ cancel : ctxCancel ,
814+ }
815+ }
816+
817+ // ReceiveBlock will query the latest Keeper round and check to see whether the round has confirmed
818+ func (o * KeeperConsumerRoundConfirmer ) ReceiveBlock (_ client.NodeBlock ) error {
819+ upkeeps , err := o .instance .Counter (context .Background ())
820+ if err != nil {
821+ return err
822+ }
823+ l := log .Info ().
824+ Str ("Contract Address" , o .instance .Address ()).
825+ Int64 ("Upkeeps" , upkeeps .Int64 ()).
826+ Int ("Required upkeeps" , o .upkeepsValue )
827+ if upkeeps .Int64 () == int64 (o .upkeepsValue ) {
828+ l .Msg ("Upkeep completed" )
829+ o .doneChan <- struct {}{}
830+ } else {
831+ l .Msg ("Waiting for upkeep round" )
832+ }
833+ return nil
834+ }
835+
836+ // Wait is a blocking function that will wait until the round has confirmed, and timeout if the deadline has passed
837+ func (o * KeeperConsumerRoundConfirmer ) Wait () error {
838+ for {
839+ select {
840+ case <- o .doneChan :
841+ o .cancel ()
842+ return nil
843+ case <- o .context .Done ():
844+ return fmt .Errorf ("timeout waiting for upkeeps to confirm: %d" , o .upkeepsValue )
845+ }
846+ }
847+ }
848+
792849// EthereumStorage acts as a conduit for the ethereum version of the storage contract
793850type EthereumStorage struct {
794851 client * client.EthereumClient
0 commit comments