Type
CONTRACT
Validation date
2024-01-04 16:06:51 UTC
Fee
0.69930365 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: 1704387240 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 1.99, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0xC24019D4063891FC6326BFEC0E0DB1AB98C1AA7A2CA7AEA526D08E558C6DDF3A,
    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: 0x000041A175F53C2CC456DA2C8198377068A2E3F4F59B9A04B5CAD677EC43F4BFD081, amount: 1.98403, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 0.00597, 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

    74628F7AC1CC58640FA5386909C6DC75123B0B5E0941BD5C6BEF603AA0EF901C3700BD4A30E121B25CB120E5730340A1898F38B198715A3BAAF45B4B

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

00018729ED2DF111AA3F7E236771653D6FB667354B34BF291BCACB0C890520310A27

Previous signature

14858EA0EAC9D1361211C5135B6EA809CEA1940F7F5D7AC4AC0B1B0C3E8792E1FC98337B48CE764DE51A91258AD734332630671C10AEEF29528F3129A72DAD05

Origin signature

3045022100DEF1293B5C7D37061AA5DC6ED5DF3DEA1A95302DCAD1D21AD33F5D3DCE99867002206DEA690820DE6811E95F1BA2B2B7825912E0D36C72B01C096C7C602F9ABBD60C

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00B677231964F452477F9777E45D5643DA64F0B2A7F3FC86C02B9659B3F958DE86

Coordinator signature

AFB170D40CA6AE545C7AB2819D97D18087A48658F28E7F832E692957C920E102E898FAB4CB20E0D5186A8C96F11249FCA8C14149EBD4BDCD107E93AB53B0220F

Validator #1 public key

000103E30584AD8DE66F9E29419D5D0ABEE5A76722C9FD0D012BDDE3A6E2B149C48D

Validator #1 signature

74E51AA4B6B609796B507BDE33A8244FE9FB0044B74B9C972A18F157C16655BFB70100D9AB5E4E26D35DFD40199C1068158C37FA9B2FD3A7731FF72DBE0C6307

Validator #2 public key

000177BA744AC778DC2D51A1B7C622E7AC4BD1E1AA8DA2D0FCE71BAAB7DAD0E020E0

Validator #2 signature

B6E4FBEDFCB857CA01C17741D908131ECC5545FB57B5B0CBAC8FD361BEAC610C845351F91064BCC5DEEBED9D2E75A770F55BD63FE338E3EF1FC1F439E09CE508