Type
CONTRACT
Validation date
2024-01-17 07:30:32 UTC
Fee
0.72157943 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: 1705483800 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.199, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

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

    FD8F5F56D4426EF3F48457E3ED36A087C19BD1CA7D75580876826FC5494B52C6DA8AD5976E603755E0154E8F41996FD728039B6A10ED7E806F65F4CB

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001416B1D281B75522109AC8C4882A7AE6885B7116087FFB042A1ED96D46A92D3A0

Previous signature

29FEC4066EAB5B2E7C86B614FFCEA379B39F3FD31A971912DE7DA1A440B7D402A4F1FAA70727464F096C42822EFD5ED14C50B3E368429A55457F91187420800D

Origin signature

3045022100B56943894C6B09826230C87E2AD20F16C37C0DED8613C648550DA006DA2CC6DF022004D283D995D04A3964FDE3D0DB0D103BFDBDF74E04C41FBEB8979B2309193DEA

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

003EB85CE050F6597DC85BE5A241A677B87A4E7BC5A68B1F38D1C89ADF3A18705E

Coordinator signature

23B393E73F605922021E2E87321325433876BBE006785033ABF2E648E9422550DA73A1F493542008046800F7DCB7A1BEE7A94C8167FDE38EB5973A30C91A0E08

Validator #1 public key

00011B58ED42235461734EAF253BD97A80B92899ABCC3BE680D44B6825DD2A88A947

Validator #1 signature

A407FA2E466F666ECF902F24F6B62772D14DDAEB016F1E6A8ABA3C207A7D2B118DD639C3D4A5E08DA397357C7E1A2C466055131688A342A9D1C70D06C878D505

Validator #2 public key

00010F2A0E4C424582A94BD90E05FE6931628F91988ABBE387D365994F1F3FCF5A12

Validator #2 signature

2C6BF8A6194A817A768C10B4BCA4B2FD44ADF1056C452FF864F2C1BDADE7E2B9D8F5F8B9AE8595BB4A184021EC6C1D8A6325CA96A5E66B6FA55AE7A8920C7C08