Skip to content

Commit

Permalink
feat(logic): add block_time/1 predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Jan 6, 2023
1 parent 70b0bc0 commit cc52351
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions x/logic/predicate/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ func BlockHeight(ctx context.Context) engine.Predicate1 {
}
}

// BlockTime is higher order function that given a context returns the following predicate:
//
// block_time(?Time)
//
// where Time represents the current chain time at the time of the query.
// The predicate is non-deterministic, producing a different time each time it is called.
func BlockTime(ctx context.Context) engine.Predicate1 {
return func(vm *engine.VM, time engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise {
sdkContext, err := UnwrapSDKContext(ctx)
if err != nil {
return engine.Error(err)
}

return engine.Unify(vm, time, engine.Integer(sdkContext.BlockTime().Unix()), cont, env)
}
}

0 comments on commit cc52351

Please sign in to comment.