Skip to content

Instantly share code, notes, and snippets.

@tomclose
Last active July 6, 2019 21:51
Show Gist options
  • Save tomclose/3fb6bb3b0c778593365941a879fcfc06 to your computer and use it in GitHub Desktop.
Save tomclose/3fb6bb3b0c778593365941a879fcfc06 to your computer and use it in GitHub Desktop.
// in application module
module Payments {
import 0x30.Adjudicator;
public validTransition(s1, s2) {
  // implement app-specific transition logic
  }
public respond(R#Adjudicator.T adjudicator, V#State s1, V#State s2) {
assert(validTransition(s1, s2));
  Adjudicator.respond(move(adjudicator), s1, s2);
  }
// ... (other code not shown) ...
}
// in adjudicator module
module Adjudicator {
public respond(Adj adjudicator, State s1, State s2) {
// framework checks
// … (not shown) …
// app-specific checks
let appDef = getAppDefinition(copy(s1));
// only allow response if the app library is calling us
assert(appDef == get_calling_module());
// if all checks pass, cancel the challenge
cancel_challenge(move(adjudicator));
}
}
// ... (other code not shown) ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment