SC CODE: /* Standard Size Contract v0 — v151-compatible (T1 HTLC traversal)
State:
"issuer_addr" String — issuer DERO address (refund payout)
"counter_addr" String — counterparty DERO address (redeem payout)
"tier" Uint64 — standard denomination (e.g. 500 = $500)
"terms_commit" String — keccak256(tier:nonce:blind) hash commitment
"preimage_hash" String — keccak256(secret) — the atomic-swap secret
"deadline" Uint64 — block height after which refund opens
"state" Uint64 — 0=OPEN 1=REDEEMED 2=REFUNDED
*/
Function Initialize(issuer_addr String, counter_addr String, tier Uint64, nonce String, blind String, secret String, deadline Uint64) Uint64
5 version("1.2.3") // v151 as-is
10 STORE("issuer_addr", issuer_addr) // explicit, no SIGNER() (K0-safe)
20 STORE("counter_addr", counter_addr)
30 STORE("tier", tier)
40 STORE("deadline", deadline)
50 STORE("state", 0)
60 STORE("terms_commit", KECCAK256(ITOA(tier) + ":" + nonce + ":" + blind))
70 STORE("preimage_hash", KECCAK256(secret))
80 RETURN 0
End Function
/* Redeem: counterparty reveals the secret; contract checks the preimage.
Pure v151: keccak256 comparison, no signature, no group ops.
DERO convention: RETURN 0 = success (state commits), nonzero = error. */
Function Redeem(secret String) Uint64
10 IF LOAD("state") != 0 THEN GOTO 900 // only OPEN
20 IF KECCAK256(secret) == LOAD("preimage_hash") THEN GOTO 100
30 GOTO 900 // wrong preimage
100 STORE("state", 1) // REDEEMED
110 SEND_DERO_TO_ADDRESS(LOAD("counter_addr"), DEROVALUE())
120 RETURN 0 // success — commits state+transfer
900 RETURN 1 // error
End Function
/* Refund: after deadline, ANYONE can trigger the refund — funds go to
the stored issuer address. No SIGNER() (no ringsize-2 requirement,
K0-safe), no authorization needed for a timelock payout. */
Function Refund() Uint64
10 IF LOAD("state") != 0 THEN GOTO 900 // only OPEN
20 IF BLOCK_HEIGHT() < LOAD("deadline") THEN GOTO 900 // not expired yet
100 STORE("state", 2) // REFUNDED
110 SEND_DERO_TO_ADDRESS(LOAD("issuer_addr"), DEROVALUE())
120 RETURN 0 // success
900 RETURN 1 // error
End Function
/* TermsReveal: counterparty reveals (tier, nonce, blind) to prove the
terms commitment; contract recomputes keccak and compares.
RETURN 0 = terms match, nonzero = mismatch. */
Function TermsReveal(tier Uint64, nonce String, blind String) Uint64
10 IF tier != LOAD("tier") THEN GOTO 900
20 IF KECCAK256(ITOA(tier) + ":" + nonce + ":" + blind) == LOAD("terms_commit") THEN GOTO 100
30 GOTO 900
100 RETURN 0 // match
900 RETURN 1 // mismatch
End Function
|
| SC Arguments: [Name:SC_ACTION Type:uint64 Value:'1' Name:SC_CODE Type:string Value:'/* Standard Size Contract v0 — v151-compatible (T1 HTLC traversal)
State:
"issuer_addr" String — issuer DERO address (refund payout)
"counter_addr" String — counterparty DERO address (redeem payout)
"tier" Uint64 — standard denomination (e.g. 500 = $500)
"terms_commit" String — keccak256(tier:nonce:blind) hash commitment
"preimage_hash" String — keccak256(secret) — the atomic-swap secret
"deadline" Uint64 — block height after which refund opens
"state" Uint64 — 0=OPEN 1=REDEEMED 2=REFUNDED
*/
Function Initialize(issuer_addr String, counter_addr String, tier Uint64, nonce String, blind String, secret String, deadline Uint64) Uint64
5 version("1.2.3") // v151 as-is
10 STORE("issuer_addr", issuer_addr) // explicit, no SIGNER() (K0-safe)
20 STORE("counter_addr", counter_addr)
30 STORE("tier", tier)
40 STORE("deadline", deadline)
50 STORE("state", 0)
60 STORE("terms_commit", KECCAK256(ITOA(tier) + ":" + nonce + ":" + blind))
70 STORE("preimage_hash", KECCAK256(secret))
80 RETURN 0
End Function
/* Redeem: counterparty reveals the secret; contract checks the preimage.
Pure v151: keccak256 comparison, no signature, no group ops.
DERO convention: RETURN 0 = success (state commits), nonzero = error. */
Function Redeem(secret String) Uint64
10 IF LOAD("state") != 0 THEN GOTO 900 // only OPEN
20 IF KECCAK256(secret) == LOAD("preimage_hash") THEN GOTO 100
30 GOTO 900 // wrong preimage
100 STORE("state", 1) // REDEEMED
110 SEND_DERO_TO_ADDRESS(LOAD("counter_addr"), DEROVALUE())
120 RETURN 0 // success — commits state+transfer
900 RETURN 1 // error
End Function
/* Refund: after deadline, ANYONE can trigger the refund — funds go to
the stored issuer address. No SIGNER() (no ringsize-2 requirement,
K0-safe), no authorization needed for a timelock payout. */
Function Refund() Uint64
10 IF LOAD("state") != 0 THEN GOTO 900 // only OPEN
20 IF BLOCK_HEIGHT() < LOAD("deadline") THEN GOTO 900 // not expired yet
100 STORE("state", 2) // REFUNDED
110 SEND_DERO_TO_ADDRESS(LOAD("issuer_addr"), DEROVALUE())
120 RETURN 0 // success
900 RETURN 1 // error
End Function
/* TermsReveal: counterparty reveals (tier, nonce, blind) to prove the
terms commitment; contract recomputes keccak and compares.
RETURN 0 = terms match, nonzero = mismatch. */
Function TermsReveal(tier Uint64, nonce String, blind String) Uint64
10 IF tier != LOAD("tier") THEN GOTO 900
20 IF KECCAK256(ITOA(tier) + ":" + nonce + ":" + blind) == LOAD("terms_commit") THEN GOTO 100
30 GOTO 900
100 RETURN 0 // match
900 RETURN 1 // mismatch
End Function
' Name:blind Type:string Value:'1f16f259f0a0a7edd7562488652c5503f41b397f851f30eabf557fbcd1773dac' Name:counter_addr Type:string Value:'.µáBÆíÏ8/Å2'[(À;ý4Ña2£/;�' Name:deadline Type:uint64 Value:'7496214' Name:entrypoint Type:string Value:'Initialize' Name:issuer_addr Type:string Value:'.µáBÆíÏ8/Å2'[(À;ý4Ña2£/;�' Name:nonce Type:string Value:'relayos-htlc-774248d5e8a8211b' Name:secret Type:string Value:'0e04dbdb6bb96bef6b98260cd615f8d9e7103565869fa1f0efd871c9a14a0d61' Name:tier Type:uint64 Value:'100'] |