Type
CONTRACT
Validation date
2023-11-26 21:28:34 UTC
Fee
0.7206914 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: 1701041220 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.00995, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0xBBACA26CFE8EF80CB440686E1FBF30B226AC52B157B9B58C5E8C3CA2249DBDA0,
    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: 0x00008EA3709AA5C52D6B072D883E80ACFDC5BCCE22C9738C98C529DF0BF84B24778A, amount: 0.00992015, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 2.985e-5, 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

    CC3CB9CDBEA5DB91BD1B1C03EA8E4E161451B72B9732917167CC4E7F22D3910247460E1C98E95E4A7F777DE3716EC3808B88B7F5A380F3E31074F6DC

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

00014FD67C4B80DCE9F2667F2873A1D3190535603A86AD328A6C277058311DE53091

Previous signature

CA23CBA5E8051EC37DC064CA9990144376C93648BC79917DD5BA846E9B815F3F4180584BA8CD29C5D2EFA32F163A801D79F19092FDB96F28AEA301CD58BC3D02

Origin signature

3045022100D14422D3DDD8190D45B5FB2F274ACB1F4F3A0B85C07E65099A5492C60587B0530220695734A86C89D27E86D05E3F91CC80864C884AEA8864602A543FADE45415A0E1

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

0007D9AFF1EC4F94EAAD77A0B50987EF3AD4E10E3D634D4377FD603098AB437E35

Coordinator signature

C3B733CFDCEF7D037AEEBCD92DD4CC0903A0702C81EB3169BAD0A2EED786EEBD12A444698596B449C05873C67B8F3126427850E62E62A80029CB67B705025D0D

Validator #1 public key

00011B58ED42235461734EAF253BD97A80B92899ABCC3BE680D44B6825DD2A88A947

Validator #1 signature

B13A827366EF43D1388885800E1C5ADD145FA75AA4BA04CF2EC20DBDE9BFF97CD69E7A6D0686773C7AE38537EBF648573E976ED2AEF97D0D5315D75C7C7FCD02

Validator #2 public key

0001B0A94804BF8ECC9897075C6207FF63EF4D339F57A0349888E6B77CD47DB53EF3

Validator #2 signature

8561FC550C71452F48C4FC69532604B679C7FEBC3418D6A508636489F335394374BE0731FCE5FC1261FDE208C307491403D007ACD3E75DF31574FE2856F84901