; This is a utility layer for a coin that allows it to prove that it came from some INITIAL_PUZZLE_HASH
(mod
  (
    INITIAL_PUZZLE_HASH  ; The ancestor's puzzle hash this layer is evidence of
    PARENT_MORPHER  ; Defines how to wrap a parent inner puzzle hash to prove that it had this layer running inside it
    INNER_PUZZLE
    lineage_proof  ; parent id, parent inner puzzle hash (wrapped with PARENT_MORPHER), parent amount
    morpher_solution  ; solution to PARENT_MORPHER
    inner_solution
  )

  (include condition_codes.clib)

  (c
    (list ASSERT_MY_PARENT_ID
      (sha256
        (f lineage_proof)
        (if (r (r lineage_proof))  ; different logic based on whether the lineage proof is 2 or 3 elements long
            (a PARENT_MORPHER (c INITIAL_PUZZLE_HASH (c (f (r lineage_proof)) morpher_solution)))
            INITIAL_PUZZLE_HASH
        )
        (if (r (r lineage_proof))  ; different logic based on whether the lineage proof is 2 or 3 elements long
            (f (r (r lineage_proof)))
            (f (r lineage_proof))
        )
      )
    )
    (a INNER_PUZZLE inner_solution)
  )
)
