Type
CONTRACT
Validation date
2023-10-24 14:11:26 UTC
Fee
1.04151359 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: 1698163860 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.00995, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

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

  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: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

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

    EE20D3A55BACBB2D7933253FD77C0E18D8D0DDDDE971D7B2F4C3FB0229EE875E19504EE028D2E6856B38762F06EE293D4092262D6851891BE1FB8867

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001814339205474B6AF4DB01651F2C9B531D939EB8B87ECE204D8E8EE2E60C32049

Previous signature

FD92D236E33C07994CA32817C675DF1CACA3FD9EBC1887C36BBC8AC0F70B902B47F1F4F8DDDA493D42B859291BF22FB1C4B500E94BEE70F84B2E339E5EB23B04

Origin signature

3045022100E3C5B1B83BBFCD907E6B71750DFD9B8AA1719B849529DAD87BCF6B15D46C928202206583DC2162C8E08FF719FB737E6D886B8E2801AE5B4E5ABB82C4FD8A9D5E658D

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

004A52570796EFC64DD6D7118101783D03ED903654F57F9DF9D5F8AC3E8F42AD18

Coordinator signature

EBEA487B26D5BFF522739313E8BDD5EF3E26E3522EEC173946BB8797A5C90986090EBE231C5ABE12EFFBC3D4E41539160A4E7F5253715A261A7A68957ABA2606

Validator #1 public key

00018A312AFA617E98B343D09AD2E73F0AB661DB0A59FB986D5DB8CE7664E14C25FC

Validator #1 signature

2560257FF6D0502DFB5D2E54F1C89A7EEF0F4B59B723EE2CA18E9E5006E92F93A0D9116F4967DEF07009EBA576EE07708FBA47E6B9384640ACD70713D02E2A0C

Validator #2 public key

0001500FBE298B79FFBDD5CCA1798F30FD88A53D26EC39DE5DDE1F4137B032A4BC34

Validator #2 signature

DA8CCF3D5A53613194AE34191FF682FEC8C4F509328B088F2E204E6786A5391FE0C81A981F731B2C376051497581EDC7223EBD94FE0FCF45E46AC5086AAF9F0C