Type
CONTRACT
Validation date
2024-01-25 16:29:13 UTC
Fee
0.75511901 UCO

Code (1.07 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: 1706207280 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.12935, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

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

    F4187CDAE83D7B092A9BB4B54844F17645EDEF49E9B916F8E6702289C12903F4783FC76F722CF2C37FA8006DDB9792F729149EFE8ACDF6A5463D8F97

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

00011806A974B1F9785F0E26606E4CF9C5568F360D5B40C549F865D3A1317423E795

Previous signature

F7EB01206D6A2F99E3B889251848A7CB5EC59922BFE61F441A6FD519B04157E27D194D9B0172E071966CD8C1DFE769B2ECB69E4B6B05989740898EAF1D42EF00

Origin signature

304402206DB13BDF01A4307CA49F0BCDDC19321DA7E3817992B502F1C56037184947813002201E23F5EB287AB8B8FDCE79BA3BC43A74E86BB45FED448BB51E0BC6B458CF2CD0

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00EF04618BE5B90EC9031A80332314357DE8D004E9BEB321DC23A9359E7203C6FE

Coordinator signature

082522A53A4FA1731E6B66C8B058245E95ACCC874F1A31264F5E3164C9AE30D029998BE08D358B7F5E05A530807AB5E7981158B4E1D3FBC8D35C00E88011EF0B

Validator #1 public key

0001B01EEF96BA7E95FC844D456CE8868F18864519FC9532E1751C2035FD044DD5D0

Validator #1 signature

97EF3EE5C3C264BB4F53E7DED9E4853705D958A9902EB0C7933AC897FAFCDAE686D629AC6831BD002F2D41E356D8BCC993FEFB6B93AC3FACDBEA4350EB66E507

Validator #2 public key

0001500FBE298B79FFBDD5CCA1798F30FD88A53D26EC39DE5DDE1F4137B032A4BC34

Validator #2 signature

4EC2EF067D96876259BE900CCF17AB5C05AF08615192A85D643425A0C81D4184A4971F38D31BBFF89F5043D2A87F747EC3CC5851C6A2ADE3A82E18F33955DE0F