Type
CONTRACT
Validation date
2023-10-21 12:17:53 UTC
Fee
0.84968815 UCO

Code (1.05 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: 1697897820 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.02985, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0xD4624D22344F87EC1772E3B3B46BE0B391CA962CE6C1A546061BE3B0BFA87E6C,
    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]]

      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: 0x00007D1163F2AEA7B80362450AB96D837F5A698980E2FCC0ABE1CDB01D9B7F0D2273, amount: 0.02976045, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 8.955e-5, 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

    CEF7D97A83F789777F96971E8E7D872B98BCE85F423506EF6EE8BBB45239AC490B44AB3A09284D2D9AA16867AB48B5417AECC1B6442AE6AEE682D077

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001CDA324F2A6DC242F1874CBCDF6BB4523E4E12457135646C48BDF33DB16316277

Previous signature

472B8B99F6CDD37EA9902DF96BEBC3FC8E89E4A82798339058763E5F878F143B24A1013D6B82A7896AC8180173D8FE4F88F73DDBD2DD7F22586B56EE0E0AD20A

Origin signature

30440220578DB62DC19455C77D3B5B2B1B322059317A1D8EFE1008B778D95C9E6FB7F84A02204737945A629D78666178CF3F29AAB9620813362A5E6320B1B70D1A4183D35DE9

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00657BD882A4287AF2D47DD6387C5517FA92B96AD4EFDD852E74A2EA9648ECDD61

Coordinator signature

31C2C4A03749FA72F673677AC9396A8226190B869F644D8AC2E639963BC316866830F2A64148DD03B0B2537393C8196F4D61D35014BBAF713D9F05A58442C200

Validator #1 public key

00018A312AFA617E98B343D09AD2E73F0AB661DB0A59FB986D5DB8CE7664E14C25FC

Validator #1 signature

19A719DAA9F7395BF2CD84132332D44982A772F0689376E0F4736A38E5AFBD33EBD4992AAAA4A8919C02ECFD01CCC05765F47E5FF71C007A5EA34D22E555BC06

Validator #2 public key

0001500FBE298B79FFBDD5CCA1798F30FD88A53D26EC39DE5DDE1F4137B032A4BC34

Validator #2 signature

995BCBD1C36035DEA3CAE4DCBCD4BC9B8A47C2BB485314B508CF0A6449572A8A88DE7655EF47E37D96E1969B1868A8551F9BBB796321A627B8D13493519C7C03