-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1956 from irisnet/segue/htlc
R4R: Implement HTLC claim and refund
- Loading branch information
Showing
12 changed files
with
413 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,36 @@ | ||
package htlc | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
|
||
"github.com/irisnet/irishub/app/v2/htlc/internal/types" | ||
sdk "github.com/irisnet/irishub/types" | ||
) | ||
|
||
// EndBlocker handles block ending logic | ||
func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) { | ||
// TODO | ||
func EndBlocker(ctx sdk.Context, k Keeper) (resTags sdk.Tags) { | ||
// check htlc expire and set state from Open to Expired | ||
ctx = ctx.WithLogger(ctx.Logger().With("handler", "EndBlock").With("module", "iris/htlc")) | ||
|
||
currentBlockHeight := uint64(ctx.BlockHeight()) | ||
iterator := k.IterateHTLCExpireQueueByHeight(ctx, currentBlockHeight) | ||
defer iterator.Close() | ||
|
||
for ; iterator.Valid(); iterator.Next() { | ||
|
||
secretHashLock := iterator.Key() | ||
htlc, _ := k.GetHTLC(ctx, secretHashLock) | ||
|
||
htlc.State = types.StateExpired | ||
k.SetHTLC(ctx, htlc, secretHashLock) | ||
k.DeleteHTLCFromExpireQueue(ctx, currentBlockHeight, secretHashLock) | ||
|
||
ctx.Logger().Info(fmt.Sprintf("HTLC [%s] is expired", hex.EncodeToString(secretHashLock))) | ||
} | ||
|
||
// TODO: alternative | ||
// check expire => refund => delete HTLC from expire queue | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.