Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor HTLC to support HTLT #146

Merged
merged 36 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3c517b7
refactor htlc
SegueII Mar 10, 2021
762d5fa
add params validate
SegueII Mar 10, 2021
a6be582
update events
SegueII Mar 10, 2021
9cb3e71
update msg test
SegueII Mar 10, 2021
19a12f0
add field closedblock
SegueII Mar 10, 2021
a931295
fix cli
SegueII Mar 10, 2021
5f017e2
fix refund
SegueII Mar 10, 2021
4e36d66
handle refund err
SegueII Mar 10, 2021
413bb0c
add query asset supplies
SegueII Mar 10, 2021
022f5ba
add legacy query
SegueII Mar 11, 2021
64c9af8
fix grpc query
SegueII Mar 11, 2021
aba51a0
update genensis export
SegueII Mar 11, 2021
cc91521
update rest query
SegueII Mar 11, 2021
f06d636
fix asset denom validate in params
SegueII Mar 11, 2021
8576c63
fix typo
SegueII Mar 11, 2021
14ccebb
draft uni test
SegueII Mar 11, 2021
9c58afc
Merge branch 'master' into htlt
SegueII Mar 11, 2021
b8415c6
fix htlt amount validate
SegueII Mar 11, 2021
3de7dcd
remove uni test
SegueII Mar 11, 2021
29973aa
update asset supplies proto and fix htlc validate
SegueII Mar 12, 2021
3c617e5
fix init genesis
SegueII Mar 12, 2021
f0af180
fix GetID
SegueII Mar 12, 2021
1795c6e
fix keys
SegueII Mar 15, 2021
c871b41
remove test
SegueII Mar 15, 2021
d1102bd
Merge branch 'master' into htlt
SegueII Mar 15, 2021
d40cff2
remove test
SegueII Mar 16, 2021
3e6ac0d
improve create htlc
SegueII Mar 16, 2021
346dfc0
fix asset supply and begin blocker
SegueII Mar 16, 2021
f9c26df
fix store
SegueII Mar 16, 2021
dfc536b
fix typo
SegueII Mar 17, 2021
45483db
remove unused func
SegueII Mar 17, 2021
f1d00fe
fix genesis validation
SegueII Mar 17, 2021
8802f8a
export all htlcs
SegueII Mar 17, 2021
636c4d6
improve htlc validate
SegueII Mar 17, 2021
c356da9
update changelog
SegueII Mar 17, 2021
01012f9
Merge branch 'master' into htlt
SegueII Mar 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

* (modules/coinswap)[\#151](https://github.com/irisnet/irismod/pull/151) Replace prefix `swap/` with `swap`
* (modules/htlc)[\#146](https://github.com/irisnet/irismod/pull/146) Refactor HTLC module to support HTLT.

## [v1.3.1] - 2021-02-09

Expand Down
13 changes: 0 additions & 13 deletions modules/coinswap/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,3 @@ func validateFee(i interface{}) error {

return nil
}

func validateStandardDenom(i interface{}) error {
v, ok := i.(string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if err := sdk.ValidateDenom(v); err != nil {
return err
}

return nil
}
4 changes: 2 additions & 2 deletions modules/coinswap/types/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func ValidateInput(input Input) error {
}

if strings.HasPrefix(input.Coin.Denom, FormatUniABSPrefix) {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid input denom,shoule not be begin with (%s)", FormatUniABSPrefix)
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid input denom, should not begin with (%s)", FormatUniABSPrefix)
}

if _, err := sdk.AccAddressFromBech32(input.Address); err != nil {
Expand All @@ -31,7 +31,7 @@ func ValidateOutput(output Output) error {
}

if strings.HasPrefix(output.Coin.Denom, FormatUniABSPrefix) {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid output denom,shoule not be begin with (%s)", FormatUniABSPrefix)
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid output denom, should not begin with (%s)", FormatUniABSPrefix)
}

if _, err := sdk.AccAddressFromBech32(output.Address); err != nil {
Expand Down
22 changes: 10 additions & 12 deletions modules/htlc/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,26 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
ctx = ctx.WithLogger(ctx.Logger().With("handler", "beginBlock").With("module", "irismod/htlc"))

currentBlockHeight := uint64(ctx.BlockHeight())

k.IterateHTLCExpiredQueueByHeight(
ctx,
currentBlockHeight,
func(hlock tmbytes.HexBytes, h types.HTLC) (stop bool) {
// update the state
h.State = types.Expired
k.SetHTLC(ctx, h, hlock)

ctx, currentBlockHeight,
func(id tmbytes.HexBytes, h types.HTLC) (stop bool) {
// refund HTLC
_ = k.RefundHTLC(ctx, h, id)
// delete from the expiration queue
k.DeleteHTLCFromExpiredQueue(ctx, currentBlockHeight, hlock)
k.DeleteHTLCFromExpiredQueue(ctx, currentBlockHeight, id)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeHTLCExpired,
sdk.NewAttribute(types.AttributeKeyHashLock, hlock.String()),
types.EventTypeRefundHTLC,
sdk.NewAttribute(types.AttributeKeyID, id.String()),
),
})

ctx.Logger().Info(fmt.Sprintf("HTLC [%s] is expired", hlock.String()))
ctx.Logger().Info(fmt.Sprintf("HTLC [%s] is refunded", id.String()))

return false
},
)

k.UpdateTimeBasedSupplyLimits(ctx)
}
Loading