Skip to content

Commit

Permalink
added in wallets and added a function to cip68 while at it
Browse files Browse the repository at this point in the history
  • Loading branch information
logicalmechanism committed Jan 30, 2024
1 parent ff7c245 commit 38b9eaf
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# v0.x.y

- Added the `Wallets` type and `to_vks` to the wallet submodule.
- Added `get` and `version` to the cip68 types submodule.

# v0.4.4

- Documentation is now hosted at logicalmechanism.io
Expand Down
22 changes: 22 additions & 0 deletions lib/assist/types/cip68.ak
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,25 @@ pub type CIP68 {
metadata: Dict<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)
/// ```
pub fn get(cip68: CIP68, key: Data) -> Data {
when dict.get(cip68.metadata, key) is {
Some(thing) -> thing
None -> fail @"Data Structure Not Found"
}
}

/// Return the version of the metadata.
///
/// ```aiken
/// datum |> cip68.version
/// ```
pub fn version(metadata: CIP68) -> Int {
metadata.version
}
43 changes: 43 additions & 0 deletions lib/assist/types/wallet.ak
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use aiken/bytearray
use aiken/list
use assist/types/hashes.{PublicKeyHash}

/// A wallet type for a non-smart contract address.
Expand All @@ -7,6 +8,48 @@ pub type Wallet {
sc: PublicKeyHash,
}

/// A list of wallets for non-smart contract addresses.
pub type Wallets =
List<Wallet>

/// Convert a list of wallets into a list of public key hashes. This is useful
/// when doing multisig validation. The output order respects the input order.
///
/// ```aiken
/// wallet.to_vks(datum.wallets)
/// ```
pub fn to_vks(wallets: Wallets) -> List<PublicKeyHash> {
list.map(wallets, fn(w) { w.pkh })
}

test empty_to_vks() {
to_vks([]) == []
}

test single_to_vks() {
let w: Wallet =
Wallet {
pkh: #"abcdef0123456789abcdef0123456789abcdef0123456789abcdef01",
sc: #"",
}
to_vks([w]) == [#"abcdef0123456789abcdef0123456789abcdef0123456789abcdef01"]
}

test multiple_to_vks() {
let w: Wallet =
Wallet {
pkh: #"abcdef0123456789abcdef0123456789abcdef0123456789abcdef01",
sc: #"",
}
let expected: List<PublicKeyHash> =
[
#"abcdef0123456789abcdef0123456789abcdef0123456789abcdef01",
#"abcdef0123456789abcdef0123456789abcdef0123456789abcdef01",
#"abcdef0123456789abcdef0123456789abcdef0123456789abcdef01",
]
to_vks([w, w, w]) == expected
}

/// Check if a wallet has a bad form and needs to be bypassed.
/// The pkh must be the length 56 hex string and the sc is either empty or
/// it is also a length 56 hex string.
Expand Down

0 comments on commit 38b9eaf

Please sign in to comment.