Type
CONTRACT
Validation date
2023-12-01 12:50:48 UTC
Fee
0.73515452 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) == 0x0000072E418B60C6DABD272BC2728B17B352B8104F068D11365D50134F96A4199609
 )
]

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: 1701442200 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 9.95e-4, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

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

  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-4, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0x719D119C85B1D4F6AC53E4361DA05556E12C14CD54CC527BFC496D335DB0B7E3,
    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: 0x00004D0AC7C11BC49690EEB0A16B3051A7BCD0E20A0ECE056852B59435CEBA359AEC, amount: 9.9202e-4, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 2.98e-6, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    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

    62E07CE0669E4897777E7B51F4F3A0767D61713E06B07273599B373F150695CA759A662DC901B5B6A14F73EA32861DBF36CBC3AA71ACC7AA2FBEB844

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

00015DB1F2FBC01A2A5BA278C1EA5A6CA3E3FC34032255CE972E021EF8C1FE42667B

Previous signature

03003E692AFE1B2BAD90E0E1245FA406DB4BFAECEA496A5384D60755AE6FF90D5881A23342F7270F29A57ABF581B45FFEEA11AA8D9EC7E37D0BB55ADD732D105

Origin signature

3044022061155AC4956E49BEA3913197B889B9E77395A58225D2C684EB693B824542E76402204C69541383BFDF3D863D4E4404BBCF945E432203D9F6B2724802993C7CAF54CD

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

008C6BF0A324686055B414E36F38A2A3648D772B535198F9BB4C40DB73BB2C2E05

Coordinator signature

D20B1CE3B9F0D795B0F56A077AE5FC6E427F9B307707DD6CA79F02D4C01B47681F8348CE505232FF65E9369E481A29AEA21E07C7C476D726A84893F329B82F0D

Validator #1 public key

0001B0A94804BF8ECC9897075C6207FF63EF4D339F57A0349888E6B77CD47DB53EF3

Validator #1 signature

149A97C0116711C94D57333FC590099955884650B435A1AF9A740B126B0C02C73B83270F72976B51FDC3A248789F602D1662B3B4A5984EBCBCB97064941F1C00

Validator #2 public key

000151C124A6211CD402FD1CFE560C5DB51ED0CBEF44B09B21A41206028E7E5942BF

Validator #2 signature

801047132CF3F1CB9F13D6E78314687C3BF2341B3B66FFDB58762970856A34C5019DB984851638575C9CFB1E5548DC79C114D417C16A12B5F96D360A48261306