generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logic): add chain_id/1 predicate
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |