Chia - Receiving Messages

A message should only be received once. Because of this, messages can only be received through a portal singleton, the source code of which can be found here. The singleton takes the message data and associated validator signatures and creates a message coin with this puzzle:

(mod (
    ; first curry (automated)
    PORTAL_RECEIVER_SINGLETON_STRUCT

    ; second curry
    (SOURCE_CHAIN . NONCE)
    SOURCE
    DESTINATION ; destination
    MESSAGE_HASH

    (receiver_parent_info . receiver_amount) ; receiver_proof
    parent_proof ; (parent_parent_info . parent_inner_puzzle_hash)
    my_coin_id
  )

  (include condition_codes.clib)
  (include curry.clib)
  (include sha256tree.clib)

  (defun main (
    PORTAL_RECEIVER_SINGLETON_STRUCT
    (parent_parent_info . parent_inner_puzzle_hash)
    my_coin_id
    receiver_coin_id
  )
    (list
      (list ASSERT_MY_COIN_ID my_coin_id)
      (list ASSERT_MY_PARENT_ID (sha256
        parent_parent_info
        (curry_hashes_inline (f PORTAL_RECEIVER_SINGLETON_STRUCT)
          (sha256tree PORTAL_RECEIVER_SINGLETON_STRUCT)
          parent_inner_puzzle_hash
        )
        1 ; parent amount
      ))
      (list CREATE_COIN_ANNOUNCEMENT receiver_coin_id) ; puzzle contains message info
      (list ASSERT_COIN_ANNOUNCEMENT (sha256 receiver_coin_id my_coin_id))
    ) 
  )

  (defun-inline value_b32_or_x (v)
    (if (= (strlen v) 32) v (x))
  )

  (main
    PORTAL_RECEIVER_SINGLETON_STRUCT
    parent_proof
    my_coin_id
    (sha256
      (value_b32_or_x receiver_parent_info)
      (value_b32_or_x DESTINATION)
      receiver_amount
    ) ; receiver_coin_id
  )
)

The message coin has an amount of 0 and locks in to a receiver coin via announcements. The message coin can optionally be spent in the same transaction that it was created so a user both relays a message and uses the intended receiver puzzle in the same transaction.

Last updated