Type
CONTRACT
Validation date
2023-10-24 14:42:33 UTC
Fee
1.04605993 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: 1698165720 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.00995, token_address: 0x0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

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

    06DD456E0C918352CD8B821DF5ECDCA0338B7C5802242C3D108CDAE7BA5F6A930BE2D56E74986D57ED103AEDF31043CBC4AEBFB1A516BACFC78C00F8

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001C789BDC08146D1C9AC960FB80BEC4A2886B03E195B801F1203E2DF067F57F546

Previous signature

BBAB5DBAF91F4DD3AE4C0FBAEE63709F74B230B31649F6C02C0D254137DA6919235A13DE17D2B074108B70AB7004D38A3CF73F052593B3B1615C6D20C1185308

Origin signature

3045022100805B8DA4C3CBEA14D967E78658016D456D510C3F27F3CE56F9C3C780945C7EC3022033DD15E969340D3F971C23A865BE8302BEEFF7BD2FFA45E92E7ECDD43030448A

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

008C60F9DD0297CF90D112FA3ABF63DD97B6687DBF76320104785B14F512EF75B2

Coordinator signature

1002B02FF351E674011E287206496C04F776C28DA98A05D61BE0BA6AF08714F76AC3A0809E82E30ECDE9CFD2FBD8DF02DDAD152E2E6B1B7BBC450AB58E3F5707

Validator #1 public key

0001500FBE298B79FFBDD5CCA1798F30FD88A53D26EC39DE5DDE1F4137B032A4BC34

Validator #1 signature

BDEFBFD4CB037A2D89E55CB7D6848484048523F60B7137E0D0B75E10A77F5A76CD8B41FFD3FBDA36D6A859492992554A1421FDF7702E0FCEE1836DC140BA3908

Validator #2 public key

00018A312AFA617E98B343D09AD2E73F0AB661DB0A59FB986D5DB8CE7664E14C25FC

Validator #2 signature

E1F092EAD3D5B733D3E854DF2F7E2BDB177AC73F64741F765256B721A0664BB59C036B1EF41C7531FB3B4054A2C77F8D5199AEFE422C4C3FBEB501F0888B9703