Type
CONTRACT
Validation date
2023-10-27 09:55:24 UTC
Fee
0.94855048 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) == 0x00008DD22E7496E86901E9B276A1BE6F9512EB09980CC04C7B76495EF37D5666A709
 )
]

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: 1698407700 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 9.95e-4, token_address: 0x0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827

    Contract.set_code ""
  end

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

  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-4, token_address: 0x0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0xBFCAF12C452CBB4A7A44B7AC1691354D2B3EC6BE657D7BD9B8177168204905B1,
    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.9202e-4, token_address: 0x0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 2.98e-6, token_address: 0x0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827

    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

    7B5EF4A6BBE6AFD377D77AC3470153C6844A7FB9EF3D790403594B9AF0131AA5D6857902470A51841A6A4F9E64119FECAA89D47C4C0C682BB374070A

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001E423FED9998B464C952FC00E5BFF1CF51457B9DA7B545B3FD41C3D4011159ABB

Previous signature

F4354072793D0C3F04FA91B60CAD0910913B7892ECB13BC41434C812C4E61342963B1F7134DB3572140AB48E877EB63A83281101FF2EA3781EF79C9FDF07D603

Origin signature

3045022100BA24B4EF304E205B11087D0E3AC201CB4FCB8E12466BCD270C5E327DCBB9731902202AC25F23EBFDBAF67C675D07604762A8B5E4FA3F167B88E13DCB8B2FD8DEEC59

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

007B29FD7C22C421CA866DF0860A8EF8CB7337FD0AA862EED55B8D2FC5F9C70495

Coordinator signature

3D97F107EBF936C9B0FA8A01FAA32749791FB8822653897366D0B1037AA02EE1A22D3B927BA399C773032A0CC4C8E498D75865789FA0542F1422195BAFFA6F05

Validator #1 public key

0001500FBE298B79FFBDD5CCA1798F30FD88A53D26EC39DE5DDE1F4137B032A4BC34

Validator #1 signature

DFFC6237D6FAEC148F80627DCC1B2B8B2006A90CBB03964ECE3DA39EBE94E83B193790E0EF8FEFAEFBDBAB1DEA3D4D22985601F46DED4F45D7C3C8237E943808

Validator #2 public key

00011ED0B570D680BE5ECD58D2D121689DA73C46DCB38A01C6E10D06286040ADE30A

Validator #2 signature

FBA4F43A9BF342C5A49E8570F64829B0B4359C245EC5CC24B5E0D4322CBB0D204E155304CF4F80F3A753E7118662CA4053073B2B4C66D984C709BF1BC6D64F04