Skip to content

Commit

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

import (
"context"

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

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

0 comments on commit eaac24b

Please sign in to comment.