Skip to content

Commit

Permalink
feat(logic): add block_height/1 predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Jan 6, 2023
1 parent 64a5523 commit 70b0bc0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions x/logic/predicate/block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package predicate

import (
"context"

"github.com/ichiban/prolog/engine"
)

// BlockHeight is higher order function that given a context returns the following predicate:
//
// block_height(?Height)
//
// where Height represents the current chain height at the time of the query.
// The predicate is non-deterministic, producing a different height each time it is called.
func BlockHeight(ctx context.Context) engine.Predicate1 {
return func(vm *engine.VM, height 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, height, engine.Integer(sdkContext.BlockHeight()), cont, env)
}
}

0 comments on commit 70b0bc0

Please sign in to comment.