Type
CONTRACT
Validation date
2023-10-24 07:14:49 UTC
Fee
1.09182352 UCO

Code (1.06 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) == 0x00008DD22E7496E86901E9B276A1BE6F9512EB09980CC04C7B76495EF37D5666A709
 )
]

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: 1698138840 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.0199, token_address: 0x0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0xD2B67FE7B7F8ED52543E199C6C246B5F9B131F3AA01FC7676572A05E2FD9945B,
    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, "latest"]]

      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: 0x00007300EFBD6F864648D3275C4A6AA0B1EF91D276C9F5D62DA49D03B8093C530F29, amount: 0.0198403, token_address: 0x0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 5.97e-5, token_address: 0x0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827

    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

    7C6C77BADE842525BB92C1A74D9044A332A25B409CF68701306117EB540F7E08182A62C65666483FDE15520FE41CA85184CCD929484F9525F5198B7F

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

000175401977392984420BC1F1D28E79D514C73413F349610F9663455AA11F4BF123

Previous signature

15D1E5063FC1C832DC08DDFD5A8E7309C9B44A8BB9DCF2E17FB956A32EBCA71AFE9EBD1F294BD8CE9566A80C01AE0B3F7E5E76A5D2A294A5F453A6EE7C541202

Origin signature

3045022100B744E665D71B4F7ADC3875996D2DF534F7B548A562D00EFB88F001719E8B607D02203419B00EA181E3E6794E822FF1ABE1FC74283D17E7DE2CBE5A06526F0D52B3BE

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00B9E60824A3AB29461FDC51395097F9084F27A78338B6C31A11007D1571A16CBD

Coordinator signature

11B9FD78EC767CDC23AD5379B381A64F7F3B0B71FC1FEC593013A056BE4796CDFE782DB964B7D260260837304FA98539C869129F60321B3BB34B63743EA1B10E

Validator #1 public key

0001500FBE298B79FFBDD5CCA1798F30FD88A53D26EC39DE5DDE1F4137B032A4BC34

Validator #1 signature

36ADD6929BA7A5DC982414A550C42AC2319B5585BB296E2DD3F222ABB1FD5CC0B19622209259AC9AA7CB414CCCB1D6BC78FAA59EE5A54F8B9C5F2CD1A538BD01

Validator #2 public key

00018A312AFA617E98B343D09AD2E73F0AB661DB0A59FB986D5DB8CE7664E14C25FC

Validator #2 signature

3C1B2BE5F4E249D986D49463577170954C70D8D61ADEFF634A0211952017D0FB8B725D5880783D1B723F3F3F654F4A1408E87A66B55D10FF27B2883AF0F79C09