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, amount Uint64) Uint64
5 version("1.2.3") // v151 as-is
10 STORE("issuer_addr", HEXDECODE(issuer_addr)) // hex -> raw compressed key
20 STORE("counter_addr", HEXDECODE(counter_addr))
30 STORE("tier", tier)
40 STORE("deadline", deadline)
50 STORE("state", 0)
60 STORE("amount", amount)
70 STORE("terms_commit", KECCAK256(ITOA(tier) + ":" + nonce + ":" + blind))
80 STORE("preimage_hash", KECCAK256(secret))
90 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"), LOAD("amount")) // pay held balance
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"), LOAD("amount")) // pay held balance
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, amount Uint64) Uint64
5 version("1.2.3") // v151 as-is
10 STORE("issuer_addr", HEXDECODE(issuer_addr)) // hex -> raw compressed key
20 STORE("counter_addr", HEXDECODE(counter_addr))
30 STORE("tier", tier)
40 STORE("deadline", deadline)
50 STORE("state", 0)
60 STORE("amount", amount)
70 STORE("terms_commit", KECCAK256(ITOA(tier) + ":" + nonce + ":" + blind))
80 STORE("preimage_hash", KECCAK256(secret))
90 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"), LOAD("amount")) // pay held balance
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"), LOAD("amount")) // pay held balance
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:amount Type:uint64 Value:'5000' Name:blind Type:string Value:'ad94aaac850e4ce75391af6f9d966adbac141e9840fc28713dd03e0c55d4f0fe' Name:counter_addr Type:string Value:'2e91b5e142c6edcf382fc59032279d5b2882821ac03b83fd34d18e6132a32f3b00' Name:deadline Type:uint64 Value:'7496250' Name:entrypoint Type:string Value:'Initialize' Name:issuer_addr Type:string Value:'2e91b5e142c6edcf382fc59032279d5b2882821ac03b83fd34d18e6132a32f3b00' Name:nonce Type:string Value:'relayos-htlc-1c1458a6cb765f92' Name:secret Type:string Value:'01eb6d7f5abdd82a76bc93249062139eab6df4f0adac676ea71c2e0180640cff' Name:tier Type:uint64 Value:'100'] |