Type
CONTRACT
Validation date
2023-10-27 10:07:53 UTC
Fee
0.94833333 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: 1698408420 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 9.95e-6, token_address: 0x0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

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

    673594ED2BAB2B67DCB8DA73ED9EC3D8DD5AA2460D254934102C983B9651BDBBF188381D71528199AA7099164BEB9EBA5273D239A78BBC2E7D199FFE

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001C2839A73DF8067DF9641AAD097B9C98B36B18068BAC79420873954160E4B8A1F

Previous signature

94A4AF2BDDD1B58AA30F28B7A17AD8777EC43E5DFFDC943D41921A4810CCD3983D01A332A41552DBA31DB7C7CAC858E2C903C743FE407441D702674FC326D10B

Origin signature

3045022100D91F5E37E38856A663EDEFCBA05C9E3361093C6AE389185A0DC37A636B683C09022035C57F41106F58B0534C5DB900D483A76E48DAFA0299958E4209998F47677C5A

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

007B150EE121B47EA2464EB1358BBEB4F81DED5BEA49156CFB59E03094B7744550

Coordinator signature

5CC4EDB8714B1F32C847ECC6417AC47988DF97200297D5D3314FD859B73103EC42817940C30B395816DBE7A8345625F6682FD4D0AFFF89269923A39D35E7A403

Validator #1 public key

0001500FBE298B79FFBDD5CCA1798F30FD88A53D26EC39DE5DDE1F4137B032A4BC34

Validator #1 signature

2074CB774F390BDA5B779DEBFCAA42DCD9158B8DF183162C7D760FA72D945347F54F1E03049CDAD459DDAAFC8002A6988597C7466131BA7DE9A3EB2878B41C06

Validator #2 public key

00011ED0B570D680BE5ECD58D2D121689DA73C46DCB38A01C6E10D06286040ADE30A

Validator #2 signature

CE876250EEBA99E819F9A3BB369B80741FA1A3748A5A35CEEE204B7E1C08E309E16F94DC06BD1BB703958A4940CA514331816E06A79A64DD5908EDDA5E6D6608