SC CODE: Function Initialize() Uint64
01 STORE("Owner",SIGNER())
02 STORE("Index",0)
03 RETURN 0
End Function
Function AddTier(Name String, Amount Uint64, Interval Uint64, Limit Uint64) Uint64
01 STORE("Tier_"+LOAD("Index")+"_"+Name+"_amount",Amount)
02 STORE("Tier_"+LOAD("Index")+"_"+Name+"_interval",Interval)
03 STORE("Tier_"+LOAD("Index")+"_"+Name+"_address",SIGNER())
04 STORE("Tier_"+LOAD("Index")+"_"+Name+"_spots",Limit)
10 STORE("Index",LOAD("Index")+1)
20 RETURN 0
End Function
//SHOULD MODIFY SO U CAN ENTER WHATEVER ADDRESS U WANT (L8R)
//addtier function could also be used to modify existing tier
Function UpdateBalance(Name String, Index Uint64, Supporter String) Uint64
10 IF EXISTS("Tier_"+Index+"_"+Name+"_supporter_"+Supporter+"_lastPaid") == 0 THEN GOTO 110
20 DIM spent,newBalance, balance as Uint64
25 LET balance = LOAD("Tier_"+Index+"_"+Name+"_supporter_"+Supporter+"_balance")
30 LET spent= LOAD("Tier_"+Index+"_"+Name+"_amount")*(BLOCK_TIMESTAMP() - LOAD("Tier_"+Index+"_"+Name+"_supporter_"+Supporter+"_lastPaid"))/LOAD("Tier_"+Index+"_"+Name+"_interval")
40 IF spent> balance THEN GOTO 50 ELSE GOTO 60
50 LET newBalance = 0
55 GOTO 70
60 LET newBalance = balance - spent
70 LET newBalance = newBalance + DEROVALUE()
75 SEND_DERO_TO_ADDRESS(LOAD("Tier_"+Index+"_"+Name+"_address"),DEROVALUE())
80 STORE("Tier_"+Index+"_"+Name+"_supporter_"+Supporter+"_balance",newBalance)
90 STORE("Tier_"+Index+"_"+Name+"_supporter_"+Supporter+"_lastPaid",BLOCK_TIMESTAMP())
100 RETURN 0
110 RETURN 1
End Function
Function AddSupporter(TierName String, Index Uint64, Supporter String, Password String) Uint64
10 IF DEROVALUE() < LOAD("Tier_"+Index+"_"+TierName+"_amount") THEN GOTO 100
15 IF LOAD("Tier_"+Index+"_"+TierName+"_spots") == 0 THEN GOTO 100
20 STORE ("Tier_"+Index+"_"+TierName+"_supporter_"+Supporter+"_balance",DEROVALUE())
30 STORE ("Tier_"+Index+"_"+TierName+"_supporter_"+Supporter+"_lastPaid",BLOCK_TIMESTAMP())
40 STORE("Tier_"+Index+"_"+TierName+"_supporter_"+Supporter+"_identity",SHA256(ADDRESS_STRING(SIGNER())+Password))
50 STORE("ASTRING",ADDRESS_STRING(SIGNER()))
60 STORE("PASS",Password)
70 STORE ("Tier_"+Index+"_"+TierName+"_spots",LOAD("Tier_"+Index+"_"+TierName+"_spots")-1)
75 SEND_DERO_TO_ADDRESS(LOAD("Tier_"+Index+"_"+TierName+"_address"),DEROVALUE())
99 RETURN 0
100 RETURN 1
End Function
Function Update(code String) Uint64
10 IF SIGNER() != LOAD("Owner") THEN GOTO 100
20 UPDATE_SC_CODE(code)
99 RETURN 0
100 RETURN 1
End Function
//OKAY FOR EXAMPLE: INTERVAL IS 1 MONTH. AMOUNT IS 1 DERO. BOB DEPOSITS 5 DERO JAN 1. LASTPAID IS JAN 1. IT IS NOW JUNE 1.
//BOB DEPOSITS 10 DERO. LAST PAID SHOULD BE UPDATED TO JUNE 1 AND BALANCE SHOULD BE 10 DERO
//WHAT IF INSTEAD BOB WANTS TO TOP-UP ON MARCH 1? HE DEPOSITS 10 DERO MARCH 1. BALANCE IS 15 DERO LAST PAID IS JAN 1ST. THAT SHOULD WORK.
//OR NO MATTER WHAT BALANCE IS UPDATED AT TOP UP TOO, SO THEN BALANCE WOULD BE 13 DERO AND LASTPAID WOULD BE MARCH 1. THAT PROB MAKES MORE SNSE
//THAT WAY LAST PAID IS APPROPRIATE VAR NAME
//SO ON DEPOSIT: CHECK HOW MUCH BALANCE HAS BEEN USED UP.. CURRENT TIME MINUS LAST PAID THEN DIVIDE BY INTERVAL THEN MULTIPLY BY AMOUNT
// THEN SUBTRACT THAT FROM BALANCE. IF LESS THEN ZERO, MAKE IT ZERO. THEN ADD DEPOSIT TO BALANCE AND UPDATE LASTPAID TO TODAY
|
SC Arguments: [Name:SC_ACTION Type:uint64 Value:'1' Name:SC_CODE Type:string Value:'Function Initialize() Uint64
01 STORE("Owner",SIGNER())
02 STORE("Index",0)
03 RETURN 0
End Function
Function AddTier(Name String, Amount Uint64, Interval Uint64, Limit Uint64) Uint64
01 STORE("Tier_"+LOAD("Index")+"_"+Name+"_amount",Amount)
02 STORE("Tier_"+LOAD("Index")+"_"+Name+"_interval",Interval)
03 STORE("Tier_"+LOAD("Index")+"_"+Name+"_address",SIGNER())
04 STORE("Tier_"+LOAD("Index")+"_"+Name+"_spots",Limit)
10 STORE("Index",LOAD("Index")+1)
20 RETURN 0
End Function
//SHOULD MODIFY SO U CAN ENTER WHATEVER ADDRESS U WANT (L8R)
//addtier function could also be used to modify existing tier
Function UpdateBalance(Name String, Index Uint64, Supporter String) Uint64
10 IF EXISTS("Tier_"+Index+"_"+Name+"_supporter_"+Supporter+"_lastPaid") == 0 THEN GOTO 110
20 DIM spent,newBalance, balance as Uint64
25 LET balance = LOAD("Tier_"+Index+"_"+Name+"_supporter_"+Supporter+"_balance")
30 LET spent= LOAD("Tier_"+Index+"_"+Name+"_amount")*(BLOCK_TIMESTAMP() - LOAD("Tier_"+Index+"_"+Name+"_supporter_"+Supporter+"_lastPaid"))/LOAD("Tier_"+Index+"_"+Name+"_interval")
40 IF spent> balance THEN GOTO 50 ELSE GOTO 60
50 LET newBalance = 0
55 GOTO 70
60 LET newBalance = balance - spent
70 LET newBalance = newBalance + DEROVALUE()
75 SEND_DERO_TO_ADDRESS(LOAD("Tier_"+Index+"_"+Name+"_address"),DEROVALUE())
80 STORE("Tier_"+Index+"_"+Name+"_supporter_"+Supporter+"_balance",newBalance)
90 STORE("Tier_"+Index+"_"+Name+"_supporter_"+Supporter+"_lastPaid",BLOCK_TIMESTAMP())
100 RETURN 0
110 RETURN 1
End Function
Function AddSupporter(TierName String, Index Uint64, Supporter String, Password String) Uint64
10 IF DEROVALUE() < LOAD("Tier_"+Index+"_"+TierName+"_amount") THEN GOTO 100
15 IF LOAD("Tier_"+Index+"_"+TierName+"_spots") == 0 THEN GOTO 100
20 STORE ("Tier_"+Index+"_"+TierName+"_supporter_"+Supporter+"_balance",DEROVALUE())
30 STORE ("Tier_"+Index+"_"+TierName+"_supporter_"+Supporter+"_lastPaid",BLOCK_TIMESTAMP())
40 STORE("Tier_"+Index+"_"+TierName+"_supporter_"+Supporter+"_identity",SHA256(ADDRESS_STRING(SIGNER())+Password))
50 STORE("ASTRING",ADDRESS_STRING(SIGNER()))
60 STORE("PASS",Password)
70 STORE ("Tier_"+Index+"_"+TierName+"_spots",LOAD("Tier_"+Index+"_"+TierName+"_spots")-1)
75 SEND_DERO_TO_ADDRESS(LOAD("Tier_"+Index+"_"+TierName+"_address"),DEROVALUE())
99 RETURN 0
100 RETURN 1
End Function
Function Update(code String) Uint64
10 IF SIGNER() != LOAD("Owner") THEN GOTO 100
20 UPDATE_SC_CODE(code)
99 RETURN 0
100 RETURN 1
End Function
//OKAY FOR EXAMPLE: INTERVAL IS 1 MONTH. AMOUNT IS 1 DERO. BOB DEPOSITS 5 DERO JAN 1. LASTPAID IS JAN 1. IT IS NOW JUNE 1.
//BOB DEPOSITS 10 DERO. LAST PAID SHOULD BE UPDATED TO JUNE 1 AND BALANCE SHOULD BE 10 DERO
//WHAT IF INSTEAD BOB WANTS TO TOP-UP ON MARCH 1? HE DEPOSITS 10 DERO MARCH 1. BALANCE IS 15 DERO LAST PAID IS JAN 1ST. THAT SHOULD WORK.
//OR NO MATTER WHAT BALANCE IS UPDATED AT TOP UP TOO, SO THEN BALANCE WOULD BE 13 DERO AND LASTPAID WOULD BE MARCH 1. THAT PROB MAKES MORE SNSE
//THAT WAY LAST PAID IS APPROPRIATE VAR NAME
//SO ON DEPOSIT: CHECK HOW MUCH BALANCE HAS BEEN USED UP.. CURRENT TIME MINUS LAST PAID THEN DIVIDE BY INTERVAL THEN MULTIPLY BY AMOUNT
// THEN SUBTRACT THAT FROM BALANCE. IF LESS THEN ZERO, MAKE IT ZERO. THEN ADD DEPOSIT TO BALANCE AND UPDATE LASTPAID TO TODAY
'] |