Type
CONTRACT
Validation date
2023-11-14 20:35:30 UTC
Fee
0.60327042 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: 1700001300 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.0995, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

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

    CC263C9CD85B884EDAD0F09BBE63AC8180204BB177BF9754825B66F999A2DE7F6D9AE864132F2D150EBF39C0520970353C1AE3C9F95B70DF07C4A2BA

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001048D588F78CA76D86D492EE824233C7E02ECDC128894BB4794DD48E7292286F3

Previous signature

B7363FE73F297FF1BEC648968019C457689CFDB8AEB4A8166B397D0165DB7AEBF85207B085D110B4A8773530B5D25489CCC45BDCA2FE076958C94941717F3A05

Origin signature

3045022100E48969EC58B7D5B232B1C06024282469D1D9F04ACE165DDCC21B4A7C316B7A5B022074826DA2E98526E2245A3BA8517C05F9AA32B400C812C969759EDDD0EED46CB0

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

0093254312B677F5AB355030F5AD66A41BD2E03EDB45FDDBAB99E77C0C0ED08D37

Coordinator signature

06E530F280C722C627B09A2C9CB0F454B92551CB7D893D87241C32172461D7544A39DFC9D74B4881EC185F6D1FEC402159A569D56EEA8EB93DDCCB1C1B2C1F06

Validator #1 public key

00011B58ED42235461734EAF253BD97A80B92899ABCC3BE680D44B6825DD2A88A947

Validator #1 signature

2991DAD1AAA6D70249AA0C67E1F28431BB54A01D090028E29ACE12036829180AC83E0F632C5408392A0256D6A5644402DE88D69BD5DFA9F336BAA09BAF5D4503

Validator #2 public key

0001B0A94804BF8ECC9897075C6207FF63EF4D339F57A0349888E6B77CD47DB53EF3

Validator #2 signature

DD301C84CCABBE5F5EE6371624A6AEF3EAFE4B209E30BD9BD2471C9E8E800EC0A9824E3BF57A9DC4B99594C2B2EFB923AFF5A75C06A3F7AE3D5F37E9F3CD5607