SC CODE: /* SHULGIN GUESTBOOK - on-chain testimonials wall for shulgin.tela.
------------------------------------------------------------------
The app (index.html) invokes Post(board, name, text) through Engram
XSWD (ws://127.0.0.1:44326/xswd) with sc_rpc:
entrypoint=Post board=board name=name text=text
The frontend reads contract variables matching:
^b:<board>:(n|t|h|a):<index>$ (regex in index.html board())
b:<board>:n:<i> = author name (string)
b:<board>:t:<i> = testimonial text (string)
b:<board>:h:<i> = block height at post (uint64)
b:<board>:a:<i> = signer address (string)
The 2000-char cap is enforced client-side: the DVM has no string
length intrinsic, and every post is a fee-paying transaction, so
spam is already bounded by the wallet. Set CFG.GB in index.html
to this contract's SCID after install. */
Function Initialize() Uint64
10 STORE("owner", SIGNER())
20 RETURN 0
End Function
/* anyone may post; a fresh index is taken per board */
Function Post(board String, name String, text String) Uint64
10 DIM i as Uint64
20 IF board == "" THEN GOTO 200
30 IF text == "" THEN GOTO 200
40 IF EXISTS("_n:" + board) THEN GOTO 70
50 LET i = 0
60 GOTO 100
70 LET i = LOAD("_n:" + board)
100 STORE("b:" + board + ":n:" + i, name)
110 STORE("b:" + board + ":t:" + i, text)
120 STORE("b:" + board + ":h:" + i, BLOCK_HEIGHT())
130 STORE("b:" + board + ":a:" + i, SIGNER())
140 STORE("_n:" + board, i + 1)
150 RETURN 0
200 RETURN 1
End Function
/* curator only - take down a single post (spam) without touching others */
Function RemovePost(board String, index Uint64) Uint64
10 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 IF EXISTS("b:" + board + ":t:" + index) THEN GOTO 50
40 RETURN 1
50 DELETE("b:" + board + ":n:" + index)
60 DELETE("b:" + board + ":t:" + index)
70 DELETE("b:" + board + ":h:" + index)
80 DELETE("b:" + board + ":a:" + index)
90 RETURN 0
End Function
Function TransferOwnership(newowner String) Uint64
10 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 STORE("tmpowner", ADDRESS_RAW(newowner))
40 RETURN 0
End Function
Function ClaimOwnership() Uint64
10 IF LOAD("tmpowner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 STORE("owner", SIGNER())
40 RETURN 0
End Function
Function UpdateCode(code String) Uint64
10 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 UPDATE_SC_CODE(code)
40 RETURN 0
End Function
|
| SC Arguments: [Name:SC_ACTION Type:uint64 Value:'1' Name:SC_CODE Type:string Value:'/* SHULGIN GUESTBOOK - on-chain testimonials wall for shulgin.tela.
------------------------------------------------------------------
The app (index.html) invokes Post(board, name, text) through Engram
XSWD (ws://127.0.0.1:44326/xswd) with sc_rpc:
entrypoint=Post board=board name=name text=text
The frontend reads contract variables matching:
^b:<board>:(n|t|h|a):<index>$ (regex in index.html board())
b:<board>:n:<i> = author name (string)
b:<board>:t:<i> = testimonial text (string)
b:<board>:h:<i> = block height at post (uint64)
b:<board>:a:<i> = signer address (string)
The 2000-char cap is enforced client-side: the DVM has no string
length intrinsic, and every post is a fee-paying transaction, so
spam is already bounded by the wallet. Set CFG.GB in index.html
to this contract's SCID after install. */
Function Initialize() Uint64
10 STORE("owner", SIGNER())
20 RETURN 0
End Function
/* anyone may post; a fresh index is taken per board */
Function Post(board String, name String, text String) Uint64
10 DIM i as Uint64
20 IF board == "" THEN GOTO 200
30 IF text == "" THEN GOTO 200
40 IF EXISTS("_n:" + board) THEN GOTO 70
50 LET i = 0
60 GOTO 100
70 LET i = LOAD("_n:" + board)
100 STORE("b:" + board + ":n:" + i, name)
110 STORE("b:" + board + ":t:" + i, text)
120 STORE("b:" + board + ":h:" + i, BLOCK_HEIGHT())
130 STORE("b:" + board + ":a:" + i, SIGNER())
140 STORE("_n:" + board, i + 1)
150 RETURN 0
200 RETURN 1
End Function
/* curator only - take down a single post (spam) without touching others */
Function RemovePost(board String, index Uint64) Uint64
10 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 IF EXISTS("b:" + board + ":t:" + index) THEN GOTO 50
40 RETURN 1
50 DELETE("b:" + board + ":n:" + index)
60 DELETE("b:" + board + ":t:" + index)
70 DELETE("b:" + board + ":h:" + index)
80 DELETE("b:" + board + ":a:" + index)
90 RETURN 0
End Function
Function TransferOwnership(newowner String) Uint64
10 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 STORE("tmpowner", ADDRESS_RAW(newowner))
40 RETURN 0
End Function
Function ClaimOwnership() Uint64
10 IF LOAD("tmpowner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 STORE("owner", SIGNER())
40 RETURN 0
End Function
Function UpdateCode(code String) Uint64
10 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 UPDATE_SC_CODE(code)
40 RETURN 0
End Function
'] |