@@ -13,9 +13,9 @@ import (
1313
1414// MigrateStore migrates the x/dlc module state from the consensus version 1 to
1515// version 2
16- func MigrateStore (ctx sdk.Context , storeKey storetypes.StoreKey , tssStoreKey storetypes. StoreKey , cdc codec.BinaryCodec ) error {
16+ func MigrateStore (ctx sdk.Context , storeKey storetypes.StoreKey , tssKeeper types. TSSKeeper , cdc codec.BinaryCodec ) error {
1717 migrateDLCEvents (ctx , storeKey , cdc )
18- migrateDCMsAndOracles (ctx , storeKey , tssStoreKey , cdc )
18+ migrateDCMsAndOracles (ctx , storeKey , tssKeeper , cdc )
1919
2020 return nil
2121}
@@ -37,34 +37,50 @@ func migrateDLCEvents(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.B
3737}
3838
3939// migrateDCMsAndOracles performs the DCMs and oracles migration
40- func migrateDCMsAndOracles (ctx sdk.Context , storeKey storetypes.StoreKey , tssStoreKey storetypes.StoreKey , cdc codec.BinaryCodec ) {
41- tssStore := ctx .KVStore (tssStoreKey )
42-
43- iterator := storetypes .KVStorePrefixIterator (tssStore , tsstypes .DKGRequestKeyPrefix )
44- defer iterator .Close ()
45-
46- for ; iterator .Valid (); iterator .Next () {
47- var dkgRequest tsstypes.DKGRequest
48- cdc .MustUnmarshal (iterator .Value (), & dkgRequest )
49-
50- if dkgRequest .Status != tsstypes .DKGStatus_DKG_STATUS_COMPLETED {
51- continue
40+ func migrateDCMsAndOracles (ctx sdk.Context , storeKey storetypes.StoreKey , tssKeeper types.TSSKeeper , cdc codec.BinaryCodec ) {
41+ // tssStore := ctx.KVStore(tssStoreKey)
42+
43+ // iterator := storetypes.KVStorePrefixIterator(tssStore, tsstypes.DKGRequestKeyPrefix)
44+ // defer iterator.Close()
45+
46+ // for ; iterator.Valid(); iterator.Next() {
47+ // var dkgRequest tsstypes.DKGRequest
48+ // cdc.MustUnmarshal(iterator.Value(), &dkgRequest)
49+
50+ // if dkgRequest.Status != tsstypes.DKGStatus_DKG_STATUS_COMPLETED {
51+ // continue
52+ // }
53+
54+ // bz := tssStore.Get(tsstypes.DKGCompletionKey(dkgRequest.Id, dkgRequest.Participants[0]))
55+ // var dkgCompletion tsstypes.DKGCompletion
56+ // cdc.MustUnmarshal(bz, &dkgCompletion)
57+
58+ // // DCM or oracle pub key
59+ // pubKey := dkgCompletion.PubKeys[0]
60+ // pubKeyBz, _ := hex.DecodeString(pubKey)
61+
62+ // if dkgRequest.Type == types.DKG_TYPE_DCM {
63+ // updateDCM(ctx, storeKey, dkgRequest.Id, pubKeyBz, cdc)
64+ // } else if dkgRequest.Type == types.DKG_TYPE_NONCE {
65+ // updateOracle(ctx, storeKey, dkgRequest.Id, pubKeyBz, cdc)
66+ // }
67+ // }
68+
69+ tssKeeper .IterateDKGRequests (ctx , func (req * tsstypes.DKGRequest ) (stop bool ) {
70+ if req .Status == tsstypes .DKGStatus_DKG_STATUS_COMPLETED {
71+ // dcm or oracle pub key
72+ pubKey := tssKeeper .GetDKGPubKeys (ctx , req .Id )[0 ]
73+ pubKeyBz , _ := hex .DecodeString (pubKey )
74+
75+ if req .Type == types .DKG_TYPE_DCM {
76+ updateDCM (ctx , storeKey , req .Id , pubKeyBz , cdc )
77+ } else if req .Type == types .DKG_TYPE_NONCE {
78+ updateOracle (ctx , storeKey , req .Id , pubKeyBz , cdc )
79+ }
5280 }
5381
54- bz := tssStore .Get (tsstypes .DKGCompletionKey (dkgRequest .Id , dkgRequest .Participants [0 ]))
55- var dkgCompletion tsstypes.DKGCompletion
56- cdc .MustUnmarshal (bz , & dkgCompletion )
57-
58- // DCM or oracle pub key
59- pubKey := dkgCompletion .PubKeys [0 ]
60- pubKeyBz , _ := hex .DecodeString (pubKey )
61-
62- if dkgRequest .Type == types .DKG_TYPE_DCM {
63- updateDCM (ctx , storeKey , dkgRequest .Id , pubKeyBz , cdc )
64- } else if dkgRequest .Type == types .DKG_TYPE_NONCE {
65- updateOracle (ctx , storeKey , dkgRequest .Id , pubKeyBz , cdc )
66- }
67- }
82+ return false
83+ })
6884}
6985
7086// updateDCM updates the given dcm
0 commit comments