Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cip68 doesn't use a dict anymore; intermediate fix until aiken 1.0.27 #82

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# v0.x.y

- Updated to Aiken 1.0.26
- Updated to stdlib 1.8.0
- Update CIP68 Data Structure
- Changed cip68.get, it loops a list instead of doing a dict.get

# v0.4.6

Expand Down
2 changes: 1 addition & 1 deletion aiken.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ platform = "github"

[[dependencies]]
name = "aiken-lang/stdlib"
version = "1.7.0"
version = "1.8.0"
source = "github"
23 changes: 16 additions & 7 deletions lib/assist/types/cip68.ak
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use aiken/dict.{Dict}
use aiken/builtin

/// (100) Reference Token Prefix
/// https://developers.cardano.org/docs/governance/cardano-improvement-proposals/cip-0068/#222-nft-standard
Expand All @@ -19,27 +19,36 @@ pub const prefix_444: ByteArray = #"001bc280"
/// The generic CIP68 metadatum type as defined in the CIP at
/// https://cips.cardano.org/cips/cip68/.
pub type CIP68 {
metadata: Dict<Data, Data>,
metadata: List<(Data, Data)>,
version: Int,
}

/// Attempt to find a data structure by a key inside the cip68 metadatum. If
/// nothing is found then fail.
///
/// ```aiken
/// cip68.get(datum, some_key)
/// cip68.get(metadatum, some_key)
/// ```
pub fn get(cip68: CIP68, key: Data) -> Data {
when dict.get(cip68.metadata, key) is {
Some(thing) -> thing
None -> fail @"Data Structure Not Found"
do_get(cip68.metadata, key)
}

fn do_get(cip68: List<(Data, Data)>, key: Data) -> Data {
when cip68 is {
[] -> fail @"Data Structure Not Found"
[d, ..ds] ->
if builtin.fst_pair(d) == key {
builtin.snd_pair(d)
} else {
do_get(ds, key)
}
}
}

/// Return the version of the metadata.
///
/// ```aiken
/// datum |> cip68.version
/// metadatum |> cip68.version
/// ```
pub fn version(metadata: CIP68) -> Int {
metadata.version
Expand Down
Loading