@@ -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