Type
CONTRACT
Validation date
2024-01-10 15:52:34 UTC
Fee
0.72352566 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: 1704909120 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.995, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0x7EF58FE0F6B861130F2EBA4D7C18590433DC955DDB915DE1ACBD57B3B2FFF60B,
    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: 0x0000859D6843D86048BE01F41C94EC778A8BAF455BCD6D63A91B3690D6E1DB8AA050, amount: 0.992015, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 0.002985, 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

    47CC78DF414285CD6D690691472D5C4A500A3F3E61A10F9A2C3964884C9FF7FDE39B3779F40A1570DB1A7D2FCCAB9D73EC45AABBF235EAE8E7C58EE3

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

00011D858639B2CCF60F8D7348BFCCF040F696B48164FB8B0E0FA8EE26E464717C3D

Previous signature

29418CC6C6C47D40A8926D4AC9A6EE76E1F48C22468FE8960A528BE5C0B06B5E191E5ED777005D822154C26112354129E0C25E6929FA8705F1130312F8502500

Origin signature

3045022100BD0F9C55627C2A0A2FEDABAECEFB2425077599D05CABD11C76908E899D1844F1022034DD6DB743CB9188F51AEBEC6D98C02D9E4F525E023E20BB0EDBBF8D609ED39F

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00D5CA6B662B48F7993215A61E4307C34EE823F9E9D10B9C8CB1EA7E0BB35A4640

Coordinator signature

C41827F574DF4A00B24925833EF4478ABBB5B412DFEDC3CAB07F542336DBAF4B706214C3C9AFF99CAC979AECDE82C1CA74CE4F335D495BBAF8A2251DA5FFCD08

Validator #1 public key

0001B01EEF96BA7E95FC844D456CE8868F18864519FC9532E1751C2035FD044DD5D0

Validator #1 signature

7F602BC83C177FF1D642336AEE6EF3B5A61C0F34EEDB0C9A291F03C668D4E188EB767BB3FB0612DAE53A8788D759FFDD9A39FDDC7C909C3AEE881CA94932A10D

Validator #2 public key

00011ED0B570D680BE5ECD58D2D121689DA73C46DCB38A01C6E10D06286040ADE30A

Validator #2 signature

B1C3B8FB90B816F1578EB530EE85D1902EE9E89258FB5E3BC809B60B0C53EAD5E7FD1B86885F2727675C1D9069C852045307FE860591984E6E3D6932E247CC06