Snippets

chromawallet futuristic-all-string

Created by Alex Mizrahi
(defcontract futuristic ()
  (fields
      (buyer :type pubkey :init nil)
      (seller :type pubkey)
      (broker :type pubkey :init nil)
      (sellers_bank :type pubkey :init nil)
      (buyers_bank :type pubkey :init nil)
      (land_registry :type pubkey :init nil)

      (property :type string :init nil)
      (price :type string :init nil)
      (description :type string :init nil)
      (security_info :type string :init nil) ; should be a list type of sorts maybe, or json string
      (state :type string :init nil)
)
  (actions
   
    (offer ((property-id string :description "Official ID of the property"))
    "Offer the property on the market (pending description of the property by the broker)"
      (guard
        (signatures seller)
        (eql state nil))
      (update property property-id
       state :invite-broker)
    )

    (invite-broker ((broker-pk pubkey))
    "Invitation of broker to the contract"
      (guard
          (signatures seller)
          (eql state :invite-broker)
          (eql broker nil))
      (locally
        (invite broker-pk))
      (update broker broker-pk
       state :describe)
    )

    (describe ((description-param string  :description "Description of the property, including it's state"))
    "Describe the property, including its extent and state"
      (guard 
          (signatures broker)
          (eql state :describe)
      )
      (update description description-param
       state :invite-buyer)
    )

    (invite-buyer ((buyer-pk pubkey))
    "You are invited as buyer to put a bid on the property"
      (guard
          (signatures broker)
          (eql state :invite-buyer)
      )
      (locally
        (invite buyer-pk)
      )
      (update buyer buyer-pk
       state :bid)
    )

    (bid ((bid-amount string :description "Price offered for buying the property"))
    "Enter your bid for the property"
      (guard 
          (signatures buyer)
          (eql state :bid)
      )
      (update price bid-amount
       state :accept)
    )

    (accept ()
    "Accept the bid for the property"
      (guard
          (signatures seller)
          (not (eql price nil))
          (eql state :accept)
      )
      (update state :commit)
    )

    (commit ()
    "Commit to your bid for the property"
      (guard
          (signatures buyer)
          (not (eql price nil))
          (eql state :commit)
      )
      (update state :invite-sellers_bank)
    )

    (invite-sellers_bank ((sellers_bank-pk pubkey))
    "Invite the bank that will handle the sale"
      (guard
          (signatures seller)
          (eql sellers_bank nil)
          (eql state :invite-sellers_bank)
      )
      (locally
        (invite sellers_bank-pk)
      )
      (update sellers_bank sellers_bank-pk
       state :security)
    )

    (security ((security-info string  :description "Ordered collection of mortgage deeds"))
    "Supply the mortgage deeds for this property"
      (guard 
          (signatures sellers_bank)
          (eql state :security)
      )
      (update security_info security-info
       state :invite-buyers_bank)
    )

    (invite-buyers_bank ((buyers_bank-pk pubkey))
    "Invite the bank that will handle the purchase"
      (guard
          (signatures seller)
          (eql buyers_bank nil)
          (eql state :invite-buyers_bank)
      )
      (locally
        (invite buyers_bank-pk)
      )
      (update buyers_bank buyers_bank-pk
       state :pay)
    )

    (pay ((amount string  :description "Buyer's bank commits to pay this amount to seller") )
    "Commit to paying the seller"
      (guard
        (signatures buyers_bank)
        ; (eql price amount) you cannot refer to params in guard clause
        (eql state :pay)
      )
      (update state :possession)
    )

    (possession ()
    "Vouch that the buyer is now in possession of the property"
      (guard
        (signatures broker)
        (eql state :possession)
      )
      (update state :invite-land_registry)
    )

    (invite-land_registry ((land_registry-pk pubkey))
    "Ask the Land Registry to close the contract"
      (guard
          (signatures broker)
          (eql state :invite-land_registry)
      )
      (locally
        (invite land_registry-pk)
      )
      (update land_registry land_registry-pk
       state :title)
    )

    (title ()
    "Transfer the title to the new owner for this property"
      (guard
        (signatures land_registry)
        (eql state :title)
      )
      (update state :title_transferred)
    )
))

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.