Type
CONTRACT
Validation date
2023-10-25 15:14:25 UTC
Fee
0.94103965 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) == 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: 1698254040 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 9.95e-4, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0xA853F6A1D156CAF3EE308E106EABB7DDA3E2C99F2E11061FBF9E60A1EAD9C479,
    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: 0x00008DD40CD42287A3C8282065F5BCA7259AC7014CD73109B570E946A977687C7BD0, amount: 9.9202e-4, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 2.98e-6, 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

    B57AD86E11FFAA2085283F6D2C01F93805B29B8E4A0D4051220C277763BEEC5D3FF2CECBFE300DB37C13DB048A04A5ACA3E26A7097E403B37E717A0F

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001609ABF3A60C61060A85D85C93F9E4A3B05AE86DCB04404F0326312BBD2DC6C49

Previous signature

C6072947BA3D2C384B28438F5FE3204E79D552023D2ADE0ADEE5C8FFB4C07B1746BEC9BAACA119A3553DD689D0D58AD2CE5AB157925184AADD5268925EA00B09

Origin signature

304402203AE148BD0FBB26604AAE077162271CC43F0616A5200061034E385F665EBA839502204C3644D40D561AA710AA8AF65B4094082AF18423EEA5E25840F9A8CEDA3D10DA

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00EBFF380AF5F88F6D9ECB5D4AB6249E7A6D7B7A745777191B88DEB4C8980D62ED

Coordinator signature

A8989202087E5D4BAFE7FFADCDCCFF41CA24117B23F2697018EA33C5595EFAF598969B99D574505D63E807131CDA0EC7F91C6860493B02F0050546F6C5C10C01

Validator #1 public key

0001500FBE298B79FFBDD5CCA1798F30FD88A53D26EC39DE5DDE1F4137B032A4BC34

Validator #1 signature

9914065CDB8A2590141D7749196579A94FD6F09A09665EB177C2F106C967F1A30E3E33A6F96FBBFE367D58A4BCADEF0EF0D0F4CA42BEF3DE4B4BACEC12907103

Validator #2 public key

00018A312AFA617E98B343D09AD2E73F0AB661DB0A59FB986D5DB8CE7664E14C25FC

Validator #2 signature

070AC812BD56CEBF116B8C03F0C2EAACDC46F35C8527F0BD93F91C24D89E5771274616EF8F85BE6D1B47BC4C06A99DA6B42BDEDCFC6C9ACEEC437F1805725A0A