SC CODE: // This function is used to initialize parameters during install time
// InitializePrivate initializes a private SC
Function InitializePrivate() Uint64
10 STORE("owner", SIGNER()) // Store in DB ["owner"] = address
40 RETURN 0
End Function
Function StorePage(name String, content String) Uint64
10 IF content == "" THEN GOTO 20
16 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 STORE(name, content)
60 RETURN 0
End Function
Function DeletePage(name String) Uint64
16 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 DELETE(name)
60 RETURN 0
End Function
// This function is used to change owner
// owner is an string form of address
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
// Until the new owner claims ownership, existing owner remains owner
Function ClaimOwnership() Uint64
10 IF LOAD("tmpowner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 STORE("owner",SIGNER()) // ownership claim successful
40 RETURN 0
End Function
// if signer is owner, provide him rights to update code anytime
// make sure update is always available to SC
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:'// This function is used to initialize parameters during install time
// InitializePrivate initializes a private SC
Function InitializePrivate() Uint64
10 STORE("owner", SIGNER()) // Store in DB ["owner"] = address
40 RETURN 0
End Function
Function StorePage(name String, content String) Uint64
10 IF content == "" THEN GOTO 20
16 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 STORE(name, content)
60 RETURN 0
End Function
Function DeletePage(name String) Uint64
16 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 DELETE(name)
60 RETURN 0
End Function
// This function is used to change owner
// owner is an string form of address
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
// Until the new owner claims ownership, existing owner remains owner
Function ClaimOwnership() Uint64
10 IF LOAD("tmpowner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 STORE("owner",SIGNER()) // ownership claim successful
40 RETURN 0
End Function
// if signer is owner, provide him rights to update code anytime
// make sure update is always available to SC
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'] |