Type
CONTRACT
Validation date
2023-10-21 12:12:13 UTC
Fee
0.84968816 UCO

Code (1.05 KB)

@version 1

condition triggered_by: transaction, on: provision(_evm_contract, _url), as: [
previous_public_key: (
   # Transaction is not yet validated so we need to use previous address
  # to get the genesis address
  previous_address = Chain.get_previous_address()
  Chain.get_genesis_address(previous_address) == 0x000066706D704329CA8C2A4153991E2DDACC968622CA10217CA14952EB7ABB966C30
 )
]

actions triggered_by: transaction, on: provision(evm_contract, url) do
  next_code = """
    @version 1

  # Automate the refunding after the given timestamp
  actions triggered_by: datetime, at: 1697897460 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.2985, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: refund(), as: [
    timestamp: timestamp >= 1697897460
  ]

  actions triggered_by: transaction, on: refund() do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.2985, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0x9DEE53E6B57A03923D156291AA84BE10EAE1E3D0C0206F2D4A19271E9622C9BA,
    address: (
      valid? = false

      abi_data = Evm.abi_encode("status()")
      tx = [to: "#{evm_contract}", data: "0x\#{abi_data}"]
      request = [jsonrpc: "2.0", id: "1", method: "eth_call", params: [tx]]

      headers = ["Content-Type": "application/json"]
      body = Json.to_string(request)

      res = Http.request("#{url}", "POST", headers, body)
      if res.status == 200 && Json.is_valid?(res.body) do
        response = Json.parse(res.body)
        result = Map.get(response, "result")
        
        if result != nil do
          decoded_abi = Evm.abi_decode("(uint)", result)
          # Withdrawn status is 1
          valid? = List.at(decoded_abi, 0) == 1
        end
      end

      valid?
    )
  ]

  actions triggered_by: transaction, on: reveal_secret(secret) do
    Contract.set_type "transfer"
    Contract.add_token_transfer to: 0x00007D1163F2AEA7B80362450AB96D837F5A698980E2FCC0ABE1CDB01D9B7F0D2273, amount: 0.2976045, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 8.955e-4, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

  """

  Contract.set_code next_code
end

Content (0 B)

State (0 B)

Movements (0)

Ownerships (1)

  • Secret shared with 1 key

    Encoded secret

    B0CB85F9B31F16AA34C23E27B1B153DAD4E150B65158F843B361362BAEECAAF727CA0A47EDB52A07D1DFAAB6FB2850B882498D5FA41EDE32FC678CBC

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001F2C27D320BF22040520B422F14FD618915B006927A41A075AB253D3A1979E374

Previous signature

26523650621795A06EF3AC89F90A6E0D4875141312D736BC6E7E58EC3628603D2B43A68C23B739CBD4DF4D1059EBFD80711AF3C8F683B971F084EEA2FB462602

Origin signature

3044022057B0017B27751B9B1A57E088D2055B9E74A1DF5590E3E7F0791B55FBF87B6A2D02201E62B3CF02A1B133700B0E231F7F14A2A8322599C1B500DF2208813A393D0C62

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00F2F0DFCF0028394C2DC2866E3E4CBEA862287C9364C7323AF199136AD9741288

Coordinator signature

5A2A255CB6D47C7F15C9639E0DC83192610280D67AD76F90FB7ACFB685162ADA2A35B4678A539FBA642817BE1A54FAE99691621276A61C9130EF89ECFFAD890D

Validator #1 public key

00018A312AFA617E98B343D09AD2E73F0AB661DB0A59FB986D5DB8CE7664E14C25FC

Validator #1 signature

0055F61BAE28DBEB54B4D90C237C100F44284BB83EC34EB373E2B7C1DAD7D4E70AA8AC3E668517D2E709A86FD3CD9F55D6586D8E136FC037615490C0009A9F07

Validator #2 public key

0001500FBE298B79FFBDD5CCA1798F30FD88A53D26EC39DE5DDE1F4137B032A4BC34

Validator #2 signature

66CA7B06041C47AD4B063337F4EA9F37EA90E413829B0A4F7A284D9CAD4EE9C556E984F475F3A7A54C6DE6280C78890C4D83274C7B674AB442C52B6C9346D00B