Type
CONTRACT
Validation date
2023-11-30 14:33:16 UTC
Fee
0.72510712 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: 1701361920 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.995, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

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

  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: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

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

    4713CDC6EDFA10889E2C0E908DEAF0EE62240687EE19BDBDE7DE32F5A0C1C1B120E813337048E7313CDE8A2D72778CE1173C0C064A55A25B6402D94A

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

000169469C3953A86B10AA46CCC3ECDF36882553E2C3981FC8DB57477EE6C8F13555

Previous signature

FCCB6BCF83426F7B95A0344A6C33148B2C4CA3731784C9AF93B565E0BD818B507922235DB054DB0DFE91A7414A69FD0390C0B5334F1CC1281C6C436E615E6A02

Origin signature

304402204997D324A6D1FE67EDD6398A6916402CF50413D7DB54A438ABA103E5842B85880220055B8D183797F06685DB7E6F6F304B9ACB529639B7804AABF7BF63D09CB71691

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

004DB59691C95E0AC4AA8E4C8532E205030013F46D83DAA3F9FF7285D3CE347C8D

Coordinator signature

B41F8CD73058CD30B5E6F0DC78F252E202F6BD0A93B54FCD5A5129A0B85460170CFA9C9C61435D38C41C276634CC25721972792240E55DF1324E5837690E1B0E

Validator #1 public key

0001B0A94804BF8ECC9897075C6207FF63EF4D339F57A0349888E6B77CD47DB53EF3

Validator #1 signature

3AB2E043C14B3105D4C4D4D6023468D91B4ECEB9B9BD814B03E1C3B696CEBD4F1793421BEFF2461A9245BE43EB18106377B43BBFAF7B06AB16C067E46D65DB08

Validator #2 public key

00011B58ED42235461734EAF253BD97A80B92899ABCC3BE680D44B6825DD2A88A947

Validator #2 signature

98FDD1E6FD92330D13000734B362154A81C3A89AEDA47BCE427EDD87D39D8C4953E8B147EB0CDFB09DD5D42626E78DF38FD7D40B79575FF7A80C39163B7E430E