Skip to content

Commit

Permalink
feat: building oracle validator logic
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Nov 22, 2023
1 parent a8bc120 commit 81110be
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 23 deletions.
77 changes: 77 additions & 0 deletions lib/aiken-content-ownership/common.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use aiken/bytearray
use aiken/list
use aiken/transaction.{Output}
use aiken/transaction/credential.{Address}
use aiken/transaction/value.{
AssetName, MintedValue, PolicyId, flatten, from_minted_value, quantity_of,
}

pub fn utxos_at(outputs: List<Output>, address: Address) {
list.filter(outputs, fn(output) { output.address == address })
}

pub fn utxos_at_with(
outputs: List<Output>,
address: Address,
policy: PolicyId,
name: AssetName,
) {
list.filter(
outputs,
fn(output) {
output.address == address && quantity_of(output.value, policy, name) == 1
},
)
}

pub fn onlyMintedToken(
mint: MintedValue,
policy: PolicyId,
name: AssetName,
quantity: Int,
) {
expect [(mPolicy, mAssetName, mQuantity)] =
from_minted_value(mint) |> flatten()
mPolicy == policy && mAssetName == name && mQuantity == quantity
}

pub fn convert_int_to_bytes(i: Int) -> ByteArray {
convert_int_to_bytes_go(i, get_number_digit(i))
}

fn convert_int_to_bytes_go(newInt: Int, digit: Int) -> ByteArray {
if digit == 1 {
bytearray.push("", newInt + 48)
} else {
bytearray.push(
convert_int_to_bytes_go(newInt % digit, digit / 10),
newInt / digit + 48,
)
}
}

pub fn get_number_digit(i: Int) -> Int {
go_get_number_digit(i, 1)
}

fn go_get_number_digit(newInt: Int, digit: Int) -> Int {
if newInt < 10 {
digit
} else {
go_get_number_digit(newInt / 10, digit * 10)
}
}

test byte_conversion() {
convert_int_to_bytes(1) == "1" && convert_int_to_bytes(123) == "123" && convert_int_to_bytes(
672912,
) == "672912"
}

pub fn key_signed(witnesses: List<ByteArray>, key: ByteArray) {
list.has(witnesses, key)
}

pub fn all_key_signed(witnesses: List<ByteArray>, keys: List<ByteArray>) {
list.all(keys, fn(key) { key_signed(witnesses, key) })
}
14 changes: 8 additions & 6 deletions lib/aiken-content-ownership/diagnostic.ak
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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"
// serialise(mock_verfication_key_credential()) == #"d8799f5820e822178d3ceaeef383a84cbd41a702b3837360bf889aaac714e6f380731d20d4ff"
}
9 changes: 8 additions & 1 deletion lib/aiken-content-ownership/placeholder.ak
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use aiken/transaction.{NoDatum, Output, OutputReference, TransactionId}
use aiken/transaction/credential.{Address, VerificationKeyCredential}
use aiken/transaction/credential.{Address,
Credential, VerificationKeyCredential}
use aiken/transaction/value.{PolicyId, from_lovelace}

pub fn mock_policy_id() -> PolicyId {
Expand Down Expand Up @@ -30,3 +31,9 @@ pub fn mock_output() -> Output {
reference_script: None,
}
}

pub fn mock_verfication_key_credential() -> Credential {
VerificationKeyCredential(
#"e822178d3ceaeef383a84cbd41a702b3837360bf889aaac714e6f380731d20d4",
)
}
7 changes: 7 additions & 0 deletions lib/aiken-content-ownership/utils.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use aiken/bytearray
use aiken/transaction/value.{AssetName}
use aiken_content_ownership/common.{convert_int_to_bytes}

pub fn get_registry_token_name(count: Int) -> AssetName {
bytearray.concat("Registry ()", convert_int_to_bytes(count))
}
212 changes: 212 additions & 0 deletions plutus.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@
],
"compiledCode": "5902020100003232323232323232322223253330073232323232533300c3370e9000000899191919299980819b87480000084c8c8c8c94ccc050cdc3a400000229445281809000991980080080111299980b8008a60103d87a80001323253330163375e026600e6028004266e9520003301a0024bd70099802002000980d801180c8009bac3016001300e008132323300100100222533301600114a226464a66602aa66602a66e3cdd71803001004099b88375a60346036603600490000a5113300400400114a060340046eb0c060004c8c8cc004004008894ccc05800452f5c0264666444646600200200644a6660380022006264666444660426e9ccc084dd4804998109ba900333021375000497ae0001375c60360026eb4c070004cc00c00cc080008c078004dd7180a8009bab301600133003003301a002301800132323300100100222533301600114bd6f7b630099191919299980b99b8f488100002100313301b337606ea4008dd3000998030030019bab3018003375c602c004603400460300026eacc054c058c058c058c058c0380208c054004c034028dd7180900098050010a50300a001300f001300f002300d001300500214984d958c94ccc01ccdc3a40000022a666014600a0062930b0a99980399b874800800454ccc028c01400c52616163005002230053754002460066ea80055cd2ab9d5573caae7d5d02ba157441",
"hash": "be3105aa3627cda80601b9f9d14ffec737fccdaf92c3771c4d013641"
},
{
"title": "oracle_validator.oracle_validator",
"datum": {
"title": "datum",
"schema": {
"$ref": "#/definitions/oracle_validator~1Datum"
}
},
"redeemer": {
"title": "redeemer",
"schema": {
"$ref": "#/definitions/oracle_validator~1Redeemer"
}
},
"compiledCode": "5906ea0100003232323232323232322223232323232533300b323232323253330103370e900100089919191919191919191919191919191919191919191919191919191919191919191919191919299981b19b87480000204cccc004080050c00803d2002153330363370e9001004099998008100089801006a40042a66606c66e1d20040081323232323232533303f3042002132533303d3370e9002181e00089919191929998209919198008008011129998238008a51132325333046323300100102c22533304b00114a026464a66609466e3c00801852889980200200098278011bae304d00113300400400114a060960046eb8c124004cc114dd480b198229ba90144bd7008008a503375e0046464646464646466e9520003304b304c0073304b304c0063304b304c0053304b304c0043304b304c0033304b304c0023304b304c0013304b304c304d0013304b3752020660966ea40392f5c060980026096002609400260920026090002608e002607c07a606e002608600260760022c60826084608460740022c6080002646600200205044a66607e002297ae013232533303e533303e3375e6086607800403e266e1cccc888c8cc88c94ccc114cdc3a4004002200426eb4c128c10c00cc10c008c94ccc10ccdc3a4004002298103d87a8000132323300100100222533304900114c103d87a8000132323232533304a3371e014004266e9520003304e375000297ae0133006006003375a60960066eb8c124008c134008c12c004dd5982418208011820800a4000646600200200844a66608c0022980103d87a800013232323253330473371e010004266e9520003304b374c00297ae0133006006003375660900066eb8c118008c128008c120004dd598219822181e001010a45004800852809982100119802002000899802002000982180118208009bae303e001303e002375c6078002606806429448888c8c94ccc0f8c1040084c8c8c8c8c94ccc1014ccc100cdc7802805099b8f00300914a0266e1c0040205281bad30440013044002375c608400260840046eb8c10000458dd6181f80099191980080080111299981f8008a5eb804c8ccc888c8cc00400400c894ccc114004400c4c8ccc888cc128dd3998251ba90093304a3752006660946ea00092f5c00026eb8c110004dd6982280099801801982480118238009bae303e0013756607e0026600600660860046082002646600200200a44a66607c002297adef6c60132323232533303f3371e9101000021003133043337606ea4008dd3000998030030019bab3040003375c607c00460840046080002466e2922010b526567697374727920282900330020013300500148008c0040048894ccc0d4cdc3800a400426600891010033700004903009980219980180199b8600200133706002900a19b803370600400290301119b8b0010023001001222533303233710004900a0800899980180199b8300248050cdc1000a4028605a0546eb8c0c8004c0c8008dd7181800098180011bad302e001302e002375a605800260580046eb8c0a8004c0a8004c0a4008dd7181380098138009813001181200098120011bae3022001301a019375860400026040002603e002603c002603a0046eacc06c004c06c004c068008dd6180c000980c000980b80098070020a50300e001301300130130023011001300900614984d958c94ccc02ccdc3a40000022a66601c601200e2930b0a99980599b874800800454ccc038c02401c526161533300b3370e90020008991919192999809180a8010a4c2c6eb8c04c004c04c008dd7180880098048038a99980599b874801800454ccc038c02401c526161630090063001006232533300a3370e90000008991919191919191919191919191919191919191929998109812001099191924c603201a6030020602e0222c6eb8c088004c088008dd7181000098100011bad301e001301e002375a603800260380046eb8c068004c068008c060004c060008dd7180b000980b001180a000980a001180900098090011bae3010001300800216300800123253330093370e9000000899191919299980818098010991924c64a66601e66e1d20000011323253330143017002132498c94ccc048cdc3a400000226464a66602e60340042649318070008b180c00098080010a99980919b87480080044c8c8c8c8c8c94ccc06cc07800852616375a603800260380046eb4c068004c068008dd6980c00098080010b18080008b180a80098068018a99980799b874800800454ccc048c03400c5261616300d00230070031630110013011002300f001300700216300700123253330083370e900000089919299980698080010a4c2c6eb8c038004c01800854ccc020cdc3a400400226464a66601a60200042930b1bae300e0013006002163006001230053754002460066ea80055cd2ab9d5573caae7d5d02ba15745",
"hash": "2f3c08311a0dae07d6e0d0152b9813fb3591305cd7685b7423e3f434"
}
],
"definitions": {
Expand All @@ -38,6 +55,29 @@
"Int": {
"dataType": "integer"
},
"Option$aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
"title": "Optional",
"anyOf": [
{
"title": "Some",
"description": "An optional value.",
"dataType": "constructor",
"index": 0,
"fields": [
{
"$ref": "#/definitions/aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"
}
]
},
{
"title": "None",
"description": "Nothing.",
"dataType": "constructor",
"index": 1,
"fields": []
}
]
},
"aiken/transaction/OutputReference": {
"title": "OutputReference",
"description": "An `OutputReference` is a unique reference to an output on-chain. The `output_index`\n corresponds to the position in the output list of the transaction (identified by its id)\n that produced that output",
Expand Down Expand Up @@ -76,6 +116,88 @@
}
]
},
"aiken/transaction/credential/Address": {
"title": "Address",
"description": "A Cardano `Address` typically holding one or two credential references.\n\n Note that legacy bootstrap addresses (a.k.a. 'Byron addresses') are\n completely excluded from Plutus contexts. Thus, from an on-chain\n perspective only exists addresses of type 00, 01, ..., 07 as detailed\n in [CIP-0019 :: Shelley Addresses](https://github.com/cardano-foundation/CIPs/tree/master/CIP-0019/#shelley-addresses).",
"anyOf": [
{
"title": "Address",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "payment_credential",
"$ref": "#/definitions/aiken~1transaction~1credential~1Credential"
},
{
"title": "stake_credential",
"$ref": "#/definitions/Option$aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"
}
]
}
]
},
"aiken/transaction/credential/Credential": {
"title": "Credential",
"description": "A general structure for representing an on-chain `Credential`.\n\n Credentials are always one of two kinds: a direct public/private key\n pair, or a script (native or Plutus).",
"anyOf": [
{
"title": "VerificationKeyCredential",
"dataType": "constructor",
"index": 0,
"fields": [
{
"$ref": "#/definitions/ByteArray"
}
]
},
{
"title": "ScriptCredential",
"dataType": "constructor",
"index": 1,
"fields": [
{
"$ref": "#/definitions/ByteArray"
}
]
}
]
},
"aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
"title": "Referenced",
"description": "Represent a type of object that can be represented either inline (by hash)\n or via a reference (i.e. a pointer to an on-chain location).\n\n This is mainly use for capturing pointers to a stake credential\n registration certificate in the case of so-called pointer addresses.",
"anyOf": [
{
"title": "Inline",
"dataType": "constructor",
"index": 0,
"fields": [
{
"$ref": "#/definitions/aiken~1transaction~1credential~1Credential"
}
]
},
{
"title": "Pointer",
"dataType": "constructor",
"index": 1,
"fields": [
{
"title": "slot_number",
"$ref": "#/definitions/Int"
},
{
"title": "transaction_index",
"$ref": "#/definitions/Int"
},
{
"title": "certificate_index",
"$ref": "#/definitions/Int"
}
]
}
]
},
"one_time_minting_policy/Redeemer": {
"title": "Redeemer",
"anyOf": [
Expand All @@ -92,6 +214,96 @@
"fields": []
}
]
},
"oracle_validator/Datum": {
"title": "Datum",
"anyOf": [
{
"title": "Datum",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "oracle_nft",
"$ref": "#/definitions/ByteArray"
},
{
"title": "oracle_address",
"$ref": "#/definitions/aiken~1transaction~1credential~1Address"
},
{
"title": "content_registry_address",
"$ref": "#/definitions/aiken~1transaction~1credential~1Address"
},
{
"title": "content_registry_ref_token",
"$ref": "#/definitions/ByteArray"
},
{
"title": "ownership_registry_address",
"$ref": "#/definitions/aiken~1transaction~1credential~1Address"
},
{
"title": "ownership_registry_ref_token",
"$ref": "#/definitions/ByteArray"
},
{
"title": "content_registry_count",
"$ref": "#/definitions/Int"
},
{
"title": "ownership_registry_count",
"$ref": "#/definitions/Int"
},
{
"title": "operation_key",
"$ref": "#/definitions/ByteArray"
},
{
"title": "stop_key",
"$ref": "#/definitions/ByteArray"
}
]
}
]
},
"oracle_validator/Redeemer": {
"title": "Redeemer",
"anyOf": [
{
"title": "CreateContentRegistry",
"dataType": "constructor",
"index": 0,
"fields": []
},
{
"title": "CreateOwnershipRegistry",
"dataType": "constructor",
"index": 1,
"fields": []
},
{
"title": "RotateKey",
"dataType": "constructor",
"index": 2,
"fields": [
{
"title": "new_operation_key",
"$ref": "#/definitions/ByteArray"
},
{
"title": "new_stop_key",
"$ref": "#/definitions/ByteArray"
}
]
},
{
"title": "StopApp",
"dataType": "constructor",
"index": 3,
"fields": []
}
]
}
}
}
Loading

0 comments on commit 81110be

Please sign in to comment.