@@ -16,6 +16,7 @@ type FutureKeeper struct {
16
16
futures repo.SeqCollection [types.Future ]
17
17
futureByCreator collections.KeySet [collections.Pair [sdk.AccAddress , uint64 ]]
18
18
results collections.Map [uint64 , types.FutureResult ]
19
+ pendingFutures collections.KeySet [uint64 ]
19
20
}
20
21
21
22
func NewFutureKeeper (sb * collections.SchemaBuilder , cdc codec.Codec ) * FutureKeeper {
@@ -27,10 +28,13 @@ func NewFutureKeeper(sb *collections.SchemaBuilder, cdc codec.Codec) *FutureKeep
27
28
28
29
results := collections .NewMap (sb , ResultsPrefix , "future_results" , collections .Uint64Key , codec.CollValue [types.FutureResult ](cdc ))
29
30
31
+ pendingFutures := collections .NewKeySet (sb , PendingFuturesPrefix , "pending_futures" , collections .Uint64Key )
32
+
30
33
return & FutureKeeper {
31
34
futures : futures ,
32
35
futureByCreator : futureByCreator ,
33
36
results : results ,
37
+ pendingFutures : pendingFutures ,
34
38
}
35
39
}
36
40
@@ -49,6 +53,10 @@ func (k *FutureKeeper) Append(ctx context.Context, t *types.Future) (uint64, err
49
53
return 0 , err
50
54
}
51
55
56
+ if err := k .pendingFutures .Set (ctx , id ); err != nil {
57
+ return 0 , err
58
+ }
59
+
52
60
return id , nil
53
61
}
54
62
@@ -61,6 +69,9 @@ func (k *FutureKeeper) Set(ctx context.Context, f types.Future) error {
61
69
}
62
70
63
71
func (k * FutureKeeper ) SetResult (ctx context.Context , result types.FutureResult ) error {
72
+ if err := k .pendingFutures .Remove (ctx , result .Id ); err != nil {
73
+ return err
74
+ }
64
75
return k .results .Set (ctx , result .Id , result )
65
76
}
66
77
@@ -75,3 +86,31 @@ func (k *FutureKeeper) HasResult(ctx context.Context, id uint64) (bool, error) {
75
86
func (k * FutureKeeper ) Futures () repo.SeqCollection [types.Future ] {
76
87
return k .futures
77
88
}
89
+
90
+ func (k * FutureKeeper ) PendingFutures (ctx context.Context , limit int ) ([]types.Future , error ) {
91
+ it , err := k .pendingFutures .IterateRaw (ctx , nil , nil , collections .OrderAscending )
92
+ if err != nil {
93
+ return nil , err
94
+ }
95
+ defer it .Close ()
96
+
97
+ futures := make ([]types.Future , 0 , limit )
98
+ for ; it .Valid (); it .Next () {
99
+ id , err := it .Key ()
100
+ if err != nil {
101
+ return nil , err
102
+ }
103
+
104
+ fut , err := k .futures .Get (ctx , id )
105
+ if err != nil {
106
+ return nil , err
107
+ }
108
+
109
+ futures = append (futures , fut )
110
+ if len (futures ) == limit {
111
+ break
112
+ }
113
+ }
114
+
115
+ return futures , nil
116
+ }
0 commit comments