Skip to content

Commit 1f5ce2d

Browse files
committed
fix migration
1 parent e8c5904 commit 1f5ce2d

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

x/lending/migrations/v2/store.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,29 @@ func migrateLoans(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.Binar
6565
// update loan
6666
store.Set(types.LoanKey(loan.VaultAddress), cdc.MustMarshal(loan))
6767

68-
// decode dlc meta to v1
69-
dlcMetaBz := store.Get(types.DLCMetaKey(loan.VaultAddress))
70-
var dlcMetaV1 types.DLCMetaV1
71-
cdc.MustUnmarshal(dlcMetaBz, &dlcMetaV1)
68+
// migrate the corresponding dlc meta if any
69+
if store.Has(types.DLCMetaKey(loan.VaultAddress)) {
70+
dlcMetaBz := store.Get(types.DLCMetaKey(loan.VaultAddress))
71+
var dlcMetaV1 types.DLCMetaV1
72+
cdc.MustUnmarshal(dlcMetaBz, &dlcMetaV1)
7273

73-
internalKey, _ := hex.DecodeString(dlcMetaV1.InternalKey)
74+
internalKey, _ := hex.DecodeString(dlcMetaV1.InternalKey)
7475

75-
// build new dlc meta
76-
dlcMeta := &types.DLCMeta{
77-
LiquidationCet: dlcMetaV1.LiquidationCet,
78-
DefaultLiquidationCet: dlcMetaV1.DefaultLiquidationCet,
79-
RepaymentCet: dlcMetaV1.RepaymentCet,
80-
TimeoutRefundTx: dlcMetaV1.TimeoutRefundTx,
81-
VaultUtxos: dlcMetaV1.VaultUtxos,
82-
InternalKey: hex.EncodeToString(internalKey[1:]),
83-
LiquidationScript: dlcMetaV1.MultisigScript,
84-
RepaymentScript: dlcMetaV1.MultisigScript,
85-
TimeoutRefundScript: dlcMetaV1.TimeoutRefundScript,
86-
}
76+
// build new dlc meta
77+
dlcMeta := &types.DLCMeta{
78+
LiquidationCet: dlcMetaV1.LiquidationCet,
79+
DefaultLiquidationCet: dlcMetaV1.DefaultLiquidationCet,
80+
RepaymentCet: dlcMetaV1.RepaymentCet,
81+
TimeoutRefundTx: dlcMetaV1.TimeoutRefundTx,
82+
VaultUtxos: dlcMetaV1.VaultUtxos,
83+
InternalKey: hex.EncodeToString(internalKey[1:]),
84+
LiquidationScript: dlcMetaV1.MultisigScript,
85+
RepaymentScript: dlcMetaV1.MultisigScript,
86+
TimeoutRefundScript: dlcMetaV1.TimeoutRefundScript,
87+
}
8788

88-
// update dlc meta
89-
store.Set(types.DLCMetaKey(loan.VaultAddress), cdc.MustMarshal(dlcMeta))
89+
// update dlc meta
90+
store.Set(types.DLCMetaKey(loan.VaultAddress), cdc.MustMarshal(dlcMeta))
91+
}
9092
}
9193
}

0 commit comments

Comments
 (0)