Type
CONTRACT
Validation date
2023-10-31 08:53:56 UTC
Fee
0.91780676 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) == 0x0000072E418B60C6DABD272BC2728B17B352B8104F068D11365D50134F96A4199609
 )
]

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: 1698749580 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 4.975e-4, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

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

  actions triggered_by: transaction, on: refund() do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 4.975e-4, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0xDB08A41F507863C5F1EFF10F12A1875925FD15FD14AC81307A0CC81DE75F1828,
    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: 0x00001C6353CF7015A1BEB7096B1ADE63CB30508CBDF143A84818B53029BA13910199, amount: 4.9601e-4, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 1.49e-6, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    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

    6F0B9E5033E80C3F2EBF74BCC9120981797355E6C8AB3F9CF212B78DD82C98E589941AE146518C6D2E9407C3714533AB2B6936206D40B3A3EFC6CAF2

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

00017B2609E58338087D6A07EDFDA76D2715717D28A7C2FD9AFD346D9C1EFF0F2A96

Previous signature

A6592BF44BB47944B80ABCA18C7D26D03B6EF5FA9C381B1127D267C4B8F65EDE8A091556D85518D7A24D80DEFFA1C0CD87EDCF4A0560C4DB2574052C65C22B02

Origin signature

3045022100E2BAE3D6646F9757E88387315660A4DD222DA708F99BFF1BE1A820B86E7873C50220676E55371E69F93FB8574139E60798D10A46E22BF36EDAA7B7D1FD75A457B1AC

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00796FFD2AD64697F9A90ABAB6FED0C6DD26EB372A259955A946AC4C76D9FF6083

Coordinator signature

AACD7FF334BCB2160A598629ABEC2C8042AA7871461FB8087AA52587F4D4C20257702789515D6CFCFB6A612EE27AA8A8ED726EF5EEA9302A8323AE1F7447E604

Validator #1 public key

00011ED0B570D680BE5ECD58D2D121689DA73C46DCB38A01C6E10D06286040ADE30A

Validator #1 signature

5B79DCF1AA0260BE68A69979B026FB76CE8B6F6121DB1D753B9CFF8951AAD5047D9824B8CFDA2A68B25E5EC2018D33EBE952500ABFC1430EA9C1486C32F8F804

Validator #2 public key

0001500FBE298B79FFBDD5CCA1798F30FD88A53D26EC39DE5DDE1F4137B032A4BC34

Validator #2 signature

5932E643FBC64779EB78694EDDC79CACCAA152AEAF6D2F3BC188ACACFDCBCD6E5071FD081BA7312E951BCC975C4A5D8F17C167D7E954BE198C27663628529D0F