-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: building oracle validator logic
- Loading branch information
1 parent
a8bc120
commit 81110be
Showing
6 changed files
with
375 additions
and
23 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,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) }) | ||
} |
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 |
---|---|---|
@@ -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" | ||
} |
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
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,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)) | ||
} |
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
Oops, something went wrong.