SC CODE: // RelayOS DERO native-asset hash timelock vault for Release151.
// No admin key. No operator release path. Native DERO only.
Function Initialize() Uint64
10 version("1.2.3")
20 RETURN 0
End Function
Function Lock(lock_id String, recipient String, hash_commitment_hex String, expires_at_height Uint64) Uint64
10 dim amount as Uint64
20 IF EXISTS("locker_" + lock_id) == 0 THEN GOTO 40
30 RETURN 1
40 LET amount = DEROVALUE()
50 IF amount != 0 THEN GOTO 70
60 RETURN 2
70 IF ADDRESS_RAW(recipient) != "" THEN GOTO 90
80 RETURN 3
90 IF expires_at_height > BLOCK_HEIGHT() THEN GOTO 110
100 RETURN 4
110 STORE("locker_" + lock_id, SIGNER())
120 STORE("recipient_" + lock_id, ADDRESS_RAW(recipient))
130 STORE("hash_" + lock_id, hash_commitment_hex)
140 STORE("expires_" + lock_id, expires_at_height)
150 STORE("amount_" + lock_id, amount)
160 STORE("settled_" + lock_id, 0)
170 RETURN 0
End Function
Function Claim(lock_id String, secret String) Uint64
10 dim computed_hash_hex as String
20 IF EXISTS("locker_" + lock_id) == 1 THEN GOTO 40
30 RETURN 1
40 IF LOAD("settled_" + lock_id) == 0 THEN GOTO 60
50 RETURN 2
60 IF SIGNER() == LOAD("recipient_" + lock_id) THEN GOTO 80
70 RETURN 3
80 IF BLOCK_HEIGHT() < LOAD("expires_" + lock_id) THEN GOTO 100
90 RETURN 4
100 LET computed_hash_hex = HEX(SHA256(secret))
110 IF computed_hash_hex == LOAD("hash_" + lock_id) THEN GOTO 130
120 RETURN 5
130 STORE("settled_" + lock_id, 1)
140 SEND_DERO_TO_ADDRESS(SIGNER(), LOAD("amount_" + lock_id))
150 RETURN 0
End Function
Function Refund(lock_id String) Uint64
10 IF EXISTS("locker_" + lock_id) == 1 THEN GOTO 30
20 RETURN 1
30 IF LOAD("settled_" + lock_id) == 0 THEN GOTO 50
40 RETURN 2
50 IF SIGNER() == LOAD("locker_" + lock_id) THEN GOTO 70
60 RETURN 3
70 IF BLOCK_HEIGHT() >= LOAD("expires_" + lock_id) THEN GOTO 90
80 RETURN 4
90 STORE("settled_" + lock_id, 1)
100 SEND_DERO_TO_ADDRESS(SIGNER(), LOAD("amount_" + lock_id))
110 RETURN 0
End Function
|
| SC Arguments: [Name:SC_ACTION Type:uint64 Value:'1' Name:SC_CODE Type:string Value:'// RelayOS DERO native-asset hash timelock vault for Release151.
// No admin key. No operator release path. Native DERO only.
Function Initialize() Uint64
10 version("1.2.3")
20 RETURN 0
End Function
Function Lock(lock_id String, recipient String, hash_commitment_hex String, expires_at_height Uint64) Uint64
10 dim amount as Uint64
20 IF EXISTS("locker_" + lock_id) == 0 THEN GOTO 40
30 RETURN 1
40 LET amount = DEROVALUE()
50 IF amount != 0 THEN GOTO 70
60 RETURN 2
70 IF ADDRESS_RAW(recipient) != "" THEN GOTO 90
80 RETURN 3
90 IF expires_at_height > BLOCK_HEIGHT() THEN GOTO 110
100 RETURN 4
110 STORE("locker_" + lock_id, SIGNER())
120 STORE("recipient_" + lock_id, ADDRESS_RAW(recipient))
130 STORE("hash_" + lock_id, hash_commitment_hex)
140 STORE("expires_" + lock_id, expires_at_height)
150 STORE("amount_" + lock_id, amount)
160 STORE("settled_" + lock_id, 0)
170 RETURN 0
End Function
Function Claim(lock_id String, secret String) Uint64
10 dim computed_hash_hex as String
20 IF EXISTS("locker_" + lock_id) == 1 THEN GOTO 40
30 RETURN 1
40 IF LOAD("settled_" + lock_id) == 0 THEN GOTO 60
50 RETURN 2
60 IF SIGNER() == LOAD("recipient_" + lock_id) THEN GOTO 80
70 RETURN 3
80 IF BLOCK_HEIGHT() < LOAD("expires_" + lock_id) THEN GOTO 100
90 RETURN 4
100 LET computed_hash_hex = HEX(SHA256(secret))
110 IF computed_hash_hex == LOAD("hash_" + lock_id) THEN GOTO 130
120 RETURN 5
130 STORE("settled_" + lock_id, 1)
140 SEND_DERO_TO_ADDRESS(SIGNER(), LOAD("amount_" + lock_id))
150 RETURN 0
End Function
Function Refund(lock_id String) Uint64
10 IF EXISTS("locker_" + lock_id) == 1 THEN GOTO 30
20 RETURN 1
30 IF LOAD("settled_" + lock_id) == 0 THEN GOTO 50
40 RETURN 2
50 IF SIGNER() == LOAD("locker_" + lock_id) THEN GOTO 70
60 RETURN 3
70 IF BLOCK_HEIGHT() >= LOAD("expires_" + lock_id) THEN GOTO 90
80 RETURN 4
90 STORE("settled_" + lock_id, 1)
100 SEND_DERO_TO_ADDRESS(SIGNER(), LOAD("amount_" + lock_id))
110 RETURN 0
End Function
'] |