Type
CONTRACT
Validation date
2023-10-25 14:32:02 UTC
Fee
0.88071999 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: 1698251460 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 9.95e-5, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

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

  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-5, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

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

    FDBBA8CF6DBC09D324908FA3A9427A8D2DFB1734BA382E764E9932241B6B4DD20D0A4C08E748A25CA23179CC9C41B9F04A17CE012EDBD287BDD8D920

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001F1A33DEF189CBC2B194C67FF4642532AE4A11F7B597198CDB69345C63A05E7E5

Previous signature

F240068FC5A5241485D5C449023E343FEFF00D6A632DCD2235E3CB3FA896974D749B9BE344FD7E9E5C12D5932585FA3E7B8A343B74BC0534FFFB1BD9B6FEAE0F

Origin signature

3045022100FD634C073E541C385C986B552857A8DDCA7976227416F5CD402E84F9958939C802203E812050E54E82CE68EE428AAB85CF545C0494D3EEFB7EBEF42D233036363034

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

0072E5678B69315A6B2D055BAD9E20BFB23FC8FD52ECA0D62DB4E2E568D13F8D2B

Coordinator signature

B81F6B478C6B24BB1B475E06BA28B15196F318BFC0617DD4A3EA0267C83E457773BF4D4C89FED5FC6E2C672A400D44327D5BF358EB1F8A6688A568F2ABB98D03

Validator #1 public key

00018A312AFA617E98B343D09AD2E73F0AB661DB0A59FB986D5DB8CE7664E14C25FC

Validator #1 signature

C0059185AD1E17BAFA27D099F076B9A1050FBFB1BD08BA6E6683FC878A5AA570AA93667EDB38698A3F5051DDBE6E5EEA995C0556675F1A4A32D69CDA0975F104

Validator #2 public key

0001500FBE298B79FFBDD5CCA1798F30FD88A53D26EC39DE5DDE1F4137B032A4BC34

Validator #2 signature

677DC6925580CC558F001FB9B19A9EBA6A9241C07239CA8441FDBCEA2B716C52454ADC4C2E61A2A295530621336E9AA7BC16EE6ECC5D69E9CCDF2B212FD9C00E