Type
CONTRACT
Validation date
2023-12-02 21:22:45 UTC
Fee
0.71207078 UCO

Code (1.07 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: 1701559320 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.00398, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

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

    A39C6AC73DFCE2DD2D940E6BFB9AAF6690012659E3B38A7B00C336D9FF2E99240E33822F6F1AF5A2D56C421D0B3FD206F53E333A5B9761582CC2C01F

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001E62CE955850692CA2EAF2EC3621FBF4F5A94C9025E2EEE7BA668327D7BAD7CD6

Previous signature

E4673D2E292D585B109DB7F4FAFA70490EBE98CE5D9F2B1EC63D3C887426E7A7ADBB2383952D0DA61BD371975DF32DD03197207FCBDE859C7FECCCB5A50D5D02

Origin signature

3044022047C0AF5110B4D0F7161C4F553FF21A5E86E03786D6DF9FD1F744CF4360F56BBE022033D8DADD2198CCDF7F1757C6E050B704874C15B438A773CFE0E72C706BEDD509

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

0048C6813932C0213F79F01A3D43483AF3875AA958B49D4D1AE7AB74A0B2FD8F46

Coordinator signature

F8DCE38E5960BDEE321FBF964B0504F0DA2E3FDF0B353A3436F11C5174707DDB1A222C06BB0E1ABC5CCD6C66C30CF8257025311D21E801795021C653D5ECA00A

Validator #1 public key

000151C124A6211CD402FD1CFE560C5DB51ED0CBEF44B09B21A41206028E7E5942BF

Validator #1 signature

CEEA616F238682F6BE5627980795BACB5F147082657F3F4AC277E0E1620CD3F9DB036F341780E4B0502A4D76DC4ABEFB550C017B3694C0FCD0C2AF1B12934305

Validator #2 public key

00011B58ED42235461734EAF253BD97A80B92899ABCC3BE680D44B6825DD2A88A947

Validator #2 signature

D124D085F119FDB91199B87067C3D94CEDD87F34190920CB14D021B00B8BFC7DB5C974A10ABF9B8A8C208214F9FAEB35363722799B9BF14EF865E69DED851D07