Skip to content

Commit

Permalink
Add CheckExpirationCondition to UnlockConditionSet
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Oct 8, 2023
1 parent 4e43c6d commit f0f4147
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ require (
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/iotaledger/hive.go/codegen v0.0.0-20231005142627-86973b2edb3b // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o
github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc=
github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE=
github.com/iotaledger/hive.go/codegen v0.0.0-20231005142627-86973b2edb3b h1:RpCqfmmxrkTdxPm56UzF1QuHppTo3VtyzhfaUUfzVA0=
github.com/iotaledger/hive.go/codegen v0.0.0-20231005142627-86973b2edb3b/go.mod h1:zBiQaY4DL7xx/gNgb1MWqMaV62x2o937nBCEaW++ztI=
github.com/iotaledger/hive.go/constraints v0.0.0-20231005142627-86973b2edb3b h1:8FdKoB755PjCL1aHTi+2rPt9lCUS4B2wg2fNKykw5dc=
github.com/iotaledger/hive.go/constraints v0.0.0-20231005142627-86973b2edb3b/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231005142627-86973b2edb3b h1:gQ+Wqg8h/LRpgX3CsmaOZYdMIBVL4fAPIrZbmA6Wn3Q=
Expand Down
1 change: 0 additions & 1 deletion nodeclient/blockissuer_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var (
)

type (

// BlockIssuerClient is a client which queries the optional blockissuer functionality of a node.
BlockIssuerClient interface {
// Info returns the info of the block issuer.
Expand Down
19 changes: 19 additions & 0 deletions unlock_cond.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,25 @@ func (f UnlockConditionSet) HasExpirationCondition() bool {
return f.Expiration() != nil
}

// CheckExpirationCondition returns the expiration return ident in case an expiration condition was set and
// the future bound slot is greater than the expiration slot.
// In case the past bound slot is smaller than the expiration slot, "nil" is returned to indicate that the original owner can unlock the output.
// The range in between is not unlockable by anyone and an "ErrExpirationConditionUnlockFailed" error will be returned.
func (f UnlockConditionSet) CheckExpirationCondition(futureBoundedSlotIndex, pastBoundedSlotIndex SlotIndex) (Address, error) {
if f.HasExpirationCondition() {
if ok, returnIdent := f.ReturnIdentCanUnlock(futureBoundedSlotIndex); ok {
return returnIdent, nil
}

if !f.OwnerIdentCanUnlock(pastBoundedSlotIndex) {
return nil, ErrExpirationConditionUnlockFailed
}
}

//nolint:nilnil // nil, nil is ok in this context, even if it is not go idiomatic
return nil, nil
}

// HasTimelockCondition tells whether this set has a TimelockUnlockCondition.
func (f UnlockConditionSet) HasTimelockCondition() bool {
return f.Timelock() != nil
Expand Down

0 comments on commit f0f4147

Please sign in to comment.