fix: unwrap used in a reachable place. Replaced with alternative option
This commit is contained in:
parent
9ae28aaa88
commit
076871492b
|
@ -1205,7 +1205,9 @@ impl<'a> CodeGenerator<'a> {
|
||||||
indices: arguments_index
|
indices: arguments_index
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(label, var_name, index)| {
|
.map(|(label, var_name, index)| {
|
||||||
let field_type = type_map.get(label).unwrap();
|
let field_type = type_map
|
||||||
|
.get(label)
|
||||||
|
.unwrap_or_else(|| type_map.get_index(*index).unwrap().1);
|
||||||
(*index, var_name.clone(), field_type.clone())
|
(*index, var_name.clone(), field_type.clone())
|
||||||
})
|
})
|
||||||
.collect_vec(),
|
.collect_vec(),
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
# This file was generated by Aiken
|
||||||
|
# You typically do not need to edit this file
|
||||||
|
|
||||||
|
[[requirements]]
|
||||||
|
name = "aiken-lang/stdlib"
|
||||||
|
version = "cf89161cbcd5e2c9519e7ea5d61986473b708179"
|
||||||
|
source = "github"
|
||||||
|
|
||||||
|
[[packages]]
|
||||||
|
name = "aiken-lang/stdlib"
|
||||||
|
version = "cf89161cbcd5e2c9519e7ea5d61986473b708179"
|
||||||
|
requirements = []
|
||||||
|
source = "github"
|
|
@ -0,0 +1,6 @@
|
||||||
|
name = "aiken-lang/acceptance_test_036"
|
||||||
|
version = "0.0.0"
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
{ name = "aiken-lang/stdlib", version="cf89161cbcd5e2c9519e7ea5d61986473b708179", source = "github" },
|
||||||
|
]
|
|
@ -0,0 +1,66 @@
|
||||||
|
use aiken/bytearray
|
||||||
|
use aiken/hash.{Hash, Sha2_256, sha2_256}
|
||||||
|
use aiken/list
|
||||||
|
use aiken/string
|
||||||
|
|
||||||
|
// MerkleTree in Aiken (ported from: https://github.com/input-output-hk/hydra/blob/master/plutus-merkle-tree/src/Plutus/MerkleTree.hs)
|
||||||
|
|
||||||
|
pub type MerkleTree {
|
||||||
|
Empty
|
||||||
|
Leaf { hash: Hash<Sha2_256, ByteArray>, value: ByteArray }
|
||||||
|
Node { hash: Hash<Sha2_256, ByteArray>, left: MerkleTree, right: MerkleTree }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn root_hash(t: MerkleTree) -> Hash<Sha2_256, ByteArray> {
|
||||||
|
when t is {
|
||||||
|
Empty -> #""
|
||||||
|
Leaf { hash, .. } -> hash
|
||||||
|
Node { hash, .. } -> hash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_equal(a: MerkleTree, b: MerkleTree) -> Bool {
|
||||||
|
root_hash(a) == root_hash(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn size(t: MerkleTree) -> Int {
|
||||||
|
when t is {
|
||||||
|
Empty -> 0
|
||||||
|
Leaf{..} -> 1
|
||||||
|
Node { left, right, .. } -> size(left) + size(right)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn combine_hash(h1: Hash<alg, a>, h2: Hash<alg, a>) -> Hash<alg, a> {
|
||||||
|
sha2_256(bytearray.concat(h1, h2))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_list(items0: List<ByteArray>) -> MerkleTree {
|
||||||
|
do_from_list(items0, list.length(items0))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn do_from_list(items: List<ByteArray>, len: Int) -> MerkleTree {
|
||||||
|
when items is {
|
||||||
|
[] -> Empty
|
||||||
|
[value] -> Leaf { hash: sha2_256(value), value }
|
||||||
|
all -> {
|
||||||
|
let cutoff: Int = len / 2
|
||||||
|
let left =
|
||||||
|
all
|
||||||
|
|> list.take(cutoff)
|
||||||
|
|> do_from_list(cutoff)
|
||||||
|
let right =
|
||||||
|
all
|
||||||
|
|> list.drop(cutoff)
|
||||||
|
|> do_from_list(len - cutoff)
|
||||||
|
let hash = combine_hash(root_hash(left), root_hash(right))
|
||||||
|
Node { hash, left, right }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test foo() {
|
||||||
|
let items = [#"aa", #"bb", #"cc"]
|
||||||
|
let mt = from_list(items)
|
||||||
|
size(mt) == 3
|
||||||
|
}
|
Loading…
Reference in New Issue