You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add ClaimPredicate DSL methods which help with creation of claim predicates.
# use class-level helpers to create simple predicates unconditional=Stellar::ClaimPredicate.unconditionalbefore_rel_time=Stellar::ClaimPredicate.before_relative_time(1.hour)before_abs_time=Stellar::ClaimPredicate.before_absolute_time(Date.tomorrow.beginning_of_day)# negate predicates using `~` unary operator
~predicate# same as predicate.not# build complex predicates using `&` and `|` infix operatorspredicate & other_predicate# same as `predicate.and(other_predicate)`predicate | other_predicate# same as `predicate.or(other_predicate)`# quickly define complex predicates using `.compose` class method with the block unconditional=Stellar::ClaimPredicate.compose{}complex=Stellar::ClaimPredicate.composedobefore_relative_time(1.week) & ~before_relative_time(10.seconds) |
end# here's what building this predicate would look like without DSL complex=Stellar::ClaimPredicate.new(Stellar::ClaimPredicateType::AND,Stellar::ClaimPredicate.new(Stellar::ClaimPredicateType::BEFORE_RELATIVE_TIME,7 * 24 * 60 * 60),Stellar::ClaimPredicate.new(Stellar::ClaimPredicateType::NOT,Stellar::ClaimPredicate.new(Stellar::ClaimPredicateType::BEFORE_RELATIVE_TIME,10)))
Extend Operation with create_claimable_balance and claim_claimable_balance helpers
Add Claimant and ClaimPredicate DSL methods to reduce the noise.
Add simple predicate evaluation feature so that developers can sanity-check their predicates
includeStellar::DSLpredicate=ClaimPredicate{before_relative_time(1.week) & ~before_relative_time(10.seconds)}# predicate.evaluate(balance_creation_time, claim_evaluation_time)predicate.evaluate("2020-10-20 09:00:00","2020-10-20 09:00:05")# => falsepredicate.evaluate("2020-10-20 09:00:00","2020-10-20 09:01:00")# => truepredicate.evaluate("2020-10-20 09:00:00","2020-10-27 08:50:00")# => true# you can also pass an instance of ActiveSupport::Duration as a second parameter, in this case# it works as a relative offset from `balance_creation_time` predicate.evaluate("2020-10-20 09:00:00",1.week + 1.second)# => false# it is effectively the same aspredicate.evaluate("2020-10-20 09:00:00","2020-10-27 09:00:01")# => false