Type
CONTRACT
Validation date
2023-12-01 03:39:43 UTC
Fee
0.49863038 UCO

Code (1.01 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) == 0x000018D60115ECE0C7558A46B4693749BF6BEAB524FDDCCF9B10B910619E4EE08801
 )
]

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: 1701409080 do
    Contract.set_type "transfer"
    # Send back UCO to bridge pool
  Contract.add_uco_transfer to: 0x000018D60115ECE0C7558A46B4693749BF6BEAB524FDDCCF9B10B910619E4EE08801, amount: 49.75

    Contract.set_code ""
  end

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

  actions triggered_by: transaction, on: refund() do
    Contract.set_type "transfer"
    # Send back UCO to bridge pool
  Contract.add_uco_transfer to: 0x000018D60115ECE0C7558A46B4693749BF6BEAB524FDDCCF9B10B910619E4EE08801, amount: 49.75

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0x807B2FCFD97FDD661AB65741F013503F8B90BC390870ED6C78D8569C7743A330,
    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_uco_transfer to: 0x0000BD8A7CCAD82D84CD740DE6C86B205E93BE1B2AD730E1699904B8F4A3023C39D1, amount: 49.60075
  Contract.add_uco_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 0.14925

    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

    95391B7A05F68BEBEEFBD8765441AED827E624D196E6815F0B0B236C650125BE47BAED7B0AB84E5C6BD70B84F7E26BC74251DBA1C0C4BF2712AAA2DB

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001A61177B3821E7F348CB5FAB9C7B9731BC21544D172C8FF3D3A84742952E101E9

Previous signature

820A2AA0247740D385C9D1DD409149C4C7568464E8E78E01BB938311284E56C563C36576EB7983E30A8FC8795F1D834B8B09872C086AF417D9FB7159AF51C108

Origin signature

3045022100C9B9A26CB306E4F72D4FC609378B82A7A4A5D03290B7DC70C68419FC26689267022009034B436E83E530F20532F181B338D9E143BAFD42C8DFB2E27E7EBDC496DFE6

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00C98431A2CC3923DED31D1B8E41EB66EE6FB6945099AC28CE308AE8B71F3CA450

Coordinator signature

0ABC1304DA97D6901B3ED2F37A61D4BA00ABF6541CAA293849CC3A725BAF29A29C1F33A4069DC679269F07DAA27950316A54A6AAF8E5D895F88894086E1D3406

Validator #1 public key

0001B0A94804BF8ECC9897075C6207FF63EF4D339F57A0349888E6B77CD47DB53EF3

Validator #1 signature

D8B6359D1DE0B6C07C56929BA647E76CCD6A4966417C0B4A985C001C302F31439CD53FC37A9B709886A7F2247B9ACC6B3271F476DAC8F8B11B552DA9882B570A

Validator #2 public key

00011B58ED42235461734EAF253BD97A80B92899ABCC3BE680D44B6825DD2A88A947

Validator #2 signature

A934380EE6CA38E5DDDB3E0F51FE65ED8EF822411DC1C3FCE4ACA9107D051FCFFCC772F66A7FA17B1F508640D71893FDFB5EE260C35E69BB0972F63569B8B901