From a8bc12076d16964096887947585e8fb0509c25d1 Mon Sep 17 00:00:00 2001 From: SIDANWhatever Date: Thu, 16 Nov 2023 00:52:37 +0800 Subject: [PATCH] feat: building basic skeleton for oracle validator --- .gitignore | 1 + lib/aiken-content-ownership/diagnostic.ak | 13 +++--- validators/content_registry.ak | 0 validators/content_registry_ref_token.ak | 0 validators/oracle_validator.ak | 48 ++++++++++++++++++++++ validators/ownership_registry.ak | 0 validators/ownership_registry_ref_token.ak | 0 7 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 validators/content_registry.ak create mode 100644 validators/content_registry_ref_token.ak create mode 100644 validators/oracle_validator.ak create mode 100644 validators/ownership_registry.ak create mode 100644 validators/ownership_registry_ref_token.ak diff --git a/.gitignore b/.gitignore index be35dd5..3ff63fa 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ build/ # Aiken's default documentation export docs/ +.vscode test.json \ No newline at end of file diff --git a/lib/aiken-content-ownership/diagnostic.ak b/lib/aiken-content-ownership/diagnostic.ak index d4a1241..53b0c47 100644 --- a/lib/aiken-content-ownership/diagnostic.ak +++ b/lib/aiken-content-ownership/diagnostic.ak @@ -1,7 +1,6 @@ -use aiken/cbor.{serialise} -use aiken_content_ownership/placeholder.{mock_utxo_ref} - -test diag() { - // serialise(mock_utxo_ref(0)) == #"d8799fd8799f58205a077cbcdffb88b104f292aacb9687ce93e2191e103a30a0cc5505c18b719f98ff00ff" - serialise(mock_utxo_ref(1)) == #"d8799fd8799f58205a077cbcdffb88b104f292aacb9687ce93e2191e103a30a0cc5505c18b719f98ff01ff" -} +// use aiken/cbor.{serialise} +// use aiken_content_ownership/placeholder.{mock_utxo_ref} +// test diag() { +// // serialise(mock_utxo_ref(0)) == #"d8799fd8799f58205a077cbcdffb88b104f292aacb9687ce93e2191e103a30a0cc5505c18b719f98ff00ff" +// serialise(mock_utxo_ref(1)) == #"d8799fd8799f58205a077cbcdffb88b104f292aacb9687ce93e2191e103a30a0cc5505c18b719f98ff01ff" +// } diff --git a/validators/content_registry.ak b/validators/content_registry.ak new file mode 100644 index 0000000..e69de29 diff --git a/validators/content_registry_ref_token.ak b/validators/content_registry_ref_token.ak new file mode 100644 index 0000000..e69de29 diff --git a/validators/oracle_validator.ak b/validators/oracle_validator.ak new file mode 100644 index 0000000..96ff0c8 --- /dev/null +++ b/validators/oracle_validator.ak @@ -0,0 +1,48 @@ +use aiken/transaction.{ScriptContext, Spend} +use aiken/transaction/credential.{Address, Credential} +use aiken/transaction/value.{PolicyId} + +type Datum { + content_registry_address: Address, + content_registry_ref_token: PolicyId, + ownership_registry_address: Address, + ownership_registry_ref_token: PolicyId, + content_registry_count: Int, + ownership_registry_count: Int, + operation_key: Credential, + stop_key: Credential, +} + +type Redeemer { + CreateContentRegistry + CreateOwnershipRegistry + RotateKey { new_operation_key: Credential, new_stop_key: Credential } + StopApp +} + +validator { + fn oracle_validator(datum: Datum, redeemer: Redeemer, context: ScriptContext) { + let ScriptContext { purpose, transaction } = context + when purpose is { + Spend(_) -> + when redeemer is { + CreateContentRegistry -> + // Ref token is minted to address + // count + 1 + True + CreateOwnershipRegistry -> + // Ref token is minted to address + // count + 1 + True + RotateKey { new_operation_key, new_stop_key } -> + // Sign by both ops and stop key + // datum update correctly (key rotated) + True + StopApp -> + // signed by stop key + True + } + _ -> False + } + } +} diff --git a/validators/ownership_registry.ak b/validators/ownership_registry.ak new file mode 100644 index 0000000..e69de29 diff --git a/validators/ownership_registry_ref_token.ak b/validators/ownership_registry_ref_token.ak new file mode 100644 index 0000000..e69de29