Type
CONTRACT
Validation date
2023-11-30 14:08:06 UTC
Fee
0.71253169 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: 1701360420 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 9.95e-5, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

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

  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-5, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

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

    DCACC27F05605B4E1F739596AF2E230F92DAA13FF8739598B0ADF1CD2842AFFB9941FC71BFC2AED6AD9BE5BD1102909C7C3063EEDA29BC9097BBB40C

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001F487368FB103CD5615EB6A4B129D468F61A9B72626575F975C572BEC2D4C7F3B

Previous signature

7580278CF7B1BB846439F641FC340781B30F0D56826BD4B36A3F448E38F5CE8986E3EE00504B3652FA88E3609C44C3841E3DD60919641955376051A162FA1400

Origin signature

30440220406DE82B0B315798B3B20FA793A9242704094697FD0DC0E8437D0711EC254C8402207EAB24522C96D168B44548D0CA95667490E0AC11D3E0B66C89E6A5B3E01887C8

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

002E732B70864EA052C66266E90B34A771664A28EA5C8358CFC0CE1615FF7BBECD

Coordinator signature

7ED2D61D05E18ECBFDB262947F1CC626DB5283063593E475B9F82033772507C5B896778D9B00621B26BA2BE9C7A1E34259C22148E8B5E8FB600003672FC0D80F

Validator #1 public key

00011B58ED42235461734EAF253BD97A80B92899ABCC3BE680D44B6825DD2A88A947

Validator #1 signature

84B5061DD9227470D654E5BB9A01D5BFE593B3B49841AE13C71C8F2EA3E233F2C4451A5465644DADD700508273C77A15B3F5EE72264E204C8D6C54DBF936810F

Validator #2 public key

0001B0A94804BF8ECC9897075C6207FF63EF4D339F57A0349888E6B77CD47DB53EF3

Validator #2 signature

C948482C88AADD9F02F3C6F8CAD02A8511519D93539653D4057BC5ED00DD95DB71715539CA5B96CA25D2FAD61A42165D40FE1DC47E026B18B78245E48F077F04